MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / peptide_identifications_to_df

Function peptide_identifications_to_df

src/pyOpenMS/pyopenms/_dataframes.py:485–582  ·  view source on GitHub ↗

Converts a list of peptide identifications to a pandas DataFrame. Parameters: peps (List[PeptideIdentification]): list of PeptideIdentification objects decode_ontology (bool): decode meta value names default_missing_values: default value for missing values for each data type expo

(peps: List[_PeptideIdentification], decode_ontology : bool = True,
                                  default_missing_values: dict = {bool: False, int: -9999, float: _np.nan, str: ''},
                                  export_unidentified : bool = True)

Source from the content-addressed store, hash-verified

483# TODO think about the best way for such top-level function. IMHO in python, encapsulation in a stateless class in unnecessary.
484# We should probably not just import this whole submodule without prefix.
485def peptide_identifications_to_df(peps: List[_PeptideIdentification], decode_ontology : bool = True,
486 default_missing_values: dict = {bool: False, int: -9999, float: _np.nan, str: ''},
487 export_unidentified : bool = True):
488 """Converts a list of peptide identifications to a pandas DataFrame.
489 Parameters:
490 peps (List[PeptideIdentification]): list of PeptideIdentification objects
491 decode_ontology (bool): decode meta value names
492 default_missing_values: default value for missing values for each data type
493 export_unidentified: export PeptideIdentifications without PeptideHit
494 Returns:
495 pandas.DataFrame: peptide identifications in a DataFrame
496 """
497 switchDict = {bool: '?', int: 'i', float: 'f', str: 'U100'}
498
499 # filter out PeptideIdentifications without PeptideHits if export_unidentified == False
500 count = len(peps)
501 if not export_unidentified:
502 count = sum(len(pep.getHits()) > 0 for pep in peps)
503
504 # get all possible metavalues
505 metavals = []
506 types = []
507 mainscorename = "score"
508 for pep in peps:
509 hits = pep.getHits()
510 if not len(hits) == 0:
511 mvs = []
512 hits[0].getKeys(mvs)
513 metavals += mvs
514 mainscorename = pep.getScoreType()
515
516 metavals = list(set(metavals))
517
518 # get type of all metavalues
519 for k in metavals:
520 if k == b"target_decoy":
521 types.append('?')
522 else:
523 for p in peps:
524 hits = p.getHits()
525 if not len(hits) == 0:
526 mv = hits[0].getMetaValue(k)
527 types.append(switchDict[type(mv)])
528 break
529
530 # get default value for each type in types to append if there are no hits in a PeptideIdentification
531 def get_key(val):
532 for key, value in switchDict.items():
533 if val == value:
534 return key
535 dmv = [default_missing_values[get_key(t)] for t in types]
536
537 decodedMVs = [m.decode("utf-8") for m in metavals]
538 if decode_ontology:
539 cv = _ControlledVocabulary()
540 cv.loadFromOBO("psims", _File.getOpenMSDataPath() + "/CV/psi-ms.obo")
541 clearMVs = [cv.getTerm(m).name if m.startswith("MS:") else m for m in decodedMVs]
542 else:

Callers

nothing calls this directly

Calls 11

sumFunction · 0.85
get_keyFunction · 0.85
extractFunction · 0.85
getScoreTypeMethod · 0.80
getMetaValueMethod · 0.80
decodeMethod · 0.80
loadFromOBOMethod · 0.80
getOpenMSDataPathMethod · 0.80
typeEnum · 0.50
getKeysMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected