| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
if [ $# -lt 3 ]; |
| 4 |
then |
| 5 |
echo "usage: $0 [regions file] [ncpus] [freebayes arguments]" |
| 6 |
echo |
| 7 |
echo "Run freebayes in parallel over regions listed in regions file, using ncpus processors." |
| 8 |
echo "Will merge and sort output, producing a uniform VCF stream on stdout. Flags to freebayes" |
| 9 |
echo "which would write to e.g. a particular file will obviously cause problms, so caution is" |
| 10 |
echo "encouraged when using this script." |
| 11 |
echo |
| 12 |
echo "examples:" |
| 13 |
echo |
| 14 |
echo "Run freebayes in parallel on 100000bp chunks of the ref (fasta_generate_regions.py is also" |
| 15 |
echo "located in the scripts/ directory in the freebayes distribution). Use 36 threads." |
| 16 |
echo |
| 17 |
echo " freebayes-parallel <(fasta_generate_regions.py ref.fa.fai 100000) 36 -f ref.fa aln.bam >out.vcf" |
| 18 |
echo |
| 19 |
echo "Generate regions that are equal in terms of data content, and thus have lower variance" |
| 20 |
echo "in runtime. This will yield better resource utilization." |
| 21 |
echo |
| 22 |
echo " bamtools coverage -in aln.bam | coverage_to_regions.py ref.fa.fai 500 >ref.fa.500.regions" |
| 23 |
echo " freebayes-parallel ref.fa.500.regions 36 -f ref.fa aln.bam >out.vcf" |
| 24 |
echo |
| 25 |
exit |
| 26 |
fi |
| 27 |
|
| 28 |
regionsfile=$1 |
| 29 |
shift |
| 30 |
ncpus=$1 |
| 31 |
shift |
| 32 |
|
| 33 |
command=("freebayes" "$@") |
| 34 |
|
| 35 |
( |
| 36 |
#$command | head -100 | grep "^#" # generate header |
| 37 |
# iterate over regions using gnu parallel to dispatch jobs |
| 38 |
cat "$regionsfile" | parallel -k -j "$ncpus" "${command[@]}" --region {} |
| 39 |
) | vcffirstheader \ |
| 40 |
| vcfstreamsort -w 1000 | vcfuniq # remove duplicates at region edges |