Search code examples
bashloopsjobs

How to submit consecutive bash jobs using another job with a loop


I have to phase (using shapeit software) 29 chromosomes, so it would be great if a could send a job that call another, the names of the files are the same, only change the chromosome number. Example phase.sh

#!/bin/bash
shapeit \
-P chr_1.ped chr_1.map \
--duohmm \
--rho 0.01 \
-O chr_1.phased 

I would need something like another job calling it

#!/bin/bash
for chr 1...29 
sbatch --phase.sh 
done

Thank you very much


Solution

  • Assuming you can change the first script to something like

    #!/bin/bash
    shapeit \
      -P "$1".ped "$1".map \
      --duohmm \
      --rho 0.01 \
      -O "$1".phased
    

    and call it sbatch (or is that phase.sh?), you can then call it with

    for chr in {1..29}; do
      sbatch --phase.sh "chr_$chr"
    done
    

    Of course, a better design might be to change the first script to run a loop over the arguments you pass it;

    for chr; do
      shapeit \
        -P "$chr".ped "$chr".map \
        --duohmm \
        --rho 0.01 \
        -O "$chr".phased
    done
    

    and then call it like

    thatscript chr_{1..29}