public PhosphoRSInput Read() { var input = new PhosphoRSInput(); while (_reader.Read()) { if (_reader.NodeType == XmlNodeType.Element) { if (_reader.Name == "Spectra") { if (input.Spectra == null) { input.Spectra = new List <Spectrum>(); } } if (_reader.Name == "Spectrum") { input.Spectra?.Add(new Spectrum( id: int.Parse(_reader["ID"]), name: _reader["Name"], precursorCharge: int.Parse(_reader["PrecursorCharge"]), activationType: SpectrumTypeHelper.ParseSpectrumType(_reader["ActivationTypes"]), peaks: null )); } if (_reader.Name == "Peaks") { var spectrum = input.Spectra?.LastOrDefault(); if (spectrum != null) { spectrum.Peaks = Peak.ParsePeaks(_reader.ReadElementContentAsString()); } } if (_reader.Name == "IdentifiedPhosphorPeptides") { var spectrum = input.Spectra?.LastOrDefault(); if (spectrum != null && spectrum.IdentifiedPhosphorPeptides == null) { spectrum.IdentifiedPhosphorPeptides = new List <Peptide>(); } } if (_reader.Name == "Peptide") { input.Spectra?.LastOrDefault()?.IdentifiedPhosphorPeptides?.Add(new Peptide( id: int.Parse(_reader["ID"]), sequence: _reader["Sequence"], modification: _reader["ModificationInfo"] )); } if (_reader.Name == "MassTolerance") { if (input.Options == null) { input.Options = new PhosphoRSOptions(); } input.Options.MassTolerance = double.Parse(_reader["Value"]); } if (_reader.Name == "MaxIsoformCount") { if (input.Options == null) { input.Options = new PhosphoRSOptions(); } input.Options.MaxIsoformCount = int.Parse(_reader["Value"]); } if (_reader.Name == "MaxPTMCount") { if (input.Options == null) { input.Options = new PhosphoRSOptions(); } input.Options.MaxPTMCount = int.Parse(_reader["Value"]); } if (_reader.Name == "ScoreNeutralLoss") { if (input.Options == null) { input.Options = new PhosphoRSOptions(); } input.Options.ScoreNeutralLoss = bool.Parse(_reader["Value"]); } if (_reader.Name == "Phosphorylation") { if (input.Options == null) { input.Options = new PhosphoRSOptions(); } input.Options.PhosphorylationSymbol = char.Parse(_reader["Symbol"]); } if (_reader.Name == "ModificationInfos") { if (input.Modifications == null) { input.Modifications = new List <Modification>(); } } if (_reader.Name == "ModificationInfo") { var s = _reader["Value"]?.Split(':'); input.Modifications?.Add(new Modification( symbol: char.Parse(_reader["Symbol"]), name: s[1], abbreviation: s[2], massDelta: double.Parse(s[3]), neutralLossAbbreviation: s[4], neutralLoss: double.Parse(s[5]), targetAminoAcids: s[6] )); } } } return(input); }
public PhosphoRSInput Read() { var spectra = new Dictionary <string, Spectral.Spectrum>(); while (true) { var spectrum = _spectralReader.Read(); if (spectrum == null) { break; } spectra.TryAdd( key: spectrum.Title, value: spectrum ); } var spectrumQueries = new List <SpectrumQuery>(); while (true) { var spectrumQuery = _peptideReader.Read(); if (spectrumQuery == null) { break; } spectrumQueries.Add(spectrumQuery); } var input = new PhosphoRSInput(); if (_options != null) { input.Options = _options; } input.Modifications.Add(Wrapper.Modification.PhosphoSTY); input.Modifications.Add(Wrapper.Modification.OxidationM); input.Modifications.Add(Wrapper.Modification.CarbamidomethylC); input.Options.PhosphorylationSymbol = input.Modifications[0].Symbol; spectrumQueries.ForEach((query, i) => { if (query.SearchResults?.Count > 0) { if (spectra.TryGetValue(query.Spectrum, out var spec)) { var spectrum = new Wrapper.Spectrum( id: (int)i, name: query.Spectrum, precursorCharge: query.Charge, activationType: input.Options.ActivationType, peaks: spec.Peaks ); query.SearchResults.ForEach(hit => { if (_options.MaxHitRank > 0 && hit.Rank > _options.MaxHitRank) { return; } var modification = Enumerable.Repeat('0', hit.Peptide.Length).ToArray(); hit.Modifications.ForEach(mod => { double Mass(char aminoAcid) { if (IMP.PhosphoRS.AminoAcid.FindAAResidue(aminoAcid, out var aa)) { return(aa.MonoisotopicMass); } return(0); }; modification[mod.Position - 1] = input.Modifications ?.Where(m => m.TargetAminoAcids.Contains(hit.Peptide[mod.Position - 1])) ?.Where(m => Math.Abs(Mass(hit.Peptide[mod.Position - 1]) + m.MassDelta - mod.Mass) <= 0.5) ?.OrderBy(m => Math.Abs(Mass(hit.Peptide[mod.Position - 1]) + m.MassDelta - mod.Mass)) ?.FirstOrDefault() ?.Symbol ?? '0'; }); var peptide = new Peptide( id: (int)i + spectrumQueries.Count * (hit.Rank - 1), sequence: hit.Peptide, modification: "0." + string.Join("", modification) + ".0" ); spectrum.IdentifiedPhosphorPeptides.Add(peptide); }); input.Spectra.Add(spectrum); } } }); return(input); }