Skip to content

Commit

Permalink
Added __repr__ to major classes
Browse files Browse the repository at this point in the history
  • Loading branch information
wfondrie committed Jul 13, 2020
1 parent acdc1b2 commit 16caf52
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
9 changes: 9 additions & 0 deletions mokapot/confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ def __init__(self, psms, scores, desc=True, eval_fdr=0.01):

self._assign_confidence(desc=desc)

def __repr__(self):
"""How to print the class"""
pass_psms = (self.psms["mokapot q-value"] <= self._eval_fdr).sum()
pass_peps = (self.peptides["mokapot q-value"] <= self._eval_fdr).sum()

return ("A mokapot.confidence.LinearConfidence object:\n"
f"\t- PSMs at q<={self._eval_fdr:g}: {pass_psms}\n"
f"\t- Peptides at q<={self._eval_fdr:g}: {pass_peps}")

def _assign_confidence(self, desc=True):
"""
Assign confidence to PSMs and peptides.
Expand Down
21 changes: 18 additions & 3 deletions mokapot/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ class LinearPsmDataset(PsmDataset):
metadata : pandas.DataFrame
features : pandas.DataFrame
spectra : pandas.DataFrame
peptides: pandas.DataFrame
targets : numpy.ndarray
columns : list of str
"""
def __init__(self,
psms,
Expand Down Expand Up @@ -349,16 +349,31 @@ def __init__(self,

if not num_targets:
raise ValueError("No target PSMs were detected.")
elif not num_decoys:
if not num_decoys:
raise ValueError("No decoy PSMs were detected.")
elif not len(self.data):
if not self.data.shape[0]:
raise ValueError("No PSMs were detected.")

def __repr__(self):
"""How to print the class"""
return (f"A mokapot.dataset.LinearPsmDataset with {len(self.data)} "
"PSMs:\n"
f"\t- target PSMs: {self.targets.sum()}\n"
f"\t- decoy PSMs: {self.targets.sum()}\n"
f"\t- unique spectra: {len(self.spectra.drop_duplicates())}\n"
f"\t- unique peptides: {len(self.peptides.drop_duplicates())}\n"
f"\t- features: {self._feature_columns}")

@property
def targets(self):
"""An array indicating whether each PSM is a target sequence."""
return self.data[self._target_column].values

@property
def peptides(self):
"""A :py:class:`pandas.DataFrame` of peptide columns."""
return self.data.loc[:, self._peptide_columns]

def _update_labels(self, scores, fdr_threshold=0.01, desc=True):
"""
Return the label for each PSM, given it's score.
Expand Down
9 changes: 8 additions & 1 deletion mokapot/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def __init__(self, estimator=None, scaler=None, is_trained=False):
self.estimator = base.clone(estimator)
self.features = None
self.is_trained = is_trained
self._base_params = self.estimator.get_params()

if scaler == "as-is":
self.scaler = DummyScaler()
Expand All @@ -93,6 +92,14 @@ def __init__(self, estimator=None, scaler=None, is_trained=False):
else:
self.scaler = base.clone(scaler)

def __repr__(self):
"""How to print the class"""
trained = {True: "A trained", False: "An untrained"}

return (f"{trained[self.is_trained]} mokapot.model.Model object:\n"
f"\testimator: {self.estimator}\n"
f"\tscaler: {self.scaler}\n"
f"\tfeatures: {self.features}")

def save(self, out_file):
"""
Expand Down

0 comments on commit 16caf52

Please sign in to comment.