Identification Data¶
In OpenMS, identifications of peptides, proteins and small molecules are stored
in dedicated data structures. These data structures are typically stored to disc
as idXML or mzIdentML file. The highest-level structure is
ProteinIdentification
. It stores all identified proteins of an identification
run as ProteinHit objects plus additional metadata (search parameters, etc.). Each
ProteinHit
contains the actual protein accession, an associated score, and
(optionally) the protein sequence.
A PeptideIdentification
object stores the
data corresponding to a single identified spectrum or feature. It has members
for the retention time, m/z, and a vector of PeptideHit
objects. Each PeptideHit
stores the information of a specific peptide-to-spectrum match or PSM (e.g., the score
and the peptide sequence). Each PeptideHit
also contains a vector of
PeptideEvidence
objects which store the reference to one or more (in the case the
peptide maps to multiple proteins) proteins and the position therein.
ProteinIdentification¶
We can create an object of type ProteinIdentification
and populate it with
ProteinHit
objects as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 | from pyopenms import *
# Create new protein identification object corresponding to a single search
protein_id = ProteinIdentification()
protein_id.setIdentifier("IdentificationRun1")
# Each ProteinIdentification object stores a vector of protein hits
protein_hit = ProteinHit()
protein_hit.setAccession("MyAccession")
protein_hit.setSequence("PEPTIDEPEPTIDEPEPTIDEPEPTIDER")
protein_hit.setScore(1.0)
protein_id.setHits([protein_hit])
|
We have now added a single ProteinHit
with the accession MyAccession
to
the ProteinIdentification
object (note how on line 14 we directly added a
list of size 1). We can continue to add meta-data for the whole identification
run (such as search parameters):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | now = DateTime.now()
date_string = now.getDate()
protein_id.setDateTime(now)
# Example of possible search parameters
search_parameters = SearchParameters() # ProteinIdentification::SearchParameters
search_parameters.db = "database"
search_parameters.charges = "+2"
protein_id.setSearchParameters(search_parameters)
# Some search engine meta data
protein_id.setSearchEngineVersion("v1.0.0")
protein_id.setSearchEngine("SearchEngine")
protein_id.setScoreType("HyperScore")
# Iterate over all protein hits
for hit in protein_id.getHits():
print("Protein hit accession:", hit.getAccession())
print("Protein hit sequence:", hit.getSequence())
print("Protein hit score:", hit.getScore())
|
PeptideIdentification¶
Next, we can also create a PeptideIdentification
object and add
corresponding PeptideHit
objects:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | peptide_id = PeptideIdentification()
peptide_id.setRT(1243.56)
peptide_id.setMZ(440.0)
peptide_id.setScoreType("ScoreType")
peptide_id.setHigherScoreBetter(False)
peptide_id.setIdentifier("IdentificationRun1")
# define additional meta value for the peptide identification
peptide_id.setMetaValue("AdditionalMetaValue", b"Value")
# create a new PeptideHit (best PSM)
peptide_hit = PeptideHit()
peptide_hit.setScore(1.0)
peptide_hit.setRank(1)
peptide_hit.setCharge(2)
peptide_hit.setSequence(AASequence.fromString("DLQM(Oxidation)TQSPSSLSVSVGDR"))
# create a new PeptideHit (second best PSM)
peptide_hit2 = PeptideHit()
peptide_hit2.setScore(0.5)
peptide_hit2.setRank(2)
peptide_hit2.setCharge(2)
peptide_hit2.setSequence(AASequence.fromString("QDLM(Oxidation)TQSPSSLSVSVGDR"))
# add PeptideHit to PeptideIdentification
peptide_id.setHits([peptide_hit, peptide_hit2])
# Iterate over PeptideIdentification
peptide_ids = [peptide_id]
for peptide_id in peptide_ids:
# Peptide identification values
print ("Peptide ID m/z:", peptide_id.getMZ())
print ("Peptide ID rt:", peptide_id.getRT())
print ("Peptide ID score type:", peptide_id.getScoreType())
# PeptideHits
for hit in peptide_id.getHits():
print(" - Peptide hit rank:", hit.getRank())
print(" - Peptide hit sequence:", hit.getSequence().toString())
print(" - Peptide hit score:", hit.getScore())
|
This allows us to represent single spectra (PeptideIdentification
at m/z
440.0 and rt 1234.56) with possible identifications that are ranked by score.
In this case, apparently two possible peptides match the spectrum which have
the first three amino acids in a different order “DLQ” vs “QDL”).
Storage on disk¶
Finally, we can store the peptide and protein identification data in a
idXML
file (a OpenMS internal file format which we have previously
discussed here)
which we would do as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # Store the identification data in an idXML file
IdXMLFile().store("out.idXML", [protein_id], peptide_ids)
# and load it back into memory
prot_ids = []; pep_ids = []
IdXMLFile().load("out.idXML", prot_ids, pep_ids)
# Iterate over all protein hits
for protein_id in prot_ids:
for hit in protein_id.getHits():
print("Protein hit accession:", hit.getAccession())
print("Protein hit sequence:", hit.getSequence().decode())
print("Protein hit score:", hit.getScore())
# Iterate over PeptideIdentification
for peptide_id in pep_ids:
# Peptide identification values
print ("Peptide ID m/z:", peptide_id.getMZ())
print ("Peptide ID rt:", peptide_id.getRT())
print ("Peptide ID score type:", peptide_id.getScoreType())
# PeptideHits
for hit in peptide_id.getHits():
print(" - Peptide hit rank:", hit.getRank())
print(" - Peptide hit sequence:", hit.getSequence().toString())
print(" - Peptide hit score:", hit.getScore())
|