diff --git a/templates/aggregate_organisms.py b/templates/aggregate_organisms.py index 5859fd8..250c5b8 100755 --- a/templates/aggregate_organisms.py +++ b/templates/aggregate_organisms.py @@ -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") @@ -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}' @@ -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 [] ) ) @@ -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. @@ -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 [