Skip to content

Commit

Permalink
Refactor code for finding experiments in DesignIP class and update ti…
Browse files Browse the repository at this point in the history
…le_size in pileup_norm.smk rule
  • Loading branch information
alsmith151 committed Apr 4, 2024
1 parent 9b6ba54 commit 5c60e36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
25 changes: 13 additions & 12 deletions seqnado/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def is_path(path: Optional[Union[str, pathlib.Path]]) -> Optional[pathlib.Path]:
else:
p = None

if p is not None:
if p is not None and str(p) != "." and str(p):
return True
else:
return False
Expand Down Expand Up @@ -421,17 +421,19 @@ def query(

name_to_query = sample_name + (f"_{ip}" if ip is not None else "")

for experiment in self.assays.values():

name_ip = experiment.name
name_control = f"{experiment.control_files.r1.sample_base_without_ip}_{experiment.control_files.r1.ip}"
# Check if the sample name is in the index of the dataframe
df = self.to_dataframe()
is_name_in_index = df.index.str.contains(name_to_query)

if name_to_query == name_ip or name_to_query == name_control:
if control is not None:
if experiment.control == control:
return experiment
else:
return experiment
if is_name_in_index.sum() == 1:
return self.assays[df.index[is_name_in_index][0]]

else:
# Check if its the name of a control
for assay in self.assays.values():
name_control = f"{assay.control_files.r1.sample_base_without_ip}_{assay.control_files.r1.ip}" if assay.control_files is not None else None
if name_to_query == name_control:
return assay

raise ValueError(
f"Could not find experiment with sample name {sample_name} and ip {ip} and control {control}"
Expand Down Expand Up @@ -605,7 +607,6 @@ def from_dataframe(cls, df: pd.DataFrame, simplified: bool = True, **kwargs):
)
else:
raise NotImplementedError("Not implemented")

return cls(assays=experiments, **kwargs)


Expand Down
4 changes: 2 additions & 2 deletions seqnado/workflow/rules/pileup_norm.smk
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ rule tile_regions:
import pyranges as pr

chromsizes = (
pd.read_csv(chromsizes, sep="\t", header=None).set_index(0)[1].to_dict()
pd.read_csv(input.chromsizes, sep="\t", header=None).set_index(0)[1].to_dict()
)
genome_tiled = pr.gf.tile_genome(chromsizes, tile_size=tile_size)
genome_tiled = pr.gf.tile_genome(chromsizes, tile_size=params.tile_size)
genome_tiled = genome_tiled.df.assign(
feature="tile", gene_id=lambda df: df.index.astype(str)
).pipe(pr.PyRanges)
Expand Down

0 comments on commit 5c60e36

Please sign in to comment.