You're looking for GNU make and the -j
option. Some clusters use a custom version of make (e.g., 'qmake' for SGE )
Search biostars for some other solutions (snakemake, ... ): e.g: Workflow management software for pipeline development in NGS,
An example of Makefile:
samtools.dir=../samtools/
samtools.exe=${samtools.dir}samtools
wgsim.exe=${samtools.dir}misc/wgsim
bwa.exe=../bwa/bwa
picard.jar=../picard-tools-1.138/picard.jar
bcftools.exe=../bcftools/bcftools
REF=ref.fa
mutations.vcf.gz : ${REF} \
$(addsuffix .bam.bai ,S1) \
$(addsuffix .bam.bai ,S2) \
$(addsuffix .bam.bai ,S3) \
$(addsuffix .bam.bai ,S4)
${samtools.exe} mpileup -u -f $< $(filter %.bam,$(basename $^)) |\
${bcftools.exe} call -c -v -O z -o $@ -
$(addsuffix .bam.bai ,S1): $(addsuffix .bam,S1)
${samtools.exe} index $<
$(addsuffix .bam,S1): \
$(addsuffix .bam,S1_01_R1.fq.gz) \
$(addsuffix .bam,S1_02_R1.fq.gz) \
$(addsuffix .bam,S1_03_R1.fq.gz)
java -jar ${picard.jar} MergeSamFiles AS=true O=$@ $(foreach B,$^, I=${B} )
$(addsuffix .bam,S1_01_R1.fq.gz): $(addsuffix .bwt,${REF}) S1_01_R1.fq.gz S1_01_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S1\tSM:S1' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S1_01_R2.fq.gz : S1_01_R1.fq.gz
gzip --best -f $(basename $@)
S1_01_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 1 -N 1000 $< $(basename S1_01_R1.fq.gz S1_01_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bam,S1_02_R1.fq.gz): $(addsuffix .bwt,${REF}) S1_02_R1.fq.gz S1_02_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S1\tSM:S1' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S1_02_R2.fq.gz : S1_02_R1.fq.gz
gzip --best -f $(basename $@)
S1_02_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 1 -N 1000 $< $(basename S1_02_R1.fq.gz S1_02_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bam,S1_03_R1.fq.gz): $(addsuffix .bwt,${REF}) S1_03_R1.fq.gz S1_03_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S1\tSM:S1' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S1_03_R2.fq.gz : S1_03_R1.fq.gz
gzip --best -f $(basename $@)
S1_03_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 1 -N 1000 $< $(basename S1_03_R1.fq.gz S1_03_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bam.bai ,S2): $(addsuffix .bam,S2)
${samtools.exe} index $<
$(addsuffix .bam,S2): \
$(addsuffix .bam,S2_01_R1.fq.gz) \
$(addsuffix .bam,S2_02_R1.fq.gz) \
$(addsuffix .bam,S2_03_R1.fq.gz)
java -jar ${picard.jar} MergeSamFiles AS=true O=$@ $(foreach B,$^, I=${B} )
$(addsuffix .bam,S2_01_R1.fq.gz): $(addsuffix .bwt,${REF}) S2_01_R1.fq.gz S2_01_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S2\tSM:S2' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S2_01_R2.fq.gz : S2_01_R1.fq.gz
gzip --best -f $(basename $@)
S2_01_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 2 -N 1000 $< $(basename S2_01_R1.fq.gz S2_01_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bam,S2_02_R1.fq.gz): $(addsuffix .bwt,${REF}) S2_02_R1.fq.gz S2_02_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S2\tSM:S2' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S2_02_R2.fq.gz : S2_02_R1.fq.gz
gzip --best -f $(basename $@)
S2_02_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 2 -N 1000 $< $(basename S2_02_R1.fq.gz S2_02_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bam,S2_03_R1.fq.gz): $(addsuffix .bwt,${REF}) S2_03_R1.fq.gz S2_03_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S2\tSM:S2' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S2_03_R2.fq.gz : S2_03_R1.fq.gz
gzip --best -f $(basename $@)
S2_03_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 2 -N 1000 $< $(basename S2_03_R1.fq.gz S2_03_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bam.bai ,S3): $(addsuffix .bam,S3)
${samtools.exe} index $<
$(addsuffix .bam,S3): \
$(addsuffix .bam,S3_01_R1.fq.gz) \
$(addsuffix .bam,S3_02_R1.fq.gz) \
$(addsuffix .bam,S3_03_R1.fq.gz) \
$(addsuffix .bam,S3_04_R1.fq.gz)
java -jar ${picard.jar} MergeSamFiles AS=true O=$@ $(foreach B,$^, I=${B} )
$(addsuffix .bam,S3_01_R1.fq.gz): $(addsuffix .bwt,${REF}) S3_01_R1.fq.gz S3_01_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S3\tSM:S3' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S3_01_R2.fq.gz : S3_01_R1.fq.gz
gzip --best -f $(basename $@)
S3_01_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 3 -N 1000 $< $(basename S3_01_R1.fq.gz S3_01_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bam,S3_02_R1.fq.gz): $(addsuffix .bwt,${REF}) S3_02_R1.fq.gz S3_02_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S3\tSM:S3' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S3_02_R2.fq.gz : S3_02_R1.fq.gz
gzip --best -f $(basename $@)
S3_02_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 3 -N 1000 $< $(basename S3_02_R1.fq.gz S3_02_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bam,S3_03_R1.fq.gz): $(addsuffix .bwt,${REF}) S3_03_R1.fq.gz S3_03_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S3\tSM:S3' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S3_03_R2.fq.gz : S3_03_R1.fq.gz
gzip --best -f $(basename $@)
S3_03_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 3 -N 1000 $< $(basename S3_03_R1.fq.gz S3_03_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bam,S3_04_R1.fq.gz): $(addsuffix .bwt,${REF}) S3_04_R1.fq.gz S3_04_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S3\tSM:S3' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S3_04_R2.fq.gz : S3_04_R1.fq.gz
gzip --best -f $(basename $@)
S3_04_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 3 -N 1000 $< $(basename S3_04_R1.fq.gz S3_04_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bam.bai ,S4): $(addsuffix .bam,S4)
${samtools.exe} index $<
$(addsuffix .bam,S4): \
$(addsuffix .bam,S4_01_R1.fq.gz)
java -jar ${picard.jar} MergeSamFiles AS=true O=$@ $(foreach B,$^, I=${B} )
$(addsuffix .bam,S4_01_R1.fq.gz): $(addsuffix .bwt,${REF}) S4_01_R1.fq.gz S4_01_R2.fq.gz
${bwa.exe} mem -R '@RG\tID:S4\tSM:S4' ${REF} $(filter %.gz,$^) |\
${samtools.exe} view -Sbu - |\
${samtools.exe} sort -O sam -o $@ -T $(basename $@) -
S4_01_R2.fq.gz : S4_01_R1.fq.gz
gzip --best -f $(basename $@)
S4_01_R1.fq.gz : ${REF}
@sleep 1
${wgsim.exe} -r 0.01 -S 4 -N 1000 $< $(basename S4_01_R1.fq.gz S4_01_R2.fq.gz)
gzip --best -f $(basename $@)
$(addsuffix .bwt,${REF}) : ${REF}
${bwa.exe} index $<
${REF}:
echo ">rotavirus" > $@
echo "GGCTTTTAATGCTTTTCAGTGGTTGCTGCTCAAGATGGAGTCTACTCAGCAGATGGTAAGCTCTATTATT" >> $@
echo "AATACTTCTTTTGAAGCTGCAGTTGTTGCTGCTACTTCAACATTAGAATTAATGGGTATTCAATATGATT" >> $@
echo "ACAATGAAGTATTTACCAGAGTTAAAAGTAAATTTGATTATGTGATGGATGACTCTGGTGTTAAAAACAA" >> $@
echo "TCTTTTGGGTAAAGCTATAACTATTGATCAGGCGTTAAATGGAAAGTTTAGCTCAGCTATTAGAAATAGA" >> $@
echo "AATTGGATGACTGATTCTAAAACGGTTGCTAAATTAGATGAAGACGTGAATAAACTTAGAATGACTTTAT" >> $@
echo "CTTCTAAAGGGATCGACCAAAAGATGAGAGTACTTAATGCTTGTTTTAGTGTAAAAAGAATACCAGGAAA" >> $@
echo "ATCATCATCAATAATTAAATGCACTAGACTTATGAAGGATAAAATAGAACGTGGAGAAGTTGAGGTTGAT" >> $@
echo "GATTCATATGTTGATGAGAAAATGGAAATTGATACTATTGATTGGAAATCTCGTTATGATCAGTTAGAAA" >> $@
echo "AAAGATTTGAATCACTAAAACAGAGGGTTAATGAGAAATACAATACTTGGGTACAAAAAGCGAAGAAAGT" >> $@
echo "AAATGAAAATATGTACTCTCTTCAGAATGTTATCTCACAACAGCAAAACCAAATAGCAGATCTTCAACAA" >> $@
echo "TATTGTAGTAAATTGGAAGCTGATTTGCAAGGTAAATTTAGTTCATTAGTGTCATCAGTTGAGTGGTATC" >> $@
echo "TAAGGTCTATGGAATTACCAGATGATGTAAAGAATGACATTGAACAGCAGTTAAATTCAATTGATTTAAT" >> $@
echo "TAATCCCATTAATGCTATAGATGATATCGAATCGCTGATTAGAAATTTAATTCAAGATTATGACAGAACA" >> $@
echo "TTTTTAATGTTAAAAGGACTGTTGAAGCAATGCAACTATGAATATGCATATGAGTAGTCATATAATTAAA" >> $@
echo "AATATTAACCATCTACACATGACCCTCTATGAGCACAATAGTTAAAAGCTAACACTGTCAAAAACCTAAA" >> $@
echo "TGGCTATAGGGGCGGTTTGTGACC" >> $@
echo "" >> $@
graph.png:
make -ndrB -f Makefile | ../makefile2graph/make2graph | dot -Tpng -o$@
Wow, that looks like a really complete and sophisticated way of doing it - you have the ability here to do much better flow-control than with parallel - allow for some jobs to be dependent on others being done, etc. awesome :)
It is a little complex for my needs however (parallelizing an existing list of commands), plus I don't know the make syntax at all, nor xml all that well. I think it's definitely worth an investment of my time for a better/more productive future... perhaps this weekend I will try and wrap my head around it :) But in the mean time I was hoping for something really simple just to get the jobs done, hehe :) (I know, I know - I have some sunk-cost-fallacy issues about getting these bash scripts running in parallel instead of doing it the proper way ;) )
back: the makefile was generated from a model, but you can write it from scratch.
no, I was wrong to put a XSL+XML example. I'll remove it. back in 5'