Skip to content

Commit

Permalink
Refactor pileup_default.smk to use sorted BAM file for bedtools conve…
Browse files Browse the repository at this point in the history
…rsion
  • Loading branch information
alsmith151 committed Jul 15, 2024
1 parent 1b16906 commit 6720440
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion seqnado/workflow/rules/pileup_default.smk
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,16 @@ rule fragment_bedgraph:
"seqnado_output/logs/bedgraphs/{sample}.log",
shell:
"""
bedtools bamtobed -bedpe -i {input.bam} > {params.outdir}/{wildcards.sample}.bed 2> {log}
samtools sort -n {input.bam} -o {input.bam}.sorted &&
bedtools bamtobed -bedpe -i {input.bam}.sorted > {params.outdir}/{wildcards.sample}.bed 2> {log}
awk '$1==$4 && $6-$2 < 1000 {{print $0}}' {params.outdir}/{wildcards.sample}.bed > {params.outdir}/{wildcards.sample}_clean.bed 2>> {log}
cut -f 1,2,6 {params.outdir}/{wildcards.sample}_clean.bed | sort -k1,1 -k2,2n -k3,3n > {params.outdir}/{wildcards.sample}_fragments.bed 2>> {log}
bedtools genomecov -bg -i {params.outdir}/{wildcards.sample}_fragments.bed -g {params.genome} > {output.bedgraph} 2>> {log}
rm {params.outdir}/{wildcards.sample}.bed
rm {params.outdir}/{wildcards.sample}_clean.bed
rm {params.outdir}/{wildcards.sample}_fragments.bed
rm {input.bam}.sorted
"""

ruleorder: deeptools_make_bigwigs_rna_plus > deeptools_make_bigwigs_rna_minus > deeptools_make_bigwigs

0 comments on commit 6720440

Please sign in to comment.