From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pjotr Prins Newsgroups: gmane.lisp.guile.user Subject: Re: using guile like a awk filter in a C program. Date: Thu, 30 May 2024 09:50:21 +0200 Message-ID: <20240530075021.uzk7ze6hebpv2jbd@mailx.thebird.nl> References: <60c7c61c6dea289c9a1d8e59829f9c91@univ-nantes.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38279"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user@gnu.org To: Pierre LINDENBAUM Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu May 30 09:51:22 2024 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sCaZG-0009kf-JG for guile-user@m.gmane-mx.org; Thu, 30 May 2024 09:51:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCaYX-0001oM-Uo; Thu, 30 May 2024 03:50:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCaYT-0001no-W1 for guile-user@gnu.org; Thu, 30 May 2024 03:50:34 -0400 Original-Received: from mailx.thebird.nl ([128.140.51.107]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCaYP-0004Ll-7w for guile-user@gnu.org; Thu, 30 May 2024 03:50:33 -0400 Original-Received: from localhost (mailx.thebird.nl [local]) by mailx.thebird.nl (OpenSMTPD) with ESMTPA id b3606856; Thu, 30 May 2024 07:50:21 +0000 (UTC) Content-Disposition: inline In-Reply-To: <60c7c61c6dea289c9a1d8e59829f9c91@univ-nantes.fr> Received-SPF: pass client-ip=128.140.51.107; envelope-from=pjotr.public12@thebird.nl; helo=mailx.thebird.nl X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19697 Archived-At: Note that the scheme shell (scsh) has an awk implementation using macros. Maybe the code helps: https://carlstrom.com/publications/scsh-manual.pdf On Fri, May 10, 2024 at 03:55:58PM +0200, Pierre LINDENBAUM wrote: > > Hi all, > > I tried to learn guile a few years ago with a side project that went > nowhere. > > I'm now back with guile that I would like to use as a filter, just like awk, > for my data. > I've got question about the general design of such program. > > My program uses a C library ( https://github.com/samtools/htslib ) scanning > mutations/variants in large VCF files ( > https://en.wikipedia.org/wiki/Variant_Call_Format ). > > A typical C program looks like (pseudo code) ; > > ``` > header = read_header(input); > variant = new_variant(); > while(read_variant(input,header,variant)) { > do_something(header,variant) > } > dispose_variant(variant) > dispose_header(header) > ``` > > I would like to use guile to filter VCF using a custom user GUILE > expression/program . So my program would now look like > > ``` > header = read_header(input); > guile_context = my_initialize_guile(header, argc_argv_user_script) > variant = new_variant(); > while(read_variant(input,header,variant)) { > if(!my_guile_test(guile_context,header,variant)) { > continue; > } > do_something(header,variant) > } > dispose_variant(variant) > my_dispose_guile(guile_context) > dispose_header(header) > ``` > > and would may be be invoked like: > > ``` > ./a.out -e '(and (variant-is-snp? ) (equals? (variant-allele-count) 2))' > input.vcf > output.vcf > ``` > > where `variant-is-snp` would test if the current variant in the 'while' loop > is a 'single nucleotide polylmorphism' using `bcf_is_snp` > https://github.com/samtools/htslib/blob/develop/htslib/vcf.h#L889 > > > So my questions are: > > - is it possible to use guile for such task ? More precisely, can I compile > the guile script just once in `my_initialize_guile` and use it in the while > loop without having to recompile it. > - furthermore, what's the best practice to include the user's script in a > larger script that would include the definitions of `variant-is-snp?` , > `variant-allele-count`, etc... > - is there any implementation that works like this (something like a AWK > script in guile) ? > - is there any way to make the program stateless ? I mean, any invocation of > `my_guile_test` would erase the definition of the previous variant > > Thanks for your answers, > > Pierre L > --