Skip to content

Commit 5f0a83e

Browse files
authored
Merge pull request #209 from singjc/master
Add exclude_decoys option and filtering in BaseWriter
2 parents d410cc2 + 72f97c9 commit 5f0a83e

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

pyprophet/_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,4 +716,7 @@ class ExportIOConfig(BaseIOConfig):
716716
intensity_calibration: bool = True
717717
min_fragments: int = 4
718718
keep_decoys: bool = False # Whether to keep decoy entries in the library
719-
rt_unit: Literal["iRT", "RT"] = "iRT"
719+
rt_unit: Literal["iRT", "RT"] = "iRT"
720+
721+
# TSV/Matrix export options
722+
exclude_decoys: bool = True # Whether to exclude decoy entries from TSV/matrix export (default: True, exclude decoys)

pyprophet/cli/export.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ def export():
159159
type=float,
160160
help="[format: matrix/legacy] Maximum PEP to consider for good alignments when use_alignment is enabled.",
161161
)
162+
@click.option(
163+
"--exclude-decoys/--no-exclude-decoys",
164+
"exclude_decoys",
165+
default=True,
166+
show_default=True,
167+
help="Exclude decoy entries from the exported results. Use --no-exclude-decoys to retain decoys.",
168+
)
162169
@measure_memory_usage_and_time
163170
def export_tsv(
164171
infile,
@@ -176,6 +183,7 @@ def export_tsv(
176183
max_global_protein_qvalue,
177184
use_alignment,
178185
max_alignment_pep,
186+
exclude_decoys,
179187
):
180188
"""
181189
Export Proteomics/Peptidoform TSV/CSV tables
@@ -207,6 +215,7 @@ def export_tsv(
207215
max_global_protein_qvalue=max_global_protein_qvalue,
208216
use_alignment=use_alignment,
209217
max_alignment_pep=max_alignment_pep,
218+
exclude_decoys=exclude_decoys,
210219
)
211220

212221
reader = ReaderDispatcher.get_reader(config)
@@ -329,6 +338,13 @@ def export_tsv(
329338
type=click.Choice(["none", "median", "medianmedian", "quantile"]),
330339
help="[format: matrix/legacy] Normalization method to apply to the quantification matrix.",
331340
)
341+
@click.option(
342+
"--exclude-decoys/--no-exclude-decoys",
343+
"exclude_decoys",
344+
default=True,
345+
show_default=True,
346+
help="Exclude decoy entries from the exported matrix. Use --no-exclude-decoys to retain decoys.",
347+
)
332348
@measure_memory_usage_and_time
333349
def export_matrix(
334350
infile,
@@ -347,6 +363,7 @@ def export_matrix(
347363
top_n,
348364
consistent_top,
349365
normalization,
366+
exclude_decoys,
350367
):
351368
"""
352369
Export Proteomics/Peptidoform Quantification Matrix
@@ -381,6 +398,7 @@ def export_matrix(
381398
top_n=top_n,
382399
consistent_top=consistent_top,
383400
normalization=normalization,
401+
exclude_decoys=exclude_decoys,
384402
)
385403

386404
reader = ReaderDispatcher.get_reader(config)

pyprophet/io/_base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,14 @@ def export_results(self, data: pd.DataFrame):
589589
"""
590590
cfg = self.config
591591

592+
# Filter out decoys if exclude_decoys is True
593+
if cfg.exclude_decoys and "decoy" in data.columns:
594+
initial_count = len(data)
595+
data = data.loc[data["decoy"].eq(0)].copy()
596+
decoy_count = initial_count - len(data)
597+
if decoy_count > 0:
598+
logger.info(f"Excluded {decoy_count} decoy entries from export.")
599+
592600
sep = "," if cfg.out_type == "csv" else "\t"
593601

594602
if cfg.export_format == "legacy_split":
@@ -737,6 +745,14 @@ def export_quant_matrix(self, data: pd.DataFrame) -> pd.DataFrame:
737745
"""
738746
cfg = self.config
739747

748+
# Filter out decoys if exclude_decoys is True
749+
if cfg.exclude_decoys and "decoy" in data.columns:
750+
initial_count = len(data)
751+
data = data[data["decoy"] == 0]
752+
decoy_count = initial_count - len(data)
753+
if decoy_count > 0:
754+
logger.info(f"Excluded {decoy_count} decoy entries from quantification matrix.")
755+
740756
# Check if data is empty
741757
if data.empty:
742758
raise ValueError(

0 commit comments

Comments
 (0)