From 9d6dbef9ef307695e57e7c60b55bc9fdf771c49a Mon Sep 17 00:00:00 2001 From: alsmith Date: Mon, 18 Nov 2024 16:06:08 +0000 Subject: [PATCH] feat(filtering): add filter options and implement BAM filtering rule --- seqnado/workflow/config/config.yaml.jinja | 2 ++ .../rules/alignment_post_processing.smk | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/seqnado/workflow/config/config.yaml.jinja b/seqnado/workflow/config/config.yaml.jinja index b6bf8053..cf2635dd 100755 --- a/seqnado/workflow/config/config.yaml.jinja +++ b/seqnado/workflow/config/config.yaml.jinja @@ -65,6 +65,8 @@ plotting_coordinates: "{{plotting_coordinates}}" plotting_genes: "{{plotting_genes}}" plotting_format: "svg" +filter_options: + ################################# # Tool specific options # ################################# diff --git a/seqnado/workflow/rules/alignment_post_processing.smk b/seqnado/workflow/rules/alignment_post_processing.smk index b327937c..85fa83f6 100755 --- a/seqnado/workflow/rules/alignment_post_processing.smk +++ b/seqnado/workflow/rules/alignment_post_processing.smk @@ -181,10 +181,32 @@ else: """ -rule move_bam_to_final_location: +rule filter_bam: input: bam="seqnado_output/aligned/shifted_for_tn5_insertion/{sample}.bam", bai="seqnado_output/aligned/shifted_for_tn5_insertion/{sample}.bam.bai", + output: + bam="seqnado_output/aligned/filtered/{sample}.bam", + bai="seqnado_output/aligned/filtered/{sample}.bam.bai", + threads: 1 + resources: + mem="500MB", + log: + "seqnado_output/logs/filter/{sample}.log", + params: + options=check_options(config["filter_options"]), + shell: + """ + samtools view -h {input.bam} {options} | samtools view -b - > {output.bam} && + samtools index {output.bam} && + echo 'Filtered reads' > {log} 2>&1 && + samtools view -f 2 -c {output.bam} >> {log} 2>&1 + """ + +rule move_bam_to_final_location: + input: + bam="seqnado_output/aligned/filtered/{sample}.bam", + bai="seqnado_output/aligned/filtered/{sample}.bam.bai", output: bam="seqnado_output/aligned/{sample,[A-Za-z\\d\\-_]+}.bam", bai="seqnado_output/aligned/{sample,[A-Za-z\\d\\-_]+}.bam.bai",