private void WriteSpectraDetails( TextWriter w, Spectrum s ) { Tag tr = new Tag( "tr", true ); Tag td = new Tag( "td", "colspan" ); Tag th = new Tag( "th", "rowspan" ); Tag a = new Tag( "a", "href" ); int i; w.WriteLine( "<table>\n<caption><a name=\"Spectrum"+s.ID+"\"/>Spectrum "+s.SpectrumID+"</caption>" ); w.WriteLine( tr.Render(th.Render("ID")+td.Render("3",s.SpectrumID)) ); w.WriteLine( tr.Render(th.Render("Location")+td.Render("3",s.File)) ); w.Write( tr+th.Render("PSM list")+"<td colspan=\"3\">" ); if( s.Psm.Count > 0 ) { for( i = 0; i < s.Psm.Count-1; i++ ) w.Write( a.Render("#PSM"+s.Psm[i].ID,s.Psm[i].ID.ToString()) + ", " ); w.Write( a.Render("#PSM"+s.Psm[i].ID,s.Psm[i].ID.ToString()) ); } w.WriteLine( "</td>"+tr ); if( s.Psm.Count == 0 ) { w.WriteLine( "</table><br/>" ); return; } w.Write( tr+th.Render((s.Psm.Count*8).ToString(),"PSMs") ); bool first = true; foreach( PSM psm in s.Psm ) { if( first ) first = false; else w.Write( tr.ToString() ); w.Write( th.Render("8",psm.ID.ToString()) ); w.WriteLine( th.Render("<a name=\"PSM"+psm.ID+"\"/>Charge")+td.Render(psm.Charge.ToString())+tr ); tr.Hold = true; w.WriteLine( tr+th.Render("M/Z")+td.Render(psm.Mz.ToString())+tr ); w.WriteLine( tr+th.Render("Rank")+td.Render(psm.Rank.ToString())+tr ); w.WriteLine( tr+th.Render("Score")+td.Render(psm.Score<0.0?"N/A":psm.Score.ToString())+tr ); w.WriteLine( tr+th.Render("Score type")+td.Render(psm.ScoreType)+tr ); w.WriteLine( tr+th.Render("Confidence")+td.Render(psm.Confidence.ToString())+tr ); w.WriteLine( tr+th.Render("PassThreshold")+td.Render(psm.passThreshold.ToString())+tr ); w.Write( tr+th.Render("Peptide")+td ); if( psm.Peptide != null ) { w.Write( psm.Peptide.ToString() ); if( psm.Peptide.Proteins.Count > 0 ) { w.Write( " (" ); for( i = 0; i < psm.Peptide.Proteins.Count - 1; i++ ) w.Write( a.Render("#"+psm.Peptide.Proteins[i].Accession+"__"+psm.Peptide.ID,psm.Peptide.Proteins[i].EntryEx) + ", " ); w.Write( a.Render("#"+psm.Peptide.Proteins[i].Accession+"__"+psm.Peptide.ID,psm.Peptide.Proteins[i].EntryEx) + ")" ); } } else w.Write( "N/A (ProCon duplicate?)" ); w.WriteLine( td.ToString()+tr); tr.Hold = false; } w.WriteLine( "</table><br/>" ); w.Flush(); }
/// <summary> /// Removes invalid PSMs and their associated peptides (if neccessary). /// </summary> private void FilterPsms() { if( Spectra.Count == 0 ) return; List<Spectrum> spectra = new List<Spectrum>(); // Remove previous relations foreach( Peptide f in Peptides ) f.Psm = new List<PSM>(); foreach( Spectrum spectrum in Spectra ) { if( spectrum.Psm == null ) continue; Spectrum tmp = null; foreach( PSM psm in spectrum.Psm ) { if( !CheckPsm(psm) ) continue; if( tmp == null ) { tmp = new Spectrum(); tmp.File = spectrum.File; tmp.ID = spectrum.ID; tmp.SpectrumID = spectrum.SpectrumID; tmp.Psm = new List<PSM>(); } tmp.Psm.Add(psm); Peptide f = psm.Peptide; if( !f.Psm.Contains(psm) ) f.Psm.Add(psm); if( f.Confidence < psm.Confidence ) f.Confidence = psm.Confidence; } if( tmp != null ) spectra.Add(tmp); } Spectra = spectra; }
private void LoadRelations( SortedList<string,string> SortedAccession, SortedList<string,Peptide> SortedPeptides) { if( m_mzid.Data.DataCollection.AnalysisData.SpectrumIdentificationList.Length != 1 ) throw new ApplicationException( "Multiple spectrum identification lists not supported" ); SortedList<string,PeptideEvidenceType> SortedEvidences = new SortedList<string, PeptideEvidenceType>(); foreach( PeptideEvidenceType evidence in m_mzid.Data.SequenceCollection.PeptideEvidence ) SortedEvidences.Add( evidence.id, evidence ); int SpectrumID = 1; int PsmID = 1; double score; string type; Peptide.ConfidenceType confidence; foreach( SpectrumIdentificationResultType idres in m_mzid.Data.DataCollection.AnalysisData.SpectrumIdentificationList[0].SpectrumIdentificationResult ) { Spectrum spectrum = new Spectrum(); spectrum.ID = SpectrumID++; spectrum.File = idres.spectraData_ref; spectrum.SpectrumID = idres.spectrumID; spectrum.Psm = new List<PSM>(); Spectra.Add(spectrum); foreach( SpectrumIdentificationItemType item in idres.SpectrumIdentificationItem ) { //Console.Out.WriteLine(item.id); GetPsmScore( item, out score, out type, out confidence ); PSM psm = new PSM(); psm.ID = PsmID++; psm.Charge = item.chargeState; psm.Mz = item.experimentalMassToCharge; psm.Rank = item.rank; psm.Score = score; psm.ScoreType = type; psm.Confidence = confidence; psm.passThreshold = item.passThreshold; psm.Spectrum = spectrum; spectrum.Psm.Add(psm); if( item.PeptideEvidenceRef == null ) continue; foreach( PeptideEvidenceRefType evref in item.PeptideEvidenceRef ) { //Console.Out.WriteLine(evref.peptideEvidence_ref); PeptideEvidenceType evidence = SortedEvidences[evref.peptideEvidence_ref]; Peptide pep = SortedPeptides[evidence.peptide_ref]; if( pep.Sequence == null || pep.Sequence.Length == 0 ) { // ProCon 0.9.348 bug //Notify( "Skiped peptide with empty sequence: " + pep.DBRef ); continue; } pep.Decoy = evidence.isDecoy; psm.Peptide = pep; //pep.Psm.Add(psm); Protein prot = m_SortedProteins[SortedAccession[evidence.dBSequence_ref]]; if( pep.Proteins.Contains(prot) ) continue; prot.Peptides.Add( pep ); pep.Proteins.Add( prot ); } } } }