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

fix: Handle missing bam columns in units.tsv #105

Merged
merged 15 commits into from
Aug 5, 2024
2 changes: 1 addition & 1 deletion .test/config/units.tsv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sample unit fragment_len_mean fragment_len_sd fq1 fq2 bam_single bam_paired
sample unit fragment_len_mean fragment_len_sd fq1 fq2
A 1 ngs-test-data/reads/a.chr21.1.fq ngs-test-data/reads/a.chr21.2.fq
B 1 ngs-test-data/reads/b.chr21.1.fq ngs-test-data/reads/b.chr21.2.fq
B 2 300 14 ngs-test-data/reads/b.chr21.1.fq
Expand Down
2 changes: 2 additions & 0 deletions workflow/rules/bam.smk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ rule bam_paired_to_fastq:
query="sample == '{sample}' & unit == '{unit}'",
within=units,
cols="bam_paired",
default=None,
),
output:
"results/fastq/{sample}-{unit}.1.fq.gz",
Expand All @@ -23,6 +24,7 @@ rule bam_single_to_fastq:
query="sample == '{sample}' & unit == '{unit}'",
within=units,
cols="bam_single",
default=None,
),
output:
"results/fastq/{sample}-{unit}.fq.gz",
Expand Down
13 changes: 10 additions & 3 deletions workflow/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,23 @@ def get_model(wildcards):

def is_single_end(sample, unit):
"""Determine whether unit is single-end."""
bam_paired_not_present = pd.isnull(units.loc[(sample, unit), "bam_paired"])
if "bam_paired" in units.columns:
bam_paired_not_present = pd.isnull(units.loc[(sample, unit), "bam_paired"])
else:
bam_paired_not_present = True
fq2_not_present = pd.isnull(units.loc[(sample, unit), "fq2"])
return fq2_not_present and bam_paired_not_present
fxwiegand marked this conversation as resolved.
Show resolved Hide resolved


def get_fastqs(wildcards):
"""Get raw FASTQ files from unit sheet."""
if not pd.isnull(units.loc[(wildcards.sample, wildcards.unit), "bam_single"]):
if "bam_single" in units.columns and not pd.isnull(
units.loc[(wildcards.sample, wildcards.unit), "bam_single"]
):
fxwiegand marked this conversation as resolved.
Show resolved Hide resolved
return f"results/fastq/{wildcards.sample}-{wildcards.unit}.fq.gz"
elif not pd.isnull(units.loc[(wildcards.sample, wildcards.unit), "bam_paired"]):
elif "bam_paired" in units.columns and not pd.isnull(
units.loc[(wildcards.sample, wildcards.unit), "bam_paired"]
):
fxwiegand marked this conversation as resolved.
Show resolved Hide resolved
fqfrombam1 = f"results/fastq/{wildcards.sample}-{wildcards.unit}.1.fq.gz"
fqfrombam2 = f"results/fastq/{wildcards.sample}-{wildcards.unit}.2.fq.gz"
return [fqfrombam1, fqfrombam2]
fxwiegand marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading