How to use gnu in parallel on a range of numbers given by command line arguments

I am trying to use gnu in parallel with some basic bioinformatics tools like. lastz. That is to say, I have 10 seconds and I want to use lastz for 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 would like this step to be part of a bash script that takes three command line arguments, so the number of sections (for example, 1 to 10) is given on the command line (with $ 2 = startValue, $ 3 = endValue). I thought I would change it to this:

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

      

but returns instead

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

      

Can someone please tell me what I am doing wrong here? It looks like it interprets $ 2 as 1 and $ 3 as 10, but then cannot treat it as a range of numbers ...

+3


source to share


2 answers


This is not what you are asking, but this 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 don't need to know in advance how many seq * .fa there are.

0


source


Bash ranges don't accept 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).

For 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 the following output:

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

      

+3


source







All Articles