Skip to content

Commit

Permalink
feat: map qc (#38)
Browse files Browse the repository at this point in the history
* feat: added qualimap rule + dependencies, moved sam_stats from Snakefile to qc.smk

* fix: add rule all input for qualimap, linting

* feat: added map_qc compression, moved sam_stats from Snakefile to qc.smk

* fix: renamed rule in profile/config.yaml to align with rule name in qc.smk
  • Loading branch information
yeising authored Jun 25, 2024
1 parent 0f8ac63 commit 4d5b8bc
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 21 deletions.
24 changes: 5 additions & 19 deletions workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ rule all:
de_heatmap="de_analysis/heatmap.svg",
lfc_analysis="de_analysis/lfc_analysis.csv",
samstats=expand("QC/samstats/{sample}.txt", sample=samples["sample"]),
map_qc=expand("QC/qualimap/{sample}.tar.gz", sample=samples["sample"]),


rule genome_to_transcriptome:
Expand Down Expand Up @@ -100,13 +101,13 @@ rule map_reads:
"""


rule sam_sort:
rule sam_view:
input:
sam=rules.map_reads.output,
output:
"sorted_alignments/{sample}.bam",
log:
"logs/samtools/samsort_{sample}.log",
"logs/samtools/samview_{sample}.log",
conda:
"envs/env.yml"
shell:
Expand All @@ -115,7 +116,7 @@ rule sam_sort:

rule sam_index:
input:
sbam=rules.sam_sort.output,
sbam=rules.sam_view.output,
output:
ibam="sorted_alignments/{sample}_index.bam",
log:
Expand All @@ -129,24 +130,9 @@ rule sam_index:
"""


rule sam_stats:
input:
bam=rules.sam_sort.output,
output:
"QC/samstats/{sample}.txt",
log:
"logs/samtools/samstats_{sample}.log",
conda:
"envs/env.yml"
shell:
"""
samtools stats -@ {resources.cpus_per_task} {input.bam} > {output} 2> {log}
"""


rule count_reads:
input:
bam=rules.sam_sort.output,
bam=rules.sam_view.output,
trs=rules.genome_to_transcriptome.output,
output:
tsv="counts/{sample}_salmon/quant.sf",
Expand Down
3 changes: 2 additions & 1 deletion workflow/envs/env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ dependencies:
- anndata>=0.8.0
- ensureconda
- gffread>=0.12.7

- qualimap>=2.3
- snakemake-wrapper-utils>=0.6.2
10 changes: 10 additions & 0 deletions workflow/profile/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ set-resources:
mem_mb_per_cpu: 1800
runtime: "2h"

map_qc:
cpus_per_task: 8
mem_mb_per_cpu: 1800
runtime: "1h"

sam_sort:
cpus_per_task: 4
mem_mb_per_cpu: 1800
runtime: "2h"

sam_view:
cpus_per_task: 1
mem_mb_per_cpu: 1800
runtime: "1h"
Expand Down
57 changes: 56 additions & 1 deletion workflow/rules/qc.smk
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import os
localrules:
compress_nplot,
compress_nplot_all,
compress_map_qc,


configfile: "config/config.yml"


inputdir = config["inputdir"] #"/lustre/project/m2_zdvhpc/transcriptome_data/"
inputdir = config["inputdir"] # "/lustre/project/m2_zdvhpc/transcriptome_data/"


# QC and metadata with NanoPlot
Expand Down Expand Up @@ -108,3 +109,57 @@ else:
None
shell:
"tar zcvf {output} {input} &> {log}"


rule sam_sort:
input:
sam="alignments/{sample}.sam",
output:
"sorted_alignments/{sample}_sorted.bam",
log:
"logs/samtools/samsort_{sample}.log",
conda:
"../envs/env.yml"
shell:
"samtools sort -@ {resources.cpus_per_task} {input.sam} -o {output} -O bam &> {log}"


rule map_qc:
input:
sorted_bam=rules.sam_sort.output,
output:
directory("QC/qualimap/{sample}"),
log:
"logs/qualimap/{sample}.log",
conda:
"../envs/env.yml"
wrapper:
"v3.12.1/bio/qualimap/bamqc"


rule compress_map_qc:
input:
map_qc=rules.map_qc.output,
output:
"QC/qualimap/{sample}.tar.gz",
log:
"logs/qualimap/compress_{sample}.log",
conda:
None
shell:
"tar zcvf {output} {input} &> {log}"


rule sam_stats:
input:
bam="sorted_alignments/{sample}.bam",
output:
"QC/samstats/{sample}.txt",
log:
"logs/samtools/samstats_{sample}.log",
conda:
"../envs/env.yml"
shell:
"""
samtools stats -@ {resources.cpus_per_task} {input.bam} > {output} 2> {log}
"""

0 comments on commit 4d5b8bc

Please sign in to comment.