Skip to content

Commit

Permalink
Fix duck typing evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
sminot authored Jul 22, 2024
2 parents f97b27a + e77bc26 commit fa1548d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions templates/aggregate_organisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ def __init__(self):
).applymap(
bool
)
self.has_edgeR_hits = True
else:
self.edgeR_hits = False
self.has_edgeR_hits = False

# Group the replicates by sample
self.logger.info("Grouping replicates by sample")
Expand Down Expand Up @@ -253,7 +254,7 @@ def group_replicates(self) -> pd.DataFrame:
hit=df.apply(self.classify_hit, axis=1),
edgeR_hit=(
self.edgeR_hits.apply(self.classify_edgeR_hit, axis=1)
if self.edgeR_hits
if self.has_edgeR_hits
else None
),
sample='!{sample_id}'
Expand All @@ -262,7 +263,7 @@ def group_replicates(self) -> pd.DataFrame:
columns=dict(index="peptide")
).drop(
columns=replicates + (
["edgeR_hit"] if self.edgeR_hits else []
["edgeR_hit"] if not self.has_edgeR_hits else []
)
)

Expand Down Expand Up @@ -290,7 +291,7 @@ def classify_hit(self, r):
else:
return "DISCORDANT"

def classify_edgeR_hit(self, r):
def classify_edgeR_hit(self, r: pd.Series) -> str:
"""
Determine whether a peptide is a hit, or discordant -
based on edgeR hits.
Expand Down Expand Up @@ -430,7 +431,7 @@ def group_sample_organisms(
(f"n_edgeR_hits_{label}", (d["edgeR_hit"] == "TRUE").sum()),
(f"n_edgeR_discordant_{label}", (d["edgeR_hit"] == "DISCORDANT").sum()),
]
if self.edgeR_hits
if self.has_edgeR_hits
else []
)
if k not in [
Expand Down

0 comments on commit fa1548d

Please sign in to comment.