Skip to content

Commit

Permalink
fix: heatmaps always created and peak files absent (#183)
Browse files Browse the repository at this point in the history
* Refactor HeatmapFiles class to include make_heatmaps property in design.py

* Refactor NonRNAOutput class in design.py to remove computed_field decorator

* fix: correct query function to provide both the ip and control if requested

* Refactor control lambda function in peak_call_chip.smk to allow null control files

* Refactor query function in DesignIP class to return IPExperiment object

---------

Co-authored-by: CChahrour <catherine.chahrour@gmail.com>
  • Loading branch information
alsmith151 and CChahrour committed May 28, 2024
1 parent 396b94b commit 05915f4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
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

0 comments on commit 05915f4

Please sign in to comment.