gizmo
gizmo

Reputation: 151

how to use gnu parallel over a range of numbers given by command-line arguments

I'm trying to use gnu parallel with some basic bioinformatic tools, e.g. lastz. So say I have 10 seqs, and I want to use lastz on all of them, I use:

parallel --dryrun lastz 'pathToFile/seq{}.fa query.fasta --format=text > LASTZ_results_seq{}' ::: {1..10} 

Which works fine and returns:

lastz pathToFile/seq1.fa query.fasta --format=text > LASTZ_results_seq1
lastz pathToFile/seq2.fa query.fasta --format=text > LASTZ_results_seq2
lastz pathToFile/seq3.fa query.fasta --format=text > LASTZ_results_seq3
...
lastz pathToFile/seq10.fa query.fasta --format=text > LASTZ_results_seq10

But ideally I'd like this step to be part of a bash script which takes three command-line arguments, so the number of seqs (eg. 1 to 10) is given in the command-line (with $2 = startValue, $3 = endValue). I thought that changing it to this would work:

parallel --dryrun lastz 'pathToFile/seq{}.fa query.fasta --format=text > LASTZ_results_seq{}' ::: {"$2".."$3"}

but instead, that returns

lastz pathToFile//seq\{\1..\10\} query.fasta --format=text > LASTZ_results_seq\{\1..\10\}

Can anyone please tell me what I'm doing wrong here? It looks like it is interpreting $2 as 1, and $3 as 10, but then fails to treat it as a range of numbers...

Upvotes: 5

Views: 3950

Answers (2)

Ole Tange
Ole Tange

Reputation: 33685

This is not what you are asking, but it might be a better solution:

parallel --dryrun lastz {} query.fasta --format=text '>' LASTZ_results_{/.} ::: pathToFile/seq*.fa

If you get Argument list too long try:

printf '%s\n' pathToFile/seq*.fa | parallel --dryrun lastz {} query.fasta --format=text '>' LASTZ_results_{/.} 

This way you do not need to know in advance how many seq*.fa there are.

Upvotes: 1

pasaba por aqui
pasaba por aqui

Reputation: 3529

Bash ranges doesn't accepts variables, see this post:

How do I iterate over a range of numbers defined by variables in Bash?

thus, I suggest you change {$1..$2} to $(seq $1 $2).

By example, see this test script:

$ cat foo
parallel echo ::: {1..3}
parallel echo ::: {$1..$2}
parallel echo ::: $(seq $1 $2)

when called as ./foo 1 3, it produces following output:

1
2
3
{1..3}
1
2
3

Upvotes: 8

Related Questions