Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REF="/path/to/human_g1k_v37.fasta"
- inputBams = Channel.from(
- "f1.bam",
- "f2.bam").
- map{file(it)}.
- flatten()
- captures=Channel.fromPath("/path/to/capture.bed")
- process cleanbed {
- tag "clean ${bed}"
- echo true
- input:
- file inputbed from captures
- output:
- file("clean.bed") into cleanbed
- script:
- """
- cat "${inputbed}" | grep -v -E '^(browser|track)' |\\
- cut -f 1,2,3 | sed 's/^chr//' |\
- LC_ALL=C sort -t \$'\\t' -k1,1 -k2,2n |\\
- uniq |\\
- bedtools slop -b 500 -g "${REF}.fai" |\\
- bedtools merge -d 500 -i - > clean.bed
- echo -n "Number of lines in bed: "
- wc -l clean.bed
- """
- }
- process bamList {
- tag "making list from ${bamVector.size()} "
- echo true
- input:
- val bamVector from inputBams.flatten().toList()
- output:
- file("bam.list") into bam_list
- script:
- """
- cat << __EOF__ > bam.list
- ${bamVector.join("\n")}
- __EOF__
- grep -m1 '.bam\$' bam.list
- """
- }
- cleanbed.
- splitText().
- map{L->L.trim().split("\t").toList()}.
- set{ bed_lines}
- process mpileupBam {
- tag "call mpileup for ${chrom}:${start}-${end} and ${bam_list}"
- echo true
- input:
- set chrom,start,end,bam_list from bed_lines.combine(bam_list)
- output:
- set chrom,start,end,file("${chrom}_${start}_${end}.vcf.gz") into called_vcfs
- script:
- """
- bcftools mpileup -Ou -f "${REF}" --bam-list "${bam_list}" --region "${chrom}:${start}-${end}" |\\
- bcftools call --ploidy GRCh37 -vmO z -o "${chrom}_${start}_${end}.vcf.gz"
- """
- }
- process vcfList {
- tag "making list from ${vcfVector.size()} "
- echo true
- input:
- val vcfVector from called_vcfs.map{L->L[0]+","+L[1]+","+L[3]}.flatten().toList()
- output:
- file("vcf.list") into vcf_list
- script:
- """
- cat << __EOF__ | sort -t, -k1,1 > tmp2.txt
- ${vcfVector.join("\n")}
- __EOF__
- awk -F '\\t' '{printf("%s,%d\\n",\$1,NR);}' "${REF}.fai" | sort -t, -k1,1 > tmp1.txt
- join -t , -1 1 -2 1 tmp1.txt tmp2.txt | sort -t, -k2,2n -k3,3n | cut -d , -f 4 > vcf.list
- rm -f tmp1.txt tmp2.txt
- grep -m1 '.vcf.gz\$' vcf.list
- """
- }
- process mergeVcf {
- tag "making list from ${vcflist} "
- echo true
- input:
- file vcflist from vcf_list
- output:
- file("merged.vcf.gz") into merged_vcf
- script:
- """
- java \\
- -jar /path/to/picard.jar GatherVcfs \\
- I=${vcflist} O=merged.vcf.gz
- """
- }
Add Comment
Please, Sign In to add comment