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: heatmaps always created and peak files absent #183

Merged
merged 7 commits into from
May 28, 2024
32 changes: 16 additions & 16 deletions seqnado/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,7 @@ def controls_performed(self) -> List[str]:
control.add(f.control_performed)
return list(control)

def query(
self, sample_name: str, full_experiment: bool = False
) -> Union[FastqSetIP, Dict[str, FastqSetIP]]:
def query(self, sample_name: str, full_experiment: bool = False) -> Union[FastqSetIP, IPExperiment]:
"""
Extracts a pair of fastq files from the design.
"""
Expand All @@ -496,32 +494,27 @@ def query(
)
is_control = False

experiment_files = dict()

if sample_name in ip_names or sample_name in control_names:
for experiment in self.experiments:
if experiment.ip_set_fullname == sample_name:
experiment_files["ip"] = experiment.ip
experiment_files["control"] = experiment.control

exp = experiment
break
elif (
experiment.has_control
and experiment.control_fullname == sample_name
):
is_control = True
experiment_files["ip"] = experiment.ip
experiment_files["control"] = experiment.control
exp = experiment
break

else:
raise ValueError(f"Could not find sample with name {sample_name}")


if full_experiment:
return experiment_files
return exp
else:
return (
experiment_files["ip"]
if not is_control
else experiment_files["control"]
)
return exp.ip if not is_control else exp.control

@classmethod
def from_fastq_files(cls, fq: List[Union[str, pathlib.Path]], **kwargs):
Expand Down Expand Up @@ -970,6 +963,7 @@ def files(self) -> List[str]:
class HeatmapFiles(BaseModel):
assay: Literal["ChIP", "ATAC", "RNA", "SNP"]
make_heatmaps: bool = False
make_heatmaps: bool = False

@property
def heatmap_files(self) -> List[str]:
Expand All @@ -985,6 +979,10 @@ def files(self) -> List[str]:
return self.heatmap_files
else:
return []
if self.make_heatmaps:
return self.heatmap_files
else:
return []


class HubFiles(BaseModel):
Expand Down Expand Up @@ -1255,8 +1253,10 @@ def peaks(self):
s
for s in self.sample_names
if not any([c in s for c in self.control_names])
if not any([c in s for c in self.control_names])
]


pcf_samples = PeakCallingFiles(
assay=self.assay,
names=ip_sample_names,
Expand Down
23 changes: 23 additions & 0 deletions seqnado/workflow/rules/peak_call_chip.smk
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,29 @@ def get_control_file(wildcards, file_type: Literal["bam", "tag", "bigwig"], allo
return []
else:
return "UNDEFINED"
def get_control_file(wildcards, file_type: Literal["bam", "tag", "bigwig"], allow_null=False):
exp = DESIGN.query(sample_name=f"{wildcards.sample}_{wildcards.treatment}", full_experiment=True)

if not exp.has_control and not allow_null: # if control is not defined, return UNDEFINED. This is to prevent the rule from running
return "UNDEFINED"
elif not exp.has_control and allow_null: # if control is not defined, return empty list
return []

match file_type:
case "bam":
fn = f"seqnado_output/aligned/{exp.control_fullname}.bam"
case "tag":
fn = f"seqnado_output/tag_dirs/{exp.control_fullname}"
case "bigwig":
fn = f"seqnado_output/bigwigs/deeptools/unscaled/{exp.control_fullname}.bigWig"
return fn


rule macs2_with_input:
input:
treatment="seqnado_output/aligned/{sample}_{treatment}.bam",
control=lambda wc: get_control_file(wc, file_type="bam", allow_null=False),
control=lambda wc: get_control_file(wc, file_type="bam", allow_null=False),
output:
peaks="seqnado_output/peaks/macs/{sample}_{treatment}.bed",
params:
Expand All @@ -65,6 +83,7 @@ rule macs2_no_input:
input:
treatment="seqnado_output/aligned/{sample}_{treatment}.bam",
control=lambda wc: get_control_file(wc, file_type="bam", allow_null=True),
control=lambda wc: get_control_file(wc, file_type="bam", allow_null=True),
output:
peaks="seqnado_output/peaks/macs/{sample}_{treatment}.bed",
params:
Expand All @@ -88,6 +107,7 @@ rule homer_with_input:
input:
treatment="seqnado_output/tag_dirs/{sample}_{treatment}",
control=lambda wc: get_control_file(wc, file_type="tag", allow_null=False),
control=lambda wc: get_control_file(wc, file_type="tag", allow_null=False),
output:
peaks="seqnado_output/peaks/homer/{sample}_{treatment}.bed",
log:
Expand All @@ -110,6 +130,7 @@ rule homer_no_input:
input:
treatment="seqnado_output/tag_dirs/{sample}_{treatment}",
control=lambda wc: get_control_file(wc, file_type="tag", allow_null=True),
control=lambda wc: get_control_file(wc, file_type="tag", allow_null=True),
output:
peaks="seqnado_output/peaks/homer/{sample}_{treatment}.bed",
log:
Expand All @@ -132,6 +153,7 @@ rule lanceotron_with_input:
input:
treatment="seqnado_output/bigwigs/deeptools/unscaled/{sample}_{treatment}.bigWig",
control=lambda wc: get_control_file(wc, file_type="bigwig", allow_null=False),
control=lambda wc: get_control_file(wc, file_type="bigwig", allow_null=False),
output:
peaks="seqnado_output/peaks/lanceotron/{sample}_{treatment}.bed",
log:
Expand All @@ -157,6 +179,7 @@ rule lanceotron_no_input:
input:
treatment="seqnado_output/bigwigs/deeptools/unscaled/{sample}_{treatment}.bigWig",
control=lambda wc: get_control_file(wc, file_type="bigwig", allow_null=True),
control=lambda wc: get_control_file(wc, file_type="bigwig", allow_null=True),
output:
peaks="seqnado_output/peaks/lanceotron/{sample}_{treatment}.bed",
log:
Expand Down
Loading