0

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

ana_gg
  • 370
  • 1
  • 9
  • 1
    Can you clarify which part of script change? – Romeo Ninov Feb 05 '20 at 10:12
  • I don't know how to do the second bash job (the for..), and in the first one, I guess that instead of "chr_1.ped chr_1.map" it should be something like "chr_*.ped chr_*.map" to indicate that it is for all the chromosomes. Thank you! – ana_gg Feb 05 '20 at 10:16

2 Answers2

1

Your phase script can be changed on this way:

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

and you can call it on this way:

#!/bin/bash
for chr in $(seq 1 29)
do
phase.sh chr_$chr
done
Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31
  • For robustness, see also https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable/27701642 – tripleee Feb 05 '20 at 10:20
  • @tripleee, it depend, as currently we control the variables quotes are overkill. if we talk about commands where you can get extra space in output or filenames with special characters will be OK. – Romeo Ninov Feb 05 '20 at 10:23
  • We have way too many answers which simply assume people will not use real-world file names. Fixing them is usually easier than adding a caveat, and teaches people to use quoting properly. – tripleee Feb 05 '20 at 10:25
  • @tripleee, this discussion go in direction of "The art of asking good questions" :) – Romeo Ninov Feb 05 '20 at 10:26
1

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}
tripleee
  • 175,061
  • 34
  • 275
  • 318