Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reduce fgbio memory usage #296

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion workflow/envs/fgbio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ channels:
- conda-forge
- bioconda
dependencies:
- fgbio =1.4
- fgbio =2.2
22 changes: 18 additions & 4 deletions workflow/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def get_sample_datatype(sample):
def get_markduplicates_input(wildcards):
aligner = "star" if get_sample_datatype(wildcards.sample) == "rna" else "bwa"
if sample_has_umis(wildcards.sample):
return "results/mapped/{aligner}/{{sample}}.annotated.bam".format(
return "results/mapped/{aligner}/{{sample}}.annotated.sorted.bam".format(
FelixMoelder marked this conversation as resolved.
Show resolved Hide resolved
aligner=aligner
)
else:
Expand Down Expand Up @@ -589,6 +589,18 @@ def get_read_group(wildcards):
)


def get_map_reads_sorting_params(wildcards, order_param=False):
match (sample_has_umis(wildcards.sample), order_param):
case (True, True):
return "queryname"
case (True, False):
return "fgbio"
case (False, True):
return "coordinate"
case (False, False):
return "samtools"


def get_mutational_burden_targets():
mutational_burden_targets = []
if is_activated("mutational_burden"):
Expand Down Expand Up @@ -1084,12 +1096,14 @@ def get_vembrane_config(wildcards, input):
def get_umi_fastq(wildcards):
umi_read = extract_unique_sample_column_value(wildcards.sample, "umi_read")
if umi_read in ["fq1", "fq2"]:
return "results/untrimmed/{S}_{R}.fastq.gz".format(
return "results/untrimmed/{S}_{R}.sorted.fastq.gz".format(
S=wildcards.sample, R=umi_read
)
elif umi_read == "both":
return expand(
"results/untrimmed/{S}_{R}.fastq.gz", S=wildcards.sample, R=["fq1", "fq2"]
"results/untrimmed/{S}_{R}.sorted.fastq.gz",
S=wildcards.sample,
R=["fq1", "fq2"],
)
else:
return umi_read
Expand All @@ -1100,7 +1114,7 @@ def sample_has_umis(sample):


def get_umi_read_structure(wildcards):
return "-r {}".format(
return "-s true -r {}".format(
extract_unique_sample_column_value(wildcards.sample, "umi_read_structure")
)
FelixMoelder marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
37 changes: 31 additions & 6 deletions workflow/rules/mapping.smk
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ rule map_reads:
"logs/bwa_mem/{sample}.log",
params:
extra=get_read_group,
sorting="samtools",
sort_order="coordinate",
sorting=get_map_reads_sorting_params,
sort_order=lambda wc: get_map_reads_sorting_params(wc, order_param=True),
threads: 8
wrapper:
"v2.3.2/bio/bwa/mem"
"v3.7.0-29-ge7ff82c/bio/bwa/mem"


rule merge_untrimmed_fastqs:
input:
get_untrimmed_fastqs,
output:
temp("results/untrimmed/{sample}_{read}.fastq.gz"),
conda:
"../envs/fgbio.yaml"
log:
"logs/merge-fastqs/untrimmed/{sample}_{read}.log",
wildcard_constraints:
Expand All @@ -28,6 +30,19 @@ rule merge_untrimmed_fastqs:
"cat {input} > {output} 2> {log}"


rule sort_untrimmed_fastqs:
input:
"results/untrimmed/{sample}_{read}.fastq.gz",
output:
temp("results/untrimmed/{sample}_{read}.sorted.fastq.gz"),
conda:
"../envs/fgbio.yaml"
log:
"logs/fgbio/sort_fastq/{sample}_{read}.log",
shell:
"fgbio SortFastq -i {input} -o {output} 2> {log}"


FelixMoelder marked this conversation as resolved.
Show resolved Hide resolved
rule annotate_umis:
input:
bam="results/mapped/{aligner}/{sample}.bam",
Expand All @@ -36,12 +51,22 @@ rule annotate_umis:
temp("results/mapped/{aligner}/{sample}.annotated.bam"),
params:
extra=get_umi_read_structure,
resources:
mem_mb=lambda wc, input: 2.5 * input.size_mb,
log:
"logs/fgbio/annotate_bam/{aligner}/{sample}.log",
wrapper:
"v2.3.2/bio/fgbio/annotatebamwithumis"
"v3.7.0/bio/fgbio/annotatebamwithumis"


rule sort_annotated_reads:
input:
"results/mapped/{aligner}/{sample}.annotated.bam",
output:
temp("results/mapped/{aligner}/{sample}.annotated.sorted.bam"),
log:
"logs/samtools_sort/{aligner}_{sample}.log",
threads: 8
wrapper:
"v3.7.0/bio/samtools/sort"


rule mark_duplicates:
Expand Down
Loading