unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* using guile like a awk filter in a C program.
@ 2024-05-10 13:55 Pierre LINDENBAUM
  2024-05-17 18:09 ` Simon Tournier
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Pierre LINDENBAUM @ 2024-05-10 13:55 UTC (permalink / raw)
  To: guile-user


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



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-06-10  9:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-10 13:55 using guile like a awk filter in a C program Pierre LINDENBAUM
2024-05-17 18:09 ` Simon Tournier
2024-05-21 13:39   ` Pierre Lindenbaum
2024-05-22 10:39     ` Simon Tournier
2024-05-24  7:31     ` Pierre Lindenbaum
2024-05-28  8:42       ` Zelphir Kaltstahl
2024-06-10  9:08       ` Maxime Devos via General Guile related discussions
2024-05-21 14:58 ` Basile Starynkevitch
2024-05-30  7:50 ` Pjotr Prins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).