diff --git a/MetaMorpheus/EngineLayer/Calibration/DataPointAcquisitionEngine.cs b/MetaMorpheus/EngineLayer/Calibration/DataPointAcquisitionEngine.cs index e3b7c2d0f..021b1a86e 100644 --- a/MetaMorpheus/EngineLayer/Calibration/DataPointAcquisitionEngine.cs +++ b/MetaMorpheus/EngineLayer/Calibration/DataPointAcquisitionEngine.cs @@ -14,7 +14,7 @@ public class DataPointAcquisitionEngine : MetaMorpheusEngine { private const double FineResolutionForIsotopeDistCalculation = 0.1; - private readonly List GoodIdentifications; + private readonly List GoodIdentifications; private readonly List GoodScans; private readonly MsDataFile MyMsDataFile; private readonly Tolerance PrecursorMassTolerance; @@ -22,7 +22,7 @@ public class DataPointAcquisitionEngine : MetaMorpheusEngine private readonly int MinMS1isotopicPeaksNeededForConfirmedIdentification; public DataPointAcquisitionEngine( - List goodIdentifications, + List goodIdentifications, List goodScans, MsDataFile myMsDataFile, Tolerance precursorMassTolerance, @@ -65,16 +65,16 @@ protected override MetaMorpheusEngineResults RunSpecific() // Stop loop if canceled if (GlobalVariables.StopLoops) { return; } - PeptideSpectralMatch identification = GoodIdentifications[matchIndex]; + SpectralMatch identification = GoodIdentifications[matchIndex]; // Each identification has an MS2 spectrum attached to it. int ms2scanNumber = identification.ScanNumber; int peptideCharge = identification.ScanPrecursorCharge; //skip if ambiguous - if (identification.FullSequence == null || identification.BestMatchingPeptides.Any(p => p.Peptide.AllModsOneIsNterminus.Any(m => m.Value.ChemicalFormula == null))) + if (identification.FullSequence == null || identification.BestMatchingBioPolymersWithSetMods.Any(p => p.Peptide.AllModsOneIsNterminus.Any(m => m.Value.ChemicalFormula == null))) continue; - var representativeSinglePeptide = identification.BestMatchingPeptides.First().Peptide; + var representativeSinglePeptide = identification.BestMatchingBioPolymersWithSetMods.First().Peptide; // Get the peptide, don't forget to add the modifications!!!! var SequenceWithChemicalFormulas = representativeSinglePeptide.SequenceWithChemicalFormulas; @@ -126,7 +126,7 @@ protected override MetaMorpheusEngineResults RunSpecific() ); } - private (List, int, int) SearchMS1Spectra(double[] theoreticalMasses, double[] theoreticalIntensities, int ms2spectrumIndex, int direction, int peptideCharge, PeptideSpectralMatch identification) + private (List, int, int) SearchMS1Spectra(double[] theoreticalMasses, double[] theoreticalIntensities, int ms2spectrumIndex, int direction, int peptideCharge, SpectralMatch identification) { List result = new List(); int numMs1MassChargeCombinationsConsidered = 0; @@ -220,7 +220,7 @@ protected override MetaMorpheusEngineResults RunSpecific() return (result, numMs1MassChargeCombinationsConsidered, numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks); } - private static List SearchMS2Spectrum(Ms2ScanWithSpecificMass ms2DataScan, PeptideSpectralMatch identification, Tolerance ms2Tolerance) + private static List SearchMS2Spectrum(Ms2ScanWithSpecificMass ms2DataScan, SpectralMatch identification, Tolerance ms2Tolerance) { List result = new List(); diff --git a/MetaMorpheus/EngineLayer/Calibration/DataPointAquisitionResults.cs b/MetaMorpheus/EngineLayer/Calibration/DataPointAquisitionResults.cs index 449f2456e..8aaf2f9fc 100644 --- a/MetaMorpheus/EngineLayer/Calibration/DataPointAquisitionResults.cs +++ b/MetaMorpheus/EngineLayer/Calibration/DataPointAquisitionResults.cs @@ -11,7 +11,7 @@ public class DataPointAquisitionResults : MetaMorpheusEngineResults { public DataPointAquisitionResults( MetaMorpheusEngine dataPointAcquisitionEngine, - List psms, + List psms, List ms1List, List ms2List, int numMs1MassChargeCombinationsConsidered, @@ -41,7 +41,7 @@ public DataPointAquisitionResults( NumMs2MassChargeCombinationsConsidered = numMs2MassChargeCombinationsConsidered; NumMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks = numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks; - var precursorErrors = psms.Select(p => (p.ScanPrecursorMass - p.PeptideMonisotopicMass.Value) / p.PeptideMonisotopicMass.Value * 1e6).ToList(); + var precursorErrors = psms.Select(p => (p.ScanPrecursorMass - p.BioPolymerWithSetModsMonoisotopicMass.Value) / p.BioPolymerWithSetModsMonoisotopicMass.Value * 1e6).ToList(); PsmPrecursorIqrPpmError = precursorErrors.InterquartileRange(); PsmPrecursorMedianPpmError = precursorErrors.Median(); @@ -67,7 +67,7 @@ public DataPointAquisitionResults( public readonly double PsmProductMedianPpmError; public readonly double PsmPrecursorIqrPpmError; public readonly double PsmProductIqrPpmError; - public readonly List Psms; + public readonly List Psms; public int Count { get { return Ms1List.Count + Ms2List.Count; } } diff --git a/MetaMorpheus/EngineLayer/Calibration/LabeledDataPoint.cs b/MetaMorpheus/EngineLayer/Calibration/LabeledDataPoint.cs index 4c8b29118..c7c14ac2d 100644 --- a/MetaMorpheus/EngineLayer/Calibration/LabeledDataPoint.cs +++ b/MetaMorpheus/EngineLayer/Calibration/LabeledDataPoint.cs @@ -9,9 +9,9 @@ public class LabeledDataPoint public readonly double LogIntensity; public readonly double TheoreticalMz; public readonly double RelativeMzError; - public readonly PeptideSpectralMatch Identification; + public readonly SpectralMatch Identification; - public LabeledDataPoint(double experimentalMz, int scanNumber, double logTotalIonCurrent, double logInjectionTime, double logIntensity, double theoreticalMz, PeptideSpectralMatch identification) + public LabeledDataPoint(double experimentalMz, int scanNumber, double logTotalIonCurrent, double logInjectionTime, double logIntensity, double theoreticalMz, SpectralMatch identification) { this.ExperimentalMz = experimentalMz; this.ScanNumber = scanNumber; diff --git a/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs b/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs index cf6a78717..ee15ab360 100644 --- a/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs @@ -20,12 +20,12 @@ public class ClassicSearchEngine : MetaMorpheusEngine private readonly List VariableModifications; private readonly List SilacLabels; private readonly (SilacLabel StartLabel, SilacLabel EndLabel)? TurnoverLabels; - private readonly PeptideSpectralMatch[] PeptideSpectralMatches; + private readonly SpectralMatch[] PeptideSpectralMatches; private readonly Ms2ScanWithSpecificMass[] ArrayOfSortedMS2Scans; private readonly double[] MyScanPrecursorMasses; private readonly bool WriteSpectralLibrary; - public ClassicSearchEngine(PeptideSpectralMatch[] globalPsms, Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans, + public ClassicSearchEngine(SpectralMatch[] globalPsms, Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans, List variableModifications, List fixedModifications, List silacLabels, SilacLabel startLabel, SilacLabel endLabel, List proteinList, MassDiffAcceptor searchMode, CommonParameters commonParameters, List<(string FileName, CommonParameters Parameters)> fileSpecificParameters, SpectralLibrary spectralLibrary, List nestedIds, bool writeSpectralLibrary) @@ -163,7 +163,7 @@ protected override MetaMorpheusEngineResults RunSpecific() }); } - foreach (PeptideSpectralMatch psm in PeptideSpectralMatches.Where(p => p != null)) + foreach (SpectralMatch psm in PeptideSpectralMatches.Where(p => p != null)) { psm.ResolveAllAmbiguities(); } @@ -201,7 +201,7 @@ private void AddPeptideCandidateToPsm(ScanWithIndexAndNotchInfo scan, object[] m // valid hit (met the cutoff score); lock the scan to prevent other threads from accessing it lock (myLocks[scan.ScanIndex]) { - bool scoreImprovement = PeptideSpectralMatches[scan.ScanIndex] == null || (thisScore - PeptideSpectralMatches[scan.ScanIndex].RunnerUpScore) > -PeptideSpectralMatch.ToleranceForScoreDifferentiation; + bool scoreImprovement = PeptideSpectralMatches[scan.ScanIndex] == null || (thisScore - PeptideSpectralMatches[scan.ScanIndex].RunnerUpScore) > -SpectralMatch.ToleranceForScoreDifferentiation; if (scoreImprovement) { diff --git a/MetaMorpheus/EngineLayer/ClassicSearch/MiniClassicSearchEngine.cs b/MetaMorpheus/EngineLayer/ClassicSearch/MiniClassicSearchEngine.cs index 6a3faca2d..854609313 100644 --- a/MetaMorpheus/EngineLayer/ClassicSearch/MiniClassicSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ClassicSearch/MiniClassicSearchEngine.cs @@ -1,6 +1,7 @@ using MassSpectrometry; using MassSpectrometry.MzSpectra; using MzLibUtil; +using Omics; using Omics.Fragmentation; using Proteomics.ProteolyticDigestion; using System; @@ -42,7 +43,7 @@ public MiniClassicSearchEngine( /// Ms2 scans in window are searched for matches to this donor peptide /// The center of the 2 minute window where the search occurs /// - public IEnumerable SearchAroundPeak(PeptideWithSetModifications donorPwsm, double peakApexRT) + public IEnumerable SearchAroundPeak(IBioPolymerWithSetMods donorPwsm, double peakApexRT) { var targetFragmentsForEachDissociationType = new Dictionary>(); @@ -66,7 +67,7 @@ public IEnumerable SearchAroundPeak(PeptideWithSetModifica return null; } - List acceptablePsms = new(); + List acceptablePsms = new(); foreach (ScanWithIndexAndNotchInfo scan in acceptableScans) { var dissociationType = FileSpecificParameters.DissociationType == DissociationType.Autodetect ? @@ -95,8 +96,8 @@ public IEnumerable SearchAroundPeak(PeptideWithSetModifica acceptablePsms.Add(new PeptideSpectralMatch(donorPwsm, scan.Notch, thisScore, scan.ScanIndex, scan.TheScan, FileSpecificParameters, matchedIons, 0)); } - IEnumerable matchedSpectra = acceptablePsms.Where(p => p != null); - foreach (PeptideSpectralMatch psm in matchedSpectra) + IEnumerable matchedSpectra = acceptablePsms.Where(p => p != null); + foreach (SpectralMatch psm in matchedSpectra) { psm.ResolveAllAmbiguities(); } @@ -106,7 +107,7 @@ public IEnumerable SearchAroundPeak(PeptideWithSetModifica return matchedSpectra; } - public static void CalculateSpectralAngles(SpectralLibrary spectralLibrary, PeptideSpectralMatch[] psms, + public static void CalculateSpectralAngles(SpectralLibrary spectralLibrary, SpectralMatch[] psms, Ms2ScanWithSpecificMass[] arrayOfSortedMs2Scans, CommonParameters commonParameters, CommonParameters fileSpecificParameters) { if (spectralLibrary != null) @@ -128,12 +129,12 @@ public static void CalculateSpectralAngles(SpectralLibrary spectralLibrary, Pept if (psms[i] != null) { Ms2ScanWithSpecificMass scan = arrayOfSortedMs2Scans[psms[i].ScanIndex]; - List<(int, PeptideWithSetModifications)> pwsms = new(); + List<(int, IBioPolymerWithSetMods)> pwsms = new(); List pwsmSpectralAngles = new(); - foreach (var (Notch, Peptide) in psms[i].BestMatchingPeptides) + foreach (var (Notch, Peptide) in psms[i].BestMatchingBioPolymersWithSetMods) { //if peptide is target, directly look for the target's spectrum in the spectral library - if (!Peptide.Protein.IsDecoy && spectralLibrary.TryGetSpectrum(Peptide.FullSequence, scan.PrecursorCharge, out var librarySpectrum)) + if (!Peptide.Parent.IsDecoy && spectralLibrary.TryGetSpectrum(Peptide.FullSequence, scan.PrecursorCharge, out var librarySpectrum)) { SpectralSimilarity s = new SpectralSimilarity(scan.TheScan.MassSpectrum, librarySpectrum.XArray, librarySpectrum.YArray, SpectralSimilarity.SpectrumNormalizationScheme.squareRootSpectrumSum, fileSpecificParameters.ProductMassTolerance.Value, false); diff --git a/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkSearchEngine.cs b/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkSearchEngine.cs index 48ea48c44..e9cda06d3 100644 --- a/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkSearchEngine.cs @@ -734,7 +734,7 @@ private List ScoreChildScan(Ms2ScanWithSpecificMass parentSc } var peptideWithMod = new PeptideWithSetModifications(mainPeptide.Protein, mainPeptide.DigestionParams, - mainPeptide.OneBasedStartResidueInProtein, mainPeptide.OneBasedEndResidueInProtein, + mainPeptide.OneBasedStartResidue, mainPeptide.OneBasedEndResidue, mainPeptide.CleavageSpecificityForFdrCategory, mainPeptide.PeptideDescription, mainPeptide.MissedCleavages, mod, mainPeptide.NumFixedMods); @@ -784,8 +784,8 @@ private CrosslinkSpectralMatch LocalizeDeadEndSite(PeptideWithSetModifications o mods.Add(location + 1, deadEndMod); - var localizedPeptide = new PeptideWithSetModifications(originalPeptide.Protein, originalPeptide.DigestionParams, originalPeptide.OneBasedStartResidueInProtein, - originalPeptide.OneBasedEndResidueInProtein, originalPeptide.CleavageSpecificityForFdrCategory, originalPeptide.PeptideDescription, originalPeptide.MissedCleavages, mods, originalPeptide.NumFixedMods); + var localizedPeptide = new PeptideWithSetModifications(originalPeptide.Protein, originalPeptide.DigestionParams, originalPeptide.OneBasedStartResidue, + originalPeptide.OneBasedEndResidue, originalPeptide.CleavageSpecificityForFdrCategory, originalPeptide.PeptideDescription, originalPeptide.MissedCleavages, mods, originalPeptide.NumFixedMods); localizedPeptide.Fragment(commonParameters.DissociationType, FragmentationTerminus.Both, products); var matchedFragmentIons = MatchFragmentIons(theScan, products, commonParameters); diff --git a/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkSpectralMatch.cs b/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkSpectralMatch.cs index 2a65083f2..4bdf2522c 100644 --- a/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkSpectralMatch.cs +++ b/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkSpectralMatch.cs @@ -23,9 +23,9 @@ public CrosslinkSpectralMatch( { //The XLTotalScore is set here because some CSMs are not crosslinks and we need this score to be non-zero. XLTotalScore = score; - _BestMatchingPeptides.Clear(); + _BestMatchingBioPolymersWithSetMods.Clear(); - _BestMatchingPeptides.Add((0, theBestPeptide)); + _BestMatchingBioPolymersWithSetMods.Add((0, theBestPeptide)); } @@ -95,40 +95,40 @@ public void ResolveProteinPosAmbiguitiesForXl() if (CrossType == PsmCrossType.Cross) { // alpha peptide crosslink residue in the protein - XlProteinPos = OneBasedStartResidueInProtein == null ? (int?)null : OneBasedStartResidueInProtein.Value + LinkPositions[0] - 1; + XlProteinPos = OneBasedStartResidue == null ? (int?)null : OneBasedStartResidue.Value + LinkPositions[0] - 1; // beta crosslink residue in protein - BetaPeptide.XlProteinPos = BetaPeptide.OneBasedStartResidueInProtein == null ? (int?)null : BetaPeptide.OneBasedStartResidueInProtein.Value + BetaPeptide.LinkPositions[0] - 1; + BetaPeptide.XlProteinPos = BetaPeptide.OneBasedStartResidue == null ? (int?)null : BetaPeptide.OneBasedStartResidue.Value + BetaPeptide.LinkPositions[0] - 1; } else if (CrossType == PsmCrossType.DeadEnd || CrossType == PsmCrossType.DeadEndH2O || CrossType == PsmCrossType.DeadEndNH2 || CrossType == PsmCrossType.DeadEndTris) { - XlProteinPos = OneBasedStartResidueInProtein == null ? (int?)null : OneBasedStartResidueInProtein.Value + LinkPositions[0] - 1; + XlProteinPos = OneBasedStartResidue == null ? (int?)null : OneBasedStartResidue.Value + LinkPositions[0] - 1; } else if (CrossType == PsmCrossType.Loop) { - XlProteinPos = OneBasedStartResidueInProtein == null ? (int?)null : OneBasedStartResidueInProtein.Value + LinkPositions[0] - 1; + XlProteinPos = OneBasedStartResidue == null ? (int?)null : OneBasedStartResidue.Value + LinkPositions[0] - 1; - XlProteinPosLoop = OneBasedStartResidueInProtein == null ? (int?)null : OneBasedStartResidueInProtein.Value + LinkPositions[1] - 1; + XlProteinPosLoop = OneBasedStartResidue == null ? (int?)null : OneBasedStartResidue.Value + LinkPositions[1] - 1; } } public static bool IsIntraCsm(CrosslinkSpectralMatch csm) { //The pair "ProteinA and Decoy_ProteinA" is count for intra-crosslink. - if (csm.ProteinAccession != null && csm.BetaPeptide.ProteinAccession != null) + if (csm.Accession != null && csm.BetaPeptide.Accession != null) { - if (csm.ProteinAccession == csm.BetaPeptide.ProteinAccession || - csm.ProteinAccession == "DECOY_"+ csm.BetaPeptide.ProteinAccession || - csm.BetaPeptide.ProteinAccession == "DECOY_" + csm.ProteinAccession) + if (csm.Accession == csm.BetaPeptide.Accession || + csm.Accession == "DECOY_"+ csm.BetaPeptide.Accession || + csm.BetaPeptide.Accession == "DECOY_" + csm.Accession) { return true; } } - if (csm.ProteinAccession == null) + if (csm.Accession == null) { - var alphaProteins = csm.BestMatchingPeptides.Select(p => p.Peptide.Protein.Accession).ToList(); - var betaProteins = csm.BetaPeptide.BestMatchingPeptides.Select(p => p.Peptide.Protein.Accession).ToList(); + var alphaProteins = csm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide.Parent.Accession).ToList(); + var betaProteins = csm.BetaPeptide.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide.Parent.Accession).ToList(); foreach (var alpha in alphaProteins) { @@ -169,20 +169,20 @@ public static void ResolveProteinPosAmbiguitiesForXl(CrosslinkSpectralMatch csm) if (csm.CrossType == PsmCrossType.Cross || csm.CrossType == PsmCrossType.Intra || csm.CrossType == PsmCrossType.Inter) { // alpha peptide crosslink residue in the protein - csm.XlProteinPos = csm.OneBasedStartResidueInProtein == null ? (int?)null : csm.OneBasedStartResidueInProtein.Value + csm.LinkPositions[0] - 1; + csm.XlProteinPos = csm.OneBasedStartResidue == null ? (int?)null : csm.OneBasedStartResidue.Value + csm.LinkPositions[0] - 1; // beta crosslink residue in protein - csm.BetaPeptide.XlProteinPos = csm.BetaPeptide.OneBasedStartResidueInProtein == null ? (int?)null : csm.BetaPeptide.OneBasedStartResidueInProtein.Value + csm.BetaPeptide.LinkPositions[0] - 1; + csm.BetaPeptide.XlProteinPos = csm.BetaPeptide.OneBasedStartResidue == null ? (int?)null : csm.BetaPeptide.OneBasedStartResidue.Value + csm.BetaPeptide.LinkPositions[0] - 1; } else if (csm.CrossType == PsmCrossType.DeadEnd || csm.CrossType == PsmCrossType.DeadEndH2O || csm.CrossType == PsmCrossType.DeadEndNH2 || csm.CrossType == PsmCrossType.DeadEndTris) { - csm.XlProteinPos = csm.OneBasedStartResidueInProtein == null ? (int?)null : csm.OneBasedStartResidueInProtein.Value + csm.LinkPositions[0] - 1; + csm.XlProteinPos = csm.OneBasedStartResidue == null ? (int?)null : csm.OneBasedStartResidue.Value + csm.LinkPositions[0] - 1; } else if (csm.CrossType == PsmCrossType.Loop) { - csm.XlProteinPos = csm.OneBasedStartResidueInProtein == null ? (int?)null : csm.OneBasedStartResidueInProtein.Value + csm.LinkPositions[0] - 1; + csm.XlProteinPos = csm.OneBasedStartResidue == null ? (int?)null : csm.OneBasedStartResidue.Value + csm.LinkPositions[0] - 1; - csm.XlProteinPosLoop = csm.OneBasedStartResidueInProtein == null ? (int?)null : csm.OneBasedStartResidueInProtein.Value + csm.LinkPositions[1] - 1; + csm.XlProteinPosLoop = csm.OneBasedStartResidue == null ? (int?)null : csm.OneBasedStartResidue.Value + csm.LinkPositions[1] - 1; } } @@ -193,8 +193,8 @@ public static List GetPossibleCrosslinkerModSites(char[] crosslinkerModSite bool wildcard = crosslinkerModSites.Any(p => p == 'X'); var range = Enumerable.Range(0, peptide.BaseSequence.Length); - if (!CrosslinkAtCleavageSite && peptide.OneBasedEndResidueInProtein != peptide.Protein.Length - && !peptide.Protein.ProteolysisProducts.Any(x => x.OneBasedEndPosition == peptide.OneBasedEndResidueInProtein)) + if (!CrosslinkAtCleavageSite && peptide.OneBasedEndResidue != peptide.Protein.Length + && !peptide.Protein.ProteolysisProducts.Any(x => x.OneBasedEndPosition == peptide.OneBasedEndResidue)) { //The C termial cannot be crosslinked and cleaved. range = Enumerable.Range(0, peptide.BaseSequence.Length - 1); @@ -373,13 +373,13 @@ public override string ToString() } sb.Append("\t"); //Intentionally left empty for readability in the tsv file. - List pepsWithMods = BestMatchingPeptides.Select(p => p.Peptide).ToList(); - var proteinAccessionString = ProteinAccession ?? PsmTsvWriter.Resolve(pepsWithMods.Select(b => b.Protein.Accession), FullSequence).ResolvedString; + List pepsWithMods = BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide as PeptideWithSetModifications).ToList(); + var proteinAccessionString = Accession ?? PsmTsvWriter.Resolve(pepsWithMods.Select(b => b.Protein.Accession), FullSequence).ResolvedString; sb.Append(proteinAccessionString + "\t"); sb.Append(XlProteinPos + (XlProteinPosLoop.HasValue ? "~" + XlProteinPosLoop.Value : null) + "\t"); sb.Append(BaseSequence + "\t"); sb.Append(FullSequence + position + "\t"); - sb.Append((PeptideMonisotopicMass.HasValue ? PeptideMonisotopicMass.Value.ToString() : "---")); + sb.Append((BioPolymerWithSetModsMonoisotopicMass.HasValue ? BioPolymerWithSetModsMonoisotopicMass.Value.ToString() : "---")); sb.Append("\t"); sb.Append(Score + "\t"); @@ -422,13 +422,13 @@ public override string ToString() if (BetaPeptide != null) { sb.Append("\t"); //Intentionally left empty for readability in the tsv file. - List betaPepsWithMods = BetaPeptide.BestMatchingPeptides.Select(p => p.Peptide).ToList(); - var betaProteinAccessionString = BetaPeptide.ProteinAccession ?? PsmTsvWriter.Resolve(betaPepsWithMods.Select(b => b.Protein.Accession), FullSequence).ResolvedString; + List betaPepsWithMods = BetaPeptide.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide as PeptideWithSetModifications).ToList(); + var betaProteinAccessionString = BetaPeptide.Accession ?? PsmTsvWriter.Resolve(betaPepsWithMods.Select(b => b.Protein.Accession), FullSequence).ResolvedString; sb.Append(betaProteinAccessionString + "\t"); sb.Append(BetaPeptide.XlProteinPos + "\t"); sb.Append(BetaPeptide.BaseSequence + "\t"); sb.Append(BetaPeptide.FullSequence + "(" + BetaPeptide.LinkPositions[0].ToString() + ")" + "\t"); - sb.Append(BetaPeptide.PeptideMonisotopicMass.ToString() + "\t"); + sb.Append(BetaPeptide.BioPolymerWithSetModsMonoisotopicMass.ToString() + "\t"); sb.Append(BetaPeptide.Score + "\t"); if (BetaPeptide.ChildMatchedFragmentIons == null) @@ -469,7 +469,7 @@ public override string ToString() sb.Append(XLTotalScore + "\t"); // mass of crosslinker - sb.Append(((PeptideMonisotopicMass.HasValue) ? (ScanPrecursorMass - BetaPeptide.PeptideMonisotopicMass - PeptideMonisotopicMass.Value).ToString() : "---")); sb.Append("\t"); + sb.Append(((BioPolymerWithSetModsMonoisotopicMass.HasValue) ? (ScanPrecursorMass - BetaPeptide.BioPolymerWithSetModsMonoisotopicMass - BioPolymerWithSetModsMonoisotopicMass.Value).ToString() : "---")); sb.Append("\t"); sb.Append(XlRank.ToString() + "\t"); diff --git a/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkedPeptides.cs b/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkedPeptides.cs index ef293057e..01270aec8 100644 --- a/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkedPeptides.cs +++ b/MetaMorpheus/EngineLayer/CrosslinkSearch/CrosslinkedPeptides.cs @@ -42,8 +42,8 @@ public static IEnumerable>> XlGetTheoreticalFragments(D testMods.Add(mod.Key, mod.Value); } - var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, - peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods); + var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidue, + peptide.OneBasedEndResidue, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods); testPeptide.Fragment(dissociationType, FragmentationTerminus.Both, fragments); @@ -110,7 +110,7 @@ public static Dictionary, List> XlLoopGetTheoreticalFra modDict.Add(position1 + 1, loopMass); } PeptideWithSetModifications peptideWithLoop = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, - peptide.OneBasedStartResidueInProtein, peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, + peptide.OneBasedStartResidue, peptide.OneBasedEndResidue, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, modDict, peptide.NumFixedMods); peptideWithLoop.Fragment(dissociationType, FragmentationTerminus.Both, loopProducts); @@ -134,7 +134,7 @@ public static Dictionary, List> XlLoopGetTheoreticalFra modDict.Add(position2 + 1, loopMass); } peptideWithLoop = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, - peptide.OneBasedStartResidueInProtein, peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, + peptide.OneBasedStartResidue, peptide.OneBasedEndResidue, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, modDict, peptide.NumFixedMods); peptideWithLoop.Fragment(dissociationType, FragmentationTerminus.Both, loopProducts); diff --git a/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs b/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs index 95c8bc3a8..0a006d5fb 100644 --- a/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs +++ b/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs @@ -6,14 +6,14 @@ namespace EngineLayer.FdrAnalysis { public class FdrAnalysisEngine : MetaMorpheusEngine { - private List AllPsms; + private List AllPsms; private readonly int MassDiffAcceptorNumNotches; private readonly double ScoreCutoff; private readonly string AnalysisType; private readonly string OutputFolder; // used for storing PEP training models private readonly bool DoPEP; - public FdrAnalysisEngine(List psms, int massDiffAcceptorNumNotches, CommonParameters commonParameters, + public FdrAnalysisEngine(List psms, int massDiffAcceptorNumNotches, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds, string analysisType = "PSM", bool doPEP = true, string outputFolder = null) : base(commonParameters, fileSpecificParameters, nestedIds) { AllPsms = psms; @@ -49,7 +49,7 @@ private void DoFalseDiscoveryRateAnalysis(FdrAnalysisResults myAnalysisResults) { var psms = proteasePsms.ToList(); - psms = psms.OrderByDescending(b => b.Score).ThenBy(b => b.PeptideMonisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.PeptideMonisotopicMass.Value) : double.MaxValue).ToList(); + psms = psms.OrderByDescending(b => b.Score).ThenBy(b => b.BioPolymerWithSetModsMonoisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.BioPolymerWithSetModsMonoisotopicMass.Value) : double.MaxValue).ToList(); QValueTraditional(psms); if (psms.Count > 100) @@ -69,7 +69,7 @@ private void DoFalseDiscoveryRateAnalysis(FdrAnalysisResults myAnalysisResults) for (int i = psms.Count - 1; i >= 0; i--) { - PeptideSpectralMatch psm = psms[i]; + SpectralMatch psm = psms[i]; // threshold q-values if (psm.FdrInfo.QValue > qValueThreshold) @@ -99,13 +99,13 @@ private void DoFalseDiscoveryRateAnalysis(FdrAnalysisResults myAnalysisResults) } } - private void QValueInverted(List psms) + private void QValueInverted(List psms) { psms.Reverse(); bool first = true; double previousQValue = 1.0; double previousQvalueNotch = 1.0; - foreach (PeptideSpectralMatch psm in psms) + foreach (SpectralMatch psm in psms) { double cumulativeTarget = psm.FdrInfo.CumulativeTarget; double cumulativeDecoy = psm.FdrInfo.CumulativeDecoy; @@ -140,7 +140,7 @@ private void QValueInverted(List psms) psms.Reverse(); //we inverted the psms for this calculation. now we need to put them back into the original order } - private void QValueTraditional(List psms) + private void QValueTraditional(List psms) { double cumulativeTarget = 0; double cumulativeDecoy = 0; @@ -155,7 +155,7 @@ private void QValueTraditional(List psms) // Stop if canceled if (GlobalVariables.StopLoops) { break; } - PeptideSpectralMatch psm = psms[i]; + SpectralMatch psm = psms[i]; int notch = psm.Notch ?? MassDiffAcceptorNumNotches; if (psm.IsDecoy) { @@ -164,10 +164,10 @@ private void QValueTraditional(List psms) // e.g. if the PSM matched to 1 target and 2 decoys, it counts as 2/3 decoy double decoyHits = 0; double totalHits = 0; - var hits = psm.BestMatchingPeptides.GroupBy(p => p.Peptide.FullSequence); + var hits = psm.BestMatchingBioPolymersWithSetMods.GroupBy(p => p.Peptide.FullSequence); foreach (var hit in hits) { - if (hit.First().Peptide.Protein.IsDecoy) + if (hit.First().Peptide.Parent.IsDecoy) { decoyHits++; } @@ -226,7 +226,7 @@ public void Compute_PEPValue(FdrAnalysisResults myAnalysisResults) } } - public static void Compute_PEPValue_Based_QValue(List psms) + public static void Compute_PEPValue_Based_QValue(List psms) { double[] allPEPValues = psms.Select(p => p.FdrInfo.PEP).ToArray(); int[] psmsArrayIndicies = Enumerable.Range(0, psms.Count).ToArray(); @@ -241,11 +241,11 @@ public static void Compute_PEPValue_Based_QValue(List psms } } - private static int GetNumPSMsAtqValueCutoff(List psms, double qValueCutoff) + private static int GetNumPSMsAtqValueCutoff(List psms, double qValueCutoff) { int cumulative_target = 0; int cumulative_decoy = 0; - foreach (PeptideSpectralMatch psm in psms) + foreach (SpectralMatch psm in psms) { if (psm.IsDecoy) { @@ -281,7 +281,7 @@ public void CountPsm() } } - foreach (PeptideSpectralMatch psm in allUnambiguousPsms) + foreach (SpectralMatch psm in allUnambiguousPsms) { if (sequenceToPsmCount.ContainsKey(psm.FullSequence)) { diff --git a/MetaMorpheus/EngineLayer/FdrAnalysis/PEPValueAnalysisGeneric.cs b/MetaMorpheus/EngineLayer/FdrAnalysis/PEPValueAnalysisGeneric.cs index 1a1ccc6af..9969e01ed 100644 --- a/MetaMorpheus/EngineLayer/FdrAnalysis/PEPValueAnalysisGeneric.cs +++ b/MetaMorpheus/EngineLayer/FdrAnalysis/PEPValueAnalysisGeneric.cs @@ -16,6 +16,7 @@ using System.Text; using System.Threading.Tasks; using Omics.Modifications; +using Omics; namespace EngineLayer { @@ -26,13 +27,13 @@ public static class PEP_Analysis_Cross_Validation private static Dictionary>> fileSpecificTimeDependantHydrophobicityAverageAndDeviation_modified = new Dictionary>>(); private static Dictionary>> fileSpecificTimeDependantHydrophobicityAverageAndDeviation_CZE = new Dictionary>>(); - public static string ComputePEPValuesForAllPSMsGeneric(List psms, string searchType, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, string outputFolder) + public static string ComputePEPValuesForAllPSMsGeneric(List psms, string searchType, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, string outputFolder) { string[] trainingVariables = PsmData.trainingInfos[searchType]; //ensure that the order is always stable. psms = psms.OrderByDescending(p => p.Score).ThenBy(p => p.FdrInfo.QValue). - ThenBy(p => p.FullFilePath).ThenBy(x => x.ScanNumber).ThenBy(p => p.FullSequence).ThenBy(p => p.ProteinAccession).ToList(); + ThenBy(p => p.FullFilePath).ThenBy(x => x.ScanNumber).ThenBy(p => p.FullSequence).ThenBy(p => p.Accession).ToList(); //These two dictionaries contain the average and standard deviations of hydrophobicitys measured in 1 minute increments accross each raw //file separately. An individully measured hydrobophicty calculated for a specific PSM sequence is compared to these values by computing @@ -175,7 +176,7 @@ public static string AggregateMetricsForOutput(List psms, List psmIndices, MLContext mLContext, TransformerChain>> trainedModel, string searchType, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, Dictionary sequenceToPsmCount, Dictionary fileSpecificMedianFragmentMassErrors, int chargeStateMode, string outputFolder) + public static int Compute_PSM_PEP(List psms, List psmIndices, MLContext mLContext, TransformerChain>> trainedModel, string searchType, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, Dictionary sequenceToPsmCount, Dictionary fileSpecificMedianFragmentMassErrors, int chargeStateMode, string outputFolder) { int maxThreads = fileSpecificParameters.FirstOrDefault().fileSpecificParameters.MaxThreadsToUsePerFile; object lockObject = new object(); @@ -212,7 +213,7 @@ public static int Compute_PSM_PEP(List psms, List psm for (int i = range.Item1; i < range.Item2; i++) { - PeptideSpectralMatch psm = psms[psmIndices[i]]; + SpectralMatch psm = psms[psmIndices[i]]; if (psm != null) { @@ -222,13 +223,13 @@ public static int Compute_PSM_PEP(List psms, List psm //Here we compute the pepvalue predection for each ambiguous peptide in a PSM. Ambiguous peptides with lower pepvalue predictions are removed from the PSM. List allBmpNotches = new List(); - List allBmpPeptides = new List(); + List allBmpPeptides = new List(); - foreach (var (Notch, Peptide) in psm.BestMatchingPeptides) + foreach (var (Notch, Peptide) in psm.BestMatchingBioPolymersWithSetMods) { allBmpNotches.Add(Notch); allBmpPeptides.Add(Peptide); - PsmData pd = CreateOnePsmDataEntry(searchType, fileSpecificParameters, psm, sequenceToPsmCount, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_unmodified, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_modified, fileSpecificMedianFragmentMassErrors, chargeStateMode, Peptide, Notch, !Peptide.Protein.IsDecoy); + PsmData pd = CreateOnePsmDataEntry(searchType, fileSpecificParameters, psm, sequenceToPsmCount, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_unmodified, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_modified, fileSpecificMedianFragmentMassErrors, chargeStateMode, Peptide, Notch, !Peptide.Parent.IsDecoy); var pepValuePrediction = threadPredictionEngine.Predict(pd); pepValuePredictions.Add(pepValuePrediction.Probability); //A score is available using the variable pepvaluePrediction.Score @@ -251,7 +252,7 @@ public static int Compute_PSM_PEP(List psms, List psm //we add the indexes of the targets and decoys to the groups separately in the hope that we'll get at least one target and one decoy in each group. //then training can possibly be more successful. - public static List[] Get_PSM_Group_Indices(List psms, int numGroups) + public static List[] Get_PSM_Group_Indices(List psms, int numGroups) { List[] groupsOfIndicies = new List[numGroups]; for (int i = 0; i < numGroups; i++) @@ -303,7 +304,7 @@ public static List[] Get_PSM_Group_Indices(List psms, return groupsOfIndicies; } - public static void RemoveBestMatchingPeptidesWithLowPEP(PeptideSpectralMatch psm, List indiciesOfPeptidesToRemove, List notches, List pwsmList, List pepValuePredictions, ref int ambiguousPeptidesRemovedCount) + public static void RemoveBestMatchingPeptidesWithLowPEP(SpectralMatch psm, List indiciesOfPeptidesToRemove, List notches, List pwsmList, List pepValuePredictions, ref int ambiguousPeptidesRemovedCount) { foreach (int i in indiciesOfPeptidesToRemove) { @@ -314,7 +315,7 @@ public static void RemoveBestMatchingPeptidesWithLowPEP(PeptideSpectralMatch psm } /// - /// Given a set of PEP values, this method will find the indicies of BestMatchingPeptides that are not within the required tolerance + /// Given a set of PEP values, this method will find the indicies of BestMatchingBioPolymersWithSetMods that are not within the required tolerance /// This method will also remove the low scoring predictions from the set. /// public static void GetIndiciesOfPeptidesToRemove(List indiciesOfPeptidesToRemove, List pepValuePredictions) @@ -337,12 +338,12 @@ public static void GetIndiciesOfPeptidesToRemove(List indiciesOfPeptidesToR /// /// Here we're getting the most common charge state for precursors that are Targets with q<=0.01. - public static int GetChargeStateMode(List psms) + public static int GetChargeStateMode(List psms) { return psms.Where(p => p.IsDecoy != true && p.FdrInfo.QValue <= 0.01).Select(p => p.ScanPrecursorCharge).GroupBy(n => n).OrderByDescending(g => g.Count()).Select(g => g.Key).FirstOrDefault(); } - public static Dictionary>> ComputeHydrophobicityValues(List psms, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, bool computeHydrophobicitiesforModifiedPeptides) + public static Dictionary>> ComputeHydrophobicityValues(List psms, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, bool computeHydrophobicitiesforModifiedPeptides) { SSRCalc3 calc = new SSRCalc3("SSRCalc 3.0 (300A)", SSRCalc3.Column.A300); @@ -358,10 +359,10 @@ public static Dictionary>> Compute Dictionary> hydrophobicities = new Dictionary>(); Dictionary> averagesCommaStandardDeviations = new Dictionary>(); - foreach (PeptideSpectralMatch psm in psms.Where(f => (f.FullFilePath == null || Path.GetFileName(f.FullFilePath) == filename) && f.FdrInfo.QValue <= 0.01 && !f.IsDecoy)) + foreach (SpectralMatch psm in psms.Where(f => (f.FullFilePath == null || Path.GetFileName(f.FullFilePath) == filename) && f.FdrInfo.QValue <= 0.01 && !f.IsDecoy)) { List fullSequences = new List(); - foreach ((int notch, PeptideWithSetModifications pwsm) in psm.BestMatchingPeptides) + foreach ((int notch, IBioPolymerWithSetMods pwsm) in psm.BestMatchingBioPolymersWithSetMods) { if (fullSequences.Contains(pwsm.FullSequence)) { @@ -369,7 +370,7 @@ public static Dictionary>> Compute } fullSequences.Add(pwsm.FullSequence); - double predictedHydrophobicity = calc.ScoreSequence(pwsm); + double predictedHydrophobicity = pwsm is PeptideWithSetModifications pep ? calc.ScoreSequence(pep) : 0; //here i'm grouping this in 2 minute increments becuase there are cases where you get too few data points to get a good standard deviation an average. This is for stability. int possibleKey = (int)(2 * Math.Round(psm.ScanRetentionTime / 2d, 0)); @@ -447,7 +448,7 @@ public static Dictionary>> Compute return rtHydrophobicityAvgDev; } - public static Dictionary>> ComputeMobilityValues(List psms, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters) + public static Dictionary>> ComputeMobilityValues(List psms, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters) { Dictionary>> rtMobilityAvgDev = new Dictionary>>(); @@ -460,10 +461,10 @@ public static Dictionary>> Compute Dictionary> mobilities = new Dictionary>(); Dictionary> averagesCommaStandardDeviations = new Dictionary>(); - foreach (PeptideSpectralMatch psm in psms.Where(f => (f.FullFilePath == null || Path.GetFileName(f.FullFilePath) == filename) && f.FdrInfo.QValue <= 0.01 && !f.IsDecoy)) + foreach (SpectralMatch psm in psms.Where(f => (f.FullFilePath == null || Path.GetFileName(f.FullFilePath) == filename) && f.FdrInfo.QValue <= 0.01 && !f.IsDecoy)) { List fullSequences = new List(); - foreach ((int notch, PeptideWithSetModifications pwsm) in psm.BestMatchingPeptides) + foreach ((int notch, IBioPolymerWithSetMods pwsm) in psm.BestMatchingBioPolymersWithSetMods) { if (fullSequences.Contains(pwsm.FullSequence)) { @@ -471,7 +472,7 @@ public static Dictionary>> Compute } fullSequences.Add(pwsm.FullSequence); - double predictedMobility = 100.0 * GetCifuentesMobility(pwsm); + double predictedMobility = pwsm is PeptideWithSetModifications pep ? 100.0 * GetCifuentesMobility(pep) : 0; //here i'm grouping this in 2 minute increments becuase there are cases where you get too few data points to get a good standard deviation an average. This is for stability. int possibleKey = (int)(2 * Math.Round(psm.ScanRetentionTime / 2d, 0)); @@ -549,7 +550,7 @@ public static void UpdateOutOfRangeStDevsWithGlobalAverage(Dictionary f == 'K') + pwsm.BaseSequence.Count(f => f == 'R') + pwsm.BaseSequence.Count(f => f == 'H') - CountModificationsThatShiftMobility(pwsm.AllModsOneIsNterminus.Values.AsEnumerable());// the 1 + is for N-terminal @@ -558,7 +559,7 @@ private static double GetCifuentesMobility(PeptideWithSetModifications pwsm) return mobility; } - private static float GetSSRCalcHydrophobicityZScore(PeptideSpectralMatch psm, PeptideWithSetModifications Peptide, Dictionary>> d) + private static float GetSSRCalcHydrophobicityZScore(SpectralMatch psm, IBioPolymerWithSetMods Peptide, Dictionary>> d) { //Using SSRCalc3 but probably any number of different calculators could be used instead. One could also use the CE mobility. SSRCalc3 calc = new SSRCalc3("SSRCalc 3.0 (300A)", SSRCalc3.Column.A300); @@ -569,7 +570,7 @@ private static float GetSSRCalcHydrophobicityZScore(PeptideSpectralMatch psm, Pe int time = (int)(2 * Math.Round(psm.ScanRetentionTime / 2d, 0)); if (d[Path.GetFileName(psm.FullFilePath)].Keys.Contains(time)) { - double predictedHydrophobicity = calc.ScoreSequence(Peptide); + double predictedHydrophobicity = Peptide is PeptideWithSetModifications pep ? calc.ScoreSequence(pep) : 0; hydrophobicityZscore = Math.Abs(d[Path.GetFileName(psm.FullFilePath)][time].Item1 - predictedHydrophobicity) / d[Path.GetFileName(psm.FullFilePath)][time].Item2; } @@ -584,7 +585,7 @@ private static float GetSSRCalcHydrophobicityZScore(PeptideSpectralMatch psm, Pe return (float)hydrophobicityZscore; } - private static float GetMobilityZScore(PeptideSpectralMatch psm, PeptideWithSetModifications selectedPeptide) + private static float GetMobilityZScore(SpectralMatch psm, IBioPolymerWithSetMods selectedPeptide) { double mobilityZScore = double.NaN; @@ -608,16 +609,16 @@ private static float GetMobilityZScore(PeptideSpectralMatch psm, PeptideWithSetM return (float)mobilityZScore; } - public static Dictionary GetSequenceToPSMCount(List psms) + public static Dictionary GetSequenceToPSMCount(List psms) { Dictionary sequenceToPsmCount = new Dictionary(); List sequences = new List(); - foreach (PeptideSpectralMatch psm in psms) + foreach (SpectralMatch psm in psms) { List fullSeqs = new List(); - foreach ((int, PeptideWithSetModifications) bmp in psm.BestMatchingPeptides) + foreach ((int, PeptideWithSetModifications) bmp in psm.BestMatchingBioPolymersWithSetMods) { fullSeqs.Add(bmp.Item2.FullSequence); } @@ -634,7 +635,7 @@ public static Dictionary GetSequenceToPSMCount(List CreatePsmData(string searchType, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, - List psms, List psmIndicies, Dictionary sequenceToPsmCount, + List psms, List psmIndicies, Dictionary sequenceToPsmCount, Dictionary>> timeDependantHydrophobicityAverageAndDeviation_unmodified, Dictionary>> timeDependantHydrophobicityAverageAndDeviation_modified, Dictionary fileSpecificMedianFragmentMassErrors, int chargeStateMode) @@ -653,7 +654,7 @@ public static IEnumerable CreatePsmData(string searchType, List<(string List localPsmOrder = new List(); for (int i = range.Item1; i < range.Item2; i++) { - PeptideSpectralMatch psm = psms[psmIndicies[i]]; + SpectralMatch psm = psms[psmIndicies[i]]; // Stop loop if canceled if (GlobalVariables.StopLoops) { return; } @@ -667,12 +668,12 @@ public static IEnumerable CreatePsmData(string searchType, List<(string if (csm.IsDecoy || csm.BetaPeptide.IsDecoy) { label = false; - newPsmData = CreateOnePsmDataEntry(searchType, fileSpecificParameters, psm, sequenceToPsmCount, timeDependantHydrophobicityAverageAndDeviation_unmodified, timeDependantHydrophobicityAverageAndDeviation_modified, fileSpecificMedianFragmentMassErrors, chargeStateMode, csm.BestMatchingPeptides.First().Peptide, 0, label); + newPsmData = CreateOnePsmDataEntry(searchType, fileSpecificParameters, psm, sequenceToPsmCount, timeDependantHydrophobicityAverageAndDeviation_unmodified, timeDependantHydrophobicityAverageAndDeviation_modified, fileSpecificMedianFragmentMassErrors, chargeStateMode, csm.BestMatchingBioPolymersWithSetMods.First().Peptide, 0, label); } else if (!csm.IsDecoy && !csm.BetaPeptide.IsDecoy && psm.FdrInfo.QValue <= 0.0005) { label = true; - newPsmData = CreateOnePsmDataEntry(searchType, fileSpecificParameters, psm, sequenceToPsmCount, timeDependantHydrophobicityAverageAndDeviation_unmodified, timeDependantHydrophobicityAverageAndDeviation_modified, fileSpecificMedianFragmentMassErrors, chargeStateMode, csm.BestMatchingPeptides.First().Peptide, 0, label); + newPsmData = CreateOnePsmDataEntry(searchType, fileSpecificParameters, psm, sequenceToPsmCount, timeDependantHydrophobicityAverageAndDeviation_unmodified, timeDependantHydrophobicityAverageAndDeviation_modified, fileSpecificMedianFragmentMassErrors, chargeStateMode, csm.BestMatchingBioPolymersWithSetMods.First().Peptide, 0, label); } localPsmDataList.Add(newPsmData); localPsmOrder.Add(i); @@ -680,16 +681,16 @@ public static IEnumerable CreatePsmData(string searchType, List<(string else { double bmp = 0; - foreach (var (notch, peptideWithSetMods) in psm.BestMatchingPeptides) + foreach (var (notch, peptideWithSetMods) in psm.BestMatchingBioPolymersWithSetMods) { bool label; - double bmpc = psm.BestMatchingPeptides.Count(); - if (peptideWithSetMods.Protein.IsDecoy) + double bmpc = psm.BestMatchingBioPolymersWithSetMods.Count(); + if (peptideWithSetMods.Parent.IsDecoy) { label = false; newPsmData = CreateOnePsmDataEntry(searchType, fileSpecificParameters, psm, sequenceToPsmCount, timeDependantHydrophobicityAverageAndDeviation_unmodified, timeDependantHydrophobicityAverageAndDeviation_modified, fileSpecificMedianFragmentMassErrors, chargeStateMode, peptideWithSetMods, notch, label); } - else if (!peptideWithSetMods.Protein.IsDecoy && psm.FdrInfo.QValue <= 0.005) + else if (!peptideWithSetMods.Parent.IsDecoy && psm.FdrInfo.QValue <= 0.005) { label = true; newPsmData = CreateOnePsmDataEntry(searchType, fileSpecificParameters, psm, sequenceToPsmCount, timeDependantHydrophobicityAverageAndDeviation_unmodified, timeDependantHydrophobicityAverageAndDeviation_modified, fileSpecificMedianFragmentMassErrors, chargeStateMode, peptideWithSetMods, notch, label); @@ -714,7 +715,15 @@ public static IEnumerable CreatePsmData(string searchType, List<(string return pda.AsEnumerable(); } - public static PsmData CreateOnePsmDataEntry(string searchType, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, PeptideSpectralMatch psm, Dictionary sequenceToPsmCount, Dictionary>> timeDependantHydrophobicityAverageAndDeviation_unmodified, Dictionary>> timeDependantHydrophobicityAverageAndDeviation_modified, Dictionary fileSpecificMedianFragmentMassErrors, int chargeStateMode, PeptideWithSetModifications selectedPeptide, int notchToUse, bool label) + public static PsmData CreateOnePsmDataEntry(string searchType, + List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, SpectralMatch psm, + Dictionary sequenceToPsmCount, + Dictionary>> + timeDependantHydrophobicityAverageAndDeviation_unmodified, + Dictionary>> + timeDependantHydrophobicityAverageAndDeviation_modified, + Dictionary fileSpecificMedianFragmentMassErrors, int chargeStateMode, + IBioPolymerWithSetMods selectedPeptide, int notchToUse, bool label) { double normalizationFactor = selectedPeptide.BaseSequence.Length; float totalMatchingFragmentCount = 0; @@ -751,20 +760,20 @@ public static PsmData CreateOnePsmDataEntry(string searchType, List<(string file { normalizationFactor /= 10.0; } - totalMatchingFragmentCount = (float)(Math.Round(psm.PeptidesToMatchingFragments[selectedPeptide].Count / normalizationFactor * 10, 0)); + totalMatchingFragmentCount = (float)(Math.Round(psm.BioPolymersWithSetModsToMatchingFragments[selectedPeptide].Count / normalizationFactor * 10, 0)); intensity = (float)Math.Min(50, Math.Round((psm.Score - (int)psm.Score) / normalizationFactor * 100.0, 0)); chargeDifference = -Math.Abs(chargeStateMode - psm.ScanPrecursorCharge); deltaScore = (float)Math.Round(psm.DeltaScore / normalizationFactor * 10.0, 0); notch = notchToUse; modCount = Math.Min((float)selectedPeptide.AllModsOneIsNterminus.Keys.Count(), 10); - if (psm.PeptidesToMatchingFragments[selectedPeptide]?.Count() > 0) + if (psm.BioPolymersWithSetModsToMatchingFragments[selectedPeptide]?.Count() > 0) { - absoluteFragmentMassError = (float)Math.Min(100.0, Math.Round(10.0 * Math.Abs(GetAverageFragmentMassError(psm.PeptidesToMatchingFragments[selectedPeptide]) - fileSpecificMedianFragmentMassErrors[Path.GetFileName(psm.FullFilePath)]))); + absoluteFragmentMassError = (float)Math.Min(100.0, Math.Round(10.0 * Math.Abs(GetAverageFragmentMassError(psm.BioPolymersWithSetModsToMatchingFragments[selectedPeptide]) - fileSpecificMedianFragmentMassErrors[Path.GetFileName(psm.FullFilePath)]))); } - ambiguity = Math.Min((float)(psm.PeptidesToMatchingFragments.Keys.Count - 1), 10); - longestSeq = (float)Math.Round(PeptideSpectralMatch.GetLongestIonSeriesBidirectional(psm.PeptidesToMatchingFragments, selectedPeptide) / normalizationFactor * 10, 0); - complementaryIonCount = (float)Math.Round(PeptideSpectralMatch.GetCountComplementaryIons(psm.PeptidesToMatchingFragments, selectedPeptide) / normalizationFactor * 10, 0); + ambiguity = Math.Min((float)(psm.BioPolymersWithSetModsToMatchingFragments.Keys.Count - 1), 10); + longestSeq = (float)Math.Round(SpectralMatch.GetLongestIonSeriesBidirectional(psm.BioPolymersWithSetModsToMatchingFragments, selectedPeptide) / normalizationFactor * 10, 0); + complementaryIonCount = (float)Math.Round(SpectralMatch.GetCountComplementaryIons(psm.BioPolymersWithSetModsToMatchingFragments, selectedPeptide) / normalizationFactor * 10, 0); //grouping psm counts as follows is done for stability. you get very nice numbers at low psms to get good statistics. But you get a few peptides with high psm counts that could be either targets or decoys and the values swing between extremes. So grouping psms in bundles really adds stability. psmCount = sequenceToPsmCount[selectedPeptide.FullSequence]; @@ -811,8 +820,8 @@ public static PsmData CreateOnePsmDataEntry(string searchType, List<(string file else { CrosslinkSpectralMatch csm = (CrosslinkSpectralMatch)psm; - PeptideWithSetModifications selectedAlphaPeptide = csm.BestMatchingPeptides.Select(p => p.Peptide).First(); - PeptideWithSetModifications selectedBetaPeptide = csm.BetaPeptide?.BestMatchingPeptides.Select(p => p.Peptide).First(); + PeptideWithSetModifications selectedAlphaPeptide = csm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide as PeptideWithSetModifications).First(); + PeptideWithSetModifications selectedBetaPeptide = csm.BetaPeptide?.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide as PeptideWithSetModifications).First(); float alphaNormalizationFactor = selectedAlphaPeptide.BaseSequence.Length; float betaNormalizationFactor = selectedBetaPeptide == null ? (float)0 : selectedBetaPeptide.BaseSequence.Length; @@ -823,17 +832,17 @@ public static PsmData CreateOnePsmDataEntry(string searchType, List<(string file //Compute fragment mass error int alphaCount = 0; float alphaError = 0; - if (csm.PeptidesToMatchingFragments[selectedAlphaPeptide]?.Count > 0) + if (csm.BioPolymersWithSetModsToMatchingFragments[selectedAlphaPeptide]?.Count > 0) { - alphaCount = csm.PeptidesToMatchingFragments[selectedAlphaPeptide].Count; - alphaError = Math.Abs(GetAverageFragmentMassError(csm.PeptidesToMatchingFragments[selectedAlphaPeptide])); + alphaCount = csm.BioPolymersWithSetModsToMatchingFragments[selectedAlphaPeptide].Count; + alphaError = Math.Abs(GetAverageFragmentMassError(csm.BioPolymersWithSetModsToMatchingFragments[selectedAlphaPeptide])); } int betaCount = 0; float betaError = 0; - if (csm.BetaPeptide.PeptidesToMatchingFragments[selectedBetaPeptide]?.Count > 0) + if (csm.BetaPeptide.BioPolymersWithSetModsToMatchingFragments[selectedBetaPeptide]?.Count > 0) { - betaCount = csm.BetaPeptide.PeptidesToMatchingFragments[selectedBetaPeptide].Count; - betaError = Math.Abs(GetAverageFragmentMassError(csm.BetaPeptide.PeptidesToMatchingFragments[selectedBetaPeptide])); + betaCount = csm.BetaPeptide.BioPolymersWithSetModsToMatchingFragments[selectedBetaPeptide].Count; + betaError = Math.Abs(GetAverageFragmentMassError(csm.BetaPeptide.BioPolymersWithSetModsToMatchingFragments[selectedBetaPeptide])); } float averageError = 0; @@ -849,8 +858,8 @@ public static PsmData CreateOnePsmDataEntry(string searchType, List<(string file chargeDifference = -Math.Abs(chargeStateMode - psm.ScanPrecursorCharge); alphaIntensity = (float)Math.Min(100, Math.Round((csm.Score - (int)csm.Score) / alphaNormalizationFactor * 100.0, 0)); betaIntensity = csm.BetaPeptide == null ? (float)0 : (float)Math.Min(100.0, Math.Round((csm.BetaPeptide.Score - (int)csm.BetaPeptide.Score) / betaNormalizationFactor * 100.0, 0)); - longestFragmentIonSeries_Alpha = (float)Math.Round(PeptideSpectralMatch.GetLongestIonSeriesBidirectional(csm.PeptidesToMatchingFragments, selectedAlphaPeptide) / alphaNormalizationFactor * 10.0, 0); - longestFragmentIonSeries_Beta = selectedBetaPeptide == null ? (float)0 : PeptideSpectralMatch.GetLongestIonSeriesBidirectional(csm.BetaPeptide.PeptidesToMatchingFragments, selectedBetaPeptide) / betaNormalizationFactor; + longestFragmentIonSeries_Alpha = (float)Math.Round(SpectralMatch.GetLongestIonSeriesBidirectional(csm.BioPolymersWithSetModsToMatchingFragments, selectedAlphaPeptide) / alphaNormalizationFactor * 10.0, 0); + longestFragmentIonSeries_Beta = selectedBetaPeptide == null ? (float)0 : SpectralMatch.GetLongestIonSeriesBidirectional(csm.BetaPeptide.BioPolymersWithSetModsToMatchingFragments, selectedBetaPeptide) / betaNormalizationFactor; longestFragmentIonSeries_Beta = (float)Math.Round(longestFragmentIonSeries_Beta * 10.0, 0); isInter = Convert.ToSingle(csm.CrossType == PsmCrossType.Inter); isIntra = Convert.ToSingle(csm.CrossType == PsmCrossType.Intra); @@ -891,8 +900,11 @@ public static PsmData CreateOnePsmDataEntry(string searchType, List<(string file return psm.PsmData_forPEPandPercolator; } - private static bool PeptideIsVariant(PeptideWithSetModifications pwsm) + private static bool PeptideIsVariant(IBioPolymerWithSetMods bpwsm) { + if (bpwsm is not PeptideWithSetModifications pwsm) + return false; + bool identifiedVariant = false; if (pwsm.Protein.AppliedSequenceVariations.Count() > 0) { @@ -908,7 +920,7 @@ private static bool PeptideIsVariant(PeptideWithSetModifications pwsm) return identifiedVariant; } - private static bool PsmHasSpectralAngle(PeptideSpectralMatch psm) + private static bool PsmHasSpectralAngle(SpectralMatch psm) { return psm.SpectralAngle >= 0; } @@ -933,7 +945,7 @@ public static int CountModificationsThatShiftMobility(IEnumerable return modifications.Select(n => n.OriginalId).Intersect(shiftingModifications).Count(); } - public static Dictionary GetFileSpecificMedianFragmentMassError(List psms) + public static Dictionary GetFileSpecificMedianFragmentMassError(List psms) { Dictionary fileSpecificMassErrors = new Dictionary(); foreach (string filename in psms.Select(p => Path.GetFileName(p.FullFilePath)).Distinct()) @@ -943,13 +955,13 @@ public static Dictionary GetFileSpecificMedianFragmentMassError(L return fileSpecificMassErrors; } - public static float GetMedianAverageMassError(IEnumerable psms) + public static float GetMedianAverageMassError(IEnumerable psms) { List averageMassErrors = new List(); - foreach (PeptideSpectralMatch psm in psms) + foreach (SpectralMatch psm in psms) { { - foreach (KeyValuePair> peptide_MFI in psm.PeptidesToMatchingFragments) + foreach (KeyValuePair> peptide_MFI in psm.BioPolymersWithSetModsToMatchingFragments) { if (peptide_MFI.Value != null && peptide_MFI.Value.Count > 0) { diff --git a/MetaMorpheus/EngineLayer/GlycoSearch/GlycoPeptides.cs b/MetaMorpheus/EngineLayer/GlycoSearch/GlycoPeptides.cs index 9a90f79ce..b7557c83e 100644 --- a/MetaMorpheus/EngineLayer/GlycoSearch/GlycoPeptides.cs +++ b/MetaMorpheus/EngineLayer/GlycoSearch/GlycoPeptides.cs @@ -162,8 +162,8 @@ public static PeptideWithSetModifications GenerateGlycopeptide(int position, Pep } } - var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, - peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods); + var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidue, + peptide.OneBasedEndResidue, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods); return testPeptide; @@ -272,8 +272,8 @@ public static PeptideWithSetModifications OGlyGetTheoreticalPeptide(int[] theMod testMods.Add(theModPositions.ElementAt(i), modifications[i]); } - var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, - peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods); + var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidue, + peptide.OneBasedEndResidue, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods); return testPeptide; } @@ -297,8 +297,8 @@ public static PeptideWithSetModifications OGlyGetTheoreticalPeptide(Route theMod testMods.Add(theModPositions.Mods[i].Item1, modifications[i]); } - var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, - peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods); + var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidue, + peptide.OneBasedEndResidue, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods); return testPeptide; } diff --git a/MetaMorpheus/EngineLayer/GlycoSearch/GlycoSearchEngine.cs b/MetaMorpheus/EngineLayer/GlycoSearch/GlycoSearchEngine.cs index 3a859f859..b1e8bccf4 100644 --- a/MetaMorpheus/EngineLayer/GlycoSearch/GlycoSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/GlycoSearch/GlycoSearchEngine.cs @@ -250,9 +250,9 @@ private void Add2GlobalGsms(ref List gsms, int scanIndex) if (preString == currentString) { - foreach (var bestMatchPeptide in gsm.BestMatchingPeptides) + foreach ((int, PeptideWithSetModifications Peptide) bestMatchPeptide in gsm.BestMatchingBioPolymersWithSetMods) { - GlobalCsms[scanIndex].Last().AddProteinMatch(bestMatchPeptide, gsm.PeptidesToMatchingFragments[bestMatchPeptide.Peptide]); + GlobalCsms[scanIndex].Last().AddProteinMatch(bestMatchPeptide, gsm.BioPolymersWithSetModsToMatchingFragments[bestMatchPeptide.Peptide]); } } diff --git a/MetaMorpheus/EngineLayer/GlycoSearch/GlycoSpectralMatch.cs b/MetaMorpheus/EngineLayer/GlycoSearch/GlycoSpectralMatch.cs index cadd62268..acc6db3be 100644 --- a/MetaMorpheus/EngineLayer/GlycoSearch/GlycoSpectralMatch.cs +++ b/MetaMorpheus/EngineLayer/GlycoSearch/GlycoSpectralMatch.cs @@ -18,7 +18,7 @@ public enum LocalizationLevel Level3 } - public class GlycoSpectralMatch : PeptideSpectralMatch + public class GlycoSpectralMatch : SpectralMatch { public GlycoSpectralMatch(PeptideWithSetModifications theBestPeptide, int notch, double score, int scanIndex, Ms2ScanWithSpecificMass scan, CommonParameters commonParameters, List matchedFragmentIons) : base(theBestPeptide, notch, score, scanIndex, scan, commonParameters, matchedFragmentIons) @@ -185,16 +185,16 @@ public string SingleToString() sb.Append(ScanPrecursorCharge + "\t"); sb.Append(ScanPrecursorMass + "\t"); - var proteinAccessionString = ProteinAccession ?? PsmTsvWriter.Resolve(BestMatchingPeptides.Select(p => p.Peptide.Protein.Accession), FullSequence).ResolvedString; + var proteinAccessionString = Accession ?? PsmTsvWriter.Resolve(BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide.Parent.Accession), FullSequence).ResolvedString; sb.Append(proteinAccessionString + "\t"); sb.Append(Organism + "\t"); - sb.Append(PsmTsvWriter.Resolve(BestMatchingPeptides.Select(b => b.Peptide.Protein.FullName), FullSequence).ResolvedString + "\t"); - int _FirstOneBasedStartResidueInProtein = OneBasedStartResidueInProtein.HasValue ? OneBasedStartResidueInProtein.Value : BestMatchingPeptides.First().Peptide.OneBasedStartResidueInProtein; - int _FirstOneBasedEndResidueInProtein = OneBasedEndResidueInProtein.HasValue ? OneBasedEndResidueInProtein.Value : BestMatchingPeptides.First().Peptide.OneBasedEndResidueInProtein; ; + sb.Append(PsmTsvWriter.Resolve(BestMatchingBioPolymersWithSetMods.Select(b => b.Peptide.Parent.FullName), FullSequence).ResolvedString + "\t"); + int _FirstOneBasedStartResidueInProtein = OneBasedStartResidue.HasValue ? OneBasedStartResidue.Value : BestMatchingBioPolymersWithSetMods.First().Peptide.OneBasedStartResidue; + int _FirstOneBasedEndResidueInProtein = OneBasedEndResidue.HasValue ? OneBasedEndResidue.Value : BestMatchingBioPolymersWithSetMods.First().Peptide.OneBasedEndResidue; ; - if (OneBasedStartResidueInProtein.HasValue) + if (OneBasedStartResidue.HasValue) { - sb.Append("[" + OneBasedStartResidueInProtein.Value.ToString() + " to " + OneBasedEndResidueInProtein.Value.ToString() + "]" + '\t'); + sb.Append("[" + OneBasedStartResidue.Value.ToString() + " to " + OneBasedEndResidue.Value.ToString() + "]" + '\t'); } else { @@ -202,11 +202,11 @@ public string SingleToString() } sb.Append(BaseSequence + "\t"); - sb.Append(BestMatchingPeptides.First().Peptide.PreviousAminoAcid + "," + BestMatchingPeptides.First().Peptide.NextAminoAcid + "\t"); + sb.Append(BestMatchingBioPolymersWithSetMods.First().Peptide.PreviousResidue + "," + BestMatchingBioPolymersWithSetMods.First().Peptide.NextResidue + "\t"); sb.Append(FullSequence + "\t"); - sb.Append(BestMatchingPeptides.First().Peptide.AllModsOneIsNterminus.Count + "\t"); + sb.Append(BestMatchingBioPolymersWithSetMods.First().Peptide.AllModsOneIsNterminus.Count + "\t"); - sb.Append((PeptideMonisotopicMass.HasValue ? PeptideMonisotopicMass.Value.ToString() : "---")); sb.Append("\t"); + sb.Append((BioPolymerWithSetModsMonoisotopicMass.HasValue ? BioPolymerWithSetModsMonoisotopicMass.Value.ToString() : "---")); sb.Append("\t"); sb.Append(Score + "\t"); sb.Append(Rank + "\t"); @@ -303,7 +303,7 @@ public string GlycoToString() string local_peptide = ""; string local_protein = ""; - LocalizedSiteSpeciLocalInfo(SiteSpeciLocalProb, LocalizedGlycan, OneBasedStartResidueInProtein, ref local_peptide, ref local_protein); + LocalizedSiteSpeciLocalInfo(SiteSpeciLocalProb, LocalizedGlycan, OneBasedStartResidue, ref local_peptide, ref local_protein); sb.Append(local_peptide); sb.Append("\t"); sb.Append(local_protein); sb.Append("\t"); diff --git a/MetaMorpheus/EngineLayer/Gptmd/GptmdEngine.cs b/MetaMorpheus/EngineLayer/Gptmd/GptmdEngine.cs index a4dcfff62..8c62576a6 100644 --- a/MetaMorpheus/EngineLayer/Gptmd/GptmdEngine.cs +++ b/MetaMorpheus/EngineLayer/Gptmd/GptmdEngine.cs @@ -4,18 +4,19 @@ using System; using System.Collections.Generic; using System.Linq; +using Omics; using Omics.Modifications; namespace EngineLayer.Gptmd { public class GptmdEngine : MetaMorpheusEngine { - private readonly List AllIdentifications; + private readonly List AllIdentifications; private readonly IEnumerable> Combos; private readonly List GptmdModifications; private readonly Dictionary FilePathToPrecursorMassTolerance; // this exists because of file-specific tolerances - public GptmdEngine(List allIdentifications, List gptmdModifications, IEnumerable> combos, Dictionary filePathToPrecursorMassTolerance, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) + public GptmdEngine(List allIdentifications, List gptmdModifications, IEnumerable> combos, Dictionary filePathToPrecursorMassTolerance, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) { AllIdentifications = allIdentifications; GptmdModifications = gptmdModifications; @@ -23,7 +24,7 @@ public GptmdEngine(List allIdentifications, List v.Peptide)) + foreach (var pepWithSetMods in psm.BestMatchingBioPolymersWithSetMods.Select(v => v.Peptide as PeptideWithSetModifications)) { foreach (Modification mod in GetPossibleMods(psm.ScanPrecursorMass, GptmdModifications, Combos, precursorMassTolerance, pepWithSetMods)) { - var isVariantProtein = pepWithSetMods.Protein != pepWithSetMods.Protein.NonVariantProtein; + var isVariantProtein = pepWithSetMods.Parent != pepWithSetMods.Protein.NonVariantProtein; for (int i = 0; i < pepWithSetMods.Length; i++) { - int indexInProtein = pepWithSetMods.OneBasedStartResidueInProtein + i; + int indexInProtein = pepWithSetMods.OneBasedStartResidue + i; - if (ModFits(mod, pepWithSetMods.Protein, i + 1, pepWithSetMods.Length, indexInProtein)) + if (ModFits(mod, pepWithSetMods.Parent, i + 1, pepWithSetMods.Length, indexInProtein)) { // if not a variant protein, index to base protein sequence if (!isVariantProtein) diff --git a/MetaMorpheus/EngineLayer/HistogramAnalysis/Bin.cs b/MetaMorpheus/EngineLayer/HistogramAnalysis/Bin.cs index c1c81590b..24d601890 100644 --- a/MetaMorpheus/EngineLayer/HistogramAnalysis/Bin.cs +++ b/MetaMorpheus/EngineLayer/HistogramAnalysis/Bin.cs @@ -12,13 +12,13 @@ public class Bin { public string AA = "-"; public Dictionary ResidueCount; - public Dictionary> UniquePSMs; + public Dictionary> UniquePSMs; public Dictionary ModsInCommon; public Bin(double massShift) { this.MassShift = massShift; - UniquePSMs = new Dictionary>(); + UniquePSMs = new Dictionary>(); } public int PepNlocCount { get; private set; } @@ -87,13 +87,13 @@ public void IdentifyResidues() if (hehe.Item3.LocalizedScores.Max() - hehe.Item3.LocalizedScores[0] < 0.5) { PepNlocCount++; - if (hehe.Item3.OneBasedStartResidueInProtein.HasValue && hehe.Item3.OneBasedStartResidueInProtein.Value <= 2) + if (hehe.Item3.OneBasedStartResidue.HasValue && hehe.Item3.OneBasedStartResidue.Value <= 2) ProtNlocCount++; } if (hehe.Item3.LocalizedScores.Max() - hehe.Item3.LocalizedScores.Last() < 0.5) { PepClocCount++; - if (hehe.Item3.OneBasedEndResidueInProtein.HasValue && hehe.Item3.ProteinLength.HasValue && hehe.Item3.OneBasedEndResidueInProtein.Value == hehe.Item3.ProteinLength.Value) + if (hehe.Item3.OneBasedEndResidue.HasValue && hehe.Item3.ParentLength.HasValue && hehe.Item3.OneBasedEndResidue.Value == hehe.Item3.ParentLength.Value) ProtClocCount++; } } @@ -132,22 +132,18 @@ public void IdentifyAA(double v) var ok = new HashSet(); for (char c = 'A'; c <= 'Z'; c++) { - if (Residue.TryGetResidue(c, out Residue residue)) + if (!Residue.TryGetResidue(c, out Residue residue)) continue; + if (Math.Abs(residue.MonoisotopicMass - MassShift) <= v) + ok.Add("Add " + residue.Name); + if (Math.Abs(residue.MonoisotopicMass + MassShift) <= v) + ok.Add("Remove " + residue.Name); + for (char cc = 'A'; cc <= 'Z'; cc++) { - if (Math.Abs(residue.MonoisotopicMass - MassShift) <= v) - ok.Add("Add " + residue.Name); - if (Math.Abs(residue.MonoisotopicMass + MassShift) <= v) - ok.Add("Remove " + residue.Name); - for (char cc = 'A'; cc <= 'Z'; cc++) - { - if (Residue.TryGetResidue(cc, out Residue residueCC)) - { - if (Math.Abs(residueCC.MonoisotopicMass + residue.MonoisotopicMass - MassShift) <= v) - ok.Add("Add (" + residue.Name + "+" + residueCC.Name + ")"); - if (Math.Abs(residueCC.MonoisotopicMass + residue.MonoisotopicMass + MassShift) <= v) - ok.Add("Remove (" + residue.Name + "+" + residueCC.Name + ")"); - } - } + if (!Residue.TryGetResidue(cc, out Residue residueCC)) continue; + if (Math.Abs(residueCC.MonoisotopicMass + residue.MonoisotopicMass - MassShift) <= v) + ok.Add("Add (" + residue.Name + "+" + residueCC.Name + ")"); + if (Math.Abs(residueCC.MonoisotopicMass + residue.MonoisotopicMass + MassShift) <= v) + ok.Add("Remove (" + residue.Name + "+" + residueCC.Name + ")"); } } AA = string.Join("|", ok); @@ -158,22 +154,19 @@ public void IdentifyUnimodBins(double v) var ok = new HashSet(); var okformula = new HashSet(); var okDiff = new HashSet(); - foreach (var hm in GlobalVariables.UnimodDeserialized) + foreach (Modification theMod in GlobalVariables.UnimodDeserialized) { - var theMod = hm as Modification; - if (Math.Abs(theMod.MonoisotopicMass.Value - MassShift) <= v) - { - ok.Add(hm.IdWithMotif); - okformula.Add(theMod.ChemicalFormula.Formula); - okDiff.Add(theMod.MonoisotopicMass.Value - MassShift); - } + if (!(Math.Abs(theMod.MonoisotopicMass.Value - MassShift) <= v)) continue; + ok.Add(theMod.IdWithMotif); + okformula.Add(theMod.ChemicalFormula.Formula); + okDiff.Add(theMod.MonoisotopicMass.Value - MassShift); } UnimodId = string.Join("|", ok); UnimodFormulas = string.Join("|", okformula); UnimodDiffs = string.Join("|", okDiff); } - internal void Add(PeptideSpectralMatch ok) + internal void Add(SpectralMatch ok) { if (ok.FullSequence != null) { @@ -181,10 +174,10 @@ internal void Add(PeptideSpectralMatch ok) { var current = UniquePSMs[ok.FullSequence]; if (current.Item3.Score < ok.Score) - UniquePSMs[ok.FullSequence] = new Tuple(ok.BaseSequence, ok.FullSequence, ok); + UniquePSMs[ok.FullSequence] = new Tuple(ok.BaseSequence, ok.FullSequence, ok); } else - UniquePSMs.Add(ok.FullSequence, new Tuple(ok.BaseSequence, ok.FullSequence, ok)); + UniquePSMs.Add(ok.FullSequence, new Tuple(ok.BaseSequence, ok.FullSequence, ok)); } } } diff --git a/MetaMorpheus/EngineLayer/HistogramAnalysis/BinTreeStructure.cs b/MetaMorpheus/EngineLayer/HistogramAnalysis/BinTreeStructure.cs index 8da75929d..51a338a5c 100644 --- a/MetaMorpheus/EngineLayer/HistogramAnalysis/BinTreeStructure.cs +++ b/MetaMorpheus/EngineLayer/HistogramAnalysis/BinTreeStructure.cs @@ -14,9 +14,9 @@ public class BinTreeStructure public List FinalBins { get; private set; } - public void GenerateBins(List targetAndDecoyMatches, double dc) + public void GenerateBins(List targetAndDecoyMatches, double dc) { - List listOfMassShifts = targetAndDecoyMatches.Where(b => b.PeptideMonisotopicMass.HasValue).Select(b => b.ScanPrecursorMass - b.PeptideMonisotopicMass.Value).OrderBy(b => b).ToList(); + List listOfMassShifts = targetAndDecoyMatches.Where(b => b.BioPolymerWithSetModsMonoisotopicMass.HasValue).Select(b => b.ScanPrecursorMass - b.BioPolymerWithSetModsMonoisotopicMass.Value).OrderBy(b => b).ToList(); double minMassShift = listOfMassShifts.Min(); double maxMassShift = listOfMassShifts.Max(); @@ -88,7 +88,7 @@ public void GenerateBins(List targetAndDecoyMatches, doubl for (int i = 0; i < targetAndDecoyMatches.Count; i++) { foreach (Bin bin in FinalBins) - if (targetAndDecoyMatches[i].PeptideMonisotopicMass.HasValue && Math.Abs(targetAndDecoyMatches[i].ScanPrecursorMass - targetAndDecoyMatches[i].PeptideMonisotopicMass.Value - bin.MassShift) <= dc) + if (targetAndDecoyMatches[i].BioPolymerWithSetModsMonoisotopicMass.HasValue && Math.Abs(targetAndDecoyMatches[i].ScanPrecursorMass - targetAndDecoyMatches[i].BioPolymerWithSetModsMonoisotopicMass.Value - bin.MassShift) <= dc) bin.Add(targetAndDecoyMatches[i]); } @@ -155,7 +155,7 @@ private void IdentifyMedianLength() { var numTarget = bin.UniquePSMs.Values.Count(b => !b.Item3.IsDecoy); if (numTarget > 0) - bin.MedianLength = Statistics.Median(bin.UniquePSMs.Values.Where(b => !b.Item3.IsDecoy).Where(b => b.Item3.PeptideLength.HasValue).Select(b => (double)b.Item3.PeptideLength.Value)); + bin.MedianLength = Statistics.Median(bin.UniquePSMs.Values.Where(b => !b.Item3.IsDecoy).Where(b => b.Item3.BioPolymerWithSetModsLength.HasValue).Select(b => (double)b.Item3.BioPolymerWithSetModsLength.Value)); } } diff --git a/MetaMorpheus/EngineLayer/Localization/LocalizationEngine.cs b/MetaMorpheus/EngineLayer/Localization/LocalizationEngine.cs index f4b03445c..97ac5f525 100644 --- a/MetaMorpheus/EngineLayer/Localization/LocalizationEngine.cs +++ b/MetaMorpheus/EngineLayer/Localization/LocalizationEngine.cs @@ -1,4 +1,5 @@ using MassSpectrometry; +using Omics; using Omics.Fragmentation; using Proteomics.ProteolyticDigestion; using System.Collections.Concurrent; @@ -16,10 +17,10 @@ namespace EngineLayer.Localization /// public class LocalizationEngine : MetaMorpheusEngine { - private readonly IEnumerable AllResultingIdentifications; + private readonly IEnumerable AllResultingIdentifications; private readonly MsDataFile MyMsDataFile; - public LocalizationEngine(IEnumerable allResultingIdentifications, MsDataFile myMsDataFile, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) + public LocalizationEngine(IEnumerable allResultingIdentifications, MsDataFile myMsDataFile, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) { AllResultingIdentifications = allResultingIdentifications; MyMsDataFile = myMsDataFile; @@ -28,7 +29,7 @@ public LocalizationEngine(IEnumerable allResultingIdentifi protected override MetaMorpheusEngineResults RunSpecific() { // don't try to localize mass differences for ambiguous peptides - PeptideSpectralMatch[] unambiguousPsms = AllResultingIdentifications.Where(b => b.FullSequence != null).ToArray(); + SpectralMatch[] unambiguousPsms = AllResultingIdentifications.Where(b => b.FullSequence != null).ToArray(); double psmsSearched = 0; int oldPercentProgress = 0; @@ -43,14 +44,14 @@ protected override MetaMorpheusEngineResults RunSpecific() for (int i = range.Item1; i < range.Item2; i++) { - PeptideSpectralMatch psm = unambiguousPsms[i]; + SpectralMatch psm = unambiguousPsms[i]; // Stop loop if canceled if (GlobalVariables.StopLoops) { break; } MsDataScan scan = MyMsDataFile.GetOneBasedScan(psm.ScanNumber); Ms2ScanWithSpecificMass scanWithSpecificMass = new Ms2ScanWithSpecificMass(scan, psm.ScanPrecursorMonoisotopicPeakMz, psm.ScanPrecursorCharge, psm.FullFilePath, CommonParameters); - PeptideWithSetModifications peptide = psm.BestMatchingPeptides.First().Peptide; + IBioPolymerWithSetMods peptide = psm.BestMatchingBioPolymersWithSetMods.First().Peptide; double massDifference = psm.ScanPrecursorMass - peptide.MonoisotopicMass; // this section will iterate through all residues of the peptide and try to localize the mass-diff at each residue and report a score for each residue diff --git a/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs b/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs index 8bf1666cf..137bc00fb 100644 --- a/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs @@ -13,7 +13,7 @@ public class ModernSearchEngine : MetaMorpheusEngine { protected const int FragmentBinsPerDalton = 1000; protected readonly List[] FragmentIndex; - protected readonly PeptideSpectralMatch[] PeptideSpectralMatches; + protected readonly SpectralMatch[] PeptideSpectralMatches; protected readonly Ms2ScanWithSpecificMass[] ListOfSortedMs2Scans; protected readonly List PeptideIndex; protected readonly int CurrentPartition; @@ -21,7 +21,7 @@ public class ModernSearchEngine : MetaMorpheusEngine protected readonly DissociationType DissociationType; protected readonly double MaxMassThatFragmentIonScoreIsDoubled; - public ModernSearchEngine(PeptideSpectralMatch[] globalPsms, Ms2ScanWithSpecificMass[] listOfSortedms2Scans, List peptideIndex, + public ModernSearchEngine(SpectralMatch[] globalPsms, Ms2ScanWithSpecificMass[] listOfSortedms2Scans, List peptideIndex, List[] fragmentIndex, int currentPartition, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, MassDiffAcceptor massDiffAcceptor, double maximumMassThatFragmentIonScoreIsDoubled, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) { @@ -82,7 +82,7 @@ protected override MetaMorpheusEngineResults RunSpecific() } }); - foreach (PeptideSpectralMatch psm in PeptideSpectralMatches.Where(p => p != null)) + foreach (SpectralMatch psm in PeptideSpectralMatches.Where(p => p != null)) { psm.ResolveAllAmbiguities(); } @@ -336,7 +336,7 @@ protected void IncrementPeptideScoresInBin(int start, int end, List bin, by /// This is a second-pass scoring method which is costly (in terms of computational time and RAM) but calculates the "normal" MetaMorpheus score instead /// of the approximation computed by the IndexScoreScan method. /// - protected PeptideSpectralMatch FineScorePeptide(int id, Ms2ScanWithSpecificMass scan, int scanIndex, List peptideTheorProducts) + protected SpectralMatch FineScorePeptide(int id, Ms2ScanWithSpecificMass scan, int scanIndex, List peptideTheorProducts) { PeptideWithSetModifications peptide = PeptideIndex[id]; @@ -348,7 +348,7 @@ protected PeptideSpectralMatch FineScorePeptide(int id, Ms2ScanWithSpecificMass int notch = MassDiffAcceptor.Accepts(scan.PrecursorMass, peptide.MonoisotopicMass); bool meetsScoreCutoff = thisScore >= CommonParameters.ScoreCutoff; - bool scoreImprovement = PeptideSpectralMatches[scanIndex] == null || (thisScore - PeptideSpectralMatches[scanIndex].RunnerUpScore) > -PeptideSpectralMatch.ToleranceForScoreDifferentiation; + bool scoreImprovement = PeptideSpectralMatches[scanIndex] == null || (thisScore - PeptideSpectralMatches[scanIndex].RunnerUpScore) > -SpectralMatch.ToleranceForScoreDifferentiation; if (meetsScoreCutoff && scoreImprovement) { @@ -384,7 +384,7 @@ protected void FineScorePeptides(List peptideIds, Ms2ScanWithSpecificMass s break; } - PeptideSpectralMatch psm = FineScorePeptide(id, scan, scanIndex, peptideTheorProducts); + SpectralMatch psm = FineScorePeptide(id, scan, scanIndex, peptideTheorProducts); if (psm != null && psm.Score > bestScore) { diff --git a/MetaMorpheus/EngineLayer/ModificationAnalysis/ModificationAnalysisEngine.cs b/MetaMorpheus/EngineLayer/ModificationAnalysis/ModificationAnalysisEngine.cs index 40d5f3357..44350e1cb 100644 --- a/MetaMorpheus/EngineLayer/ModificationAnalysis/ModificationAnalysisEngine.cs +++ b/MetaMorpheus/EngineLayer/ModificationAnalysis/ModificationAnalysisEngine.cs @@ -6,9 +6,9 @@ namespace EngineLayer.ModificationAnalysis { public class ModificationAnalysisEngine : MetaMorpheusEngine { - private readonly List NewPsms; + private readonly List NewPsms; - public ModificationAnalysisEngine(List newPsms, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) + public ModificationAnalysisEngine(List newPsms, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) { NewPsms = newPsms; } @@ -23,17 +23,17 @@ protected override MetaMorpheusEngineResults RunSpecific() // For the database ones, only need un-ambiguous protein and location in protein var forObserved = confidentTargetPsms - .Where(b => b.ProteinAccession != null && b.OneBasedEndResidueInProtein != null && b.OneBasedStartResidueInProtein != null); + .Where(b => b.Accession != null && b.OneBasedEndResidue != null && b.OneBasedStartResidue != null); // For the unambiguously localized ones, need FullSequence and un-ambiguous protein and location in protein var forUnambiguouslyLocalized = confidentTargetPsms - .Where(b => b.FullSequence != null && b.ProteinAccession != null && b.OneBasedEndResidueInProtein != null && b.OneBasedStartResidueInProtein != null); + .Where(b => b.FullSequence != null && b.Accession != null && b.OneBasedEndResidue != null && b.OneBasedStartResidue != null); //**DEBUG - List toby = new List(); - foreach (PeptideSpectralMatch psm in confidentTargetPsms) + List toby = new List(); + foreach (SpectralMatch psm in confidentTargetPsms) { - if (psm.FullSequence != null && psm.ProteinAccession != null && psm.OneBasedEndResidueInProtein != null && psm.OneBasedStartResidueInProtein != null) + if (psm.FullSequence != null && psm.Accession != null && psm.OneBasedEndResidue != null && psm.OneBasedStartResidue != null) toby.Add(psm); } @@ -42,7 +42,7 @@ protected override MetaMorpheusEngineResults RunSpecific() // For the localized but ambiguous ones, need FullSequence var forAmbiguousButLocalized = confidentTargetPsms - .Where(b => b.FullSequence != null && !(b.ProteinAccession != null && b.OneBasedEndResidueInProtein != null && b.OneBasedStartResidueInProtein != null)) + .Where(b => b.FullSequence != null && !(b.Accession != null && b.OneBasedEndResidue != null && b.OneBasedStartResidue != null)) .GroupBy(b => b.FullSequence); // For unlocalized but identified modifications, skip ones with full sequences! @@ -59,28 +59,28 @@ protected override MetaMorpheusEngineResults RunSpecific() HashSet<(string, string, int)> modsOnProteins = new HashSet<(string, string, int)>(); foreach (var psm in forObserved) { - var singlePeptide = psm.BestMatchingPeptides.First().Peptide; - foreach (var modInProtein in singlePeptide.Protein.OneBasedPossibleLocalizedModifications.Where(b => b.Key >= singlePeptide.OneBasedStartResidueInProtein && b.Key <= singlePeptide.OneBasedEndResidueInProtein)) + var singlePeptide = psm.BestMatchingBioPolymersWithSetMods.First().Peptide; + foreach (var modInProtein in singlePeptide.Parent.OneBasedPossibleLocalizedModifications.Where(b => b.Key >= singlePeptide.OneBasedStartResidue && b.Key <= singlePeptide.OneBasedEndResidue)) foreach (var huh in modInProtein.Value) - modsOnProteins.Add((singlePeptide.Protein.Accession, huh.IdWithMotif, modInProtein.Key)); + modsOnProteins.Add((singlePeptide.Parent.Accession, huh.IdWithMotif, modInProtein.Key)); } // We do not want to double-count modifications. Hence the HashSet!!! HashSet<(string, string, int)> modsSeenAndLocalized = new HashSet<(string, string, int)>(); foreach (var psm in forUnambiguouslyLocalized) { - var singlePeptide = psm.BestMatchingPeptides.First().Peptide; + var singlePeptide = psm.BestMatchingBioPolymersWithSetMods.First().Peptide; foreach (var nice in singlePeptide.AllModsOneIsNterminus) { int locInProtein; if (nice.Key == 1) - locInProtein = singlePeptide.OneBasedStartResidueInProtein; + locInProtein = singlePeptide.OneBasedStartResidue; else if (nice.Key == singlePeptide.Length + 2) - locInProtein = singlePeptide.OneBasedEndResidueInProtein; + locInProtein = singlePeptide.OneBasedEndResidue; else - locInProtein = singlePeptide.OneBasedStartResidueInProtein + nice.Key - 2; - modsSeenAndLocalized.Add((singlePeptide.Protein.Accession, nice.Value.IdWithMotif, locInProtein)); + locInProtein = singlePeptide.OneBasedStartResidue + nice.Key - 2; + modsSeenAndLocalized.Add((singlePeptide.Parent.Accession, nice.Value.IdWithMotif, locInProtein)); } } diff --git a/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs b/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs index b35eb8f15..1426bd4aa 100644 --- a/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs @@ -22,13 +22,13 @@ public class NonSpecificEnzymeSearchEngine : ModernSearchEngine private readonly List[] PrecursorIndex; private readonly int MinimumPeptideLength; - readonly PeptideSpectralMatch[][] GlobalCategorySpecificPsms; + readonly SpectralMatch[][] GlobalCategorySpecificPsms; readonly CommonParameters ModifiedParametersNoComp; readonly List ProductTypesToSearch; readonly List VariableTerminalModifications; readonly List[] CoisolationIndex; - public NonSpecificEnzymeSearchEngine(PeptideSpectralMatch[][] globalPsms, Ms2ScanWithSpecificMass[] listOfSortedms2Scans, List[] coisolationIndex, + public NonSpecificEnzymeSearchEngine(SpectralMatch[][] globalPsms, Ms2ScanWithSpecificMass[] listOfSortedms2Scans, List[] coisolationIndex, List peptideIndex, List[] fragmentIndex, List[] precursorIndex, int currentPartition, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List variableModifications, MassDiffAcceptor massDiffAcceptor, double maximumMassThatFragmentIonScoreIsDoubled, List nestedIds) : base(null, listOfSortedms2Scans, peptideIndex, fragmentIndex, currentPartition, commonParameters, fileSpecificParameters, massDiffAcceptor, maximumMassThatFragmentIonScoreIsDoubled, nestedIds) @@ -136,7 +136,7 @@ protected override MetaMorpheusEngineResults RunSpecific() double thisScore = CalculatePeptideScore(scan.TheScan, matchedIons); if (thisScore > CommonParameters.ScoreCutoff) { - PeptideSpectralMatch[] localPeptideSpectralMatches = GlobalCategorySpecificPsms[(int)FdrClassifier.GetCleavageSpecificityCategory(peptide.CleavageSpecificityForFdrCategory)]; + SpectralMatch[] localPeptideSpectralMatches = GlobalCategorySpecificPsms[(int)FdrClassifier.GetCleavageSpecificityCategory(peptide.CleavageSpecificityForFdrCategory)]; if (localPeptideSpectralMatches[ms2ArrayIndex] == null) { localPeptideSpectralMatches[ms2ArrayIndex] = new PeptideSpectralMatch(peptide, notch, thisScore, ms2ArrayIndex, scan, CommonParameters, matchedIons); @@ -349,11 +349,11 @@ private Tuple Accepts(List fragments, PeptideWithSetModifications updatedPwsm = null; if (fragmentationTerminus == FragmentationTerminus.N) { - int endResidue = peptide.OneBasedStartResidueInProtein + fragment.FragmentNumber - 1; //-1 for one based index + int endResidue = peptide.OneBasedStartResidue + fragment.FragmentNumber - 1; //-1 for one based index Dictionary updatedMods = new Dictionary(); foreach (KeyValuePair mod in peptide.AllModsOneIsNterminus) { - if (mod.Key < endResidue - peptide.OneBasedStartResidueInProtein + 3) //check if we cleaved it off, +1 for N-terminus being mod 1 and first residue being mod 2, +1 again for the -1 on end residue for one based index, +1 (again) for the one-based start residue + if (mod.Key < endResidue - peptide.OneBasedStartResidue + 3) //check if we cleaved it off, +1 for N-terminus being mod 1 and first residue being mod 2, +1 again for the -1 on end residue for one based index, +1 (again) for the one-based start residue { updatedMods.Add(mod.Key, mod.Value); } @@ -362,13 +362,13 @@ private Tuple Accepts(List fragments, { updatedMods.Add(endResidue, terminalMod); } - updatedPwsm = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, endResidue, CleavageSpecificity.Unknown, "", 0, updatedMods, 0); + updatedPwsm = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidue, endResidue, CleavageSpecificity.Unknown, "", 0, updatedMods, 0); } else //if C terminal ions, shave off the n-terminus { - int startResidue = peptide.OneBasedEndResidueInProtein - fragment.FragmentNumber + 1; //plus one for one based index + int startResidue = peptide.OneBasedEndResidue - fragment.FragmentNumber + 1; //plus one for one based index Dictionary updatedMods = new Dictionary(); //updateMods - int indexShift = startResidue - peptide.OneBasedStartResidueInProtein; + int indexShift = startResidue - peptide.OneBasedStartResidue; foreach (KeyValuePair mod in peptide.AllModsOneIsNterminus) { if (mod.Key > indexShift + 1) //check if we cleaved it off, +1 for N-terminus being mod 1 and first residue being 2 @@ -381,7 +381,7 @@ private Tuple Accepts(List fragments, { updatedMods.Add(startResidue - 1, terminalMod); } - updatedPwsm = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, startResidue, peptide.OneBasedEndResidueInProtein, CleavageSpecificity.Unknown, "", 0, updatedMods, 0); + updatedPwsm = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, startResidue, peptide.OneBasedEndResidue, CleavageSpecificity.Unknown, "", 0, updatedMods, 0); } return new Tuple(notch, updatedPwsm); } @@ -399,7 +399,7 @@ private Tuple Accepts(List fragments, if (notch >= 0) { //need to update so that the cleavage specificity is recorded - PeptideWithSetModifications updatedPwsm = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, peptide.OneBasedEndResidueInProtein, CleavageSpecificity.Unknown, "", 0, peptide.AllModsOneIsNterminus, peptide.NumFixedMods); + PeptideWithSetModifications updatedPwsm = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidue, peptide.OneBasedEndResidue, CleavageSpecificity.Unknown, "", 0, peptide.AllModsOneIsNterminus, peptide.NumFixedMods); return new Tuple(notch, updatedPwsm); } else //try a terminal mod (if it exists) @@ -421,14 +421,14 @@ private Tuple Accepts(List fragments, //add the terminal mod if (fragmentationTerminus == FragmentationTerminus.N) { - updatedMods[peptide.OneBasedEndResidueInProtein] = terminalMod; + updatedMods[peptide.OneBasedEndResidue] = terminalMod; } else { - updatedMods[peptide.OneBasedStartResidueInProtein - 1] = terminalMod; + updatedMods[peptide.OneBasedStartResidue - 1] = terminalMod; } - PeptideWithSetModifications updatedPwsm = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, peptide.OneBasedEndResidueInProtein, CleavageSpecificity.Unknown, "", 0, updatedMods, peptide.NumFixedMods); + PeptideWithSetModifications updatedPwsm = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidue, peptide.OneBasedEndResidue, CleavageSpecificity.Unknown, "", 0, updatedMods, peptide.NumFixedMods); return new Tuple(notch, updatedPwsm); } } @@ -438,7 +438,7 @@ private Tuple Accepts(List fragments, return new Tuple(-1, null); } - public static List ResolveFdrCategorySpecificPsms(List[] AllPsms, int numNotches, string taskId, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters) + public static List ResolveFdrCategorySpecificPsms(List[] AllPsms, int numNotches, string taskId, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters) { //update all psms with peptide info AllPsms.ToList() @@ -446,13 +446,13 @@ public static List ResolveFdrCategorySpecificPsms(List psmArray.Where(psm => psm != null).ToList() .ForEach(psm => psm.ResolveAllAmbiguities())); - foreach (List psmsArray in AllPsms) + foreach (List psmsArray in AllPsms) { if (psmsArray != null) { - List cleanedPsmsArray = psmsArray.Where(b => b != null).OrderByDescending(b => b.Score) - .ThenBy(b => b.PeptideMonisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.PeptideMonisotopicMass.Value) : double.MaxValue) - .GroupBy(b => (b.FullFilePath, b.ScanNumber, b.PeptideMonisotopicMass)).Select(b => b.First()).ToList(); + List cleanedPsmsArray = psmsArray.Where(b => b != null).OrderByDescending(b => b.Score) + .ThenBy(b => b.BioPolymerWithSetModsMonoisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.BioPolymerWithSetModsMonoisotopicMass.Value) : double.MaxValue) + .GroupBy(b => (b.FullFilePath, b.ScanNumber, b.BioPolymerWithSetModsMonoisotopicMass)).Select(b => b.First()).ToList(); new FdrAnalysisEngine(cleanedPsmsArray, numNotches, commonParameters, fileSpecificParameters, new List { taskId }).Run(); @@ -495,19 +495,19 @@ public static List ResolveFdrCategorySpecificPsms(List majorCategoryPsms = AllPsms[majorCategoryIndex].Where(x => x != null).OrderByDescending(x => x.Score).ToList(); //get sorted major category + List majorCategoryPsms = AllPsms[majorCategoryIndex].Where(x => x != null).OrderByDescending(x => x.Score).ToList(); //get sorted major category for (int i = 0; i < indexesOfInterest.Count; i++) { int minorCategoryIndex = indexesOfInterest[i]; if (minorCategoryIndex != majorCategoryIndex) { - List minorCategoryPsms = AllPsms[minorCategoryIndex].Where(x => x != null).OrderByDescending(x => x.Score).ToList(); //get sorted minor category + List minorCategoryPsms = AllPsms[minorCategoryIndex].Where(x => x != null).OrderByDescending(x => x.Score).ToList(); //get sorted minor category int minorPsmIndex = 0; int majorPsmIndex = 0; while (minorPsmIndex < minorCategoryPsms.Count && majorPsmIndex < majorCategoryPsms.Count) //while in the lists { - PeptideSpectralMatch majorPsm = majorCategoryPsms[majorPsmIndex]; - PeptideSpectralMatch minorPsm = minorCategoryPsms[minorPsmIndex]; + SpectralMatch majorPsm = majorCategoryPsms[majorPsmIndex]; + SpectralMatch minorPsm = minorCategoryPsms[minorPsmIndex]; //major needs to be a lower score than the minor if (majorPsm.Score > minorPsm.Score) { @@ -525,8 +525,8 @@ public static List ResolveFdrCategorySpecificPsms(List minorPsm.FdrInfo.QValue) { minorPsm.FdrInfo.QValue = majorPsm.FdrInfo.QValue; @@ -537,15 +537,15 @@ public static List ResolveFdrCategorySpecificPsms(List bestPsmsList = new List(); + List bestPsmsList = new List(); for (int i = 0; i < numTotalSpectraWithPrecursors; i++) { - PeptideSpectralMatch bestPsm = null; + SpectralMatch bestPsm = null; double lowestQ = double.MaxValue; int bestIndex = -1; foreach (int index in indexesOfInterest) //foreach category { - PeptideSpectralMatch currentPsm = AllPsms[index][i]; + SpectralMatch currentPsm = AllPsms[index][i]; if (currentPsm != null) { double currentQValue = currentPsm.FdrInfo.QValue; @@ -575,12 +575,12 @@ public static List ResolveFdrCategorySpecificPsms(List psmsArray in AllPsms) + foreach (List psmsArray in AllPsms) { if (psmsArray != null) { - List cleanedPsmsArray = psmsArray.Where(b => b != null).OrderByDescending(b => b.Score) - .ThenBy(b => b.PeptideMonisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.PeptideMonisotopicMass.Value) : double.MaxValue) + List cleanedPsmsArray = psmsArray.Where(b => b != null).OrderByDescending(b => b.Score) + .ThenBy(b => b.BioPolymerWithSetModsMonoisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.BioPolymerWithSetModsMonoisotopicMass.Value) : double.MaxValue) .ToList(); new FdrAnalysisEngine(cleanedPsmsArray, numNotches, commonParameters, fileSpecificParameters, new List { taskId }).Run(); @@ -605,11 +605,11 @@ public static Dictionary> GetTerminalModPositions(Peptid //determine the start and end index ranges when considering the minimum peptide length int startResidue = nTerminus ? - peptide.OneBasedStartResidueInProtein + digestionParams.MinPeptideLength - 1 : - peptide.OneBasedStartResidueInProtein; + peptide.OneBasedStartResidue + digestionParams.MinPeptideLength - 1 : + peptide.OneBasedStartResidue; int endResidue = nTerminus ? - peptide.OneBasedEndResidueInProtein : - peptide.OneBasedEndResidueInProtein - digestionParams.MinPeptideLength + 1; + peptide.OneBasedEndResidue : + peptide.OneBasedEndResidue - digestionParams.MinPeptideLength + 1; string terminalStringToFind = nTerminus ? "C-terminal" : "N-terminal"; //if singleN, want to find c-terminal mods and vice-versa //get all the mods for this protein @@ -627,11 +627,11 @@ public static Dictionary> GetTerminalModPositions(Peptid { if (nTerminus) { - annotatedTerminalModDictionary.Add(index - peptide.OneBasedStartResidueInProtein + 1, terminalModsHere); + annotatedTerminalModDictionary.Add(index - peptide.OneBasedStartResidue + 1, terminalModsHere); } else { - annotatedTerminalModDictionary.Add(peptide.OneBasedEndResidueInProtein - index + 1, terminalModsHere); + annotatedTerminalModDictionary.Add(peptide.OneBasedEndResidue - index + 1, terminalModsHere); } } } diff --git a/MetaMorpheus/EngineLayer/OligoSpectralMatch.cs b/MetaMorpheus/EngineLayer/OligoSpectralMatch.cs new file mode 100644 index 000000000..d32130288 --- /dev/null +++ b/MetaMorpheus/EngineLayer/OligoSpectralMatch.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using Omics; +using Omics.Fragmentation; + +namespace EngineLayer; + +/// +/// Placeholder class for when RNA code gets fully incorporated +/// +[ExcludeFromCodeCoverage] +public class OligoSpectralMatch : SpectralMatch +{ + public OligoSpectralMatch(IBioPolymerWithSetMods peptide, int notch, double score, int scanIndex, + Ms2ScanWithSpecificMass scan, CommonParameters commonParameters, + List matchedFragmentIons, double xcorr = 0) : base(peptide, notch, score, scanIndex, + scan, commonParameters, matchedFragmentIons, xcorr) + { + + } + + protected OligoSpectralMatch(SpectralMatch psm, List<(int Notch, IBioPolymerWithSetMods Peptide)> bestMatchingPeptides) + : base(psm, bestMatchingPeptides) + { + } +} \ No newline at end of file diff --git a/MetaMorpheus/EngineLayer/PeptideSpectralMatch.cs b/MetaMorpheus/EngineLayer/PeptideSpectralMatch.cs index ba65d0c1a..ea67808f1 100644 --- a/MetaMorpheus/EngineLayer/PeptideSpectralMatch.cs +++ b/MetaMorpheus/EngineLayer/PeptideSpectralMatch.cs @@ -1,400 +1,27 @@ using System; -using Chemistry; -using EngineLayer.FdrAnalysis; -using MassSpectrometry; -using Proteomics; -using Omics.Fragmentation; -using Proteomics.ProteolyticDigestion; using System.Collections.Generic; -using System.Collections.Immutable; using System.Linq; -using System.Runtime.CompilerServices; -using Easy.Common.Extensions; +using System.Text; +using System.Threading.Tasks; using Omics; +using Omics.Fragmentation; using Omics.Modifications; -using Proteomics.AminoAcidPolymer; -using ThermoFisher.CommonCore.Data; +using Proteomics.ProteolyticDigestion; +using Transcriptomics; namespace EngineLayer { - public class PeptideSpectralMatch + public class PeptideSpectralMatch : SpectralMatch { - public const double ToleranceForScoreDifferentiation = 1e-9; - protected List<(int Notch, PeptideWithSetModifications Pwsm)> _BestMatchingPeptides; - - public PeptideSpectralMatch(PeptideWithSetModifications peptide, int notch, double score, int scanIndex, Ms2ScanWithSpecificMass scan, CommonParameters commonParameters, List matchedFragmentIons, double xcorr = 0) - { - _BestMatchingPeptides = new List<(int, PeptideWithSetModifications)>(); - ScanIndex = scanIndex; - FullFilePath = scan.FullFilePath; - ScanNumber = scan.OneBasedScanNumber; - PrecursorScanNumber = scan.OneBasedPrecursorScanNumber; - ScanRetentionTime = scan.RetentionTime; - ScanExperimentalPeaks = scan.NumPeaks; - TotalIonCurrent = scan.TotalIonCurrent; - ScanPrecursorCharge = scan.PrecursorCharge; - ScanPrecursorMonoisotopicPeakMz = scan.PrecursorMonoisotopicPeakMz; - ScanPrecursorMass = scan.PrecursorMass; - DigestionParams = commonParameters.DigestionParams; - PeptidesToMatchingFragments = new Dictionary>(); - Xcorr = xcorr; - NativeId = scan.NativeId; - RunnerUpScore = commonParameters.ScoreCutoff; - MsDataScan = scan.TheScan; - SpectralAngle = -1; - - AddOrReplace(peptide, score, notch, true, matchedFragmentIons, xcorr); - } - - public MsDataScan MsDataScan { get; set; } - public ChemicalFormula ModsChemicalFormula { get; private set; } // these fields will be null if they are ambiguous - public string FullSequence { get; private set; } - public string EssentialSequence { get; private set; } - public int? Notch { get; private set; } - public string BaseSequence { get; private set; } - public int? PeptideLength { get; private set; } - public int? OneBasedStartResidueInProtein { get; private set; } - public int? OneBasedEndResidueInProtein { get; private set; } - public double? PeptideMonisotopicMass { get; private set; } - public int? ProteinLength { get; private set; } - public string ProteinAccession { get; private set; } - public string Organism { get; private set; } - public List MatchedFragmentIons { get; protected set; } - public int PsmCount { get; internal set; } - public Dictionary ModsIdentified { get; private set; } // these should never be null under normal circumstances - public List LocalizedScores { get; internal set; } - public int ScanNumber { get; } - public int? PrecursorScanNumber { get; } - public double ScanRetentionTime { get; } - public int ScanExperimentalPeaks { get; } - public double TotalIonCurrent { get; } - public int ScanPrecursorCharge { get; } - public double ScanPrecursorMonoisotopicPeakMz { get; } - public double ScanPrecursorMass { get; } - public string FullFilePath { get; private set; } - public int ScanIndex { get; } - public int NumDifferentMatchingPeptides { get { return _BestMatchingPeptides.Count; } } - public FdrInfo FdrInfo { get; private set; } - public PsmData PsmData_forPEPandPercolator { get; set; } - - public double Score { get; private set; } - public double Xcorr; - public double SpectralAngle { get; set; } - public string NativeId; // this is a property of the scan. used for mzID writing - - public double DeltaScore { get { return (Score - RunnerUpScore); } } - - public double RunnerUpScore { get; set; } - public bool IsDecoy { get; private set; } - public bool IsContaminant { get; private set; } - - //One-based positions in peptide that are covered by fragments on both sides of amino acids - public List FragmentCoveragePositionInPeptide { get; private set; } - - - public DigestionParams DigestionParams { get; } - public Dictionary> PeptidesToMatchingFragments { get; private set; } - - public IEnumerable<(int Notch, PeptideWithSetModifications Peptide)> BestMatchingPeptides - { - get - { - return _BestMatchingPeptides.OrderBy(p => p.Pwsm.FullSequence) - .ThenBy(p => p.Pwsm.Protein.Accession) - .ThenBy(p => p.Pwsm.OneBasedStartResidueInProtein); - } - } - - public static string GetTabSeparatedHeader() - { - return string.Join("\t", DataDictionary(null, null).Keys); - } - - public void AddOrReplace(PeptideWithSetModifications pwsm, double newScore, int notch, bool reportAllAmbiguity, List matchedFragmentIons, double newXcorr) - { - if (newScore - Score > ToleranceForScoreDifferentiation) //if new score beat the old score, overwrite it - { - _BestMatchingPeptides.Clear(); - _BestMatchingPeptides.Add((notch, pwsm)); - - if (Score - RunnerUpScore > ToleranceForScoreDifferentiation) - { - RunnerUpScore = Score; - } - - Score = newScore; - Xcorr = newXcorr; - - PeptidesToMatchingFragments.Clear(); - PeptidesToMatchingFragments.Add(pwsm, matchedFragmentIons); - } - else if (newScore - Score > -ToleranceForScoreDifferentiation && reportAllAmbiguity) //else if the same score and ambiguity is allowed - { - _BestMatchingPeptides.Add((notch, pwsm)); - - if (!PeptidesToMatchingFragments.ContainsKey(pwsm)) - { - PeptidesToMatchingFragments.Add(pwsm, matchedFragmentIons); - } - } - else if (newScore - RunnerUpScore > ToleranceForScoreDifferentiation) - { - RunnerUpScore = newScore; - } - } - - //PEP-Value analysis identifies ambiguous peptides with lower probability. These are removed from the bestmatchingpeptides dictionary, which lowers ambiguity. - public void RemoveThisAmbiguousPeptide(int notch, PeptideWithSetModifications pwsm) - { - _BestMatchingPeptides.Remove((notch, pwsm)); - if (!_BestMatchingPeptides.Any(x => x.Pwsm.Equals(pwsm))) - { - PeptidesToMatchingFragments.Remove(pwsm); - } - this.ResolveAllAmbiguities(); - } - - public override string ToString() - { - return ToString(new Dictionary()); - } - - public string ToString(IReadOnlyDictionary ModstoWritePruned) - { - return string.Join("\t", DataDictionary(this, ModstoWritePruned).Values); - } - - public static Dictionary DataDictionary(PeptideSpectralMatch psm, IReadOnlyDictionary ModsToWritePruned) - { - Dictionary s = new Dictionary(); - PsmTsvWriter.AddBasicMatchData(s, psm); - PsmTsvWriter.AddPeptideSequenceData(s, psm, ModsToWritePruned); - PsmTsvWriter.AddMatchedIonsData(s, psm?.MatchedFragmentIons); - PsmTsvWriter.AddMatchScoreData(s, psm); - return s; - } - - public void SetFdrValues(double cumulativeTarget, double cumulativeDecoy, double qValue, double cumulativeTargetNotch, double cumulativeDecoyNotch, double qValueNotch, double pep, double pepQValue) - { - FdrInfo = new FdrInfo - { - CumulativeTarget = cumulativeTarget, - CumulativeDecoy = cumulativeDecoy, - QValue = qValue, - CumulativeTargetNotch = cumulativeTargetNotch, - CumulativeDecoyNotch = cumulativeDecoyNotch, - QValueNotch = qValueNotch, - PEP = pep, - PEP_QValue = pepQValue - }; - } - - /// - /// This method saves properties of this PSM for internal use. It is NOT used for any output. - /// These resolved fields are (usually) null if there is more than one option. - /// e.g., if this PSM can be explained by more than one base sequence, the BaseSequence property will be null - /// - public void ResolveAllAmbiguities() - { - IsDecoy = _BestMatchingPeptides.Any(p => p.Pwsm.Protein.IsDecoy); - IsContaminant = _BestMatchingPeptides.Any(p => p.Pwsm.Protein.IsContaminant); - FullSequence = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.FullSequence)).ResolvedValue; - BaseSequence = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.BaseSequence)).ResolvedValue; - PeptideLength = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.Length)).ResolvedValue; - OneBasedStartResidueInProtein = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.OneBasedStartResidueInProtein)).ResolvedValue; - OneBasedEndResidueInProtein = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.OneBasedEndResidueInProtein)).ResolvedValue; - ProteinLength = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.Protein.Length)).ResolvedValue; - PeptideMonisotopicMass = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.MonoisotopicMass)).ResolvedValue; - ProteinAccession = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.Protein.Accession)).ResolvedValue; - Organism = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.Protein.Organism)).ResolvedValue; - ModsIdentified = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.AllModsOneIsNterminus)).ResolvedValue; - ModsChemicalFormula = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.AllModsOneIsNterminus.Select(c => (c.Value)))).ResolvedValue; - Notch = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Notch)).ResolvedValue; - - // if the PSM matches a target and a decoy and they are the SAME SEQUENCE, remove the decoy - if (IsDecoy) - { - bool removedPeptides = false; - var hits = _BestMatchingPeptides.GroupBy(p => p.Pwsm.FullSequence); - - foreach (var hit in hits) - { - if (hit.Any(p => p.Pwsm.Protein.IsDecoy) && hit.Any(p => !p.Pwsm.Protein.IsDecoy)) - { - // at least one peptide with this sequence is a target and at least one is a decoy - // remove the decoys with this sequence - var pwsmToRemove = _BestMatchingPeptides.Where(p => p.Pwsm.FullSequence == hit.Key && p.Pwsm.Protein.IsDecoy).ToList(); - _BestMatchingPeptides.RemoveAll(p => p.Pwsm.FullSequence == hit.Key && p.Pwsm.Protein.IsDecoy); - foreach ((int, PeptideWithSetModifications) pwsm in pwsmToRemove) - { - PeptidesToMatchingFragments.Remove(pwsm.Item2); - } - - removedPeptides = true; - } - } - - if (removedPeptides) - { - ResolveAllAmbiguities(); - } - } - - // TODO: technically, different peptide options for this PSM can have different matched ions - // we can write a Resolve method for this if we want... - MatchedFragmentIons = PeptidesToMatchingFragments.First().Value; - } - - public static int GetLongestIonSeriesBidirectional(Dictionary> PeptidesToMatchingFragments, PeptideWithSetModifications peptide) + public PeptideSpectralMatch(IBioPolymerWithSetMods peptide, int notch, double score, int scanIndex, + Ms2ScanWithSpecificMass scan, CommonParameters commonParameters, + List matchedFragmentIons, double xcorr = 0) : base(peptide, notch, score, scanIndex, + scan, commonParameters, matchedFragmentIons, xcorr) { - List maxDiffs = new List { 1 }; - if (PeptidesToMatchingFragments != null && PeptidesToMatchingFragments.TryGetValue(peptide, out var matchedFragments) && matchedFragments != null && matchedFragments.Any()) - { - var jointSeries = matchedFragments.Select(p => p.NeutralTheoreticalProduct.AminoAcidPosition).Distinct().ToList(); - - if (jointSeries.Count > 0) - { - jointSeries.Sort(); - - List aminoAcidPostionsThatCouldBeObserved = Enumerable.Range(1, peptide.BaseSequence.Length).ToList(); - - List missing = aminoAcidPostionsThatCouldBeObserved.Except(jointSeries).ToList(); - - int localMaxDiff = 0; - for (int i = 0; i < aminoAcidPostionsThatCouldBeObserved.Count; i++) - { - if (!missing.Contains(aminoAcidPostionsThatCouldBeObserved[i])) - { - localMaxDiff++; - } - else - { - maxDiffs.Add(localMaxDiff); - localMaxDiff = 0; - } - } - maxDiffs.Add(localMaxDiff); - } - } - - return maxDiffs.Max(); - } - - /// - /// Determine the Fragment Coverage the PSM - /// Assigns fragment coverage indices for the PSM and the protein based on Amino Acid Position in Matched Ion Fragments - /// - public void GetAminoAcidCoverage() - { - if (string.IsNullOrEmpty(this.BaseSequence) || - !this.MatchedFragmentIons.Any()) return; - //Pull C terminal and N terminal Fragments and amino acid numbers - var nTermFragmentAAPositions = this.MatchedFragmentIons.Where(p => - p.NeutralTheoreticalProduct.Terminus == FragmentationTerminus.N) - .Select(j => j.NeutralTheoreticalProduct.AminoAcidPosition).Distinct().ToList(); - - var cTermFragmentAAPositions = this.MatchedFragmentIons.Where(p => - p.NeutralTheoreticalProduct.Terminus == FragmentationTerminus.C) - .Select(j => j.NeutralTheoreticalProduct.AminoAcidPosition).Distinct().ToList(); - - //Create a hashset to store the covered amino acid positions - HashSet fragmentCoveredAminoAcids = new(); - - //Check N term frags first - if (nTermFragmentAAPositions.Any()) - { - nTermFragmentAAPositions.Sort(); - - //if the final NFragment is present, last AA is covered - if (nTermFragmentAAPositions.Contains(this.BaseSequence.Length - 1)) - { - fragmentCoveredAminoAcids.Add(this.BaseSequence.Length); - } - - // if the first NFragment is present, first AA is covered - if (nTermFragmentAAPositions.Contains(1)) - { - fragmentCoveredAminoAcids.Add(1); - } - - //Check all amino acids except for the last one in the list - for (int i = 0; i < nTermFragmentAAPositions.Count - 1; i++) - { - //sequential AA, second one is covered - if (nTermFragmentAAPositions[i + 1] - nTermFragmentAAPositions[i] == 1) - { - fragmentCoveredAminoAcids.Add(nTermFragmentAAPositions[i + 1]); - } - //check to see if the position is covered from both directions, inclusive - if (cTermFragmentAAPositions.Contains(nTermFragmentAAPositions[i + 1])) - { - fragmentCoveredAminoAcids.Add(nTermFragmentAAPositions[i + 1]); - } - - //check to see if the position is covered from both directions, exclusive - if (cTermFragmentAAPositions.Contains(nTermFragmentAAPositions[i + 1] + 2)) - { - fragmentCoveredAminoAcids.Add(nTermFragmentAAPositions[i + 1] + 1); - } - } - - } - - //Check C term frags - if (cTermFragmentAAPositions.Any()) - { - cTermFragmentAAPositions.Sort(); - - //if the second AA is present, the first AA is covered - if (cTermFragmentAAPositions.Contains(2)) - { - fragmentCoveredAminoAcids.Add(1); - } - - //if the last AA is present, the final AA is covered - if (cTermFragmentAAPositions.Contains(this.BaseSequence.Length)) - { - fragmentCoveredAminoAcids.Add(this.BaseSequence.Length); - } - - //check all amino acids except for the last one in the list - for (int i = 0; i < cTermFragmentAAPositions.Count - 1; i++) - { - //sequential AA, the first one is covered - if (cTermFragmentAAPositions[i + 1] - cTermFragmentAAPositions[i] == 1) - { - fragmentCoveredAminoAcids.Add(cTermFragmentAAPositions[i]); - } - } - } - - //store in PSM - var fragmentCoveredAminoAcidsList = fragmentCoveredAminoAcids.ToList(); - fragmentCoveredAminoAcidsList.Sort(); - this.FragmentCoveragePositionInPeptide = fragmentCoveredAminoAcidsList; } - public static int GetCountComplementaryIons(Dictionary> PeptidesToMatchingFragments, PeptideWithSetModifications peptide) - { - if (PeptidesToMatchingFragments != null && PeptidesToMatchingFragments.TryGetValue(peptide, out var matchedFragments) && matchedFragments != null && matchedFragments.Any()) - { - List nIons = matchedFragments.Where(f => f.NeutralTheoreticalProduct.Terminus == FragmentationTerminus.N).Select(f => f.NeutralTheoreticalProduct.FragmentNumber).ToList(); - List cIons = matchedFragments.Where(f => f.NeutralTheoreticalProduct.Terminus == FragmentationTerminus.C).Select(f => (peptide.BaseSequence.Length - f.NeutralTheoreticalProduct.FragmentNumber)).ToList(); - if (nIons.Any() && cIons.Any()) - { - return nIons.Intersect(cIons).Count(); - } - else - { - return 0; - } - } - else - { - return 0; - } - } + #region Silac /// /// This method changes the base and full sequences to reflect heavy silac labels @@ -403,103 +30,30 @@ public static int GetCountComplementaryIons(Dictionary labels, IReadOnlyDictionary modsToWritePruned) { //FullSequence - FullSequence = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.FullSequence)).ResolvedString; //string, not value + FullSequence = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.FullSequence)).ResolvedString; //string, not value FullSequence = SilacConversions.GetAmbiguousLightSequence(FullSequence, labels, false); //BaseSequence - BaseSequence = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.BaseSequence)).ResolvedString; //string, not value + BaseSequence = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.BaseSequence)).ResolvedString; //string, not value BaseSequence = SilacConversions.GetAmbiguousLightSequence(BaseSequence, labels, true); //EssentialSequence - EssentialSequence = PsmTsvWriter.Resolve(_BestMatchingPeptides.Select(b => b.Pwsm.EssentialSequence(modsToWritePruned))).ResolvedString; //string, not value + EssentialSequence = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.EssentialSequence(modsToWritePruned))).ResolvedString; //string, not value EssentialSequence = SilacConversions.GetAmbiguousLightSequence(EssentialSequence, labels, false); } - /// - /// This method is used by protein parsimony to remove PeptideWithSetModifications objects that have non-parsimonious protein associations - /// - public void TrimProteinMatches(HashSet parsimoniousProteins) - { - if (IsDecoy) - { - if (_BestMatchingPeptides.Any(p => parsimoniousProteins.Contains(p.Pwsm.Protein) && p.Pwsm.Protein.IsDecoy)) - { - _BestMatchingPeptides.RemoveAll(p => !parsimoniousProteins.Contains(p.Pwsm.Protein)); - } - // else do nothing - } - else - { - _BestMatchingPeptides.RemoveAll(p => !parsimoniousProteins.Contains(p.Pwsm.Protein)); - } - - ResolveAllAmbiguities(); - } - - /// - /// This method is used by protein parsimony to add PeptideWithSetModifications objects for modification-agnostic parsimony - /// - public void AddProteinMatch((int, PeptideWithSetModifications) peptideWithNotch, List mfi) - { - if (!_BestMatchingPeptides.Select(p => p.Pwsm).Contains(peptideWithNotch.Item2)) - { - _BestMatchingPeptides.Add(peptideWithNotch); - if (!PeptidesToMatchingFragments.ContainsKey(peptideWithNotch.Item2)) - { - PeptidesToMatchingFragments.Add(peptideWithNotch.Item2, mfi); - } - ResolveAllAmbiguities(); - } - } - /// /// This method is used by SILAC quantification to add heavy/light psms /// Don't have access to the scans at that point, so a new contructor is needed /// - public PeptideSpectralMatch Clone(List<(int Notch, PeptideWithSetModifications Peptide)> bestMatchingPeptides) + public PeptideSpectralMatch Clone(List<(int Notch, IBioPolymerWithSetMods Peptide)> bestMatchingPeptides) => new PeptideSpectralMatch(this, bestMatchingPeptides); + + protected PeptideSpectralMatch(SpectralMatch psm, List<(int Notch, IBioPolymerWithSetMods Peptide)> bestMatchingPeptides) + : base(psm, bestMatchingPeptides) { - return new PeptideSpectralMatch(this, bestMatchingPeptides); } - protected PeptideSpectralMatch(PeptideSpectralMatch psm, List<(int Notch, PeptideWithSetModifications Peptide)> bestMatchingPeptides) - { - _BestMatchingPeptides = bestMatchingPeptides; - BaseSequence = PsmTsvWriter.Resolve(bestMatchingPeptides.Select(b => b.Peptide.BaseSequence)).ResolvedValue; - FullSequence = PsmTsvWriter.Resolve(bestMatchingPeptides.Select(b => b.Peptide.FullSequence)).ResolvedValue; - - ModsChemicalFormula = psm.ModsChemicalFormula; - Notch = psm.Notch; - PeptideLength = psm.PeptideLength; - OneBasedStartResidueInProtein = psm.OneBasedStartResidueInProtein; - OneBasedEndResidueInProtein = psm.OneBasedEndResidueInProtein; - PeptideMonisotopicMass = psm.PeptideMonisotopicMass; - ProteinLength = psm.ProteinLength; - ProteinAccession = psm.ProteinAccession; - Organism = psm.Organism; - MatchedFragmentIons = psm.MatchedFragmentIons; - PsmCount = psm.PsmCount; - ModsIdentified = psm.ModsIdentified; - LocalizedScores = psm.LocalizedScores; - ScanNumber = psm.ScanNumber; - PrecursorScanNumber = psm.PrecursorScanNumber; - ScanRetentionTime = psm.ScanRetentionTime; - ScanExperimentalPeaks = psm.ScanExperimentalPeaks; - TotalIonCurrent = psm.TotalIonCurrent; - ScanPrecursorCharge = psm.ScanPrecursorCharge; - ScanPrecursorMonoisotopicPeakMz = psm.ScanPrecursorMonoisotopicPeakMz; - ScanPrecursorMass = psm.ScanPrecursorMass; - FullFilePath = psm.FullFilePath; - ScanIndex = psm.ScanIndex; - FdrInfo = psm.FdrInfo; - Score = psm.Score; - Xcorr = psm.Xcorr; - RunnerUpScore = psm.RunnerUpScore; - IsDecoy = psm.IsDecoy; - IsContaminant = psm.IsContaminant; - DigestionParams = psm.DigestionParams; - PeptidesToMatchingFragments = psm.PeptidesToMatchingFragments; - SpectralAngle = psm.SpectralAngle; - } + #endregion } -} \ No newline at end of file +} diff --git a/MetaMorpheus/EngineLayer/ProteinParsimony/ProteinGroup.cs b/MetaMorpheus/EngineLayer/ProteinParsimony/ProteinGroup.cs index b8252a28c..e882391b0 100644 --- a/MetaMorpheus/EngineLayer/ProteinParsimony/ProteinGroup.cs +++ b/MetaMorpheus/EngineLayer/ProteinParsimony/ProteinGroup.cs @@ -20,7 +20,7 @@ public ProteinGroup(HashSet proteins, HashSet p.Accession)); AllPeptides = peptides; UniquePeptides = uniquePeptides; - AllPsmsBelowOnePercentFDR = new HashSet(); + AllPsmsBelowOnePercentFDR = new HashSet(); SequenceCoverageFraction = new List(); SequenceCoverageDisplayList = new List(); SequenceCoverageDisplayListWithMods = new List(); @@ -65,7 +65,7 @@ public ProteinGroup(HashSet proteins, HashSet UniquePeptides { get; set; } - public HashSet AllPsmsBelowOnePercentFDR { get; set; } + public HashSet AllPsmsBelowOnePercentFDR { get; set; } public List SequenceCoverageFraction { get; private set; } @@ -404,7 +404,7 @@ public void CalculateSequenceCoverage() { psm.GetAminoAcidCoverage(); - foreach (var peptide in psm.BestMatchingPeptides.Select(psm => psm.Peptide).DistinctBy(pep => pep.FullSequence)) + foreach (var peptide in psm.BestMatchingBioPolymersWithSetMods.Select(psm => psm.Peptide as PeptideWithSetModifications).DistinctBy(pep => pep.FullSequence)) { // might be unambiguous but also shared; make sure this protein group contains this peptide+protein combo if (Proteins.Contains(peptide.Protein)) @@ -430,13 +430,13 @@ public void CalculateSequenceCoverage() HashSet coveredResiduesInProteinOneBased = new(); //loop through PSMs - foreach (PeptideSpectralMatch psm in AllPsmsBelowOnePercentFDR.Where(psm => psm.BaseSequence != null)) + foreach (SpectralMatch psm in AllPsmsBelowOnePercentFDR.Where(psm => psm.BaseSequence != null)) { //Calculate the covered bases within the psm. This is one based numbering for the peptide only psm.GetAminoAcidCoverage(); if (psm.FragmentCoveragePositionInPeptide == null) continue; //loop through each peptide within the psm - IEnumerable pwsms = psm.BestMatchingPeptides.Select(p => p.Peptide) + IEnumerable pwsms = psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide as PeptideWithSetModifications) .Where(p => p.Protein.Accession == protein.Accession); foreach (PeptideWithSetModifications pwsm in pwsms) { @@ -445,7 +445,7 @@ public void CalculateSequenceCoverage() //add the peptide start position within the protein to each covered index of the psm foreach (var position in psm.FragmentCoveragePositionInPeptide) { - coveredResiduesInPeptide.Add(position + pwsm.OneBasedStartResidueInProtein - + coveredResiduesInPeptide.Add(position + pwsm.OneBasedStartResidue - 1); //subtract one because these are both one based } @@ -472,7 +472,7 @@ public void CalculateSequenceCoverage() // get residue numbers of each peptide in the protein and identify them as observed if the sequence is unambiguous foreach (var peptide in proteinsWithUnambigSeqPsms[protein]) { - for (int i = peptide.OneBasedStartResidueInProtein; i <= peptide.OneBasedEndResidueInProtein; i++) + for (int i = peptide.OneBasedStartResidue; i <= peptide.OneBasedEndResidue; i++) { coveredOneBasedResidues.Add(i); } @@ -509,7 +509,7 @@ public void CalculateSequenceCoverage() && !mod.Value.ModificationType.Contains("Common Fixed")) { modsOnThisProtein.Add( - new KeyValuePair(pep.OneBasedStartResidueInProtein + mod.Key - 2, + new KeyValuePair(pep.OneBasedStartResidue + mod.Key - 2, mod.Value)); } } @@ -572,7 +572,7 @@ public void CalculateSequenceCoverage() } else if (mod.Value.LocationRestriction.Equals("Anywhere.")) { - indexInProtein = pep.OneBasedStartResidueInProtein + mod.Key - 2; + indexInProtein = pep.OneBasedStartResidue + mod.Key - 2; } else if (mod.Value.LocationRestriction.Equals("C-terminal.")) { @@ -595,8 +595,8 @@ public void CalculateSequenceCoverage() modIndex.Add(modKey); foreach (var pept in proteinsWithPsmsWithLocalizedMods[protein]) { - if (indexInProtein >= pept.OneBasedStartResidueInProtein - (indexInProtein == 1 ? 1 : 0) - && indexInProtein <= pept.OneBasedEndResidueInProtein) + if (indexInProtein >= pept.OneBasedStartResidue - (indexInProtein == 1 ? 1 : 0) + && indexInProtein <= pept.OneBasedEndResidue) { pepNumTotal += 1; } @@ -644,11 +644,11 @@ public void MergeProteinGroupWith(ProteinGroup other) public ProteinGroup ConstructSubsetProteinGroup(string fullFilePath, List silacLabels = null) { var allPsmsForThisFile = - new HashSet( + new HashSet( AllPsmsBelowOnePercentFDR.Where(p => p.FullFilePath.Equals(fullFilePath))); var allPeptidesForThisFile = new HashSet( - allPsmsForThisFile.SelectMany(p => p.BestMatchingPeptides.Select(v => v.Peptide))); + allPsmsForThisFile.SelectMany(p => p.BestMatchingBioPolymersWithSetMods.Select(v => v.Peptide as PeptideWithSetModifications))); var allUniquePeptidesForThisFile = new HashSet(UniquePeptides.Intersect(allPeptidesForThisFile)); diff --git a/MetaMorpheus/EngineLayer/ProteinParsimony/ProteinParsimonyEngine.cs b/MetaMorpheus/EngineLayer/ProteinParsimony/ProteinParsimonyEngine.cs index 6139fcd7c..d57cc666b 100644 --- a/MetaMorpheus/EngineLayer/ProteinParsimony/ProteinParsimonyEngine.cs +++ b/MetaMorpheus/EngineLayer/ProteinParsimony/ProteinParsimonyEngine.cs @@ -5,7 +5,9 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; +using System.Reflection.Metadata.Ecma335; using System.Threading.Tasks; +using Omics; using IDigestionParams = Omics.Digestion.IDigestionParams; namespace EngineLayer @@ -15,10 +17,10 @@ public class ProteinParsimonyEngine : MetaMorpheusEngine /// /// All peptides meeting the prefiltering criteria for parsimony (e.g., peptides from non-ambiguous high-confidence PSMs) /// - private readonly HashSet _fdrFilteredPeptides; + private readonly HashSet _fdrFilteredPeptides; - private readonly List _fdrFilteredPsms; - private readonly List _allPsms; + private readonly List _fdrFilteredPsms; + private readonly List _allPsms; private const double FdrCutoffForParsimony = 0.01; /// @@ -26,13 +28,13 @@ public class ProteinParsimonyEngine : MetaMorpheusEngine /// private readonly bool _treatModPeptidesAsDifferentPeptides; - public ProteinParsimonyEngine(List allPsms, bool modPeptidesAreDifferent, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) + public ProteinParsimonyEngine(List allPsms, bool modPeptidesAreDifferent, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) { _treatModPeptidesAsDifferentPeptides = modPeptidesAreDifferent; if (!allPsms.Any()) { - _fdrFilteredPsms = new List(); + _fdrFilteredPsms = new List(); } // parsimony will only use non-ambiguous, high-confidence PSMs @@ -47,10 +49,10 @@ public ProteinParsimonyEngine(List allPsms, bool modPeptid } // peptides to use in parsimony = peptides observed in high-confidence PSMs (including decoys) - _fdrFilteredPeptides = new HashSet(); + _fdrFilteredPeptides = new HashSet(); foreach (var psm in _fdrFilteredPsms) { - foreach (var peptide in psm.BestMatchingPeptides.Select(p => p.Peptide)) + foreach (var peptide in psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide)) { _fdrFilteredPeptides.Add(peptide); } @@ -96,18 +98,18 @@ private List RunProteinParsimonyEngine() { foreach (var protease in _fdrFilteredPsms.GroupBy(p => p.DigestionParams.Protease)) { - Dictionary> sequenceWithPsms = new Dictionary>(); + Dictionary> sequenceWithPsms = new Dictionary>(); // for each protease, match the base sequence of each peptide to its PSMs - foreach (PeptideSpectralMatch psm in protease) + foreach (SpectralMatch psm in protease) { - if (sequenceWithPsms.TryGetValue(psm.BaseSequence, out List peptidesForThisBaseSequence)) + if (sequenceWithPsms.TryGetValue(psm.BaseSequence, out List peptidesForThisBaseSequence)) { peptidesForThisBaseSequence.Add(psm); } else { - sequenceWithPsms[psm.BaseSequence] = new List { psm }; + sequenceWithPsms[psm.BaseSequence] = new List { psm }; } } @@ -122,7 +124,7 @@ private List RunProteinParsimonyEngine() { var baseSequence = sequenceWithPsmsList[i]; - var peptidesWithNotchInfo = baseSequence.Value.SelectMany(p => p.BestMatchingPeptides).Distinct().ToList(); + var peptidesWithNotchInfo = baseSequence.Value.SelectMany(p => p.BestMatchingBioPolymersWithSetMods).Distinct().ToList(); // if the base seq has >1 PeptideWithSetMods object and has >0 mods, it might need to be matched to new proteins if (peptidesWithNotchInfo.Count > 1 && peptidesWithNotchInfo.Any(p => p.Peptide.NumMods > 0)) @@ -130,7 +132,7 @@ private List RunProteinParsimonyEngine() bool needToAddPeptideToProteinAssociations = false; // numProteinsForThisBaseSequence is the total number of proteins that this base sequence is a digestion product of - int numProteinsForThisBaseSequence = peptidesWithNotchInfo.Select(p => p.Peptide.Protein).Distinct().Count(); + int numProteinsForThisBaseSequence = peptidesWithNotchInfo.Select(p => p.Peptide.Parent).Distinct().Count(); if (numProteinsForThisBaseSequence == 1) { @@ -140,7 +142,7 @@ private List RunProteinParsimonyEngine() foreach (var psm in baseSequence.Value) { // numProteinsForThisPsm is the number of proteins that this PSM's peptides are associated with - int numProteinsForThisPsm = psm.BestMatchingPeptides.Select(p => p.Peptide.Protein).Distinct().Count(); + int numProteinsForThisPsm = psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide.Parent).Distinct().Count(); if (numProteinsForThisPsm != numProteinsForThisBaseSequence) { @@ -160,19 +162,19 @@ private List RunProteinParsimonyEngine() (IDigestionParams DigestParams, int OneBasedStart, int OneBasedEnd, int MissedCleavages, int Notch, Omics.Digestion.CleavageSpecificity CleavageSpecificity)>(); - foreach (PeptideSpectralMatch psm in baseSequence.Value) + foreach (SpectralMatch psm in baseSequence.Value) { - foreach (var peptideWithNotch in psm.BestMatchingPeptides) + foreach (var peptideWithNotch in psm.BestMatchingBioPolymersWithSetMods) { - PeptideWithSetModifications peptide = peptideWithNotch.Peptide; + PeptideWithSetModifications peptide = peptideWithNotch.Peptide as PeptideWithSetModifications; Protein protein = peptide.Protein; if (!proteinToPeptideInfo.ContainsKey(protein)) { proteinToPeptideInfo.Add(protein, (peptideWithNotch.Peptide.DigestionParams, - peptideWithNotch.Peptide.OneBasedStartResidueInProtein, - peptideWithNotch.Peptide.OneBasedEndResidueInProtein, + peptideWithNotch.Peptide.OneBasedStartResidue, + peptideWithNotch.Peptide.OneBasedEndResidue, peptideWithNotch.Peptide.MissedCleavages, peptideWithNotch.Notch, peptideWithNotch.Peptide.CleavageSpecificityForFdrCategory)); @@ -183,9 +185,9 @@ private List RunProteinParsimonyEngine() // create any new associations that need to be made foreach (PeptideSpectralMatch psm in baseSequence.Value) { - PeptideWithSetModifications originalPeptide = psm.BestMatchingPeptides.First().Peptide; - List mfi = psm.PeptidesToMatchingFragments[originalPeptide]; - HashSet psmProteins = new HashSet(psm.BestMatchingPeptides.Select(p => p.Peptide.Protein)); + IBioPolymerWithSetMods originalPeptide = psm.BestMatchingBioPolymersWithSetMods.First().Peptide; + List mfi = psm.BioPolymersWithSetModsToMatchingFragments[originalPeptide]; + HashSet psmProteins = new HashSet(psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide.Parent as Protein)); foreach (var proteinWithDigestInfo in proteinToPeptideInfo) { @@ -197,7 +199,7 @@ private List RunProteinParsimonyEngine() proteinWithDigestInfo.Value.OneBasedStart, proteinWithDigestInfo.Value.OneBasedEnd, proteinWithDigestInfo.Value.CleavageSpecificity, - originalPeptide.PeptideDescription, + originalPeptide.Description, proteinWithDigestInfo.Value.MissedCleavages, originalPeptide.AllModsOneIsNterminus, originalPeptide.NumFixedMods); @@ -276,23 +278,27 @@ private List RunProteinParsimonyEngine() foreach (var peptide in _fdrFilteredPeptides) { ParsimonySequence sequence = new ParsimonySequence(peptide, _treatModPeptidesAsDifferentPeptides); + if (peptide.Parent is not Protein protein) + { + continue; + } if (peptideSequenceToProteins.TryGetValue(sequence, out List proteinsForThisPeptideSequence)) { - proteinsForThisPeptideSequence.Add(peptide.Protein); + proteinsForThisPeptideSequence.Add(protein); } else { - peptideSequenceToProteins.Add(sequence, new List { peptide.Protein }); + peptideSequenceToProteins.Add(sequence, new List { protein }); } - if (proteinToPepSeqMatch.TryGetValue(peptide.Protein, out var peptideSequences)) + if (proteinToPepSeqMatch.TryGetValue(protein, out var peptideSequences)) { peptideSequences.Add(sequence); } else { - proteinToPepSeqMatch.Add(peptide.Protein, new HashSet { sequence }); + proteinToPepSeqMatch.Add(protein, new HashSet { sequence }); } } @@ -421,12 +427,12 @@ private List RunProteinParsimonyEngine() } // Parsimony stage 5: remove peptide objects that do not have proteins in the parsimonious list - foreach (PeptideSpectralMatch psm in _allPsms) + foreach (SpectralMatch psm in _allPsms) { // if this PSM has a protein in the parsimonious list, it removes the proteins NOT in the parsimonious list // otherwise, no proteins are removed (i.e., for PSMs that cannot be explained by a parsimonious protein, // no protein associations are removed) - if (psm.BestMatchingPeptides.Any(p => parsimoniousProteinList.Contains(p.Peptide.Protein))) + if (psm.BestMatchingBioPolymersWithSetMods.Any(p => parsimoniousProteinList.Contains(p.Peptide.Parent as Protein))) { psm.TrimProteinMatches(parsimoniousProteinList); } @@ -449,8 +455,9 @@ private List ConstructProteinGroups(HashSet proteinGroups = new List(); var proteinToPeptidesMatching = new Dictionary>(); - foreach (var peptide in _fdrFilteredPeptides) + foreach (var bioPolymerWithSetMods in _fdrFilteredPeptides) { + var peptide = (PeptideWithSetModifications)bioPolymerWithSetMods; if (proteinToPeptidesMatching.TryGetValue(peptide.Protein, out HashSet peptidesHere)) { peptidesHere.Add(peptide); diff --git a/MetaMorpheus/EngineLayer/ProteinScoringAndFdr/ProteinScoringAndFdrEngine.cs b/MetaMorpheus/EngineLayer/ProteinScoringAndFdr/ProteinScoringAndFdrEngine.cs index 28924565d..d1459cc87 100644 --- a/MetaMorpheus/EngineLayer/ProteinScoringAndFdr/ProteinScoringAndFdrEngine.cs +++ b/MetaMorpheus/EngineLayer/ProteinScoringAndFdr/ProteinScoringAndFdrEngine.cs @@ -1,18 +1,19 @@ using Proteomics.ProteolyticDigestion; using System.Collections.Generic; using System.Linq; +using Omics; namespace EngineLayer { public class ProteinScoringAndFdrEngine : MetaMorpheusEngine { - private readonly IEnumerable NewPsms; + private readonly IEnumerable NewPsms; private readonly bool NoOneHitWonders; private readonly bool TreatModPeptidesAsDifferentPeptides; private readonly bool MergeIndistinguishableProteinGroups; private readonly List ProteinGroups; - public ProteinScoringAndFdrEngine(List proteinGroups, List newPsms, bool noOneHitWonders, bool treatModPeptidesAsDifferentPeptides, bool mergeIndistinguishableProteinGroups, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) + public ProteinScoringAndFdrEngine(List proteinGroups, List newPsms, bool noOneHitWonders, bool treatModPeptidesAsDifferentPeptides, bool mergeIndistinguishableProteinGroups, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds) : base(commonParameters, fileSpecificParameters, nestedIds) { NewPsms = newPsms; ProteinGroups = proteinGroups; @@ -35,20 +36,20 @@ protected override MetaMorpheusEngineResults RunSpecific() return proteinGroupName.Contains("DECOY_") ? proteinGroupName.Replace("DECOY_", "") : proteinGroupName; } - private void ScoreProteinGroups(List proteinGroups, IEnumerable psmList) + private void ScoreProteinGroups(List proteinGroups, IEnumerable psmList) { // add each protein groups PSMs - var peptideToPsmMatching = new Dictionary>(); + var peptideToPsmMatching = new Dictionary>(); foreach (var psm in psmList) { if (psm.FdrInfo.QValueNotch <= 0.01 && psm.FdrInfo.QValue <= 0.01) { if ((TreatModPeptidesAsDifferentPeptides && psm.FullSequence != null) || (!TreatModPeptidesAsDifferentPeptides && psm.BaseSequence != null)) { - foreach (var pepWithSetMods in psm.BestMatchingPeptides.Select(p => p.Peptide)) + foreach (var pepWithSetMods in psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide)) { - if (!peptideToPsmMatching.TryGetValue(pepWithSetMods, out HashSet psmsForThisPeptide)) - peptideToPsmMatching.Add(pepWithSetMods, new HashSet { psm }); + if (!peptideToPsmMatching.TryGetValue(pepWithSetMods, out HashSet psmsForThisPeptide)) + peptideToPsmMatching.Add(pepWithSetMods, new HashSet { psm }); else psmsForThisPeptide.Add(psm); } @@ -62,7 +63,7 @@ private void ScoreProteinGroups(List proteinGroups, IEnumerable psms)) + if (peptideToPsmMatching.TryGetValue(peptide, out HashSet psms)) proteinGroup.AllPsmsBelowOnePercentFDR.UnionWith(psms); else pepsToRemove.Add(peptide); diff --git a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs index 3f7f6d7d5..524805427 100644 --- a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs +++ b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs @@ -44,7 +44,7 @@ public static List ReadTsv(string filePath, out List warning { psms.Add(new PsmFromTsv(line, Split, parsedHeader)); } - catch (Exception) + catch (Exception e) { warnings.Add("Could not read line: " + lineCount); } diff --git a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvWriter.cs b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvWriter.cs index fa2dfbb54..786b72c3b 100644 --- a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvWriter.cs +++ b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvWriter.cs @@ -176,7 +176,7 @@ internal static (string ResolvedString, string ResolvedValue) Resolve(IEnumerabl } } - internal static void AddBasicMatchData(Dictionary s, PeptideSpectralMatch psm) + internal static void AddBasicMatchData(Dictionary s, SpectralMatch psm) { s[PsmTsvHeader.FileName] = psm == null ? " " : Path.GetFileNameWithoutExtension(psm.FullFilePath); s[PsmTsvHeader.Ms2ScanNumber] = psm == null ? " " : psm.ScanNumber.ToString(CultureInfo.InvariantCulture); @@ -189,21 +189,21 @@ internal static void AddBasicMatchData(Dictionary s, PeptideSpec s[PsmTsvHeader.PrecursorMass] = psm == null ? " " : psm.ScanPrecursorMass.ToString("F5", CultureInfo.InvariantCulture); s[PsmTsvHeader.Score] = psm == null ? " " : psm.Score.ToString("F3", CultureInfo.InvariantCulture); s[PsmTsvHeader.DeltaScore] = psm == null ? " " : psm.DeltaScore.ToString("F3", CultureInfo.InvariantCulture); - s[PsmTsvHeader.Notch] = psm == null ? " " : Resolve(psm.BestMatchingPeptides.Select(p => p.Notch)).ResolvedString; + s[PsmTsvHeader.Notch] = psm == null ? " " : Resolve(psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Notch)).ResolvedString; } - internal static void AddPeptideSequenceData(Dictionary s, PeptideSpectralMatch psm, IReadOnlyDictionary ModsToWritePruned) + internal static void AddPeptideSequenceData(Dictionary s, SpectralMatch sm, IReadOnlyDictionary ModsToWritePruned) { - bool pepWithModsIsNull = psm == null || psm.BestMatchingPeptides == null || !psm.BestMatchingPeptides.Any(); + bool pepWithModsIsNull = sm == null || sm.BestMatchingBioPolymersWithSetMods == null || !sm.BestMatchingBioPolymersWithSetMods.Any(); - List pepsWithMods = pepWithModsIsNull ? null : psm.BestMatchingPeptides.Select(p => p.Peptide).ToList(); + List pepsWithMods = pepWithModsIsNull ? null : sm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide).ToList(); - s[PsmTsvHeader.BaseSequence] = pepWithModsIsNull ? " " : (psm.BaseSequence ?? Resolve(pepWithModsIsNull ? null : pepsWithMods.Select(b => b.BaseSequence)).ResolvedString); - s[PsmTsvHeader.FullSequence] = pepWithModsIsNull ? " " : (psm.FullSequence != null ? psm.FullSequence : Resolve(pepWithModsIsNull ? null : pepsWithMods.Select(b => b.FullSequence)).ResolvedString); - s[PsmTsvHeader.EssentialSequence] = pepWithModsIsNull ? " " : (psm.EssentialSequence != null ? psm.EssentialSequence : Resolve(pepWithModsIsNull ? null : pepsWithMods.Select(b => b.EssentialSequence(ModsToWritePruned))).ResolvedString); - string geneString = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => string.Join(", ", b.Protein.GeneNames.Select(d => $"{d.Item1}:{d.Item2}"))), psm.FullSequence).ResolvedString; + s[PsmTsvHeader.BaseSequence] = pepWithModsIsNull ? " " : (sm.BaseSequence ?? Resolve(pepWithModsIsNull ? null : pepsWithMods.Select(b => b.BaseSequence)).ResolvedString); + s[PsmTsvHeader.FullSequence] = pepWithModsIsNull ? " " : (sm.FullSequence != null ? sm.FullSequence : Resolve(pepWithModsIsNull ? null : pepsWithMods.Select(b => b.FullSequence)).ResolvedString); + s[PsmTsvHeader.EssentialSequence] = pepWithModsIsNull ? " " : (sm.EssentialSequence != null ? sm.EssentialSequence : Resolve(pepWithModsIsNull ? null : pepsWithMods.Select(b => b.EssentialSequence(ModsToWritePruned))).ResolvedString); + string geneString = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => string.Join(", ", b.Parent.GeneNames.Select(d => $"{d.Item1}:{d.Item2}"))), sm.FullSequence).ResolvedString; s[PsmTsvHeader.AmbiguityLevel] = ProteoformLevelClassifier.ClassifyPrSM(s[PsmTsvHeader.FullSequence], geneString); - s[PsmTsvHeader.PsmCount] = pepWithModsIsNull ? " " : psm.PsmCount.ToString(); + s[PsmTsvHeader.PsmCount] = pepWithModsIsNull ? " " : sm.PsmCount.ToString(); s[PsmTsvHeader.Mods] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.AllModsOneIsNterminus)).ResolvedString; s[PsmTsvHeader.ModsChemicalFormulas] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(p => p.AllModsOneIsNterminus.Select(v => v.Value))).ResolvedString; @@ -211,31 +211,38 @@ internal static void AddPeptideSequenceData(Dictionary s, Peptid s[PsmTsvHeader.NumVariableMods] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.NumVariableMods)).ResolvedString; s[PsmTsvHeader.MissedCleavages] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.MissedCleavages.ToString(CultureInfo.InvariantCulture))).ResolvedString; s[PsmTsvHeader.PeptideMonoMass] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.MonoisotopicMass)).ResolvedString; - s[PsmTsvHeader.MassDiffDa] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => psm.ScanPrecursorMass - b.MonoisotopicMass)).ResolvedString; - s[PsmTsvHeader.MassDiffPpm] = pepWithModsIsNull ? " " : ResolveF2(pepsWithMods.Select(b => ((psm.ScanPrecursorMass - b.MonoisotopicMass) / b.MonoisotopicMass * 1e6))).ResolvedString; - s[PsmTsvHeader.ProteinAccession] = pepWithModsIsNull ? " " : (psm.ProteinAccession != null ? psm.ProteinAccession : Resolve(pepsWithMods.Select(b => b.Protein.Accession), psm.FullSequence).ResolvedString); - s[PsmTsvHeader.ProteinName] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Protein.FullName), psm.FullSequence).ResolvedString; + s[PsmTsvHeader.MassDiffDa] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => sm.ScanPrecursorMass - b.MonoisotopicMass)).ResolvedString; + s[PsmTsvHeader.MassDiffPpm] = pepWithModsIsNull ? " " : ResolveF2(pepsWithMods.Select(b => ((sm.ScanPrecursorMass - b.MonoisotopicMass) / b.MonoisotopicMass * 1e6))).ResolvedString; + s[PsmTsvHeader.ProteinAccession] = pepWithModsIsNull ? " " : (sm.Accession != null ? sm.Accession : Resolve(pepsWithMods.Select(b => b.Parent.Accession), sm.FullSequence).ResolvedString); + s[PsmTsvHeader.ProteinName] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Parent.FullName), sm.FullSequence).ResolvedString; s[PsmTsvHeader.GeneName] = geneString; - s[PsmTsvHeader.OrganismName] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Protein.Organism)).ResolvedString; - s[PsmTsvHeader.IdentifiedSequenceVariations] = pepWithModsIsNull ? " " : - Resolve(pepsWithMods.Select(b => string.Join(", ", b.Protein.AppliedSequenceVariations - .Where(av => b.IntersectsAndIdentifiesVariation(av).identifies) - .Select(av => b.SequenceVariantString(av, b.IntersectsAndIdentifiesVariation(av).intersects))))).ResolvedString; - s[PsmTsvHeader.SpliceSites] = pepWithModsIsNull ? " " : - Resolve(pepsWithMods.Select(b => string.Join(", ", b.Protein.SpliceSites - .Where(d => Includes(b, d)) - .Select(d => $"{d.OneBasedBeginPosition.ToString()}-{d.OneBasedEndPosition.ToString()}")))).ResolvedString; - s[PsmTsvHeader.Contaminant] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Protein.IsContaminant ? "Y" : "N")).ResolvedString; - s[PsmTsvHeader.Decoy] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Protein.IsDecoy ? "Y" : "N")).ResolvedString; - s[PsmTsvHeader.PeptideDesicription] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.PeptideDescription)).ResolvedString; + s[PsmTsvHeader.OrganismName] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Parent.Organism)).ResolvedString; + + if (sm is PeptideSpectralMatch psm || sm is null) + { + s[PsmTsvHeader.IdentifiedSequenceVariations] = pepWithModsIsNull ? " " : + Resolve(pepsWithMods.Select(p => p as PeptideWithSetModifications) + .Select(b => string.Join(", ", b.Protein.AppliedSequenceVariations + .Where(av => b.IntersectsAndIdentifiesVariation(av).identifies) + .Select(av => b.SequenceVariantString(av, b.IntersectsAndIdentifiesVariation(av).intersects))))).ResolvedString; + s[PsmTsvHeader.SpliceSites] = pepWithModsIsNull ? " " : + Resolve(pepsWithMods.Select(p => p as PeptideWithSetModifications) + .Select(b => string.Join(", ", b.Protein.SpliceSites + .Where(d => Includes(b, d)) + .Select(d => $"{d.OneBasedBeginPosition.ToString()}-{d.OneBasedEndPosition.ToString()}")))).ResolvedString; + } + + s[PsmTsvHeader.Contaminant] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Parent.IsContaminant ? "Y" : "N")).ResolvedString; + s[PsmTsvHeader.Decoy] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Parent.IsDecoy ? "Y" : "N")).ResolvedString; + s[PsmTsvHeader.PeptideDesicription] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Description)).ResolvedString; s[PsmTsvHeader.StartAndEndResiduesInProtein] = pepWithModsIsNull ? " " : - Resolve(pepsWithMods.Select(b => ($"[{b.OneBasedStartResidueInProtein.ToString(CultureInfo.InvariantCulture)} to {b.OneBasedEndResidueInProtein.ToString(CultureInfo.InvariantCulture)}]")), psm.FullSequence).ResolvedString; - s[PsmTsvHeader.PreviousAminoAcid] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.PreviousAminoAcid.ToString())).ResolvedString; - s[PsmTsvHeader.NextAminoAcid] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.NextAminoAcid.ToString())).ResolvedString; + Resolve(pepsWithMods.Select(b => ($"[{b.OneBasedStartResidue.ToString(CultureInfo.InvariantCulture)} to {b.OneBasedEndResidue.ToString(CultureInfo.InvariantCulture)}]")), sm.FullSequence).ResolvedString; + s[PsmTsvHeader.PreviousAminoAcid] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.PreviousResidue.ToString())).ResolvedString; + s[PsmTsvHeader.NextAminoAcid] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.NextResidue.ToString())).ResolvedString; string theoreticalsSearched = " "; s[PsmTsvHeader.TheoreticalsSearched] = theoreticalsSearched; - s[PsmTsvHeader.DecoyContaminantTarget] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Protein.IsDecoy ? "D" : b.Protein.IsContaminant ? "C" : "T")).ResolvedString; + s[PsmTsvHeader.DecoyContaminantTarget] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Parent.IsDecoy ? "D" : b.Parent.IsContaminant ? "C" : "T")).ResolvedString; } /// @@ -246,7 +253,7 @@ internal static void AddPeptideSequenceData(Dictionary s, Peptid /// private static bool Includes(PeptideWithSetModifications pep, SpliceSite site) { - return pep.OneBasedStartResidueInProtein <= site.OneBasedBeginPosition && pep.OneBasedEndResidueInProtein >= site.OneBasedEndPosition; + return pep.OneBasedStartResidue <= site.OneBasedBeginPosition && pep.OneBasedEndResidue >= site.OneBasedEndPosition; } internal static void AddMatchedIonsData(Dictionary s, List matchedIons) @@ -322,7 +329,7 @@ internal static void AddMatchedIonsData(Dictionary s, List s, PeptideSpectralMatch peptide) + internal static void AddMatchScoreData(Dictionary s, SpectralMatch peptide) { string spectralAngle = peptide == null ? " " : peptide.SpectralAngle.ToString("F4"); string localizedScores = " "; diff --git a/MetaMorpheus/EngineLayer/Silac/SilacConversions.cs b/MetaMorpheus/EngineLayer/Silac/SilacConversions.cs index 5b7a90dbe..42d8cff0d 100644 --- a/MetaMorpheus/EngineLayer/Silac/SilacConversions.cs +++ b/MetaMorpheus/EngineLayer/Silac/SilacConversions.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using Omics.Modifications; +using Omics; namespace EngineLayer { @@ -40,36 +41,36 @@ public static PeptideSpectralMatch GetLabeledPsm(PeptideSpectralMatch psm, int n PeptideWithSetModifications labeledPwsm = new PeptideWithSetModifications( pwsm.Protein, pwsm.DigestionParams, - pwsm.OneBasedStartResidueInProtein, - pwsm.OneBasedEndResidueInProtein, + pwsm.OneBasedStartResidue, + pwsm.OneBasedEndResidue, pwsm.CleavageSpecificityForFdrCategory, pwsm.PeptideDescription, pwsm.MissedCleavages, pwsm.AllModsOneIsNterminus, pwsm.NumFixedMods, labeledBaseSequence); - return psm.Clone(new List<(int Notch, PeptideWithSetModifications Peptide)> { (notch, labeledPwsm) }); + return psm.Clone(new List<(int Notch, IBioPolymerWithSetMods Peptide)> { (notch, labeledPwsm) }); } public static PeptideSpectralMatch GetSilacPsm(PeptideSpectralMatch psm, SilacLabel silacLabel) { - List<(int Notch, PeptideWithSetModifications Peptide)> updatedBestMatchingPeptides = new List<(int Notch, PeptideWithSetModifications Peptide)>(); - foreach ((int Notch, PeptideWithSetModifications Peptide) notchAndPwsm in psm.BestMatchingPeptides) + List<(int Notch, IBioPolymerWithSetMods Peptide)> updatedBestMatchingPeptides = new List<(int Notch, IBioPolymerWithSetMods Peptide)>(); + foreach ((int Notch, PeptideWithSetModifications Peptide) notchAndPwsm in psm.BestMatchingBioPolymersWithSetMods) { PeptideWithSetModifications modifiedPwsm = CreateSilacPwsm(silacLabel, notchAndPwsm.Peptide); updatedBestMatchingPeptides.Add((notchAndPwsm.Notch, modifiedPwsm)); } - return psm.Clone(updatedBestMatchingPeptides); + return psm.Clone(updatedBestMatchingPeptides) as PeptideSpectralMatch; } //modify the proteins to appear only light (we want a protein sequence to look like PROTEINK instead of PROTEINa) - public static List UpdateProteinSequencesToLight(List originalPsms, List labels) + public static List UpdateProteinSequencesToLight(List originalPsms, List labels) { - List psmsToReturn = new List(); + List psmsToReturn = new List(); foreach (PeptideSpectralMatch psm in originalPsms) { - List<(int Notch, PeptideWithSetModifications Peptide)> originalPeptides = psm.BestMatchingPeptides.ToList(); - List<(int Notch, PeptideWithSetModifications Peptide)> updatedPeptides = new List<(int Notch, PeptideWithSetModifications Peptide)>(); + List<(int Notch, IBioPolymerWithSetMods Peptide)> originalPeptides = psm.BestMatchingBioPolymersWithSetMods.ToList(); + List<(int Notch, IBioPolymerWithSetMods Peptide)> updatedPeptides = new List<(int Notch, IBioPolymerWithSetMods Peptide)>(); foreach ((int Notch, PeptideWithSetModifications Peptide) notchPwsm in originalPeptides) { PeptideWithSetModifications pwsm = notchPwsm.Peptide; @@ -91,8 +92,8 @@ public static List UpdateProteinSequencesToLight(List pwsms = new(); + List<(int, IBioPolymerWithSetMods)> pwsms = new(); List pwsmSpectralAngles = new(); - foreach (var (Notch, Peptide) in psms[i].BestMatchingPeptides) + foreach (var (Notch, Peptide) in psms[i].BestMatchingBioPolymersWithSetMods) { //if peptide is target, directly look for the target's spectrum in the spectral library - if (!Peptide.Protein.IsDecoy && spectralLibrary.TryGetSpectrum(Peptide.FullSequence, scan.PrecursorCharge, out var librarySpectrum)) + if (!Peptide.Parent.IsDecoy && spectralLibrary.TryGetSpectrum(Peptide.FullSequence, scan.PrecursorCharge, out var librarySpectrum)) { SpectralSimilarity s = new SpectralSimilarity(scan.TheScan.MassSpectrum, librarySpectrum.XArray, librarySpectrum.YArray, SpectralSimilarity.SpectrumNormalizationScheme.squareRootSpectrumSum, commonParameters.ProductMassTolerance.Value, false); if (s.SpectralContrastAngle().HasValue) @@ -55,7 +56,7 @@ public static void CalculateSpectralAngles(SpectralLibrary spectralLibrary, Pept } //if peptide is decoy, look for the decoy's corresponding target's spectrum in the spectral library and generate decoy spectrum by function GetDecoyLibrarySpectrumFromTargetByRevers - else if (Peptide.Protein.IsDecoy && spectralLibrary.TryGetSpectrum(Peptide.PeptideDescription, scan.PrecursorCharge, out var targetlibrarySpectrum)) + else if (Peptide.Parent.IsDecoy && spectralLibrary.TryGetSpectrum(Peptide.Description, scan.PrecursorCharge, out var targetlibrarySpectrum)) { var decoyPeptideTheorProducts = new List(); Peptide.Fragment(commonParameters.DissociationType, commonParameters.DigestionParams.FragmentationTerminus, decoyPeptideTheorProducts); diff --git a/MetaMorpheus/EngineLayer/SpectralMatch.cs b/MetaMorpheus/EngineLayer/SpectralMatch.cs new file mode 100644 index 000000000..2341e12fc --- /dev/null +++ b/MetaMorpheus/EngineLayer/SpectralMatch.cs @@ -0,0 +1,496 @@ +using System; +using Chemistry; +using EngineLayer.FdrAnalysis; +using MassSpectrometry; +using Proteomics; +using Omics.Fragmentation; +using Proteomics.ProteolyticDigestion; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Runtime.CompilerServices; +using Easy.Common.Extensions; +using Omics; +using Omics.Modifications; +using Proteomics.AminoAcidPolymer; +using ThermoFisher.CommonCore.Data; + +namespace EngineLayer +{ + public abstract class SpectralMatch + { + public const double ToleranceForScoreDifferentiation = 1e-9; + + protected SpectralMatch(IBioPolymerWithSetMods peptide, int notch, double score, int scanIndex, Ms2ScanWithSpecificMass scan, CommonParameters commonParameters, List matchedFragmentIons, double xcorr = 0) + { + _BestMatchingBioPolymersWithSetMods = new List<(int, IBioPolymerWithSetMods)>(); + ScanIndex = scanIndex; + FullFilePath = scan.FullFilePath; + ScanNumber = scan.OneBasedScanNumber; + PrecursorScanNumber = scan.OneBasedPrecursorScanNumber; + ScanRetentionTime = scan.RetentionTime; + ScanExperimentalPeaks = scan.NumPeaks; + TotalIonCurrent = scan.TotalIonCurrent; + ScanPrecursorCharge = scan.PrecursorCharge; + ScanPrecursorMonoisotopicPeakMz = scan.PrecursorMonoisotopicPeakMz; + ScanPrecursorMass = scan.PrecursorMass; + DigestionParams = commonParameters.DigestionParams; + BioPolymersWithSetModsToMatchingFragments = new Dictionary>(); + Xcorr = xcorr; + NativeId = scan.NativeId; + RunnerUpScore = commonParameters.ScoreCutoff; + MsDataScan = scan.TheScan; + SpectralAngle = -1; + + AddOrReplace(peptide, score, notch, true, matchedFragmentIons, xcorr); + } + + public MsDataScan MsDataScan { get; set; } + public ChemicalFormula ModsChemicalFormula { get; private set; } // these fields will be null if they are ambiguous + public string FullSequence { get; protected set; } + public string EssentialSequence { get; protected set; } + public int? Notch { get; private set; } + public string BaseSequence { get; protected set; } + public int? BioPolymerWithSetModsLength { get; private set; } + public int? OneBasedStartResidue { get; private set; } + public int? OneBasedEndResidue { get; private set; } + public double? BioPolymerWithSetModsMonoisotopicMass { get; private set; } + public int? ParentLength { get; private set; } + public string Accession { get; private set; } + public string Organism { get; private set; } + public List MatchedFragmentIons { get; protected set; } + public int PsmCount { get; internal set; } + public Dictionary ModsIdentified { get; private set; } // these should never be null under normal circumstances + public List LocalizedScores { get; internal set; } + public int ScanNumber { get; } + public int? PrecursorScanNumber { get; } + public double ScanRetentionTime { get; } + public int ScanExperimentalPeaks { get; } + public double TotalIonCurrent { get; } + public int ScanPrecursorCharge { get; } + public double ScanPrecursorMonoisotopicPeakMz { get; } + public double ScanPrecursorMass { get; } + public string FullFilePath { get; private set; } + public int ScanIndex { get; } + public int NumDifferentMatchingPeptides { get { return _BestMatchingBioPolymersWithSetMods.Count; } } + public FdrInfo FdrInfo { get; private set; } + public PsmData PsmData_forPEPandPercolator { get; set; } + + public double Score { get; private set; } + public double Xcorr; + public double SpectralAngle { get; set; } + public string NativeId; // this is a property of the scan. used for mzID writing + + public double DeltaScore { get { return (Score - RunnerUpScore); } } + + public double RunnerUpScore { get; set; } + public bool IsDecoy { get; private set; } + public bool IsContaminant { get; private set; } + + //One-based positions in peptide that are covered by fragments on both sides of amino acids + public List FragmentCoveragePositionInPeptide { get; private set; } + + + + #region Search + public DigestionParams DigestionParams { get; } + public Dictionary> BioPolymersWithSetModsToMatchingFragments { get; private set; } + + protected List<(int Notch, IBioPolymerWithSetMods Pwsm)> _BestMatchingBioPolymersWithSetMods; + public IEnumerable<(int Notch, IBioPolymerWithSetMods Peptide)> BestMatchingBioPolymersWithSetMods + { + get + { + return _BestMatchingBioPolymersWithSetMods.OrderBy(p => p.Pwsm.FullSequence) + .ThenBy(p => p.Pwsm.Parent.Accession) + .ThenBy(p => p.Pwsm.OneBasedStartResidue); + } + } + + public void AddOrReplace(IBioPolymerWithSetMods pwsm, double newScore, int notch, bool reportAllAmbiguity, List matchedFragmentIons, double newXcorr) + { + if (newScore - Score > ToleranceForScoreDifferentiation) //if new score beat the old score, overwrite it + { + _BestMatchingBioPolymersWithSetMods.Clear(); + _BestMatchingBioPolymersWithSetMods.Add((notch, pwsm)); + + if (Score - RunnerUpScore > ToleranceForScoreDifferentiation) + { + RunnerUpScore = Score; + } + + Score = newScore; + Xcorr = newXcorr; + + BioPolymersWithSetModsToMatchingFragments.Clear(); + BioPolymersWithSetModsToMatchingFragments.Add(pwsm, matchedFragmentIons); + } + else if (newScore - Score > -ToleranceForScoreDifferentiation && reportAllAmbiguity) //else if the same score and ambiguity is allowed + { + _BestMatchingBioPolymersWithSetMods.Add((notch, pwsm)); + + if (!BioPolymersWithSetModsToMatchingFragments.ContainsKey(pwsm)) + { + BioPolymersWithSetModsToMatchingFragments.Add(pwsm, matchedFragmentIons); + } + } + else if (newScore - RunnerUpScore > ToleranceForScoreDifferentiation) + { + RunnerUpScore = newScore; + } + } + + //PEP-Value analysis identifies ambiguous peptides with lower probability. These are removed from the bestmatchingpeptides dictionary, which lowers ambiguity. + public void RemoveThisAmbiguousPeptide(int notch, IBioPolymerWithSetMods pwsm) + { + _BestMatchingBioPolymersWithSetMods.Remove((notch, pwsm)); + if (!_BestMatchingBioPolymersWithSetMods.Any(x => x.Pwsm.Equals(pwsm))) + { + BioPolymersWithSetModsToMatchingFragments.Remove(pwsm); + } + this.ResolveAllAmbiguities(); + } + + /// + /// This method saves properties of this PSM for internal use. It is NOT used for any output. + /// These resolved fields are (usually) null if there is more than one option. + /// e.g., if this PSM can be explained by more than one base sequence, the BaseSequence property will be null + /// + public void ResolveAllAmbiguities() + { + IsDecoy = _BestMatchingBioPolymersWithSetMods.Any(p => p.Pwsm.Parent.IsDecoy); + IsContaminant = _BestMatchingBioPolymersWithSetMods.Any(p => p.Pwsm.Parent.IsContaminant); + FullSequence = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.FullSequence)).ResolvedValue; + BaseSequence = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.BaseSequence)).ResolvedValue; + BioPolymerWithSetModsLength = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.Length)).ResolvedValue; + OneBasedStartResidue = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.OneBasedStartResidue)).ResolvedValue; + OneBasedEndResidue = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.OneBasedEndResidue)).ResolvedValue; + ParentLength = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.Parent.Length)).ResolvedValue; + BioPolymerWithSetModsMonoisotopicMass = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.MonoisotopicMass)).ResolvedValue; + Accession = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.Parent.Accession)).ResolvedValue; + Organism = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.Parent.Organism)).ResolvedValue; + ModsIdentified = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.AllModsOneIsNterminus)).ResolvedValue; + ModsChemicalFormula = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Pwsm.AllModsOneIsNterminus.Select(c => (c.Value)))).ResolvedValue; + Notch = PsmTsvWriter.Resolve(_BestMatchingBioPolymersWithSetMods.Select(b => b.Notch)).ResolvedValue; + + // if the PSM matches a target and a decoy and they are the SAME SEQUENCE, remove the decoy + if (IsDecoy) + { + bool removedPeptides = false; + var hits = _BestMatchingBioPolymersWithSetMods.GroupBy(p => p.Pwsm.FullSequence); + + foreach (var hit in hits) + { + if (hit.Any(p => p.Pwsm.Parent.IsDecoy) && hit.Any(p => !p.Pwsm.Parent.IsDecoy)) + { + // at least one peptide with this sequence is a target and at least one is a decoy + // remove the decoys with this sequence + var pwsmToRemove = _BestMatchingBioPolymersWithSetMods.Where(p => p.Pwsm.FullSequence == hit.Key && p.Pwsm.Parent.IsDecoy).ToList(); + _BestMatchingBioPolymersWithSetMods.RemoveAll(p => p.Pwsm.FullSequence == hit.Key && p.Pwsm.Parent.IsDecoy); + foreach ((int, IBioPolymerWithSetMods) pwsm in pwsmToRemove) + { + BioPolymersWithSetModsToMatchingFragments.Remove(pwsm.Item2); + } + + removedPeptides = true; + } + } + + if (removedPeptides) + { + ResolveAllAmbiguities(); + } + } + + // TODO: technically, different peptide options for this PSM can have different matched ions + // we can write a Resolve method for this if we want... + MatchedFragmentIons = BioPolymersWithSetModsToMatchingFragments.First().Value; + } + + public void SetFdrValues(double cumulativeTarget, double cumulativeDecoy, double qValue, double cumulativeTargetNotch, double cumulativeDecoyNotch, double qValueNotch, double pep, double pepQValue) + { + FdrInfo = new FdrInfo + { + CumulativeTarget = cumulativeTarget, + CumulativeDecoy = cumulativeDecoy, + QValue = qValue, + CumulativeTargetNotch = cumulativeTargetNotch, + CumulativeDecoyNotch = cumulativeDecoyNotch, + QValueNotch = qValueNotch, + PEP = pep, + PEP_QValue = pepQValue + }; + } + + #endregion + + #region IO + + public static string GetTabSeparatedHeader() + { + return string.Join("\t", DataDictionary(null, null).Keys); + } + + public override string ToString() + { + return ToString(new Dictionary()); + } + + public string ToString(IReadOnlyDictionary ModstoWritePruned) + { + return string.Join("\t", DataDictionary(this, ModstoWritePruned).Values); + } + + public static Dictionary DataDictionary(SpectralMatch psm, IReadOnlyDictionary ModsToWritePruned) + { + Dictionary s = new Dictionary(); + PsmTsvWriter.AddBasicMatchData(s, psm); + PsmTsvWriter.AddPeptideSequenceData(s, psm, ModsToWritePruned); + PsmTsvWriter.AddMatchedIonsData(s, psm?.MatchedFragmentIons); + PsmTsvWriter.AddMatchScoreData(s, psm); + return s; + } + + #endregion + + #region Parsimony + + /// + /// This method is used by protein parsimony to remove PeptideWithSetModifications objects that have non-parsimonious protein associations + /// + public void TrimProteinMatches(HashSet parsimoniousProteins) + { + if (IsDecoy) + { + if (_BestMatchingBioPolymersWithSetMods.Any(p => parsimoniousProteins.Contains(p.Pwsm.Parent) && p.Pwsm.Parent.IsDecoy)) + { + _BestMatchingBioPolymersWithSetMods.RemoveAll(p => !parsimoniousProteins.Contains(p.Pwsm.Parent)); + } + // else do nothing + } + else + { + _BestMatchingBioPolymersWithSetMods.RemoveAll(p => !parsimoniousProteins.Contains(p.Pwsm.Parent)); + } + + ResolveAllAmbiguities(); + } + + /// + /// This method is used by protein parsimony to add PeptideWithSetModifications objects for modification-agnostic parsimony + /// + public void AddProteinMatch((int, IBioPolymerWithSetMods) peptideWithNotch, List mfi) + { + if (!_BestMatchingBioPolymersWithSetMods.Select(p => p.Pwsm).Contains(peptideWithNotch.Item2)) + { + _BestMatchingBioPolymersWithSetMods.Add(peptideWithNotch); + if (!BioPolymersWithSetModsToMatchingFragments.ContainsKey(peptideWithNotch.Item2)) + { + BioPolymersWithSetModsToMatchingFragments.Add(peptideWithNotch.Item2, mfi); + } + ResolveAllAmbiguities(); + } + } + + #endregion + + #region Silac + + protected SpectralMatch(SpectralMatch psm, List<(int Notch, IBioPolymerWithSetMods Peptide)> bestMatchingPeptides) + { + _BestMatchingBioPolymersWithSetMods = bestMatchingPeptides; + BaseSequence = PsmTsvWriter.Resolve(bestMatchingPeptides.Select(b => b.Peptide.BaseSequence)).ResolvedValue; + FullSequence = PsmTsvWriter.Resolve(bestMatchingPeptides.Select(b => b.Peptide.FullSequence)).ResolvedValue; + + ModsChemicalFormula = psm.ModsChemicalFormula; + Notch = psm.Notch; + BioPolymerWithSetModsLength = psm.BioPolymerWithSetModsLength; + OneBasedStartResidue = psm.OneBasedStartResidue; + OneBasedEndResidue = psm.OneBasedEndResidue; + BioPolymerWithSetModsMonoisotopicMass = psm.BioPolymerWithSetModsMonoisotopicMass; + ParentLength = psm.ParentLength; + Accession = psm.Accession; + Organism = psm.Organism; + MatchedFragmentIons = psm.MatchedFragmentIons; + PsmCount = psm.PsmCount; + ModsIdentified = psm.ModsIdentified; + LocalizedScores = psm.LocalizedScores; + ScanNumber = psm.ScanNumber; + PrecursorScanNumber = psm.PrecursorScanNumber; + ScanRetentionTime = psm.ScanRetentionTime; + ScanExperimentalPeaks = psm.ScanExperimentalPeaks; + TotalIonCurrent = psm.TotalIonCurrent; + ScanPrecursorCharge = psm.ScanPrecursorCharge; + ScanPrecursorMonoisotopicPeakMz = psm.ScanPrecursorMonoisotopicPeakMz; + ScanPrecursorMass = psm.ScanPrecursorMass; + FullFilePath = psm.FullFilePath; + ScanIndex = psm.ScanIndex; + FdrInfo = psm.FdrInfo; + Score = psm.Score; + Xcorr = psm.Xcorr; + RunnerUpScore = psm.RunnerUpScore; + IsDecoy = psm.IsDecoy; + IsContaminant = psm.IsContaminant; + DigestionParams = psm.DigestionParams; + BioPolymersWithSetModsToMatchingFragments = psm.BioPolymersWithSetModsToMatchingFragments; + SpectralAngle = psm.SpectralAngle; + } + + #endregion + + + public static int GetLongestIonSeriesBidirectional(Dictionary> PeptidesToMatchingFragments, IBioPolymerWithSetMods peptide) + { + List maxDiffs = new List { 1 }; + if (PeptidesToMatchingFragments != null && PeptidesToMatchingFragments.TryGetValue(peptide, out var matchedFragments) && matchedFragments != null && matchedFragments.Any()) + { + var jointSeries = matchedFragments.Select(p => p.NeutralTheoreticalProduct.AminoAcidPosition).Distinct().ToList(); + + if (jointSeries.Count > 0) + { + jointSeries.Sort(); + + List aminoAcidPostionsThatCouldBeObserved = Enumerable.Range(1, peptide.BaseSequence.Length).ToList(); + + List missing = aminoAcidPostionsThatCouldBeObserved.Except(jointSeries).ToList(); + + int localMaxDiff = 0; + for (int i = 0; i < aminoAcidPostionsThatCouldBeObserved.Count; i++) + { + if (!missing.Contains(aminoAcidPostionsThatCouldBeObserved[i])) + { + localMaxDiff++; + } + else + { + maxDiffs.Add(localMaxDiff); + localMaxDiff = 0; + } + } + maxDiffs.Add(localMaxDiff); + } + } + + return maxDiffs.Max(); + } + + /// + /// Determine the Fragment Coverage the PSM + /// Assigns fragment coverage indices for the PSM and the protein based on Amino Acid Position in Matched Ion Fragments + /// + public void GetAminoAcidCoverage() + { + if (string.IsNullOrEmpty(this.BaseSequence) || + !this.MatchedFragmentIons.Any()) return; + //Pull C terminal and N terminal Fragments and amino acid numbers + var nTermFragmentAAPositions = this.MatchedFragmentIons.Where(p => + p.NeutralTheoreticalProduct.Terminus == FragmentationTerminus.N) + .Select(j => j.NeutralTheoreticalProduct.AminoAcidPosition).Distinct().ToList(); + + var cTermFragmentAAPositions = this.MatchedFragmentIons.Where(p => + p.NeutralTheoreticalProduct.Terminus == FragmentationTerminus.C) + .Select(j => j.NeutralTheoreticalProduct.AminoAcidPosition).Distinct().ToList(); + + //Create a hashset to store the covered amino acid positions + HashSet fragmentCoveredAminoAcids = new(); + + //Check N term frags first + if (nTermFragmentAAPositions.Any()) + { + nTermFragmentAAPositions.Sort(); + + //if the final NFragment is present, last AA is covered + if (nTermFragmentAAPositions.Contains(this.BaseSequence.Length - 1)) + { + fragmentCoveredAminoAcids.Add(this.BaseSequence.Length); + } + + // if the first NFragment is present, first AA is covered + if (nTermFragmentAAPositions.Contains(1)) + { + fragmentCoveredAminoAcids.Add(1); + } + + //Check all amino acids except for the last one in the list + for (int i = 0; i < nTermFragmentAAPositions.Count - 1; i++) + { + //sequential AA, second one is covered + if (nTermFragmentAAPositions[i + 1] - nTermFragmentAAPositions[i] == 1) + { + fragmentCoveredAminoAcids.Add(nTermFragmentAAPositions[i + 1]); + } + + //check to see if the position is covered from both directions, inclusive + if (cTermFragmentAAPositions.Contains(nTermFragmentAAPositions[i + 1])) + { + fragmentCoveredAminoAcids.Add(nTermFragmentAAPositions[i + 1]); + } + + //check to see if the position is covered from both directions, exclusive + if (cTermFragmentAAPositions.Contains(nTermFragmentAAPositions[i + 1] + 2)) + { + fragmentCoveredAminoAcids.Add(nTermFragmentAAPositions[i + 1] + 1); + } + } + + } + + //Check C term frags + if (cTermFragmentAAPositions.Any()) + { + cTermFragmentAAPositions.Sort(); + + //if the second AA is present, the first AA is covered + if (cTermFragmentAAPositions.Contains(2)) + { + fragmentCoveredAminoAcids.Add(1); + } + + //if the last AA is present, the final AA is covered + if (cTermFragmentAAPositions.Contains(this.BaseSequence.Length)) + { + fragmentCoveredAminoAcids.Add(this.BaseSequence.Length); + } + + //check all amino acids except for the last one in the list + for (int i = 0; i < cTermFragmentAAPositions.Count - 1; i++) + { + //sequential AA, the first one is covered + if (cTermFragmentAAPositions[i + 1] - cTermFragmentAAPositions[i] == 1) + { + fragmentCoveredAminoAcids.Add(cTermFragmentAAPositions[i]); + } + } + } + + //store in PSM + var fragmentCoveredAminoAcidsList = fragmentCoveredAminoAcids.ToList(); + fragmentCoveredAminoAcidsList.Sort(); + this.FragmentCoveragePositionInPeptide = fragmentCoveredAminoAcidsList; + } + + public static int GetCountComplementaryIons(Dictionary> PeptidesToMatchingFragments, IBioPolymerWithSetMods peptide) + { + if (PeptidesToMatchingFragments != null && PeptidesToMatchingFragments.TryGetValue(peptide, out var matchedFragments) && matchedFragments != null && matchedFragments.Any()) + { + List nIons = matchedFragments.Where(f => f.NeutralTheoreticalProduct.Terminus == FragmentationTerminus.N).Select(f => f.NeutralTheoreticalProduct.FragmentNumber).ToList(); + List cIons = matchedFragments.Where(f => f.NeutralTheoreticalProduct.Terminus == FragmentationTerminus.C).Select(f => (peptide.BaseSequence.Length - f.NeutralTheoreticalProduct.FragmentNumber)).ToList(); + if (nIons.Any() && cIons.Any()) + { + return nIons.Intersect(cIons).Count(); + } + else + { + return 0; + } + } + else + { + return 0; + } + } + + + + } +} \ No newline at end of file diff --git a/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs b/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs index 669a09399..82b2762a1 100644 --- a/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs +++ b/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs @@ -262,7 +262,7 @@ private DataPointAquisitionResults GetDataAcquisitionResults(MsDataFile myMsData new SingleAbsoluteAroundZeroSearchMode(initPrecTol.Value); Ms2ScanWithSpecificMass[] listOfSortedms2Scans = GetMs2Scans(myMsDataFile, currentDataFile, combinedParameters).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; Log("Searching with searchMode: " + searchMode, new List { taskId, "Individual Spectra Files", fileNameWithoutExtension }); Log("Searching with productMassTolerance: " + initProdTol, new List { taskId, "Individual Spectra Files", fileNameWithoutExtension }); @@ -270,25 +270,25 @@ private DataPointAquisitionResults GetDataAcquisitionResults(MsDataFile myMsData bool writeSpectralLibrary = false; _ = new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, combinedParameters, FileSpecificParameters, null, new List { taskId, "Individual Spectra Files", fileNameWithoutExtension }, writeSpectralLibrary).Run(); - List allPsms = allPsmsArray.Where(b => b != null).ToList(); + List allPsms = allPsmsArray.Where(b => b != null).ToList(); allPsms = allPsms.OrderByDescending(b => b.Score) - .ThenBy(b => b.PeptideMonisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.PeptideMonisotopicMass.Value) : double.MaxValue) - .GroupBy(b => (b.FullFilePath, b.ScanNumber, b.PeptideMonisotopicMass)).Select(b => b.First()).ToList(); + .ThenBy(b => b.BioPolymerWithSetModsMonoisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.BioPolymerWithSetModsMonoisotopicMass.Value) : double.MaxValue) + .GroupBy(b => (b.FullFilePath, b.ScanNumber, b.BioPolymerWithSetModsMonoisotopicMass)).Select(b => b.First()).ToList(); _ = new FdrAnalysisEngine(allPsms, searchMode.NumNotches, CommonParameters, FileSpecificParameters, new List { taskId, "Individual Spectra Files", fileNameWithoutExtension }, doPEP: false).Run(); - List goodIdentifications = allPsms.Where(b => b.FdrInfo.QValueNotch < 0.001 && !b.IsDecoy && b.FullSequence != null).ToList(); + List goodIdentifications = allPsms.Where(b => b.FdrInfo.QValueNotch < 0.001 && !b.IsDecoy && b.FullSequence != null).ToList(); if (!goodIdentifications.Any()) { - return new DataPointAquisitionResults(null, new List(), new List(), new List(), 0, 0, 0, 0); + return new DataPointAquisitionResults(null, new List(), new List(), new List(), 0, 0, 0, 0); } //get the deconvoluted ms2scans for the good identifications List goodScans = new List(); - List unfilteredPsms = allPsmsArray.ToList(); - foreach (PeptideSpectralMatch psm in goodIdentifications) + List unfilteredPsms = allPsmsArray.ToList(); + foreach (SpectralMatch psm in goodIdentifications) { goodScans.Add(listOfSortedms2Scans[unfilteredPsms.IndexOf(psm)]); } diff --git a/MetaMorpheus/TaskLayer/GPTMDTask/GPTMDTask.cs b/MetaMorpheus/TaskLayer/GPTMDTask/GPTMDTask.cs index cde4fad40..5d04226cc 100644 --- a/MetaMorpheus/TaskLayer/GPTMDTask/GPTMDTask.cs +++ b/MetaMorpheus/TaskLayer/GPTMDTask/GPTMDTask.cs @@ -39,7 +39,7 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List proteinList = LoadProteins(taskId, dbFilenameList, true, DecoyType.Reverse, localizeableModificationTypes, CommonParameters); - List allPsms = new List(); + List allPsms = new List(); var numRawFiles = currentRawFileList.Count; @@ -98,7 +98,7 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List { taskId, "Individual Spectra Files", origDataFile }); Ms2ScanWithSpecificMass[] arrayOfMs2ScansSortedByMass = GetMs2Scans(myMsDataFile, origDataFile, combinedParams).OrderBy(b => b.PrecursorMass).ToArray(); myFileManager.DoneWithFile(origDataFile); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[arrayOfMs2ScansSortedByMass.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[arrayOfMs2ScansSortedByMass.Length]; //spectral Library search and library generation have't applied to GPTMD yet bool writeSpctralLibrary = false; @@ -111,8 +111,8 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List { taskId, "Individual Spectra Files" })); allPsms = allPsms.OrderByDescending(b => b.Score) - .ThenBy(b => b.PeptideMonisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.PeptideMonisotopicMass.Value) : double.MaxValue) - .GroupBy(b => new Tuple(b.FullFilePath, b.ScanNumber, b.PeptideMonisotopicMass)) + .ThenBy(b => b.BioPolymerWithSetModsMonoisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.BioPolymerWithSetModsMonoisotopicMass.Value) : double.MaxValue) + .GroupBy(b => new Tuple(b.FullFilePath, b.ScanNumber, b.BioPolymerWithSetModsMonoisotopicMass)) .Select(b => b.First()).ToList(); new FdrAnalysisEngine(allPsms, tempSearchMode.NumNotches, CommonParameters, this.FileSpecificParameters, new List { taskId }).Run(); diff --git a/MetaMorpheus/TaskLayer/GlycoSearchTask/GlycoProteinParsimony.cs b/MetaMorpheus/TaskLayer/GlycoSearchTask/GlycoProteinParsimony.cs index e22f1d9ba..9d90d65d5 100644 --- a/MetaMorpheus/TaskLayer/GlycoSearchTask/GlycoProteinParsimony.cs +++ b/MetaMorpheus/TaskLayer/GlycoSearchTask/GlycoProteinParsimony.cs @@ -9,7 +9,7 @@ namespace TaskLayer { public class GlycoProteinParsimony { - //id: ProteinAccession, ProtienPos, GlycanId.islocalized, minQValue, maxProb + //id: Accession, ProtienPos, GlycanId.islocalized, minQValue, maxProb public GlycoProteinParsimony(string proteinAccess, int proteinPos, char aminoAcid, bool isLocalized, double minQValue, LocalizationLevel bestLocalizeLevel, double maxProb) { @@ -57,9 +57,9 @@ public GlycoProteinParsimony(string proteinAccess, int proteinPos, char aminoAci { foreach (var local in gsm.LocalizedGlycan) { - int proteinPos = local.Item1 + gsm.OneBasedStartResidueInProtein.Value - 2; + int proteinPos = local.Item1 + gsm.OneBasedStartResidue.Value - 2; - (string,string,int) proPosId = new (gsm.ProteinAccession, proteinPos.ToString(), local.Item2); + (string,string,int) proPosId = new (gsm.Accession, proteinPos.ToString(), local.Item2); double prob = -1; if (gsm.SiteSpeciLocalProb != null && gsm.SiteSpeciLocalProb.ContainsKey(local.Item1)) @@ -70,7 +70,7 @@ public GlycoProteinParsimony(string proteinAccess, int proteinPos, char aminoAci if (!localizedGlycan.ContainsKey(proPosId)) { - GlycoProteinParsimony gpp = new GlycoProteinParsimony(gsm.ProteinAccession, proteinPos, gsm.BaseSequence[local.Item1-2], local.Item3, gsm.FdrInfo.QValue, gsm.LocalizationLevel, prob); + GlycoProteinParsimony gpp = new GlycoProteinParsimony(gsm.Accession, proteinPos, gsm.BaseSequence[local.Item1-2], local.Item3, gsm.FdrInfo.QValue, gsm.LocalizationLevel, prob); localizedGlycan.Add(proPosId, gpp); } else diff --git a/MetaMorpheus/TaskLayer/GlycoSearchTask/PostGlycoSearchAnalysisTask.cs b/MetaMorpheus/TaskLayer/GlycoSearchTask/PostGlycoSearchAnalysisTask.cs index c49feea6e..6578a1790 100644 --- a/MetaMorpheus/TaskLayer/GlycoSearchTask/PostGlycoSearchAnalysisTask.cs +++ b/MetaMorpheus/TaskLayer/GlycoSearchTask/PostGlycoSearchAnalysisTask.cs @@ -90,7 +90,7 @@ public MyTaskResults Run(string OutputFolder, List dbFilenameList, Li SingleFDRAnalysis(allPsmsOgly, commonParameters, new List { taskId }); var writtenFileOGlyco = Path.Combine(OutputFolder + "\\oglyco" + ".psmtsv"); - var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsOgly.Where(p => p.ProteinAccession != null && p.OneBasedStartResidueInProtein.HasValue).ToList()); + var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsOgly.Where(p => p.Accession != null && p.OneBasedStartResidue.HasValue).ToList()); var seen_oglyco_localization_file = Path.Combine(OutputFolder + "\\seen_oglyco_localization" + ".tsv"); WriteGlycoFile.WriteSeenProteinGlycoLocalization(ProteinLevelLocalization, seen_oglyco_localization_file); @@ -107,7 +107,7 @@ public MyTaskResults Run(string OutputFolder, List dbFilenameList, Li var writtenFileNGlyco = Path.Combine(OutputFolder + "\\nglyco" + ".psmtsv"); - var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsNgly.Where(p => p.ProteinAccession != null && p.OneBasedStartResidueInProtein.HasValue).ToList()); + var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsNgly.Where(p => p.Accession != null && p.OneBasedStartResidue.HasValue).ToList()); var seen_nglyco_localization_file = Path.Combine(OutputFolder + "\\seen_nglyco_localization" + ".tsv"); WriteGlycoFile.WriteSeenProteinGlycoLocalization(ProteinLevelLocalization, seen_nglyco_localization_file); @@ -125,7 +125,7 @@ public MyTaskResults Run(string OutputFolder, List dbFilenameList, Li var writtenFileNOGlyco = Path.Combine(OutputFolder + "\\no_glyco" + ".psmtsv"); - var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsgly.Where(p => p.ProteinAccession != null && p.OneBasedStartResidueInProtein.HasValue).ToList()); + var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsgly.Where(p => p.Accession != null && p.OneBasedStartResidue.HasValue).ToList()); var seen_no_glyco_localization_file = Path.Combine(OutputFolder + "\\seen_no_glyco_localization" + ".tsv"); WriteGlycoFile.WriteSeenProteinGlycoLocalization(ProteinLevelLocalization, seen_no_glyco_localization_file); @@ -179,7 +179,7 @@ private void DivideGlycoPsmsIntoGroupsWriteToTsv(GlycoSearchType glycoSearchType SingleFDRAnalysis(allPsmsOgly, commonParameters, new List { taskId }); var writtenFileOGlyco = Path.Combine(individualFileFolderPath, individualFileFolder + "oglyco" + ".psmtsv"); - var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsOgly.Where(p => p.ProteinAccession != null && p.OneBasedStartResidueInProtein.HasValue).ToList()); + var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsOgly.Where(p => p.Accession != null && p.OneBasedStartResidue.HasValue).ToList()); var seen_oglyco_localization_file = Path.Combine(individualFileFolderPath, individualFileFolder + "seen_oglyco_localization" + ".tsv"); WriteGlycoFile.WriteSeenProteinGlycoLocalization(ProteinLevelLocalization, seen_oglyco_localization_file); @@ -195,7 +195,7 @@ private void DivideGlycoPsmsIntoGroupsWriteToTsv(GlycoSearchType glycoSearchType SingleFDRAnalysis(allPsmsNgly, commonParameters, new List { taskId }); var writtenFileNGlyco = Path.Combine(individualFileFolderPath, individualFileFolder + "nglyco" + ".psmtsv"); - var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsNgly.Where(p => p.ProteinAccession != null && p.OneBasedStartResidueInProtein.HasValue).ToList()); + var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsNgly.Where(p => p.Accession != null && p.OneBasedStartResidue.HasValue).ToList()); var seen_nglyco_localization_file = Path.Combine(individualFileFolderPath, individualFileFolder + "seen_nglyco_localization" + ".tsv"); WriteGlycoFile.WriteSeenProteinGlycoLocalization(ProteinLevelLocalization, seen_nglyco_localization_file); @@ -212,7 +212,7 @@ private void DivideGlycoPsmsIntoGroupsWriteToTsv(GlycoSearchType glycoSearchType var writtenFileNOGlyco = Path.Combine(individualFileFolderPath, individualFileFolder + "no_glyco" + ".psmtsv"); WriteGlycoFile.WritePsmGlycoToTsv(allPsmsGly, writtenFileNOGlyco, true); - var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsGly.Where(p => p.ProteinAccession != null && p.OneBasedStartResidueInProtein.HasValue).ToList()); + var ProteinLevelLocalization = GlycoProteinParsimony.ProteinLevelGlycoParsimony(allPsmsGly.Where(p => p.Accession != null && p.OneBasedStartResidue.HasValue).ToList()); var seen_no_glyco_localization_file = Path.Combine(individualFileFolderPath, individualFileFolder + "seen_no_glyco_localization" + ".tsv"); WriteGlycoFile.WriteSeenProteinGlycoLocalization(ProteinLevelLocalization, seen_no_glyco_localization_file); @@ -227,14 +227,14 @@ private void DivideGlycoPsmsIntoGroupsWriteToTsv(GlycoSearchType glycoSearchType private void SingleFDRAnalysis(List items, CommonParameters commonParameters, List taskIds) { // calculate single PSM FDR - List psms = items.Select(p => p as PeptideSpectralMatch).ToList(); + List psms = items.Select(p => p as SpectralMatch).ToList(); new FdrAnalysisEngine(psms, 0, commonParameters, this.FileSpecificParameters, taskIds).Run(); } private void GlycoProteinAnalysis(List gsms, string outputFolder, string individualFileFolder = null) { // convert gsms to psms - List psmsForProteinParsimony = gsms.Select(p => p as PeptideSpectralMatch).ToList(); + List psmsForProteinParsimony = gsms.Select(p => p as SpectralMatch).ToList(); Status("Constructing protein groups...", Parameters.SearchTaskId); @@ -255,7 +255,7 @@ private void GlycoAccessionAnalysis(List gsms, string indivi List _proteinGroups = new List(); // convert gsms to psms - List psmsForProteinParsimony = gsms.Select(p => p as PeptideSpectralMatch).ToList(); + List psmsForProteinParsimony = gsms.Select(p => p as SpectralMatch).ToList(); foreach (var psm in psmsForProteinParsimony) { @@ -263,16 +263,16 @@ private void GlycoAccessionAnalysis(List gsms, string indivi } //get non-ambigous psms above cutoffs that are normally used for parsimony - List _filteredPsms = psmsForProteinParsimony.Where(p => p.FullSequence != null && p.FdrInfo.QValue <= 0.01 && p.FdrInfo.QValueNotch <= 0.01).ToList(); + List _filteredPsms = psmsForProteinParsimony.Where(p => p.FullSequence != null && p.FdrInfo.QValue <= 0.01 && p.FdrInfo.QValueNotch <= 0.01).ToList(); // if there are no peptides observed, there are no proteins; return an empty list of protein groups if (_filteredPsms.Count != 0) { foreach (var psm in _filteredPsms) { - List proteinList = psm.BestMatchingPeptides.Select(p => p.Peptide.Protein).ToList(); + List proteinList = psm.BestMatchingBioPolymersWithSetMods.Select(p => ((PeptideWithSetModifications)p.Peptide).Protein).ToList(); ProteinGroup newProteinGroup = new ProteinGroup(new HashSet(proteinList), - new HashSet(new List(psm.BestMatchingPeptides.Select(p=>p.Peptide).ToList())), new HashSet()); + new HashSet(new List(psm.BestMatchingBioPolymersWithSetMods.Select(p=> (PeptideWithSetModifications)p.Peptide).ToList())), new HashSet()); if (_proteinGroups.Any(p => p.Equals(newProteinGroup))) { @@ -372,7 +372,7 @@ private void QuantificationAnalysis() && p.FullSequence != null).ToList(); // pass protein group info for each PSM - var psmToProteinGroups = new Dictionary>(); + var psmToProteinGroups = new Dictionary>(); if (ProteinGroups != null && ProteinGroups.Count != 0) //ProteinGroups can be null if parsimony wasn't done, and it can be empty if you're doing the two peptide rule { foreach (var proteinGroup in ProteinGroups) @@ -401,7 +401,7 @@ private void QuantificationAnalysis() var accessionToPg = new Dictionary(); foreach (var psm in unambiguousPsmsBelowOnePercentFdr) { - var proteins = psm.BestMatchingPeptides.Select(b => b.Peptide.Protein).Distinct(); + var proteins = psm.BestMatchingBioPolymersWithSetMods.Select(b => ((PeptideWithSetModifications)b.Peptide).Protein).Distinct(); foreach (var protein in proteins) { @@ -411,7 +411,7 @@ private void QuantificationAnalysis() } } - psmToProteinGroups.Add(psm, new List { accessionToPg[psm.ProteinAccession] }); + psmToProteinGroups.Add(psm, new List { accessionToPg[psm.Accession] }); } } @@ -422,14 +422,14 @@ private void QuantificationAnalysis() // the peptides should still be quantified but not considered for protein quantification var undefinedPg = new FlashLFQ.ProteinGroup("UNDEFINED", "", ""); //sort the unambiguous psms by protease to make MBR compatible with multiple proteases - Dictionary> proteaseSortedPsms = new Dictionary>(); + Dictionary> proteaseSortedPsms = new Dictionary>(); Dictionary proteaseSortedFlashLFQResults = new Dictionary(); foreach (DigestionParams dp in Parameters.ListOfDigestionParams) { if (!proteaseSortedPsms.ContainsKey(dp.Protease)) { - proteaseSortedPsms.Add(dp.Protease, new List()); + proteaseSortedPsms.Add(dp.Protease, new List()); } } foreach (var psm in unambiguousPsmsBelowOnePercentFdr) @@ -451,7 +451,7 @@ private void QuantificationAnalysis() foreach (var psm in spectraFile) { flashLFQIdentifications.Add(new Identification(rawfileinfo, psm.BaseSequence, psm.FullSequence, - psm.PeptideMonisotopicMass.Value, psm.ScanRetentionTime, psm.ScanPrecursorCharge, psmToProteinGroups[psm])); + psm.BioPolymerWithSetModsMonoisotopicMass.Value, psm.ScanRetentionTime, psm.ScanPrecursorCharge, psmToProteinGroups[psm])); } } diff --git a/MetaMorpheus/TaskLayer/MbrAnalysis/SpectralRecoveryPSM.cs b/MetaMorpheus/TaskLayer/MbrAnalysis/SpectralRecoveryPSM.cs index ac87103d1..a1543e674 100644 --- a/MetaMorpheus/TaskLayer/MbrAnalysis/SpectralRecoveryPSM.cs +++ b/MetaMorpheus/TaskLayer/MbrAnalysis/SpectralRecoveryPSM.cs @@ -9,28 +9,28 @@ namespace TaskLayer.MbrAnalysis { public class SpectralRecoveryPSM { - public PeptideSpectralMatch spectralLibraryMatch { get; set; } + public SpectralMatch spectralLibraryMatch { get; set; } public ChromatographicPeak acceptorPeak { get; set; } public bool originalMatchFound { get; private set; } - public PeptideSpectralMatch originalSpectralMatch { get; private set; } + public SpectralMatch originalSpectralMatch { get; private set; } - public SpectralRecoveryPSM(PeptideSpectralMatch spectralLibraryMatch, ChromatographicPeak acceptorPeak) + public SpectralRecoveryPSM(SpectralMatch spectralLibraryMatch, ChromatographicPeak acceptorPeak) { this.spectralLibraryMatch = spectralLibraryMatch; this.acceptorPeak = acceptorPeak; originalMatchFound = false; } - public void FindOriginalPsm(List originalSearchPsms) + public void FindOriginalPsm(List originalSearchPsms) { if (spectralLibraryMatch == null) return; int oneBasedScanNumber = spectralLibraryMatch.ScanNumber; string spectraFile = spectralLibraryMatch.FullFilePath; string fullSequence = spectralLibraryMatch.FullSequence; - PeptideSpectralMatch originalPsm = null; + SpectralMatch originalPsm = null; originalPsm = @@ -53,7 +53,7 @@ public static string TabSeparatedHeader get { var sb = new StringBuilder(); - sb.Append(PeptideSpectralMatch.GetTabSeparatedHeader()); + sb.Append(SpectralMatch.GetTabSeparatedHeader()); sb.Append('\t'); sb.Append("Initial Search Q-Value"); sb.Append('\t'); diff --git a/MetaMorpheus/TaskLayer/MbrAnalysis/SpectralRecoveryRunner.cs b/MetaMorpheus/TaskLayer/MbrAnalysis/SpectralRecoveryRunner.cs index 5cd52183e..d098271ae 100644 --- a/MetaMorpheus/TaskLayer/MbrAnalysis/SpectralRecoveryRunner.cs +++ b/MetaMorpheus/TaskLayer/MbrAnalysis/SpectralRecoveryRunner.cs @@ -12,6 +12,7 @@ using System.Collections.Concurrent; using Microsoft.ML; using Microsoft.ML.Data; +using Omics; namespace TaskLayer.MbrAnalysis { @@ -40,7 +41,7 @@ public static SpectralRecoveryResults RunSpectralRecoveryAlgorithm( } List spectraFiles = parameters.FlashLfqResults.Peaks.Select(p => p.Key).ToList(); - List allPeptides = GetAllPeptides(parameters, commonParameters, fileSpecificParameters); + List allPeptides = GetAllPeptides(parameters, commonParameters, fileSpecificParameters); int maxThreadsPerFile = commonParameters.MaxThreadsToUsePerFile; int[] threads = Enumerable.Range(0, maxThreadsPerFile).ToArray(); @@ -87,15 +88,15 @@ public static SpectralRecoveryResults RunSpectralRecoveryAlgorithm( for (; i < fileSpecificMbrPeaks.Count; i += maxThreadsPerFile) { ChromatographicPeak mbrPeak = fileSpecificMbrPeaks[i]; - PeptideSpectralMatch bestDonorPsm = allPeptides.Where(p => + SpectralMatch bestDonorPsm = allPeptides.Where(p => p.FullSequence == mbrPeak.Identifications.First().ModifiedSequence).FirstOrDefault(); if (bestDonorPsm == null) { break; } - PeptideWithSetModifications bestDonorPwsm = bestDonorPsm.BestMatchingPeptides.First().Peptide; + IBioPolymerWithSetMods bestDonorPwsm = bestDonorPsm.BestMatchingBioPolymersWithSetMods.First().Peptide; - IEnumerable peptideSpectralMatches = + IEnumerable peptideSpectralMatches = mcse.SearchAroundPeak(bestDonorPwsm, mbrPeak.Apex.IndexedPeak.RetentionTime); if (peptideSpectralMatches == null || !peptideSpectralMatches.Any()) @@ -115,13 +116,13 @@ public static SpectralRecoveryResults RunSpectralRecoveryAlgorithm( if (bestMbrMatches.Any()) { - List allPsms = parameters.AllPsms. + List allPsms = parameters.AllPsms. OrderByDescending(p => p.Score). ThenBy(p => p.FdrInfo.QValue). ThenBy(p => p.FullFilePath). ThenBy(x => x.ScanNumber). ThenBy(p => p.FullSequence). - ThenBy(p => p.ProteinAccession).ToList(); + ThenBy(p => p.Accession).ToList(); AssignEstimatedPsmQvalue(bestMbrMatches, allPsms); FDRAnalysisOfMbrPsms(bestMbrMatches, allPsms, parameters, fileSpecificParameters); @@ -135,12 +136,12 @@ public static SpectralRecoveryResults RunSpectralRecoveryAlgorithm( return new SpectralRecoveryResults(bestMbrMatches, parameters.FlashLfqResults); } - private static List GetAllPeptides( + private static List GetAllPeptides( PostSearchAnalysisParameters parameters, CommonParameters commonParameters, List<(string, CommonParameters)> fileSpecificParameters) { - List peptides = new(); + List peptides = new(); peptides = parameters.AllPsms.Where(b => b.FullSequence != null).GroupBy(b => b.FullSequence).Select(b => b.FirstOrDefault()).ToList(); new FdrAnalysisEngine(peptides, parameters.NumNotches, commonParameters, fileSpecificParameters, new List { parameters.SearchTaskId }, "Peptide").Run(); @@ -167,14 +168,14 @@ private static List GetAllPeptides( return peptides; } - private static PeptideSpectralMatch BestPsmForMbrPeak(IEnumerable peptideSpectralMatches) + private static SpectralMatch BestPsmForMbrPeak(IEnumerable peptideSpectralMatches) { - List nonNullPsms = peptideSpectralMatches.Where(p => p != null).ToList(); + List nonNullPsms = peptideSpectralMatches.Where(p => p != null).ToList(); if (nonNullPsms.Any()) { // Setting Qvalue, QValueNotch, PEP, and PEP_Qvalue equal to 0 is necessary for MetaDraw to read the .psmtsv - foreach (PeptideSpectralMatch psm in nonNullPsms) + foreach (SpectralMatch psm in nonNullPsms) { psm.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); } @@ -187,7 +188,7 @@ private static PeptideSpectralMatch BestPsmForMbrPeak(IEnumerable bestMbrMatches, List allPsms) + private static void AssignEstimatedPsmQvalue(ConcurrentDictionary bestMbrMatches, List allPsms) { double[] allScores = allPsms.Select(s => s.Score).OrderByDescending(s => s).ToArray(); double[] allQValues = allPsms.OrderByDescending(s => s.Score).Select(q => q.FdrInfo.QValue).ToArray(); @@ -213,10 +214,10 @@ private static void AssignEstimatedPsmQvalue(ConcurrentDictionary bestMbrMatches, List allPsms, + private static void FDRAnalysisOfMbrPsms(ConcurrentDictionary bestMbrMatches, List allPsms, PostSearchAnalysisParameters parameters, List<(string, CommonParameters)> fileSpecificParameters) { - List psms = bestMbrMatches. + List psms = bestMbrMatches. Select(p => p.Value.spectralLibraryMatch). Where(v => v != null). ToList(); @@ -257,7 +258,7 @@ private static void FDRAnalysisOfMbrPsms(ConcurrentDictionary bestMbrMatches, List allPsms) + private static void AssignEstimatedPsmPepQValue(ConcurrentDictionary bestMbrMatches, List allPsms) { List pepValues = bestMbrMatches. Select(p => p.Value.spectralLibraryMatch). diff --git a/MetaMorpheus/TaskLayer/MetaMorpheusTask.cs b/MetaMorpheus/TaskLayer/MetaMorpheusTask.cs index 083c42052..93cb32a21 100644 --- a/MetaMorpheus/TaskLayer/MetaMorpheusTask.cs +++ b/MetaMorpheus/TaskLayer/MetaMorpheusTask.cs @@ -457,7 +457,8 @@ public static CommonParameters SetAllFileSpecificCommonParams(CommonParameters c maxHeterozygousVariants: commonParams.MaxHeterozygousVariants, minVariantDepth: commonParams.MinVariantDepth, addTruncations: commonParams.AddTruncations, - precursorDeconParams: commonParams.PrecursorDeconvolutionParameters); + precursorDeconParams: commonParams.PrecursorDeconvolutionParameters, + productDeconParams: commonParams.ProductDeconvolutionParameters ); return returnParams; } @@ -662,11 +663,11 @@ protected void LoadModifications(string taskId, out List variableM } } - protected static void WritePsmsToTsv(IEnumerable psms, string filePath, IReadOnlyDictionary modstoWritePruned) + protected static void WritePsmsToTsv(IEnumerable psms, string filePath, IReadOnlyDictionary modstoWritePruned) { using (StreamWriter output = new StreamWriter(filePath)) { - output.WriteLine(PeptideSpectralMatch.GetTabSeparatedHeader()); + output.WriteLine(SpectralMatch.GetTabSeparatedHeader()); foreach (var psm in psms) { output.WriteLine(psm.ToString(modstoWritePruned)); diff --git a/MetaMorpheus/TaskLayer/PepXMLWriter.cs b/MetaMorpheus/TaskLayer/PepXMLWriter.cs index e4e2b3c68..3b30ab068 100644 --- a/MetaMorpheus/TaskLayer/PepXMLWriter.cs +++ b/MetaMorpheus/TaskLayer/PepXMLWriter.cs @@ -14,7 +14,7 @@ namespace TaskLayer { public static class PepXMLWriter { - public static void WritePepXml(List psms, List database, List variableModifications, List fixedModifications, CommonParameters CommonParameters, string outputPath) + public static void WritePepXml(List psms, List database, List variableModifications, List fixedModifications, CommonParameters CommonParameters, string outputPath) { if (!psms.Any()) { @@ -119,7 +119,7 @@ public static void WritePepXml(List psms, List foreach (var psm in psms) { - PeptideWithSetModifications peptide = psm.BestMatchingPeptides.First().Peptide; + PeptideWithSetModifications peptide = psm.BestMatchingBioPolymersWithSetMods.First().Peptide as PeptideWithSetModifications; var mods = new List(); foreach (var mod in peptide.AllModsOneIsNterminus) @@ -132,7 +132,7 @@ public static void WritePepXml(List psms, List mods.Add(pepXmlMod); } - var proteinAccessions = psm.BestMatchingPeptides.Select(p => p.Peptide.Protein.Accession).Distinct(); + var proteinAccessions = psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide.Parent.Accession).Distinct(); var searchHit = new pepXML.Generated.msms_pipeline_analysisMsms_run_summarySpectrum_querySearch_resultSearch_hit { @@ -141,12 +141,12 @@ public static void WritePepXml(List psms, List // TODO: add amino acid substitution hit_rank = 1, peptide = ((psm.BaseSequence != null) ? psm.BaseSequence : "Ambiguous"), - peptide_prev_aa = peptide.PreviousAminoAcid.ToString(), - peptide_next_aa = peptide.NextAminoAcid.ToString(), + peptide_prev_aa = peptide.PreviousResidue.ToString(), + peptide_next_aa = peptide.NextResidue.ToString(), protein = ((peptide.Protein.Accession != null) ? peptide.Protein.Accession : string.Join("|", proteinAccessions)), num_tot_proteins = (uint)proteinAccessions.Count(), - calc_neutral_pep_mass = (float)((psm.PeptideMonisotopicMass != null) ? psm.PeptideMonisotopicMass : float.NaN), - massdiff = ((psm.PeptideMonisotopicMass != null) ? (psm.ScanPrecursorMass - psm.PeptideMonisotopicMass.Value).ToString() : "Ambiguous"), + calc_neutral_pep_mass = (float)((psm.BioPolymerWithSetModsMonoisotopicMass != null) ? psm.BioPolymerWithSetModsMonoisotopicMass : float.NaN), + massdiff = ((psm.BioPolymerWithSetModsMonoisotopicMass != null) ? (psm.ScanPrecursorMass - psm.BioPolymerWithSetModsMonoisotopicMass.Value).ToString() : "Ambiguous"), modification_info = (mods.Count == 0 ? new pepXML.Generated.modInfoDataType { mod_aminoacid_mass = mods.ToArray() } : null), search_score = new pepXML.Generated.nameValueType[] { diff --git a/MetaMorpheus/TaskLayer/SearchTask/MzIdentMLWriter.cs b/MetaMorpheus/TaskLayer/SearchTask/MzIdentMLWriter.cs index 05ecd5a7c..4b842483d 100644 --- a/MetaMorpheus/TaskLayer/SearchTask/MzIdentMLWriter.cs +++ b/MetaMorpheus/TaskLayer/SearchTask/MzIdentMLWriter.cs @@ -17,7 +17,7 @@ namespace TaskLayer { public static class MzIdentMLWriter { - public static void WriteMzIdentMl(IEnumerable psms, List groups, List variableMods, + public static void WriteMzIdentMl(IEnumerable psms, List groups, List variableMods, List fixedMods, List silacLabels, List proteases, Tolerance productTolerance, Tolerance parentTolerance, int missedCleavages, string outputPath, bool appendMotifToModNames) { @@ -40,7 +40,7 @@ public static void WriteMzIdentMl(IEnumerable psms, List p.BaseSequence != null && !p.FullSequence.Contains("|") && !labelsToSearch.Any(x => p.BaseSequence.Contains(x))); } - List peptides = psms.SelectMany(i => i.BestMatchingPeptides.Select(v => v.Peptide)).Distinct().ToList(); + List peptides = psms.SelectMany(i => i.BestMatchingBioPolymersWithSetMods.Select(v => v.Peptide as PeptideWithSetModifications)).Distinct().ToList(); List proteins = peptides.Select(p => p.Protein).Distinct().ToList(); List filenames = psms.Select(i => i.FullFilePath).Distinct().ToList(); Dictionary database_reference = new Dictionary(); @@ -325,9 +325,9 @@ public static void WriteMzIdentMl(IEnumerable psms, List psm.FullSequence != null); - foreach (PeptideSpectralMatch psm in unambiguousPsms) + foreach (SpectralMatch psm in unambiguousPsms) { - foreach (PeptideWithSetModifications peptide in psm.BestMatchingPeptides.Select(p => p.Peptide).Distinct()) + foreach (PeptideWithSetModifications peptide in psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide).Distinct()) { //if first peptide on list hasn't been added, add peptide and peptide evidence if (!peptide_ids.TryGetValue(peptide.FullSequence, out Tuple> peptide_id)) @@ -369,11 +369,11 @@ public static void WriteMzIdentMl(IEnumerable psms, List psms, List(psm.FullFilePath, psm.ScanNumber)] = new Tuple(scan_result_scan_item.Item1, scan_result_scan_item.Item2 + 1); scan_result_scan_item = psm_per_scan[new Tuple(psm.FullFilePath, psm.ScanNumber)]; } - foreach (PeptideWithSetModifications p in psm.BestMatchingPeptides.Select(p => p.Peptide).Distinct()) + foreach (PeptideWithSetModifications p in psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide).Distinct()) { peptide_ids[p.FullSequence].Item2.Add("SII_" + scan_result_scan_item.Item1 + "_" + scan_result_scan_item.Item2); } @@ -421,7 +421,7 @@ public static void WriteMzIdentMl(IEnumerable psms, List p.Peptide).Distinct().Count()], + PeptideEvidenceRef = new mzIdentML110.Generated.PeptideEvidenceRefType[psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide).Distinct().Count()], cvParam = new mzIdentML110.Generated.CVParamType[2] { new mzIdentML110.Generated.CVParamType @@ -440,14 +440,14 @@ public static void WriteMzIdentMl(IEnumerable psms, List p.Peptide).Distinct()) + foreach (PeptideWithSetModifications p in psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide).Distinct()) { _mzid.DataCollection.AnalysisData.SpectrumIdentificationList[0].SpectrumIdentificationResult[scan_result_scan_item.Item1].SpectrumIdentificationItem[scan_result_scan_item.Item2].PeptideEvidenceRef[pe] = new mzIdentML110.Generated.PeptideEvidenceRefType diff --git a/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisParameters.cs b/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisParameters.cs index 1251e6dd0..58a0dafda 100644 --- a/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisParameters.cs +++ b/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisParameters.cs @@ -17,7 +17,7 @@ public class PostSearchAnalysisParameters public List FixedModifications { get; set; } public Modification MultiplexModification { get; set; } public HashSet ListOfDigestionParams { get; set; } - public List AllPsms { get; set; } + public List AllPsms { get; set; } public FlashLfqResults FlashLfqResults { get; set; } public int NumNotches { get; set; } public string OutputFolder { get; set; } diff --git a/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisTask.cs b/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisTask.cs index f04b2d308..2962bb75f 100644 --- a/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisTask.cs +++ b/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisTask.cs @@ -31,9 +31,9 @@ public class PostSearchAnalysisTask : MetaMorpheusTask { public PostSearchAnalysisParameters Parameters { get; set; } private List ProteinGroups { get; set; } - private IEnumerable> PsmsGroupedByFile { get; set; } + private IEnumerable> PsmsGroupedByFile { get; set; } private SpectralRecoveryResults SpectralRecoveryResults { get; set; } - private List _filteredPsms; + private List _filteredPsms; private bool _pepFilteringNotPerformed; private string _filterType; private double _filterThreshold; @@ -67,8 +67,8 @@ public MyTaskResults Run() Parameters.AllPsms = Parameters.AllPsms.Where(psm => psm != null).ToList(); Parameters.AllPsms.ForEach(psm => psm.ResolveAllAmbiguities()); Parameters.AllPsms = Parameters.AllPsms.OrderByDescending(b => b.Score) - .ThenBy(b => b.PeptideMonisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.PeptideMonisotopicMass.Value) : double.MaxValue) - .GroupBy(b => (b.FullFilePath, b.ScanNumber, b.PeptideMonisotopicMass)).Select(b => b.First()).ToList(); + .ThenBy(b => b.BioPolymerWithSetModsMonoisotopicMass.HasValue ? Math.Abs(b.ScanPrecursorMass - b.BioPolymerWithSetModsMonoisotopicMass.Value) : double.MaxValue) + .GroupBy(b => (b.FullFilePath, b.ScanNumber, b.BioPolymerWithSetModsMonoisotopicMass)).Select(b => b.First()).ToList(); CalculatePsmFdr(); } @@ -157,7 +157,7 @@ private void FilterAllPsms() PsmsGroupedByFile = Parameters.AllPsms.GroupBy(p => p.FullFilePath); } - public IEnumerable GetFilteredPsms(bool includeDecoys, bool includeContaminants, + public IEnumerable GetFilteredPsms(bool includeDecoys, bool includeContaminants, bool includeAmbiguous) { return _filteredPsms.Where(p => @@ -171,7 +171,7 @@ public IEnumerable GetFilteredPsms(bool includeDecoys, boo /// /// A list of PSMs to be modified in place /// The number of target psms scoring below threshold - private void FilterSpecificPsms(List fileSpecificPsmsOrPeptides, out int psmOrPeptideCountForResults) + private void FilterSpecificPsms(List fileSpecificPsmsOrPeptides, out int psmOrPeptideCountForResults) { psmOrPeptideCountForResults = _filterType.Equals("q-value") ? fileSpecificPsmsOrPeptides.Count(p => @@ -239,17 +239,17 @@ private void ProteinAnalysis() Status("Constructing protein groups...", Parameters.SearchTaskId); //if SILAC, modify the proteins to appear only light (we want a protein sequence to look like PROTEINK instead of PROTEINa) - if (Parameters.SearchParameters.SilacLabels != null) + if (Parameters.SearchParameters.SilacLabels != null && Parameters.AllPsms.First() is PeptideSpectralMatch) { - Parameters.AllPsms = SilacConversions.UpdateProteinSequencesToLight(Parameters.AllPsms, Parameters.SearchParameters.SilacLabels); - foreach (PeptideSpectralMatch psm in Parameters.AllPsms) + Parameters.AllPsms = SilacConversions.UpdateProteinSequencesToLight(Parameters.AllPsms.Cast().ToList(), Parameters.SearchParameters.SilacLabels); + foreach (SpectralMatch psm in Parameters.AllPsms) { psm.ResolveAllAmbiguities(); } FilterAllPsms(); } - List psmsForProteinParsimony = Parameters.AllPsms; + List psmsForProteinParsimony = Parameters.AllPsms; // run parsimony ProteinParsimonyResults proteinAnalysisResults = (ProteinParsimonyResults)(new ProteinParsimonyEngine(psmsForProteinParsimony, Parameters.SearchParameters.ModPeptidesAreDifferent, CommonParameters, this.FileSpecificParameters, new List { Parameters.SearchTaskId }).Run()); @@ -365,7 +365,7 @@ private void QuantificationAnalysis() includeAmbiguous: false); // pass protein group info for each PSM - var psmToProteinGroups = new Dictionary>(); + var psmToProteinGroups = new Dictionary>(); if (ProteinGroups != null && ProteinGroups.Count != 0) //ProteinGroups can be null if parsimony wasn't done, and it can be empty if you're doing the two peptide rule { foreach (var proteinGroup in ProteinGroups) @@ -395,7 +395,7 @@ private void QuantificationAnalysis() var accessionToPg = new Dictionary(); foreach (var psm in unambiguousPsmsBelowOnePercentFdr) { - var proteins = psm.BestMatchingPeptides.Select(b => b.Peptide.Protein).Distinct(); + var proteins = psm.BestMatchingBioPolymersWithSetMods.Select(b => b.Peptide.Parent).Distinct(); foreach (var protein in proteins) { @@ -446,8 +446,8 @@ private void QuantificationAnalysis() //get easy access to values we need for new psm generation string unlabeledBaseSequence = lightPsm.BaseSequence; - int notch = psm.BestMatchingPeptides.First().Notch; - PeptideWithSetModifications pwsm = psm.BestMatchingPeptides.First().Peptide; + int notch = psm.BestMatchingBioPolymersWithSetMods.First().Notch; + PeptideWithSetModifications pwsm = psm.BestMatchingBioPolymersWithSetMods.First().Peptide as PeptideWithSetModifications; //check if turnover or multiplex experiment if (startLabel == null && endLabel == null) //if multiplex @@ -548,14 +548,14 @@ private void QuantificationAnalysis() // the peptides should still be quantified but not considered for protein quantification var undefinedPg = new FlashLFQ.ProteinGroup("UNDEFINED", "", ""); //sort the unambiguous psms by protease to make MBR compatible with multiple proteases - Dictionary> proteaseSortedPsms = new Dictionary>(); + Dictionary> proteaseSortedPsms = new Dictionary>(); Dictionary proteaseSortedFlashLFQResults = new Dictionary(); foreach (DigestionParams dp in Parameters.ListOfDigestionParams) { if (!proteaseSortedPsms.ContainsKey(dp.Protease)) { - proteaseSortedPsms.Add(dp.Protease, new List()); + proteaseSortedPsms.Add(dp.Protease, new List()); } } foreach (var psm in unambiguousPsmsBelowOnePercentFdr) @@ -577,7 +577,7 @@ private void QuantificationAnalysis() foreach (var psm in spectraFile) { flashLFQIdentifications.Add(new Identification(rawfileinfo, psm.BaseSequence, psm.FullSequence, - psm.PeptideMonisotopicMass.Value, psm.ScanRetentionTime, psm.ScanPrecursorCharge, psmToProteinGroups[psm])); + psm.BioPolymerWithSetModsMonoisotopicMass.Value, psm.ScanRetentionTime, psm.ScanPrecursorCharge, psmToProteinGroups[psm])); } } @@ -620,10 +620,10 @@ private void QuantificationAnalysis() } //Silac stuff for post-quantification - if (Parameters.SearchParameters.SilacLabels != null) //if we're doing silac + if (Parameters.SearchParameters.SilacLabels != null && Parameters.AllPsms.First() is PeptideSpectralMatch) //if we're doing silac { SilacConversions.SilacConversionsPostQuantification(allSilacLabels, startLabel, endLabel, spectraFileInfo, ProteinGroups, Parameters.ListOfDigestionParams, - Parameters.FlashLfqResults, Parameters.AllPsms, Parameters.SearchParameters.ModsToWriteSelection, quantifyUnlabeledPeptides); + Parameters.FlashLfqResults, Parameters.AllPsms.Cast().ToList(), Parameters.SearchParameters.ModsToWriteSelection, quantifyUnlabeledPeptides); } } @@ -653,11 +653,11 @@ private void HistogramAnalysis() /// /// PSMs to be written /// Full file path, up to and including the filename and extensioh. - protected void WritePsmsToTsv(IEnumerable psms, string filePath) + protected void WritePsmsToTsv(IEnumerable psms, string filePath) { if (Parameters.SearchParameters.DoMultiplexQuantification && Parameters.MultiplexModification != null && - psms.Any(p => p.BestMatchingPeptides + psms.Any(p => p.BestMatchingBioPolymersWithSetMods .SelectMany(pwsm => pwsm.Peptide.AllModsOneIsNterminus.Values) .Any(mod => mod.OriginalId.Equals(Parameters.MultiplexModification.OriginalId)))) { @@ -679,7 +679,7 @@ private void WritePsmResults() includeAmbiguous: true).ToList(); // If filter output is false, we need to write all psms, not just ones with Q-value < threshold - List filteredPsmListForOutput = Parameters.SearchParameters.WriteHighQValuePsms + List filteredPsmListForOutput = Parameters.SearchParameters.WriteHighQValuePsms ? Parameters.AllPsms.Where(p => (Parameters.SearchParameters.WriteDecoys || !p.IsDecoy) && (Parameters.SearchParameters.WriteContaminants || !p.IsContaminant)) @@ -764,10 +764,10 @@ private void UpdateSpectralLibrary() includeAmbiguous: false); //group psms by peptide and charge, the psms having same sequence and same charge will be in the same group - Dictionary<(String, int), List> PsmsGroupByPeptideAndCharge = new Dictionary<(String, int), List>(); + Dictionary<(String, int), List> PsmsGroupByPeptideAndCharge = new Dictionary<(String, int), List>(); foreach (var x in filteredPsmList) { - List psmsWithSamePeptideAndSameCharge = filteredPsmList.Where(b => b.FullSequence == x.FullSequence && b.ScanPrecursorCharge == x.ScanPrecursorCharge).OrderByDescending(p => p.Score).ToList(); + List psmsWithSamePeptideAndSameCharge = filteredPsmList.Where(b => b.FullSequence == x.FullSequence && b.ScanPrecursorCharge == x.ScanPrecursorCharge).OrderByDescending(p => p.Score).ToList(); (String, int) peptideWithChargeState = (x.FullSequence, x.ScanPrecursorCharge); if (!PsmsGroupByPeptideAndCharge.ContainsKey(peptideWithChargeState)) @@ -777,7 +777,7 @@ private void UpdateSpectralLibrary() } //group psms by peptide and charge, then write highest scoring PSM to dictionary - Dictionary<(string, int), PeptideSpectralMatch> psmSeqChargeDictionary = filteredPsmList + Dictionary<(string, int), SpectralMatch> psmSeqChargeDictionary = filteredPsmList .GroupBy(p => (p.FullSequence, p.ScanPrecursorCharge)) .ToDictionary( // Key is a (FullSequence, Charge) tuple @@ -847,7 +847,7 @@ private void SpectralLibraryGeneration() List spectraLibrary = new(); foreach (var matchGroup in fullSeqChargeGrouping) { - PeptideSpectralMatch bestPsm = matchGroup.MaxBy(p => p.Score); + SpectralMatch bestPsm = matchGroup.MaxBy(p => p.Score); if (bestPsm == null) continue; spectraLibrary.Add(new LibrarySpectrum( bestPsm.FullSequence, @@ -894,7 +894,7 @@ private void WriteProteinResults() EngineLayer.ProteinGroup firstProteinGroup = ProteinGroups.FirstOrDefault(); //grab the first protein to extract the files used for quantification if (firstProteinGroup != null) //check that we even have a protein group to write { - var tempPsmsGroupedByFile = new List>(); + var tempPsmsGroupedByFile = new List>(); //foreach original file foreach (string originalFile in fileNamesThatHadPsms) { @@ -909,7 +909,7 @@ private void WriteProteinResults() } //rename the file group for all of the relevant psms to their original file - List psms = PsmsGroupedByFile.Where(g => labeledFiles.Contains(g.Key)).SelectMany(x => x).ToList(); //grab all the psms + List psms = PsmsGroupedByFile.Where(g => labeledFiles.Contains(g.Key)).SelectMany(x => x).ToList(); //grab all the psms tempPsmsGroupedByFile.AddRange(psms.GroupBy(x => originalFile)); } //overwrite the grouping for downstream processing @@ -922,7 +922,7 @@ private void WriteProteinResults() { string strippedFileName = Path.GetFileNameWithoutExtension(fullFilePath); - List psmsForThisFile = PsmsGroupedByFile.Where(p => p.Key == fullFilePath).SelectMany(g => g).ToList(); + List psmsForThisFile = PsmsGroupedByFile.Where(p => p.Key == fullFilePath).SelectMany(g => g).ToList(); var subsetProteinGroupsForThisFile = ProteinGroups.Select(p => p.ConstructSubsetProteinGroup(fullFilePath, Parameters.SearchParameters.SilacLabels)).ToList(); ProteinScoringAndFdrResults subsetProteinScoringAndFdrResults = (ProteinScoringAndFdrResults)new ProteinScoringAndFdrEngine(subsetProteinGroupsForThisFile, psmsForThisFile, @@ -1048,11 +1048,11 @@ private void WritePrunedDatabase() var proteinToConfidentBaseSequences = new Dictionary>(); // associate all confident PSMs with all possible proteins they could be digest products of (before or after parsimony) - foreach (PeptideSpectralMatch psm in confidentPsms) + foreach (SpectralMatch psm in confidentPsms) { - var myPepsWithSetMods = psm.BestMatchingPeptides.Select(p => p.Peptide); + var myPepsWithSetMods = psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide); - foreach (var peptide in myPepsWithSetMods) + foreach (PeptideWithSetModifications peptide in myPepsWithSetMods) { if (proteinToConfidentBaseSequences.TryGetValue(peptide.Protein.NonVariantProtein, out var myPepList)) { @@ -1098,11 +1098,11 @@ private void WritePrunedDatabase() HashSet originalModPsmsFullSeq = originalModPsms.Select(p => p.FullSequence).ToHashSet(); modPsmsFullSeq.ExceptWith(originalModPsmsFullSeq); - foreach (PeptideSpectralMatch psm in modPsms) + foreach (SpectralMatch psm in modPsms) { - var myPepsWithSetMods = psm.BestMatchingPeptides.Select(p => p.Peptide); + var myPepsWithSetMods = psm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide); - foreach (var peptide in myPepsWithSetMods) + foreach (PeptideWithSetModifications peptide in myPepsWithSetMods) { if (proteinToConfidentModifiedSequences.TryGetValue(peptide.Protein.NonVariantProtein, out var myPepList)) { @@ -1319,7 +1319,7 @@ private void WritePeptideResults() // write best (highest-scoring) PSM per peptide string filename = "All" + GlobalVariables.AnalyteType + "s.psmtsv"; string writtenFile = Path.Combine(Parameters.OutputFolder, filename); - List peptides = Parameters.AllPsms + List peptides = Parameters.AllPsms .GroupBy(b => b.FullSequence) .Select(b => b.FirstOrDefault()).ToList(); @@ -1374,7 +1374,7 @@ private void WritePeptideResults() } } - private void WritePsmPlusMultiplexIons(IEnumerable psms, string filePath) + private void WritePsmPlusMultiplexIons(IEnumerable psms, string filePath) { PpmTolerance ionTolerance = new PpmTolerance(10); double[] reporterIonMzs = Parameters.MultiplexModification.DiagnosticIons.First().Value @@ -1384,7 +1384,7 @@ private void WritePsmPlusMultiplexIons(IEnumerable psms, s using (StreamWriter output = new StreamWriter(filePath)) { - string headerWithReporterIons = PeptideSpectralMatch.GetTabSeparatedHeader().Trim() + '\t' + + string headerWithReporterIons = SpectralMatch.GetTabSeparatedHeader().Trim() + '\t' + GetMultiplexHeader(); output.WriteLine(headerWithReporterIons); foreach (var psm in psms) @@ -1494,7 +1494,7 @@ private void WriteVariantResults() .ToList(); var possibleVariantPsms = fdrPsms.Where(p => - p.BestMatchingPeptides.Any(pep => pep.Peptide.IsVariantPeptide())) + p.BestMatchingBioPolymersWithSetMods.Any(pep => pep.Peptide is PeptideWithSetModifications pwsm && pwsm.IsVariantPeptide())) .OrderByDescending(pep => pep.Score) .ToList(); @@ -1510,12 +1510,12 @@ private void WriteVariantResults() FilterSpecificPsms(possibleVariantPsms, out int countOfConfidentPsms); WritePsmsToTsv(possibleVariantPsms, variantPsmFile); - List variantPeptides = possibleVariantPsms + List variantPeptides = possibleVariantPsms .GroupBy(b => b.FullSequence) .Select(b => b.FirstOrDefault()) .OrderByDescending(b => b.Score) .ToList(); - List confidentVariantPeps = new List(); + List confidentVariantPeps = new List(); new FdrAnalysisEngine(variantPeptides, Parameters.NumNotches, CommonParameters, FileSpecificParameters, new List { Parameters.SearchTaskId }, "variant_Peptides").Run(); @@ -1526,8 +1526,8 @@ private void WriteVariantResults() //because it is most probable that the peptide originated from the canonical protien. foreach (var entry in variantPeptides) { - var pwsm = entry.BestMatchingPeptides; - var nonVariantOption = pwsm.Any(p => p.Peptide.IsVariantPeptide() == false); + var pwsm = entry.BestMatchingBioPolymersWithSetMods; + var nonVariantOption = pwsm.Any(p => p.Peptide is PeptideWithSetModifications pwsm && pwsm.IsVariantPeptide() == false); if (nonVariantOption == false) { confidentVariantPeps.Add(entry); @@ -1554,16 +1554,19 @@ private void WriteVariantResults() FilterSpecificPsms(confidentVariantPeps, out int countOfConfidentPeptides); // Filter psms in place List modifiedVariantPeptides = confidentVariantPeps - .Where(p => p.ModsIdentified != null && p.ModsIdentified.Count > 0) + .Where(p => p.ModsIdentified != null && p.ModsIdentified.Count > 0 && p is PeptideSpectralMatch) + .Select(p => (PeptideSpectralMatch)p) .ToList(); //modification can be on any AA in variant peptide List modifiedVariantSitePeptides = new();// modification is speciifcally on the variant residue within the peptide - foreach (var entry in modifiedVariantPeptides) + foreach (PeptideSpectralMatch entry in modifiedVariantPeptides) { - var variantPWSM = entry.BestMatchingPeptides.FirstOrDefault().Peptide; + PeptideWithSetModifications firstOrDefault = entry.BestMatchingBioPolymersWithSetMods.FirstOrDefault().Peptide as PeptideWithSetModifications; + + var variantPWSM = firstOrDefault; var peptideMods = variantPWSM.AllModsOneIsNterminus.Values.ToList(); - var variantProteinModifications = variantPWSM.Protein.OneBasedPossibleLocalizedModifications.Where(k => k.Key >= variantPWSM.OneBasedStartResidueInProtein && k.Key <= variantPWSM.OneBasedEndResidueInProtein).ToList(); - var variants = entry.BestMatchingPeptides.FirstOrDefault().Peptide.Protein.AppliedSequenceVariations.Where(v => entry.BestMatchingPeptides.FirstOrDefault().Peptide.IntersectsAndIdentifiesVariation(v).identifies).ToList(); + var variantProteinModifications = variantPWSM.Parent.OneBasedPossibleLocalizedModifications.Where(k => k.Key >= variantPWSM.OneBasedStartResidue && k.Key <= variantPWSM.OneBasedEndResidue).ToList(); + var variants = firstOrDefault.Protein.AppliedSequenceVariations.Where(v => firstOrDefault.IntersectsAndIdentifiesVariation(v).identifies).ToList(); bool modifiedVariant = false; foreach (var mod in variantProteinModifications) { @@ -1582,7 +1585,11 @@ private void WriteVariantResults() } foreach (var peptide in confidentVariantPeps) { - var variantPWSM = peptide.BestMatchingPeptides.FirstOrDefault();//TODO: expand to all peptide options not just the first + var variantPWSM = + peptide.BestMatchingBioPolymersWithSetMods.FirstOrDefault() is (_, PeptideWithSetModifications) + ? ((int Notch, PeptideWithSetModifications Peptide))peptide.BestMatchingBioPolymersWithSetMods + .FirstOrDefault() + : (0, null);//TODO: expand to all peptide options not just the first var variants = variantPWSM.Peptide.Protein.AppliedSequenceVariations; var culture = CultureInfo.CurrentCulture; // these bools allow for us to accurrately count the number of peptides that have at least one variants of a given type. @@ -1792,13 +1799,13 @@ private static int GetOneBasedIndexInProtein(int oneIsNterminus, PeptideWithSetM { if (oneIsNterminus == 1) { - return peptideWithSetModifications.OneBasedStartResidueInProtein; + return peptideWithSetModifications.OneBasedStartResidue; } if (oneIsNterminus == peptideWithSetModifications.Length + 2) { - return peptideWithSetModifications.OneBasedEndResidueInProtein; + return peptideWithSetModifications.OneBasedEndResidue; } - return peptideWithSetModifications.OneBasedStartResidueInProtein + oneIsNterminus - 2; + return peptideWithSetModifications.OneBasedStartResidue + oneIsNterminus - 2; } private static void WriteTree(BinTreeStructure myTreeStructure, string writtenFile) @@ -1839,7 +1846,7 @@ private static void WriteTree(BinTreeStructure myTreeStructure, string writtenFi } } - private static void WritePsmsForPercolator(List psmList, string writtenFileForPercolator) + private static void WritePsmsForPercolator(List psmList, string writtenFileForPercolator) { using (StreamWriter output = new StreamWriter(writtenFileForPercolator)) { @@ -1872,16 +1879,16 @@ private static void WritePsmsForPercolator(List psmList, s int idNumber = 0; psmList.OrderByDescending(p => p.Score); - foreach (PeptideSpectralMatch psm in psmList.Where(p => p.PsmData_forPEPandPercolator != null)) + foreach (SpectralMatch psm in psmList.Where(p => p.PsmData_forPEPandPercolator != null)) { - foreach (var peptide in psm.BestMatchingPeptides) + foreach (var peptide in psm.BestMatchingBioPolymersWithSetMods) { output.Write(idNumber.ToString()); - output.Write('\t' + (peptide.Peptide.Protein.IsDecoy ? -1 : 1).ToString()); + output.Write('\t' + (peptide.Peptide.Parent.IsDecoy ? -1 : 1).ToString()); output.Write('\t' + psm.ScanNumber.ToString()); output.Write(psm.PsmData_forPEPandPercolator.ToString(searchType)); - output.Write('\t' + (peptide.Peptide.PreviousAminoAcid + "." + peptide.Peptide.FullSequence + "." + peptide.Peptide.NextAminoAcid).ToString()); - output.Write('\t' + (peptide.Peptide.Protein.Accession).ToString()); + output.Write('\t' + (peptide.Peptide.PreviousResidue + "." + peptide.Peptide.FullSequence + "." + peptide.Peptide.NextResidue).ToString()); + output.Write('\t' + (peptide.Peptide.Parent.Accession).ToString()); output.WriteLine(); } idNumber++; diff --git a/MetaMorpheus/TaskLayer/SearchTask/SearchTask.cs b/MetaMorpheus/TaskLayer/SearchTask/SearchTask.cs index f2183db07..6ed4ca3d2 100644 --- a/MetaMorpheus/TaskLayer/SearchTask/SearchTask.cs +++ b/MetaMorpheus/TaskLayer/SearchTask/SearchTask.cs @@ -16,6 +16,7 @@ using System.Linq; using Omics.Digestion; using Omics.Modifications; +using Omics; namespace TaskLayer { @@ -166,14 +167,14 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List allPsms = new List(); + List allPsms = new List(); //generate an array to store category specific fdr values (for speedy semi/nonspecific searches) int numFdrCategories = (int)(Enum.GetValues(typeof(FdrCategory)).Cast().Last() + 1); //+1 because it starts at zero - List[] allCategorySpecificPsms = new List[numFdrCategories]; + List[] allCategorySpecificPsms = new List[numFdrCategories]; for (int i = 0; i < numFdrCategories; i++) { - allCategorySpecificPsms[i] = new List(); + allCategorySpecificPsms[i] = new List(); } FlashLfqResults flashLfqResults = null; @@ -212,7 +213,7 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List p.MsnOrder == 2), arrayOfMs2ScansSortedByMass.Length }); myFileManager.DoneWithFile(origDataFile); - PeptideSpectralMatch[] fileSpecificPsms = new PeptideSpectralMatch[arrayOfMs2ScansSortedByMass.Length]; + SpectralMatch[] fileSpecificPsms = new PeptideSpectralMatch[arrayOfMs2ScansSortedByMass.Length]; // modern search if (SearchParameters.SearchType == SearchType.Modern) @@ -247,7 +248,7 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List 0) + SpectralMatch psm = fileSpecificPsms[index]; + if (psm != null && psm.BestMatchingBioPolymersWithSetMods.Count() > 0) { //Get the scan Ms2ScanWithSpecificMass scanForThisPsm = arrayOfMs2ScansSortedByMass[index]; @@ -494,9 +495,9 @@ public static void MatchInternalFragmentIons(PeptideSpectralMatch[] fileSpecific scanForThisPsm.TheScan.DissociationType.Value : combinedParams.DissociationType; //Get the theoretical peptides - List ambiguousPeptides = new List(); + List ambiguousPeptides = new List(); List notches = new List(); - foreach (var (Notch, Peptide) in psm.BestMatchingPeptides) + foreach (var (Notch, Peptide) in psm.BestMatchingBioPolymersWithSetMods) { ambiguousPeptides.Add(Peptide); notches.Add(Notch); @@ -518,7 +519,7 @@ public static void MatchInternalFragmentIons(PeptideSpectralMatch[] fileSpecific //remove peptides if they have fewer than max-1 matched ions, thus requiring at least two internal ions to disambiguate an ID //if not removed, then add the matched internal ions - HashSet PeptidesToMatchingInternalFragments = new HashSet(); + HashSet PeptidesToMatchingInternalFragments = new HashSet(); for (int peptideIndex = 0; peptideIndex < ambiguousPeptides.Count; peptideIndex++) { //if we should remove the theoretical, remove it @@ -529,12 +530,12 @@ public static void MatchInternalFragmentIons(PeptideSpectralMatch[] fileSpecific // otherwise add the matched internal ions to the total ions else { - PeptideWithSetModifications currentPwsm = ambiguousPeptides[peptideIndex]; + IBioPolymerWithSetMods currentPwsm = ambiguousPeptides[peptideIndex]; //check that we haven't already added the matched ions for this peptide if (!PeptidesToMatchingInternalFragments.Contains(currentPwsm)) { PeptidesToMatchingInternalFragments.Add(currentPwsm); //record that we've seen this peptide - psm.PeptidesToMatchingFragments[currentPwsm].AddRange(matchedIonsForAllAmbiguousPeptides[peptideIndex]); //add the matched ions + psm.BioPolymersWithSetModsToMatchingFragments[currentPwsm].AddRange(matchedIonsForAllAmbiguousPeptides[peptideIndex]); //add the matched ions } } } diff --git a/MetaMorpheus/TaskLayer/XLSearchTask/PostXLSearchAnalysisTask.cs b/MetaMorpheus/TaskLayer/XLSearchTask/PostXLSearchAnalysisTask.cs index dba76f197..fdf0e6f76 100644 --- a/MetaMorpheus/TaskLayer/XLSearchTask/PostXLSearchAnalysisTask.cs +++ b/MetaMorpheus/TaskLayer/XLSearchTask/PostXLSearchAnalysisTask.cs @@ -177,10 +177,10 @@ public void WriteCsvFiles(string outputFolder, List inte public void ComputeXlinkQandPValues(List allPsms, List intraCsms, List interCsms, CommonParameters commonParameters, string taskId) { List crossCsms = allPsms.Where(p => p.CrossType == PsmCrossType.Inter || p.CrossType == PsmCrossType.Intra).OrderByDescending(p => p.XLTotalScore).ToList(); - new FdrAnalysisEngine(crossCsms.ToList(), 0, commonParameters, this.FileSpecificParameters, new List { taskId }, "crosslink").Run(); + new FdrAnalysisEngine(crossCsms.ToList(), 0, commonParameters, this.FileSpecificParameters, new List { taskId }, "crosslink").Run(); List singles = allPsms.Where(p => p.CrossType != PsmCrossType.Inter).Where(p => p.CrossType != PsmCrossType.Intra).OrderByDescending(p => p.Score).ToList(); - new FdrAnalysisEngine(singles.ToList(), 0, commonParameters, this.FileSpecificParameters, new List { taskId }, "PSM").Run(); + new FdrAnalysisEngine(singles.ToList(), 0, commonParameters, this.FileSpecificParameters, new List { taskId }, "PSM").Run(); SingleFDRAnalysis(singles, commonParameters, new List { taskId }); // calculate FDR @@ -192,18 +192,18 @@ public void ComputeXlinkQandPValues(List allPsms, List items, CommonParameters commonParameters, List taskIds) { // calculate single PSM FDR - List psms = items.Where(p => p.CrossType == PsmCrossType.Single).Select(p => p as PeptideSpectralMatch).OrderByDescending(p => p.Score).ToList(); + List psms = items.Where(p => p.CrossType == PsmCrossType.Single).Select(p => p as SpectralMatch).OrderByDescending(p => p.Score).ToList(); new FdrAnalysisEngine(psms, 0, commonParameters, this.FileSpecificParameters, taskIds, "skippep").Run(); // calculate loop PSM FDR - psms = items.Where(p => p.CrossType == PsmCrossType.Loop).Select(p => p as PeptideSpectralMatch).OrderByDescending(p => p.Score).ToList(); + psms = items.Where(p => p.CrossType == PsmCrossType.Loop).Select(p => p as SpectralMatch).OrderByDescending(p => p.Score).ToList(); new FdrAnalysisEngine(psms, 0, commonParameters, this.FileSpecificParameters, taskIds, "skippep").Run(); // calculate deadend FDR psms = items.Where(p => p.CrossType == PsmCrossType.DeadEnd || p.CrossType == PsmCrossType.DeadEndH2O || p.CrossType == PsmCrossType.DeadEndNH2 || - p.CrossType == PsmCrossType.DeadEndTris).Select(p => p as PeptideSpectralMatch).OrderByDescending(p => p.Score).ToList(); + p.CrossType == PsmCrossType.DeadEndTris).Select(p => p as SpectralMatch).OrderByDescending(p => p.Score).ToList(); new FdrAnalysisEngine(psms, 0, commonParameters, this.FileSpecificParameters, taskIds, "skippep").Run(); } diff --git a/MetaMorpheus/TaskLayer/XLSearchTask/WriteXlFile.cs b/MetaMorpheus/TaskLayer/XLSearchTask/WriteXlFile.cs index 1b8f8846e..65800667a 100644 --- a/MetaMorpheus/TaskLayer/XLSearchTask/WriteXlFile.cs +++ b/MetaMorpheus/TaskLayer/XLSearchTask/WriteXlFile.cs @@ -58,7 +58,7 @@ public static void WriteCrosslinkToTxtForPercolator(List "\tPeptide\tProtein"); foreach (var item in items) { - if (item.BaseSequence != null && item.BetaPeptide.BaseSequence != null && item.ProteinAccession != null && item.BetaPeptide.ProteinAccession != null) + if (item.BaseSequence != null && item.BetaPeptide.BaseSequence != null && item.Accession != null && item.BetaPeptide.Accession != null) { string x = "T"; int label = 1; if (item.IsDecoy || item.BetaPeptide.IsDecoy) @@ -73,14 +73,14 @@ public static void WriteCrosslinkToTxtForPercolator(List + "\t" + item.DeltaScore.ToString(CultureInfo.InvariantCulture) + "\t" + item.ScanPrecursorCharge.ToString(CultureInfo.InvariantCulture) + "\t" + item.ScanPrecursorMass.ToString(CultureInfo.InvariantCulture) - + "\t" + ((item.PeptideMonisotopicMass.HasValue && item.BetaPeptide.PeptideMonisotopicMass.HasValue) ? ((item.ScanPrecursorMass - item.BetaPeptide.PeptideMonisotopicMass.Value - item.PeptideMonisotopicMass.Value - crosslinker.TotalMass) / item.ScanPrecursorMass * 1E6).ToString(CultureInfo.InvariantCulture) : "---") + + "\t" + ((item.BioPolymerWithSetModsMonoisotopicMass.HasValue && item.BetaPeptide.BioPolymerWithSetModsMonoisotopicMass.HasValue) ? ((item.ScanPrecursorMass - item.BetaPeptide.BioPolymerWithSetModsMonoisotopicMass.Value - item.BioPolymerWithSetModsMonoisotopicMass.Value - crosslinker.TotalMass) / item.ScanPrecursorMass * 1E6).ToString(CultureInfo.InvariantCulture) : "---") + "\t" + item.BetaPeptide.BaseSequence.Length.ToString(CultureInfo.InvariantCulture) + "\t" + item.BaseSequence.Length.ToString(CultureInfo.InvariantCulture) + "\t" + (item.BetaPeptide.BaseSequence.Length + item.BaseSequence.Length).ToString(CultureInfo.InvariantCulture) + "\t" + "-." + item.FullSequence + item.LinkPositions.First().ToString(CultureInfo.InvariantCulture) + "--" + item.BetaPeptide.FullSequence + item.BetaPeptide.LinkPositions.First().ToString(CultureInfo.InvariantCulture) + ".-" - + "\t" + item.BestMatchingPeptides.First().Peptide.Protein.Accession.ToString(CultureInfo.InvariantCulture) + + "\t" + item.BestMatchingBioPolymersWithSetMods.First().Peptide.Parent.Accession.ToString(CultureInfo.InvariantCulture) + "(" + (item.XlProteinPos.HasValue ? item.XlProteinPos.Value.ToString(CultureInfo.InvariantCulture) : string.Empty) + ")" - + "\t" + item.BetaPeptide.BestMatchingPeptides.First().Peptide.Protein.Accession.ToString(CultureInfo.InvariantCulture) + + "\t" + item.BetaPeptide.BestMatchingBioPolymersWithSetMods.First().Peptide.Parent.Accession.ToString(CultureInfo.InvariantCulture) + "(" + (item.BetaPeptide.XlProteinPos.HasValue ? item.BetaPeptide.XlProteinPos.Value.ToString(CultureInfo.InvariantCulture) : string.Empty) + ")" ); } @@ -199,7 +199,7 @@ public static void WritePepXML_xl(List items, List(); - var alphaPeptide = items[i].BestMatchingPeptides.First().Peptide; + var alphaPeptide = items[i].BestMatchingBioPolymersWithSetMods.First().Peptide; foreach (var modification in alphaPeptide.AllModsOneIsNterminus) { @@ -220,12 +220,12 @@ public static void WritePepXML_xl(List items, List items, List items, List(); foreach (var mod in betaPeptide.AllModsOneIsNterminus) @@ -295,11 +295,11 @@ public static void WritePepXML_xl(List items, List items, List items, List RemoveDuplicateFromCsmsPerScan(List(); fsp.Add(("", CommonParameters)); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, @@ -61,7 +61,7 @@ public static void TestAddCompIonsClassic() addCompIons: true); var fsp2 = new List<(string fileName, CommonParameters fileSpecificParameters)>(); fsp2.Add(("", CommonParameters2)); - PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray2, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters2, fsp2, null, new List(), writeSpectralLibrary).Run(); @@ -137,11 +137,11 @@ public static void TestCompIons_ModernSearch() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); // without complementary ions - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, fsp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); // with complementary ions - PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray2, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, withCompIons, fspComp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); // Single search mode @@ -215,11 +215,11 @@ public static void TestCompIons_ETHCD_ModernSearch() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); // without complementary ions - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, fsp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); // with complementary ions - PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray2, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, withCompIons, fspComp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); // Single search mode @@ -292,11 +292,11 @@ public static void TestCompIons_LowCID_ModernSearch() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); // without complementary ions - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, fsp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); // with complementary ions - PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray2, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, withCompIons, fspComp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); // Single search mode @@ -440,7 +440,7 @@ public static void AddCompIonsCommonParams() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(cp.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); // without complementary ions - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; var mse = new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, cp, fsp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); } diff --git a/MetaMorpheus/Test/AmbiguityTest.cs b/MetaMorpheus/Test/AmbiguityTest.cs index 96dbc0e13..1ba0b4186 100644 --- a/MetaMorpheus/Test/AmbiguityTest.cs +++ b/MetaMorpheus/Test/AmbiguityTest.cs @@ -55,9 +55,9 @@ public static void TestResolveAmbiguities() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray_withAmbiguity = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray_withAmbiguity = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; - PeptideSpectralMatch[] allPsmsArray_withOutAmbiguity = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray_withOutAmbiguity = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray_withAmbiguity, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, @@ -67,10 +67,10 @@ public static void TestResolveAmbiguities() Assert.AreEqual("QQQ", allPsmsArray_withAmbiguity[0].BaseSequence); Assert.AreEqual("QQQ", allPsmsArray_withOutAmbiguity[0].BaseSequence); - Assert.IsTrue(allPsmsArray_withAmbiguity[0].ProteinLength == null); - Assert.IsTrue(allPsmsArray_withOutAmbiguity[0].ProteinLength != null); - Assert.IsTrue(allPsmsArray_withAmbiguity[0].OneBasedStartResidueInProtein == null); - Assert.IsTrue(allPsmsArray_withOutAmbiguity[0].OneBasedStartResidueInProtein != null); + Assert.IsTrue(allPsmsArray_withAmbiguity[0].ParentLength == null); + Assert.IsTrue(allPsmsArray_withOutAmbiguity[0].ParentLength != null); + Assert.IsTrue(allPsmsArray_withAmbiguity[0].OneBasedStartResidue == null); + Assert.IsTrue(allPsmsArray_withOutAmbiguity[0].OneBasedStartResidue != null); } [Test] diff --git a/MetaMorpheus/Test/AnalysisEngineTest.cs b/MetaMorpheus/Test/AnalysisEngineTest.cs index a4cd54884..548cedb1e 100644 --- a/MetaMorpheus/Test/AnalysisEngineTest.cs +++ b/MetaMorpheus/Test/AnalysisEngineTest.cs @@ -77,16 +77,16 @@ public static void TestAnalysisEngineTests() Ms2ScanWithSpecificMass scanB = new Ms2ScanWithSpecificMass(new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 3, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=2", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null), 2 + 132.040, 1, null, new CommonParameters()); Ms2ScanWithSpecificMass scanC = new Ms2ScanWithSpecificMass(new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 4, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=3", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null), 3, 1, null, new CommonParameters()); - PeptideSpectralMatch matchA = new PeptideSpectralMatch(compactPeptide1, 0, 0, 0, scanA, CommonParameters, new List()); - PeptideSpectralMatch matchB = new PeptideSpectralMatch(compactPeptide2, 0, 0, 0, scanB, CommonParameters, new List()); - PeptideSpectralMatch matchC = new PeptideSpectralMatch(compactPeptide3, 0, 0, 0, scanC, CommonParameters, new List()); + SpectralMatch matchA = new PeptideSpectralMatch(compactPeptide1, 0, 0, 0, scanA, CommonParameters, new List()); + SpectralMatch matchB = new PeptideSpectralMatch(compactPeptide2, 0, 0, 0, scanB, CommonParameters, new List()); + SpectralMatch matchC = new PeptideSpectralMatch(compactPeptide3, 0, 0, 0, scanC, CommonParameters, new List()); - var newPsms = new List { matchA, matchB, matchC }; + var newPsms = new List { matchA, matchB, matchC }; MsDataFile myMsDataFile = new TestDataFile(new List { value1.First(), value2.First(), value3.First() }); var searchMode = new SinglePpmAroundZeroSearchMode(5); - Action, string, List> action2 = (List l, string s, List sdf) => {; }; + Action, string, List> action2 = (List l, string s, List sdf) => {; }; Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); diff --git a/MetaMorpheus/Test/BinGenerationTest.cs b/MetaMorpheus/Test/BinGenerationTest.cs index 47cde2c42..703f9c9a7 100644 --- a/MetaMorpheus/Test/BinGenerationTest.cs +++ b/MetaMorpheus/Test/BinGenerationTest.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using EngineLayer.HistogramAnalysis; using Omics.Modifications; using TaskLayer; using UsefulProteomicsDatabases; @@ -139,5 +140,36 @@ public static void TestProteinSplitAcrossFiles() File.Delete(mzmlFilePath2); Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true); } + + + [Test] + public static void TestBin_IdentifyAA() + { + var bin = new Bin(71); + bin.IdentifyAA(1); + Assert.AreEqual("Add Alanine", bin.AA); + + bin = new Bin(-56.1); + bin.IdentifyAA(1); + Assert.AreEqual("Remove Glycine", bin.AA); + + + bin = new Bin(114.102); + bin.IdentifyAA(1); + Assert.AreEqual("Add Aspartic Acid|Add (Glycine+Glycine)|Add Asparagine", bin.AA); + + bin = new Bin(-142.156); + bin.IdentifyAA(1); + Assert.AreEqual("Remove (Alanine+Alanine)", bin.AA); + } + + [Test] + public static void TestBin_IdentifyUnimodBins() + { + var bin = new Bin(77.987066); + bin.IdentifyUnimodBins(0.001); + Assert.AreEqual("Methylphosphonate on Y|Methylphosphonate on T|Methylphosphonate on S", bin.UnimodId); + Assert.AreEqual("CH3O2P", bin.UnimodFormulas); + } } } \ No newline at end of file diff --git a/MetaMorpheus/Test/CoIsolationTests.cs b/MetaMorpheus/Test/CoIsolationTests.cs index 5f932119f..0c4748ca9 100644 --- a/MetaMorpheus/Test/CoIsolationTests.cs +++ b/MetaMorpheus/Test/CoIsolationTests.cs @@ -63,7 +63,7 @@ public static void TestCoIsolation() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters(deconvolutionIntensityRatio: 50)).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; ; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; ; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, diff --git a/MetaMorpheus/Test/EventArgsTest.cs b/MetaMorpheus/Test/EventArgsTest.cs index 986630c16..9a489d430 100644 --- a/MetaMorpheus/Test/EventArgsTest.cs +++ b/MetaMorpheus/Test/EventArgsTest.cs @@ -44,9 +44,9 @@ public static void SingleEventArgsTest() ps.Fragment(DissociationType.HCD, FragmentationTerminus.Both, theoreticalProducts); var matchedIons = MetaMorpheusEngine.MatchFragmentIons(scan, theoreticalProducts, new CommonParameters()); - PeptideSpectralMatch newPsm = new PeptideSpectralMatch(ps, 0, 0, 2, scan, commonParameters, matchedIons); + SpectralMatch newPsm = new PeptideSpectralMatch(ps, 0, 0, 2, scan, commonParameters, matchedIons); - LocalizationEngine f = new LocalizationEngine(new List { newPsm }, myMsDataFile, new CommonParameters(), fsp, new List()); + LocalizationEngine f = new LocalizationEngine(new List { newPsm }, myMsDataFile, new CommonParameters(), fsp, new List()); var singleEngine= new SingleEngineEventArgs(f); Assert.That(singleEngine.MyEngine.Equals(f)); diff --git a/MetaMorpheus/Test/FdrTest.cs b/MetaMorpheus/Test/FdrTest.cs index 63d2d3098..27414bca0 100644 --- a/MetaMorpheus/Test/FdrTest.cs +++ b/MetaMorpheus/Test/FdrTest.cs @@ -18,6 +18,7 @@ using Omics.Modifications; using TaskLayer; using UsefulProteomicsDatabases; +using Omics; namespace Test { @@ -65,20 +66,20 @@ public static void FdrTestMethod() MsDataScan mzLibScan1 = t.GetOneBasedScan(2); Ms2ScanWithSpecificMass scan1 = new Ms2ScanWithSpecificMass(mzLibScan1, pep1.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); - PeptideSpectralMatch psm1 = new PeptideSpectralMatch(pep1, 0, 3, 0, scan1, commonParameters, new List()); + SpectralMatch psm1 = new PeptideSpectralMatch(pep1, 0, 3, 0, scan1, commonParameters, new List()); MsDataScan mzLibScan2 = t.GetOneBasedScan(4); Ms2ScanWithSpecificMass scan2 = new Ms2ScanWithSpecificMass(mzLibScan2, pep2.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); - PeptideSpectralMatch psm2 = new PeptideSpectralMatch(pep2, 1, 2, 1, scan2, commonParameters, new List()); + SpectralMatch psm2 = new PeptideSpectralMatch(pep2, 1, 2, 1, scan2, commonParameters, new List()); MsDataScan mzLibScan3 = t.GetOneBasedScan(6); Ms2ScanWithSpecificMass scan3 = new Ms2ScanWithSpecificMass(mzLibScan3, pep3.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); - PeptideSpectralMatch psm3 = new PeptideSpectralMatch(pep3, 0, 1, 2, scan3, commonParameters, new List()); + SpectralMatch psm3 = new PeptideSpectralMatch(pep3, 0, 1, 2, scan3, commonParameters, new List()); psm3.AddOrReplace(pep4, 1, 1, true, new List(), 0); - var newPsms = new List { psm1, psm2, psm3 }; - foreach (PeptideSpectralMatch psm in newPsms) + var newPsms = new List { psm1, psm2, psm3 }; + foreach (SpectralMatch psm in newPsms) { psm.ResolveAllAmbiguities(); } @@ -125,20 +126,20 @@ public static void FdrAnalysisEngineFileSpecificParametersNotNull() MsDataScan mzLibScan1 = t.GetOneBasedScan(2); Ms2ScanWithSpecificMass scan1 = new Ms2ScanWithSpecificMass(mzLibScan1, pep1.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); - PeptideSpectralMatch psm1 = new PeptideSpectralMatch(pep1, 0, 3, 0, scan1, commonParameters, new List()); + SpectralMatch psm1 = new PeptideSpectralMatch(pep1, 0, 3, 0, scan1, commonParameters, new List()); MsDataScan mzLibScan2 = t.GetOneBasedScan(4); Ms2ScanWithSpecificMass scan2 = new Ms2ScanWithSpecificMass(mzLibScan2, pep2.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); - PeptideSpectralMatch psm2 = new PeptideSpectralMatch(pep2, 1, 2, 1, scan2, commonParameters, new List()); + SpectralMatch psm2 = new PeptideSpectralMatch(pep2, 1, 2, 1, scan2, commonParameters, new List()); MsDataScan mzLibScan3 = t.GetOneBasedScan(6); Ms2ScanWithSpecificMass scan3 = new Ms2ScanWithSpecificMass(mzLibScan3, pep3.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); - PeptideSpectralMatch psm3 = new PeptideSpectralMatch(pep3, 0, 1, 2, scan3, commonParameters, new List()); + SpectralMatch psm3 = new PeptideSpectralMatch(pep3, 0, 1, 2, scan3, commonParameters, new List()); psm3.AddOrReplace(pep4, 1, 1, true, new List(), 0); - var newPsms = new List { psm1, psm2, psm3 }; - foreach (PeptideSpectralMatch psm in newPsms) + var newPsms = new List { psm1, psm2, psm3 }; + foreach (SpectralMatch psm in newPsms) { psm.ResolveAllAmbiguities(); } @@ -164,7 +165,7 @@ public static void TestComputePEPValue() List proteinList = ProteinDbLoader.LoadProteinFasta(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\hela_snip_for_unitTest.fasta"), true, DecoyType.Reverse, false, out var dbErrors, ProteinDbLoader.UniprotAccessionRegex, ProteinDbLoader.UniprotFullNameRegex, ProteinDbLoader.UniprotFullNameRegex, ProteinDbLoader.UniprotGeneNameRegex, ProteinDbLoader.UniprotOrganismRegex, -1); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, @"TestData\TaGe_SA_HeLa_04_subset_longestSeq.mzML", CommonParameters).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters, fsp, null, new List(), SearchParameters.WriteSpectralLibrary).Run(); FdrAnalysisResults fdrResultsClassicDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.Where(p => p != null).ToList(), 1, @@ -174,14 +175,14 @@ public static void TestComputePEPValue() var nonNullPsmsOriginalCopy = allPsmsArray.Where(p => p != null).ToList(); var maxScore = nonNullPsms.Select(n => n.Score).Max(); - PeptideSpectralMatch maxScorePsm = nonNullPsms.Where(n => n.Score == maxScore).First(); + SpectralMatch maxScorePsm = nonNullPsms.Where(n => n.Score == maxScore).First(); Dictionary sequenceToPsmCount = new Dictionary(); List sequences = new List(); - foreach (PeptideSpectralMatch psm in nonNullPsms) + foreach (SpectralMatch psm in nonNullPsms) { - var ss = psm.BestMatchingPeptides.Select(b => b.Peptide.FullSequence).ToList(); + var ss = psm.BestMatchingBioPolymersWithSetMods.Select(b => b.Peptide.FullSequence).ToList(); sequences.Add(String.Join("|", ss)); } @@ -206,30 +207,30 @@ public static void TestComputePEPValue() fileSpecificRetTimeHI_behavior.Add("TaGe_SA_HeLa_04_subset_longestSeq.mzML", HI_Time_avg_dev); int chargeStateMode = 4; - var (notch, pwsm) = maxScorePsm.BestMatchingPeptides.First(); + var (notch, pwsm) = maxScorePsm.BestMatchingBioPolymersWithSetMods.First(); Dictionary massError = new Dictionary { { Path.GetFileName(maxScorePsm.FullFilePath), 0 } }; - var maxPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("standard", fsp, maxScorePsm, sequenceToPsmCount, fileSpecificRetTimeHI_behavior, fileSpecificRetTemHI_behaviorModifiedPeptides, massError, chargeStateMode, pwsm, notch, !pwsm.Protein.IsDecoy); - Assert.That(maxScorePsm.PeptidesToMatchingFragments.Count - 1, Is.EqualTo(maxPsmData.Ambiguity)); + var maxPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("standard", fsp, maxScorePsm, sequenceToPsmCount, fileSpecificRetTimeHI_behavior, fileSpecificRetTemHI_behaviorModifiedPeptides, massError, chargeStateMode, pwsm, notch, !pwsm.Parent.IsDecoy); + Assert.That(maxScorePsm.BioPolymersWithSetModsToMatchingFragments.Count - 1, Is.EqualTo(maxPsmData.Ambiguity)); double normalizationFactor = (double)pwsm.BaseSequence.Length; float maxPsmDeltaScore = (float)Math.Round(maxScorePsm.DeltaScore / normalizationFactor * 10.0, 0); Assert.That(maxPsmDeltaScore, Is.EqualTo(maxPsmData.DeltaScore).Within(0.05)); float maxPsmIntensity = Math.Min(50, (float)Math.Round((maxScorePsm.Score - (int)maxScorePsm.Score) / normalizationFactor * 100.0, 0)); Assert.That(maxPsmIntensity, Is.EqualTo(maxPsmData.Intensity).Within(0.05)); Assert.That(maxPsmData.HydrophobicityZScore, Is.EqualTo(52.0).Within(0.05)); - Assert.That(maxScorePsm.BestMatchingPeptides.Select(p => p.Peptide).First().MissedCleavages, Is.EqualTo(maxPsmData.MissedCleavagesCount)); - Assert.That(maxScorePsm.BestMatchingPeptides.Select(p => p.Peptide).First().AllModsOneIsNterminus.Values.Count(), Is.EqualTo(maxPsmData.ModsCount)); + Assert.That(maxScorePsm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide).First().MissedCleavages, Is.EqualTo(maxPsmData.MissedCleavagesCount)); + Assert.That(maxScorePsm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide).First().AllModsOneIsNterminus.Values.Count(), Is.EqualTo(maxPsmData.ModsCount)); Assert.That(maxScorePsm.Notch ?? 0, Is.EqualTo(maxPsmData.Notch)); Assert.That(maxScorePsm.PsmCount, Is.EqualTo(maxPsmData.PsmCount)); Assert.That(-Math.Abs(chargeStateMode - maxScorePsm.ScanPrecursorCharge), Is.EqualTo(maxPsmData.PrecursorChargeDiffToMode)); Assert.AreEqual((float)0, maxPsmData.IsVariantPeptide); - List psmCopyForCZETest = nonNullPsms.ToList(); - List psmCopyForPEPFailure = nonNullPsms.ToList(); - List psmCopyForNoOutputFolder = nonNullPsms.ToList(); + List psmCopyForCZETest = nonNullPsms.ToList(); + List psmCopyForPEPFailure = nonNullPsms.ToList(); + List psmCopyForNoOutputFolder = nonNullPsms.ToList(); PEP_Analysis_Cross_Validation.ComputePEPValuesForAllPSMsGeneric(nonNullPsms, "standard", fsp, Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\")); @@ -244,11 +245,11 @@ public static void TestComputePEPValue() } } - List moreNonNullPSMs = new List(); + List moreNonNullPSMs = new List(); for (int i = 0; i < 3; i++) { - foreach (PeptideSpectralMatch psm in nonNullPsms) + foreach (SpectralMatch psm in nonNullPsms) { moreNonNullPSMs.Add(psm); } @@ -267,14 +268,14 @@ public static void TestComputePEPValue() Product prod = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); List mfi = new List { new MatchedFragmentIon(prod, 1, 1.0, 1) }; - PeptideSpectralMatch variantPSM = new PeptideSpectralMatch(varPep, 0, maxScorePsm.Score, maxScorePsm.ScanIndex, scan, new CommonParameters(), mfi); + SpectralMatch variantPSM = new PeptideSpectralMatch(varPep, 0, maxScorePsm.Score, maxScorePsm.ScanIndex, scan, new CommonParameters(), mfi); sequenceToPsmCount = new Dictionary(); sequences = new List(); nonNullPsms.Add(variantPSM); - foreach (PeptideSpectralMatch psm in nonNullPsms) + foreach (SpectralMatch psm in nonNullPsms) { - var ss = psm.BestMatchingPeptides.Select(b => b.Peptide.FullSequence).ToList(); + var ss = psm.BestMatchingBioPolymersWithSetMods.Select(b => b.Peptide.FullSequence).ToList(); sequences.Add(String.Join("|", ss)); } @@ -284,7 +285,7 @@ public static void TestComputePEPValue() { sequenceToPsmCount.Add(grp.Key, grp.Count()); } - var (vnotch, vpwsm) = variantPSM.BestMatchingPeptides.First(); + var (vnotch, vpwsm) = variantPSM.BestMatchingBioPolymersWithSetMods.First(); massError.Add(Path.GetFileName(variantPSM.FullFilePath), 0); PsmData variantPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("standard", fsp, variantPSM, sequenceToPsmCount, fileSpecificRetTimeHI_behavior, fileSpecificRetTemHI_behaviorModifiedPeptides, massError, chargeStateMode, vpwsm, vnotch, !maxScorePsm.IsDecoy); @@ -310,11 +311,11 @@ public static void TestComputePEPValue() } } - List moreNonNullPSMsCZE = new List(); + List moreNonNullPSMsCZE = new List(); for (int i = 0; i < 3; i++) { - foreach (PeptideSpectralMatch psm in psmCopyForCZETest) + foreach (SpectralMatch psm in psmCopyForCZETest) { moreNonNullPSMsCZE.Add(psm); } @@ -362,18 +363,18 @@ public static void TestComputePEPValueTopDown() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, origDataFile, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, fsp, null, new List(), writeSpectralLibrary).Run(); var nonNullPsms = allPsmsArray.Where(p => p != null).ToList(); - List moreNonNullPSMs = new List(); + List moreNonNullPSMs = new List(); int reps = 10; for (int i = 0; i < reps; i++) { - foreach (PeptideSpectralMatch psm in nonNullPsms) + foreach (SpectralMatch psm in nonNullPsms) { moreNonNullPSMs.Add(psm); } @@ -382,12 +383,12 @@ public static void TestComputePEPValueTopDown() FdrAnalysisResults fdrResultsClassicDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(moreNonNullPSMs.Where(p => p != null).OrderByDescending(f=>f.Score).ToList(), 1, CommonParameters, fsp, new List(), analysisType: "PSM", outputFolder: Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\")).Run()); var maxScore = nonNullPsms.Select(n => n.Score).Max(); - PeptideSpectralMatch maxScorePsm = nonNullPsms.Where(n => n.Score == maxScore).First(); + SpectralMatch maxScorePsm = nonNullPsms.Where(n => n.Score == maxScore).First(); Dictionary sequenceToPsmCount = new Dictionary(); List sequences = new List(); - foreach (PeptideSpectralMatch psm in nonNullPsms) + foreach (SpectralMatch psm in nonNullPsms) { - var ss = psm.BestMatchingPeptides.Select(b => b.Peptide.FullSequence).ToList(); + var ss = psm.BestMatchingBioPolymersWithSetMods.Select(b => b.Peptide.FullSequence).ToList(); sequences.Add(String.Join(" | ", ss)); } var s = sequences.GroupBy(i => i); @@ -401,22 +402,22 @@ public static void TestComputePEPValueTopDown() Dictionary>> fileSpecificRetTemHI_behaviorModifiedPeptides = new Dictionary>>(); int chargeStateMode = 4; - var (notch, pwsm) = maxScorePsm.BestMatchingPeptides.First(); + var (notch, pwsm) = maxScorePsm.BestMatchingBioPolymersWithSetMods.First(); Dictionary massError = new Dictionary { { Path.GetFileName(maxScorePsm.FullFilePath), 0 } }; - var maxPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("top-down", fsp, maxScorePsm, sequenceToPsmCount, fileSpecificRetTimeHI_behavior, fileSpecificRetTemHI_behaviorModifiedPeptides, massError, chargeStateMode, pwsm, notch, !pwsm.Protein.IsDecoy); - Assert.That(maxScorePsm.PeptidesToMatchingFragments.Count - 1, Is.EqualTo(maxPsmData.Ambiguity)); + var maxPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("top-down", fsp, maxScorePsm, sequenceToPsmCount, fileSpecificRetTimeHI_behavior, fileSpecificRetTemHI_behaviorModifiedPeptides, massError, chargeStateMode, pwsm, notch, !pwsm.Parent.IsDecoy); + Assert.That(maxScorePsm.BioPolymersWithSetModsToMatchingFragments.Count - 1, Is.EqualTo(maxPsmData.Ambiguity)); double normalizationFactor = (double)pwsm.BaseSequence.Length / 10.0; float maxPsmDeltaScore = (float)Math.Round(maxScorePsm.DeltaScore / normalizationFactor * 10.0, 0); Assert.That(maxPsmDeltaScore, Is.EqualTo(maxPsmData.DeltaScore).Within(0.05)); float maxPsmIntensity = (float)Math.Min(50, Math.Round((maxScorePsm.Score - (int)maxScorePsm.Score) / normalizationFactor * 100.0, 0)); Assert.That(maxPsmIntensity, Is.EqualTo(maxPsmData.Intensity).Within(0.05)); Assert.AreEqual(maxPsmData.HydrophobicityZScore, float.NaN); - Assert.That(maxScorePsm.BestMatchingPeptides.Select(p => p.Peptide).First().MissedCleavages, Is.EqualTo(maxPsmData.MissedCleavagesCount)); - Assert.That(maxScorePsm.BestMatchingPeptides.Select(p => p.Peptide).First().AllModsOneIsNterminus.Values.Count(), Is.EqualTo(maxPsmData.ModsCount)); + Assert.That(maxScorePsm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide).First().MissedCleavages, Is.EqualTo(maxPsmData.MissedCleavagesCount)); + Assert.That(maxScorePsm.BestMatchingBioPolymersWithSetMods.Select(p => p.Peptide).First().AllModsOneIsNterminus.Values.Count(), Is.EqualTo(maxPsmData.ModsCount)); Assert.That(maxScorePsm.Notch ?? 0, Is.EqualTo(maxPsmData.Notch)); Assert.That(maxScorePsm.PsmCount, Is.EqualTo(maxPsmData.PsmCount * reps)); Assert.That(-Math.Abs(chargeStateMode - maxScorePsm.ScanPrecursorCharge), Is.EqualTo(maxPsmData.PrecursorChargeDiffToMode)); @@ -436,7 +437,7 @@ public static void TestPEP_peptideRemoval() PeptideWithSetModifications pwsm = new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0); - PeptideSpectralMatch psm = new PeptideSpectralMatch(pwsm, 0, 1, 1, scan, new CommonParameters(), new List()); + SpectralMatch psm = new PeptideSpectralMatch(pwsm, 0, 1, 1, scan, new CommonParameters(), new List()); psm.AddOrReplace(pwsm, 1, 1, true, new List(), 0); psm.AddOrReplace(pwsm, 1, 2, true, new List(), 0); psm.SetFdrValues(1, 0, 0, 1, 0, 0, 1, 0); @@ -451,8 +452,8 @@ public static void TestPEP_peptideRemoval() Assert.AreEqual(2, pepValuePredictions.Count); List notches = new List(); - List peptides = new List(); - foreach (var bmp in psm.BestMatchingPeptides) + List peptides = new List(); + foreach (var bmp in psm.BestMatchingBioPolymersWithSetMods) { notches.Add(bmp.Notch); peptides.Add(bmp.Peptide); @@ -460,7 +461,7 @@ public static void TestPEP_peptideRemoval() PEP_Analysis_Cross_Validation.RemoveBestMatchingPeptidesWithLowPEP(psm, indiciesOfPeptidesToRemove, notches, peptides, pepValuePredictions, ref ambiguousPeptidesRemovedCount); Assert.AreEqual(1, ambiguousPeptidesRemovedCount); - Assert.AreEqual(2, psm.BestMatchingPeptides.Select(b => b.Notch).ToList().Count); + Assert.AreEqual(2, psm.BestMatchingBioPolymersWithSetMods.Select(b => b.Notch).ToList().Count); } [Test] @@ -526,14 +527,14 @@ public static void ReplaceBadStdevOne() extendedArray = extendedArray.OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[extendedArray.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[extendedArray.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, extendedArray, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters, fsp, null, new List(), writeSpectralLibrary).Run(); - List nonNullPsms = allPsmsArray.Where(p => p != null).ToList(); + List nonNullPsms = allPsmsArray.Where(p => p != null).ToList(); nonNullPsms = nonNullPsms.OrderByDescending(p => p.Score).ToList(); - List psmBloated = new List(); + List psmBloated = new List(); psmBloated.AddRange(nonNullPsms); int arrayMax = nonNullPsms.Count; psmBloated.AddRange(nonNullPsms.GetRange(2, arrayMax - 2)); @@ -580,22 +581,22 @@ public static void ReplaceBadStdevTwo() extendedArray = extendedArray.OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[extendedArray.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[extendedArray.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, extendedArray, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters, fsp, null, new List(), writeSpectralLibrary).Run(); - List nonNullPsms = allPsmsArray.Where(p => p != null).ToList(); + List nonNullPsms = allPsmsArray.Where(p => p != null).ToList(); nonNullPsms = nonNullPsms.OrderByDescending(p => p.Score).ToList(); - List psmBloated = new List(); + List psmBloated = new List(); psmBloated.AddRange(nonNullPsms); int arrayMax = nonNullPsms.Count; psmBloated.AddRange(nonNullPsms.GetRange(2, arrayMax - 2)); psmBloated.AddRange(nonNullPsms.GetRange(2, arrayMax - 2)); - PeptideSpectralMatch pp = psmBloated.OrderBy(p => p.ScanRetentionTime).First(); + SpectralMatch pp = psmBloated.OrderBy(p => p.ScanRetentionTime).First(); PeptideWithSetModifications newPwsmTwo = new PeptideWithSetModifications(new Protein("WAGVLPWFPWAAVVWGFWF", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0); - PeptideSpectralMatch newPsmTwo = new PeptideSpectralMatch(newPwsmTwo, pp.BestMatchingPeptides.First().Notch, pp.Score, pp.ScanIndex, mwsm, new CommonParameters(), pp.MatchedFragmentIons); + SpectralMatch newPsmTwo = new PeptideSpectralMatch(newPwsmTwo, pp.BestMatchingBioPolymersWithSetMods.First().Notch, pp.Score, pp.ScanIndex, mwsm, new CommonParameters(), pp.MatchedFragmentIons); psmBloated.Add(newPsmTwo); @@ -611,17 +612,17 @@ public static void TestRemoveThisAmbiguousePeptide() 2, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null), 100, 1, null, new CommonParameters(), null); - PeptideSpectralMatch psm1 = new PeptideSpectralMatch(new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0), 0, 10, 1, scanB, new CommonParameters(), new List(), 0); + SpectralMatch psm1 = new PeptideSpectralMatch(new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0), 0, 10, 1, scanB, new CommonParameters(), new List(), 0); PeptideWithSetModifications pwsm = new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0); psm1.AddOrReplace(pwsm, 10, 1, true, new List(), 0); - Assert.AreEqual(2, psm1.BestMatchingPeptides.Count()); + Assert.AreEqual(2, psm1.BestMatchingBioPolymersWithSetMods.Count()); psm1.RemoveThisAmbiguousPeptide(1, pwsm); - Assert.AreEqual(1, psm1.BestMatchingPeptides.Count()); + Assert.AreEqual(1, psm1.BestMatchingBioPolymersWithSetMods.Count()); } [Test] diff --git a/MetaMorpheus/Test/GPTMDengineTest.cs b/MetaMorpheus/Test/GPTMDengineTest.cs index dfc0fcef3..622d1f25f 100644 --- a/MetaMorpheus/Test/GPTMDengineTest.cs +++ b/MetaMorpheus/Test/GPTMDengineTest.cs @@ -24,13 +24,13 @@ public static class GptmdEngineTest [TestCase("NNNNN", "accession", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", 4)] public static void TestGptmdEngine(string proteinSequence, string accession, string sequenceVariantDescription, int numModifiedResidues) { - List allResultingIdentifications = null; + List allResultingIdentifications = null; ModificationMotif.TryGetMotif("N", out ModificationMotif motifN); var gptmdModifications = new List { new Modification(_originalId: "21", _modificationType: "mt", _target: motifN, _locationRestriction: "Anywhere.", _monoisotopicMass: 21.981943) }; IEnumerable> combos = new List>(); Tolerance precursorMassTolerance = new PpmTolerance(10); - allResultingIdentifications = new List(); + allResultingIdentifications = new List(); var fsp = new List<(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", new CommonParameters())); @@ -50,7 +50,7 @@ public static void TestGptmdEngine(string proteinSequence, string accession, str Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null), (new Proteomics.AminoAcidPolymer.Peptide(modPep.BaseSequence).MonoisotopicMass + 21.981943).ToMz(1), 1, "filepath", new CommonParameters()); var peptidesWithSetModifications = new List { modPep }; - PeptideSpectralMatch newPsm = new PeptideSpectralMatch(peptidesWithSetModifications.First(), 0, 0, 0, scan, commonParameters, new List()); + SpectralMatch newPsm = new PeptideSpectralMatch(peptidesWithSetModifications.First(), 0, 0, 0, scan, commonParameters, new List()); Tolerance fragmentTolerance = new AbsoluteTolerance(0.01); @@ -69,7 +69,7 @@ public static void TestGptmdEngine(string proteinSequence, string accession, str [TestCase("NNNPPP", "accession", "P", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", 2, 5, 2, 3, 1)] public static void TestCombos(string proteinSequence, string accession, string variantAA, string sequenceVariantDescription, int numModHashes, int numModifiedResidues, int numModifiedResiduesN, int numModifiedResiduesP, int numModifiedResiduesNP) { - List allIdentifications = null; + List allIdentifications = null; ModificationMotif.TryGetMotif("N", out ModificationMotif motifN); ModificationMotif.TryGetMotif("P", out ModificationMotif motifP); var gptmdModifications = new List { new Modification(_originalId: "21", _modificationType: "mt", _target: motifN, _locationRestriction: "Anywhere.", _monoisotopicMass: 21.981943), @@ -88,12 +88,12 @@ public static void TestCombos(string proteinSequence, string accession, string v Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfd, (new Proteomics.AminoAcidPolymer.Peptide(modPep.BaseSequence).MonoisotopicMass + 21.981943 + 15.994915).ToMz(1), 1, "filepath", new CommonParameters()); var peptidesWithSetModifications = new List { modPep }; - PeptideSpectralMatch match = new PeptideSpectralMatch(peptidesWithSetModifications.First(), 0, 0, 0, scan, commonParameters, new List()); + SpectralMatch match = new PeptideSpectralMatch(peptidesWithSetModifications.First(), 0, 0, 0, scan, commonParameters, new List()); Tolerance fragmentTolerance = new AbsoluteTolerance(0.01); match.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0); - allIdentifications = new List { match }; + allIdentifications = new List { match }; var engine = new GptmdEngine(allIdentifications, gptmdModifications, combos, new Dictionary { { "filepath", precursorMassTolerance } }, new CommonParameters(), null, new List()); var res = (GptmdResults)engine.Run(); @@ -240,7 +240,7 @@ public static void TestUniProtGptmdConflict() // mod should not fit anywhere on the protein for (int i = 0; i < pep.Length; i++) { - bool modFits = GptmdEngine.ModFits(mmPhospho, protein, i + 1, pep.Length, pep.OneBasedStartResidueInProtein + i); + bool modFits = GptmdEngine.ModFits(mmPhospho, protein, i + 1, pep.Length, pep.OneBasedStartResidue + i); Assert.That(!modFits); } @@ -257,7 +257,7 @@ public static void TestUniProtGptmdConflict() // mod should fit at position 8 for (int i = 0; i < pep.Length; i++) { - bool modFits = GptmdEngine.ModFits(mmPhospho, protein, i + 1, pep.Length, pep.OneBasedStartResidueInProtein + i); + bool modFits = GptmdEngine.ModFits(mmPhospho, protein, i + 1, pep.Length, pep.OneBasedStartResidue + i); if (i + 1 == 8) { diff --git a/MetaMorpheus/Test/LocalizationTest.cs b/MetaMorpheus/Test/LocalizationTest.cs index cc553ff84..4df8a6c79 100644 --- a/MetaMorpheus/Test/LocalizationTest.cs +++ b/MetaMorpheus/Test/LocalizationTest.cs @@ -51,10 +51,10 @@ public static void TestLocalization() var theoreticalProducts = new List(); ps.Fragment(DissociationType.HCD, FragmentationTerminus.Both, theoreticalProducts); var matchedIons = MetaMorpheusEngine.MatchFragmentIons(scan, theoreticalProducts, new CommonParameters()); - PeptideSpectralMatch newPsm = new PeptideSpectralMatch(ps, 0, 0, 2, scan, commonParameters, matchedIons); + SpectralMatch newPsm = new PeptideSpectralMatch(ps, 0, 0, 2, scan, commonParameters, matchedIons); newPsm.ResolveAllAmbiguities(); - LocalizationEngine f = new LocalizationEngine(new List { newPsm }, myMsDataFile, commonParameters, fsp, new List()); + LocalizationEngine f = new LocalizationEngine(new List { newPsm }, myMsDataFile, commonParameters, fsp, new List()); f.Run(); // single peak matches diff --git a/MetaMorpheus/Test/MatchIonsOfAllCharges.cs b/MetaMorpheus/Test/MatchIonsOfAllCharges.cs index bcd129f99..6319fb455 100644 --- a/MetaMorpheus/Test/MatchIonsOfAllCharges.cs +++ b/MetaMorpheus/Test/MatchIonsOfAllCharges.cs @@ -49,7 +49,7 @@ public static void TestMatchIonsOfAllChargesBottomUp() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); //search by new method of looking for all charges - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, null, new List(), true).Run(); @@ -63,7 +63,7 @@ public static void TestMatchIonsOfAllChargesBottomUp() Assert.That(psm[4].MatchedFragmentIons.Count == 16); //search by old method of looking for only one charge - PeptideSpectralMatch[] allPsmsArray_oneCharge = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray_oneCharge = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray_oneCharge, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, null, new List(), false).Run(); var psm_oneCharge = allPsmsArray_oneCharge.Where(p => p != null).ToList(); @@ -77,7 +77,7 @@ public static void TestMatchIonsOfAllChargesBottomUp() var peptideTheorProducts = new List(); Assert.That(psm_oneCharge[1].MatchedFragmentIons.Count == 12); var differences = psm[1].MatchedFragmentIons.Except(psm_oneCharge[1].MatchedFragmentIons); - psm[1].BestMatchingPeptides.First().Peptide.Fragment(CommonParameters.DissociationType, CommonParameters.DigestionParams.FragmentationTerminus, peptideTheorProducts); + psm[1].BestMatchingBioPolymersWithSetMods.First().Peptide.Fragment(CommonParameters.DissociationType, CommonParameters.DigestionParams.FragmentationTerminus, peptideTheorProducts); foreach (var ion in differences) { foreach (var product in peptideTheorProducts) @@ -112,7 +112,7 @@ public static void TestMatchIonsOfAllChargesBottomUp() addCompIons: false); var fsp = new List<(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", CommonParameters)); - PeptideSpectralMatch[] allPsmsArray1 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray1 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = true; new ClassicSearchEngine(allPsmsArray1, listOfSortedms2Scans1, variableModifications1, fixedModifications1, null, null, null, @@ -151,7 +151,7 @@ public static void TestMatchIonsOfAllChargesTopDown() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); //search by new method of looking for all charges - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, null, new List(), true).Run(); @@ -160,7 +160,7 @@ public static void TestMatchIonsOfAllChargesTopDown() //search by old method of looking for only one charge - PeptideSpectralMatch[] allPsmsArray_oneCharge = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray_oneCharge = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray_oneCharge, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, null, new List(), false).Run(); @@ -175,7 +175,7 @@ public static void TestMatchIonsOfAllChargesTopDown() //compare 2 results and evaluate the different matched ions var peptideTheorProducts = new List(); var differences = psm.MatchedFragmentIons.Except(psm_oneCharge.MatchedFragmentIons); - psm.BestMatchingPeptides.First().Peptide.Fragment(CommonParameters.DissociationType, CommonParameters.DigestionParams.FragmentationTerminus, peptideTheorProducts); + psm.BestMatchingBioPolymersWithSetMods.First().Peptide.Fragment(CommonParameters.DissociationType, CommonParameters.DigestionParams.FragmentationTerminus, peptideTheorProducts); foreach (var ion in differences) { foreach (var product in peptideTheorProducts) @@ -274,7 +274,7 @@ public static void TestReverseDecoyGenerationDuringSearch() //test when doing spectral library search without generating library - PeptideSpectralMatch[] allPsmsArray1 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray1 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray1, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, testLibrary, new List(), false).Run(); var psm1 = allPsmsArray1.Where(p => p != null).ToList(); @@ -289,7 +289,7 @@ public static void TestReverseDecoyGenerationDuringSearch() proteinList.Add(new Protein("LSISNVAK", "", isDecoy: true)); //test when doing spectral library search with generating library; non spectral search won't generate decoy by "decoy on the fly" , so proteinlist used by non spectral library search would contain decoys - PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray2, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, testLibrary, new List(), true).Run(); var psm2 = allPsmsArray2.Where(p => p != null).ToList(); @@ -302,7 +302,7 @@ public static void TestReverseDecoyGenerationDuringSearch() Assert.That(psm2[6].IsDecoy == false && psm2[6].FullSequence == "EKAEAEAEK"); //test when doing non spectral library search without generating library - PeptideSpectralMatch[] allPsmsArray3 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray3 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray3, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, null, new List(), false).Run(); var psm3 = allPsmsArray3.Where(p => p != null).ToList(); @@ -316,7 +316,7 @@ public static void TestReverseDecoyGenerationDuringSearch() //test when doing non spectral library search with generating library - PeptideSpectralMatch[] allPsmsArray4 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray4 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray4, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, null, new List(), true).Run(); var psm4 = allPsmsArray4.Where(p => p != null).ToList(); diff --git a/MetaMorpheus/Test/ModificationAnalysisTest.cs b/MetaMorpheus/Test/ModificationAnalysisTest.cs index ae6275616..c184f94fe 100644 --- a/MetaMorpheus/Test/ModificationAnalysisTest.cs +++ b/MetaMorpheus/Test/ModificationAnalysisTest.cs @@ -71,7 +71,7 @@ public static void TestModificationAnalysis() var fsp = new List<(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", CommonParameters)); - var newPsms = new List + var newPsms = new List { new PeptideSpectralMatch(pwsm1, 0, 10, 0, scan, CommonParameters, new List()), new PeptideSpectralMatch(pwsm1, 0, 10, 0, scan, CommonParameters, new List()), @@ -139,7 +139,7 @@ public static void TestModificationAnalysisWithNonLocalizedPtms() var fsp = new List<(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", CommonParameters)); - PeptideSpectralMatch myPsm = new PeptideSpectralMatch(pwsm1, 0, 10, 0, scan, new CommonParameters(), new List()); + SpectralMatch myPsm = new PeptideSpectralMatch(pwsm1, 0, 10, 0, scan, new CommonParameters(), new List()); myPsm.AddOrReplace(pwsm2, 10, 0, true, new List(),0); myPsm.ResolveAllAmbiguities(); @@ -147,9 +147,9 @@ public static void TestModificationAnalysisWithNonLocalizedPtms() MassDiffAcceptor searchMode = new SinglePpmAroundZeroSearchMode(5); List proteinList = new List { protein1 }; - FdrAnalysisEngine fdrAnalysisEngine = new FdrAnalysisEngine(new List { myPsm }, searchMode.NumNotches, CommonParameters, fsp, new List()); + FdrAnalysisEngine fdrAnalysisEngine = new FdrAnalysisEngine(new List { myPsm }, searchMode.NumNotches, CommonParameters, fsp, new List()); fdrAnalysisEngine.Run(); - ModificationAnalysisEngine modificationAnalysisEngine = new ModificationAnalysisEngine(new List { myPsm }, new CommonParameters(), fsp, new List()); + ModificationAnalysisEngine modificationAnalysisEngine = new ModificationAnalysisEngine(new List { myPsm }, new CommonParameters(), fsp, new List()); var res = (ModificationAnalysisResults)modificationAnalysisEngine.Run(); Assert.AreEqual(1, res.CountOfEachModSeenOnProteins.Count()); diff --git a/MetaMorpheus/Test/MultiProteaseParsimonyTest.cs b/MetaMorpheus/Test/MultiProteaseParsimonyTest.cs index 2fdd76fc4..5865d0a67 100644 --- a/MetaMorpheus/Test/MultiProteaseParsimonyTest.cs +++ b/MetaMorpheus/Test/MultiProteaseParsimonyTest.cs @@ -52,14 +52,14 @@ public static void MultiProteaseTest() MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); - PeptideSpectralMatch psmPEPR_T = new PeptideSpectralMatch(pepA_1T, 0, 10, 0, scan, commonParameters_Tryp, new List()); + SpectralMatch psmPEPR_T = new PeptideSpectralMatch(pepA_1T, 0, 10, 0, scan, commonParameters_Tryp, new List()); psmPEPR_T.AddOrReplace(pepA_2T, 10, 0, true, new List(),0); psmPEPR_T.AddOrReplace(pepA_3T, 10, 0, true, new List(),0); - PeptideSpectralMatch psmPEPR_A = new PeptideSpectralMatch(pepA_2A, 0, 10, 0, scan, commonParameters_ArgC, new List()); + SpectralMatch psmPEPR_A = new PeptideSpectralMatch(pepA_2A, 0, 10, 0, scan, commonParameters_ArgC, new List()); psmPEPR_A.AddOrReplace(pepA_3A, 10, 0, true, new List(),0); - PeptideSpectralMatch psmABCK_T = new PeptideSpectralMatch(pepB_1T, 0, 10, 0, scan, commonParameters_Tryp, new List()); + SpectralMatch psmABCK_T = new PeptideSpectralMatch(pepB_1T, 0, 10, 0, scan, commonParameters_Tryp, new List()); - List psms = new List { psmPEPR_T, psmPEPR_A, psmABCK_T }; + List psms = new List { psmPEPR_T, psmPEPR_A, psmABCK_T }; psms.ForEach(j => j.ResolveAllAmbiguities()); psms.ForEach(j => j.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0)); @@ -139,14 +139,14 @@ public static void MultiProteaseSamePeptideSameProteinsDifferentProteases() MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); - PeptideSpectralMatch psmABC_Dp1 = new PeptideSpectralMatch(pepA_1Dp1, 0, 10, 0, scan, commonParameters1, new List()); + SpectralMatch psmABC_Dp1 = new PeptideSpectralMatch(pepA_1Dp1, 0, 10, 0, scan, commonParameters1, new List()); psmABC_Dp1.AddOrReplace(pepA_2Dp1, 10, 0, true, new List(),0); - PeptideSpectralMatch psmABC_Dp2 = new PeptideSpectralMatch(pepA_1Dp2, 0, 10, 0, scan, commonParameters2, new List()); + SpectralMatch psmABC_Dp2 = new PeptideSpectralMatch(pepA_1Dp2, 0, 10, 0, scan, commonParameters2, new List()); psmABC_Dp2.AddOrReplace(pepA_2Dp2, 10, 0, true, new List(),0); - PeptideSpectralMatch psmEFG_Dp1 = new PeptideSpectralMatch(pepB_2Dp1, 0, 10, 0, scan, commonParameters1, new List()); + SpectralMatch psmEFG_Dp1 = new PeptideSpectralMatch(pepB_2Dp1, 0, 10, 0, scan, commonParameters1, new List()); // builds psm list to match to peptides - List psms = new List() { psmABC_Dp1, psmABC_Dp2, psmEFG_Dp1 }; + List psms = new List() { psmABC_Dp1, psmABC_Dp2, psmEFG_Dp1 }; psms.ForEach(p => p.ResolveAllAmbiguities()); psms.ForEach(p => p.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0)); @@ -217,14 +217,14 @@ public static void MultiProteaseParsimony_SharedSequenceCanBeUniquePeptide() MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); - PeptideSpectralMatch psmABC_Dp1 = new PeptideSpectralMatch(pepB_1Dp1, 0, 10, 0, scan, commonParameters, new List()); - PeptideSpectralMatch psmABC_Dp2 = new PeptideSpectralMatch(pepB_2Dp2, 0, 10, 0, scan, commonParameters2, new List()); - PeptideSpectralMatch psmEFGABC_Dp1 = new PeptideSpectralMatch(pepC_2Dp1, 0, 10, 0, scan, commonParameters, new List()); - PeptideSpectralMatch psmXYZ_Dp1 = new PeptideSpectralMatch(pepA_1Dp1, 0, 10, 0, scan, commonParameters, new List()); + SpectralMatch psmABC_Dp1 = new PeptideSpectralMatch(pepB_1Dp1, 0, 10, 0, scan, commonParameters, new List()); + SpectralMatch psmABC_Dp2 = new PeptideSpectralMatch(pepB_2Dp2, 0, 10, 0, scan, commonParameters2, new List()); + SpectralMatch psmEFGABC_Dp1 = new PeptideSpectralMatch(pepC_2Dp1, 0, 10, 0, scan, commonParameters, new List()); + SpectralMatch psmXYZ_Dp1 = new PeptideSpectralMatch(pepA_1Dp1, 0, 10, 0, scan, commonParameters, new List()); psmXYZ_Dp1.AddOrReplace(pepA_2Dp1, 10, 0, true, new List(),0); // builds psm list to match to peptides - List psms = new List() { psmABC_Dp1, psmABC_Dp2, psmEFGABC_Dp1, psmXYZ_Dp1 }; + List psms = new List() { psmABC_Dp1, psmABC_Dp2, psmEFGABC_Dp1, psmXYZ_Dp1 }; psms.ForEach(p => p.ResolveAllAmbiguities()); psms.ForEach(p => p.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0)); @@ -320,13 +320,13 @@ public static void MultiProteaseParsimony_IndistringuishableProteinsNowDistingui MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); - PeptideSpectralMatch psmABC_Dp1 = new PeptideSpectralMatch(pepA_1Dp1, 0, 10, 0, scan, commonParameters, new List()); - PeptideSpectralMatch psmABC_Dp2 = new PeptideSpectralMatch(pepA_2Dp2, 0, 10, 0, scan, commonParameters2, new List()); - PeptideSpectralMatch psmEFG_Dp1 = new PeptideSpectralMatch(pepB_1Dp1, 0, 10, 0, scan, commonParameters, new List()); - PeptideSpectralMatch psmEFG_Dp2 = new PeptideSpectralMatch(pepB_2Dp2, 0, 10, 0, scan, commonParameters2, new List()); + SpectralMatch psmABC_Dp1 = new PeptideSpectralMatch(pepA_1Dp1, 0, 10, 0, scan, commonParameters, new List()); + SpectralMatch psmABC_Dp2 = new PeptideSpectralMatch(pepA_2Dp2, 0, 10, 0, scan, commonParameters2, new List()); + SpectralMatch psmEFG_Dp1 = new PeptideSpectralMatch(pepB_1Dp1, 0, 10, 0, scan, commonParameters, new List()); + SpectralMatch psmEFG_Dp2 = new PeptideSpectralMatch(pepB_2Dp2, 0, 10, 0, scan, commonParameters2, new List()); // builds psm list to match to peptides - List psms = new List() { psmABC_Dp1, psmABC_Dp2, psmEFG_Dp1, psmEFG_Dp2 }; + List psms = new List() { psmABC_Dp1, psmABC_Dp2, psmEFG_Dp1, psmEFG_Dp2 }; psms.ForEach(h => h.ResolveAllAmbiguities()); psms.ForEach(h => h.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0)); @@ -404,7 +404,7 @@ public static void MultiProteaseParsimony_SameAminoAcidsResultInTwoUniquePeptide }; // builds psm list to match to peptides - List psms = new List(); + List psms = new List(); MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); @@ -477,12 +477,12 @@ public static void MultiProteaseParsimony_TestingPeptideBaseSequenceCanBeBothSha MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); - PeptideSpectralMatch psmABC_Dp1 = new PeptideSpectralMatch(pepA_1Dp1, 0, 10, 0, scan, commonParameters, new List()); - PeptideSpectralMatch psmABC_Dp2 = new PeptideSpectralMatch(pepA_2Dp2, 0, 10, 0, scan, commonParameters2, new List()); + SpectralMatch psmABC_Dp1 = new PeptideSpectralMatch(pepA_1Dp1, 0, 10, 0, scan, commonParameters, new List()); + SpectralMatch psmABC_Dp2 = new PeptideSpectralMatch(pepA_2Dp2, 0, 10, 0, scan, commonParameters2, new List()); psmABC_Dp2.AddOrReplace(pepA_3Dp2, 10, 0, true, new List(),0); // builds psm list to match to peptides - List psms = new List() { psmABC_Dp1, psmABC_Dp2 }; + List psms = new List() { psmABC_Dp1, psmABC_Dp2 }; psms.ForEach(h => h.ResolveAllAmbiguities()); psms.ForEach(h => h.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0)); @@ -564,7 +564,7 @@ public static void MultiProteaseParsimony_BaseSequenceCanBeSharedOrUniqueButOnly } // builds psm list to match to peptides - List psms = new List(); + List psms = new List(); MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); @@ -647,7 +647,7 @@ public static void TestPSMFdrFiltering_Simulated() } // builds psm list to match to peptides - List psms = new List(); + List psms = new List(); MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); @@ -707,8 +707,8 @@ public static void TestPSMFdrFiltering_Simulated() psms.ElementAt(5).SetFdrValues(0, 0, goodFdr, 0, goodFdr, 0, 0, 0); //this iscopy of code that filteres psms in PostSearch Analysis Task - var fdrFilteredPsms = new List(); - foreach (PeptideSpectralMatch psm in psms) + var fdrFilteredPsms = new List(); + foreach (SpectralMatch psm in psms) { if (psm != null && psm.FdrInfo.QValue <= 0.0100 && psm.FdrInfo.QValueNotch <= 0.0100) { @@ -812,13 +812,13 @@ public static void MultiProteaseParsimony_TestingSameBaseSequenceSharedandUnique MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); - PeptideSpectralMatch psmABC_Alpha = new PeptideSpectralMatch(pepABC_1Alpha, 0, 10, 0, scan, commonParameters, new List()); - PeptideSpectralMatch psmABC_Beta = new PeptideSpectralMatch(pepABC_2Beta, 0, 10, 0, scan, commonParameters2, new List()); + SpectralMatch psmABC_Alpha = new PeptideSpectralMatch(pepABC_1Alpha, 0, 10, 0, scan, commonParameters, new List()); + SpectralMatch psmABC_Beta = new PeptideSpectralMatch(pepABC_2Beta, 0, 10, 0, scan, commonParameters2, new List()); psmABC_Beta.AddOrReplace(pepABC_4Beta, 10, 0, true, new List(),0); - PeptideSpectralMatch psmEFG_Beta = new PeptideSpectralMatch(pepEFG_3Beta, 0, 10, 0, scan, commonParameters2, new List()); + SpectralMatch psmEFG_Beta = new PeptideSpectralMatch(pepEFG_3Beta, 0, 10, 0, scan, commonParameters2, new List()); psmEFG_Beta.AddOrReplace(pepEFG_4Beta, 10, 0, true, new List(),0); - List psms = new List { psmABC_Alpha, psmABC_Beta, psmEFG_Beta }; + List psms = new List { psmABC_Alpha, psmABC_Beta, psmEFG_Beta }; psms.ForEach(j => j.ResolveAllAmbiguities()); psms.ForEach(j => j.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0)); @@ -882,16 +882,16 @@ public static void MultiProteaseParsimony_TestingActuallyIndistinguisableProtein MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); - PeptideSpectralMatch psmABCK_T = new PeptideSpectralMatch(pepABCK_1T, 0, 10, 0, scan, commonParameters_tryp, new List()); + SpectralMatch psmABCK_T = new PeptideSpectralMatch(pepABCK_1T, 0, 10, 0, scan, commonParameters_tryp, new List()); psmABCK_T.AddOrReplace(pepABCK_2T, 10, 0, true, new List(),0); - PeptideSpectralMatch psmABCK_L = new PeptideSpectralMatch(pepABCK_1L, 0, 10, 0, scan, commonParameters_LysC, new List()); + SpectralMatch psmABCK_L = new PeptideSpectralMatch(pepABCK_1L, 0, 10, 0, scan, commonParameters_LysC, new List()); psmABCK_L.AddOrReplace(pepABCK_2L, 10, 0, true, new List(),0); - PeptideSpectralMatch psmXYZK_T = new PeptideSpectralMatch(pepXYZK_1T, 0, 10, 0, scan, commonParameters_LysC, new List()); + SpectralMatch psmXYZK_T = new PeptideSpectralMatch(pepXYZK_1T, 0, 10, 0, scan, commonParameters_LysC, new List()); psmXYZK_T.AddOrReplace(pepXYZK_2T, 10, 0, true, new List(),0); - PeptideSpectralMatch psmXYZK_L = new PeptideSpectralMatch(pepXYZK_1L, 0, 10, 0, scan, commonParameters_LysC, new List()); + SpectralMatch psmXYZK_L = new PeptideSpectralMatch(pepXYZK_1L, 0, 10, 0, scan, commonParameters_LysC, new List()); psmXYZK_L.AddOrReplace(pepXYZK_2L, 10, 0, true, new List(),0); - List psms = new List { psmABCK_T, psmABCK_L, psmXYZK_T, psmXYZK_L }; + List psms = new List { psmABCK_T, psmABCK_L, psmXYZK_T, psmXYZK_L }; psms.ForEach(j => j.ResolveAllAmbiguities()); psms.ForEach(j => j.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0)); @@ -956,12 +956,12 @@ public static void MultiProteaseParsimony_TestingGreedyAlgorithm() MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); - PeptideSpectralMatch psmABC_Dash = new PeptideSpectralMatch(pepABC_1Dash, 0, 10, 0, scan, commonParameters, new List()); + SpectralMatch psmABC_Dash = new PeptideSpectralMatch(pepABC_1Dash, 0, 10, 0, scan, commonParameters, new List()); psmABC_Dash.AddOrReplace(pepABC_2Dash, 10, 0, true, new List(),0); - PeptideSpectralMatch psmABC_G = new PeptideSpectralMatch(pepABC_2G, 0, 10, 0, scan, commonParameters2, new List()); + SpectralMatch psmABC_G = new PeptideSpectralMatch(pepABC_2G, 0, 10, 0, scan, commonParameters2, new List()); psmABC_G.AddOrReplace(pepABC_3G, 10, 0, true, new List(),0); - List psms = new List { psmABC_Dash, psmABC_G }; + List psms = new List { psmABC_Dash, psmABC_G }; psms.ForEach(j => j.ResolveAllAmbiguities()); psms.ForEach(j => j.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0)); @@ -1011,7 +1011,7 @@ public static void MultiProteaseParsimony_TestingProteaseSpecificFDRCalculations Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); List f = new List(); - List psms = new List + List psms = new List { new PeptideSpectralMatch(new PeptideWithSetModifications("P", null, digestionParams: commonParameters_tryp.DigestionParams, p: t), 0, 20, 1, scan, commonParameters_tryp, f), new PeptideSpectralMatch(new PeptideWithSetModifications("P", null, digestionParams: commonParameters_gluC.DigestionParams, p: t), 0, 19, 1, scan, commonParameters_gluC, f), diff --git a/MetaMorpheus/Test/MyPeptideTest.cs b/MetaMorpheus/Test/MyPeptideTest.cs index 04af2371e..4d82c08a8 100644 --- a/MetaMorpheus/Test/MyPeptideTest.cs +++ b/MetaMorpheus/Test/MyPeptideTest.cs @@ -40,7 +40,7 @@ public static void TestIdenticalPeaks() MzSpectrum massSpectrum = new MzSpectrum(mz, intensities, false); MsDataScan scan = new MsDataScan(massSpectrum, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, null, null, "scan=1", 0, null, null, 0, null, DissociationType.Unknown, 1, null); - PeptideSpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; + SpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 0, 1, null, new CommonParameters()) }; CommonParameters CommonParameters = new CommonParameters( productMassTolerance: new PpmTolerance(5), @@ -75,7 +75,7 @@ public static void TestLastPeaks() MzSpectrum massSpectrum = new MzSpectrum(mz, intensities, false); MsDataScan scan = new MsDataScan(massSpectrum, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, null, null, "scan=1", 0, null, null, 0, null, DissociationType.Unknown, 1, null); - PeptideSpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; + SpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 0, 1, null, new CommonParameters()) }; CommonParameters CommonParameters = new CommonParameters( scoreCutoff: 1, @@ -112,7 +112,7 @@ public static void TestVeryCloseExperimentalsClassic() MzSpectrum massSpectrum = new MzSpectrum(mz, intensities, false); MsDataScan scan = new MsDataScan(massSpectrum, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, null, null, "scan=1", 0, null, null, 0, null, DissociationType.Unknown, 1, null); - PeptideSpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; + SpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 0, 1, null, new CommonParameters()) }; CommonParameters CommonParameters = new CommonParameters( productMassTolerance: new PpmTolerance(5), @@ -149,7 +149,7 @@ public static void TestVeryCloseExperimentalsModern() MzSpectrum massSpectrum = new MzSpectrum(mz, intensities, false); MsDataScan scan = new MsDataScan(massSpectrum, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, null, null, "scan=1", 0, null, null, 0, null, DissociationType.Unknown, 1, null); - PeptideSpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; + SpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 600, 1, null, new CommonParameters()) }; CommonParameters CommonParameters = new CommonParameters(productMassTolerance: new PpmTolerance(5), scoreCutoff: 1, digestionParams: new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, maxModificationIsoforms: int.MaxValue, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain)); @@ -180,7 +180,7 @@ public static void TestAllNaN() MzSpectrum massSpectrum = new MzSpectrum(mz, intensities, false); MsDataScan scan = new MsDataScan(massSpectrum, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, null, null, "scan=1", 0, null, null, 0, null, DissociationType.Unknown, 1, null); - PeptideSpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; + SpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 0, 0, null, new CommonParameters()) }; CommonParameters CommonParameters = new CommonParameters(productMassTolerance: new PpmTolerance(5), scoreCutoff: 1, digestionParams: new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, maxModificationIsoforms: int.MaxValue, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain)); bool writeSpetralLibrary = false; diff --git a/MetaMorpheus/Test/PsmTsvWriterTests.cs b/MetaMorpheus/Test/PsmTsvWriterTests.cs index db9b9f74f..2f27be8b8 100644 --- a/MetaMorpheus/Test/PsmTsvWriterTests.cs +++ b/MetaMorpheus/Test/PsmTsvWriterTests.cs @@ -57,7 +57,7 @@ public static void ResolveModificationsTest() //we're adding a neutral loss of 5 to the product to make sure we hit the right spot in the unit test to add that loss to the product ion string Product p = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 5); mfi.Add(new MatchedFragmentIon(p, 1, 1, 1)); - PeptideSpectralMatch myPsm = new PeptideSpectralMatch(pwsm1, 0, 10, 0, scan, new CommonParameters(), mfi); + SpectralMatch myPsm = new PeptideSpectralMatch(pwsm1, 0, 10, 0, scan, new CommonParameters(), mfi); myPsm.AddOrReplace(pwsm2, 10, 0, true, mfi, 10); diff --git a/MetaMorpheus/Test/RobTest.cs b/MetaMorpheus/Test/RobTest.cs index 9c7ce8f56..1b87dcd13 100644 --- a/MetaMorpheus/Test/RobTest.cs +++ b/MetaMorpheus/Test/RobTest.cs @@ -86,7 +86,7 @@ public static void TestParsimony() } // create PSMs for the peptides - Dictionary temp = new Dictionary(); + Dictionary temp = new Dictionary(); MsDataScan fakeScan = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, @@ -106,7 +106,7 @@ public static void TestParsimony() } } - List psms = temp.Values.ToList(); + List psms = temp.Values.ToList(); foreach (var psm in psms) { @@ -124,7 +124,7 @@ public static void TestParsimony() proteinGroups = proteinScoringAndFdrResults.SortedAndScoredProteinGroups; // select the PSMs' proteins - List parsimonyProteinSequences = psms.SelectMany(p => p.BestMatchingPeptides.Select(v => v.Peptide.Protein)).Select(v => v.BaseSequence).Distinct().ToList(); + List parsimonyProteinSequences = psms.SelectMany(p => p.BestMatchingBioPolymersWithSetMods.Select(v => v.Peptide.Parent)).Select(v => v.BaseSequence).Distinct().ToList(); // check that correct proteins are in parsimony list Assert.Contains("AB--------", parsimonyProteinSequences); @@ -230,7 +230,7 @@ public static void TestPTMOutput() match66.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); - List psms = new List + List psms = new List { match1, match2, diff --git a/MetaMorpheus/Test/SearchEngineTests.cs b/MetaMorpheus/Test/SearchEngineTests.cs index 5d02cefce..2721fe645 100644 --- a/MetaMorpheus/Test/SearchEngineTests.cs +++ b/MetaMorpheus/Test/SearchEngineTests.cs @@ -48,7 +48,7 @@ public static void TestClassicSearchEngine() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters, null, null, new List(), writeSpectralLibrary).Run(); @@ -282,7 +282,7 @@ public static void TestClassicSearchEngineXcorr() scan.TheScan.MassSpectrum.XCorrPrePreprocessing(0, 1969, scan.TheScan.IsolationMz.Value); } - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedXcorrms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedXcorrms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedXcorrms2Scans, variableModifications, fixedModifications, null, null, null, @@ -335,7 +335,7 @@ public static void TestClassicSearchEngineWithWeirdPeptide() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, @@ -383,7 +383,7 @@ public static void TestModernSearchEngine() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, null, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); // Single search mode @@ -437,7 +437,7 @@ public static void TestModernSearchEngineLowResTrivial() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, null, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); // Single search mode @@ -539,7 +539,7 @@ public static void TestModernSearchEngineLowResOneRealSpectrum() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray, losm2, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, null, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); var nonNullPsms = allPsmsArray.Where(p => p != null).ToList(); @@ -601,7 +601,7 @@ public static void TestClassicSearchEngineLowResSimple() Assert.AreEqual(147, numSpectra); - PeptideSpectralMatch[] fileSpecificPsms = new PeptideSpectralMatch[arrayOfMs2ScansSortedByMass.Length]; + SpectralMatch[] fileSpecificPsms = new PeptideSpectralMatch[arrayOfMs2ScansSortedByMass.Length]; string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestClassicSearchEngineLowResSimple"); string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\TaGe_SA_A549_3_snip.fasta"); @@ -638,7 +638,7 @@ public static void TestClassicSearchEngineLowResSimple() Assert.AreEqual(535, listOfSortedXcorrms2Scans.Count()); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedXcorrms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedXcorrms2Scans.Length]; var fsp = new List<(string, CommonParameters)>(); fsp.Add(("sliced_b6.mzML", CommonParameters)); @@ -697,7 +697,7 @@ public static void TestModernSearchEngineLowResSimple() Ms2ScanWithSpecificMass[] arrayOfMs2ScansSortedByMass = MetaMorpheusTask.GetMs2Scans(myMsDataFile, origDataFile, CommonParameters).OrderBy(b => b.PrecursorMass).ToArray(); int numSpectra = myMsDataFile.GetAllScansList().Count(p => p.MsnOrder == 2); - PeptideSpectralMatch[] fileSpecificPsms = new PeptideSpectralMatch[arrayOfMs2ScansSortedByMass.Length]; + SpectralMatch[] fileSpecificPsms = new PeptideSpectralMatch[arrayOfMs2ScansSortedByMass.Length]; string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestModernSearchEngineLowResSimple"); //string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\LowResSnip_B6_mouse_11700_117500.xml.gz"); @@ -737,7 +737,7 @@ public static void TestModernSearchEngineLowResSimple() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, fsp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); var nonNullPsms = allPsmsArray.Where(p => p != null).ToList(); @@ -780,7 +780,7 @@ public static void TestModernSearchFragmentEdges() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, null, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()).Run(); // no assertions... just don't crash... @@ -813,9 +813,9 @@ public static void TestNonViablePSM() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[1][]; + SpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[1][]; allPsmsArrays[0] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; - PeptideSpectralMatch[] allPsmsArray = allPsmsArrays[0]; + SpectralMatch[] allPsmsArray = allPsmsArrays[0]; //Classic bool writeSpectralLibrary = false; @@ -864,7 +864,7 @@ public static void TestModernSearchEngineWithWeirdPeptide() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; var engine = new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, null, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List()); var searchResults = engine.Run(); @@ -925,11 +925,11 @@ public static void TestNonSpecificEnzymeSearchEngineSingleN() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; + SpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; allPsmsArrays[0] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[1] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[2] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; - PeptideSpectralMatch[] allPsmsArray = allPsmsArrays[2]; + SpectralMatch[] allPsmsArray = allPsmsArrays[2]; //coisolation index List[] coisolationIndex = new List[listOfSortedms2Scans.Length]; @@ -1001,11 +1001,11 @@ public static void TestNonSpecificEnzymeSearchEngineSingleNLowCID() MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; + SpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; allPsmsArrays[0] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[1] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[2] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; - PeptideSpectralMatch[] allPsmsArray = allPsmsArrays[2]; + SpectralMatch[] allPsmsArray = allPsmsArrays[2]; //coisolation index List[] coisolationIndex = new List[listOfSortedms2Scans.Length]; @@ -1078,11 +1078,11 @@ public static void TestNonSpecificEnzymeSearchEngineSingleCModifications() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; + SpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; allPsmsArrays[0] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[1] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[2] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; - PeptideSpectralMatch[] allPsmsArray = allPsmsArrays[2]; + SpectralMatch[] allPsmsArray = allPsmsArrays[2]; //coisolation index List[] coisolationIndex = new List[listOfSortedms2Scans.Length]; @@ -1185,11 +1185,11 @@ public static void TestNonSpecificEnzymeSearchEngineSingleNModifications() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; + SpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; allPsmsArrays[0] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[1] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[2] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; - PeptideSpectralMatch[] allPsmsArray = allPsmsArrays[2]; + SpectralMatch[] allPsmsArray = allPsmsArrays[2]; //coisolation index List[] coisolationIndex = new List[listOfSortedms2Scans.Length]; @@ -1255,7 +1255,7 @@ public static void TestSnesFifteenMer() PeptideWithSetModifications pwsm = new PeptideWithSetModifications("ACDEFGHIKLMNPQR", new Dictionary()); TestDataFile msFile = new TestDataFile(pwsm); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(msFile, null, new CommonParameters()).ToArray(); - PeptideSpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; + SpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; allPsmsArrays[0] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[1] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[2] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; @@ -1330,11 +1330,11 @@ public static void TestNonSpecificEnzymeSearchEngineSingleC() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac); - PeptideSpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; + SpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; allPsmsArrays[0] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[1] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[2] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; - PeptideSpectralMatch[] allPsmsArray = allPsmsArrays[2]; + SpectralMatch[] allPsmsArray = allPsmsArrays[2]; //coisolation index List[] coisolationIndex = new List[listOfSortedms2Scans.Length]; @@ -1473,10 +1473,10 @@ public static void TestSemiSpecificEnzymeEngineSingleN() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[2][]; + SpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[2][]; allPsmsArrays[0] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[1] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; - PeptideSpectralMatch[] allPsmsArray = allPsmsArrays[1]; + SpectralMatch[] allPsmsArray = allPsmsArrays[1]; //coisolation index List[] coisolationIndex = new List[listOfSortedms2Scans.Length]; @@ -1547,11 +1547,11 @@ public static void TestSemiSpecificEnzymeEngineSingleC() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; + SpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; allPsmsArrays[0] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[1] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; allPsmsArrays[2] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; - PeptideSpectralMatch[] allPsmsArray = allPsmsArrays[2]; + SpectralMatch[] allPsmsArray = allPsmsArrays[2]; //coisolation index List[] coisolationIndex = new List[listOfSortedms2Scans.Length]; @@ -1627,7 +1627,7 @@ public static void TestClassicSemiProtease() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, @@ -1647,7 +1647,7 @@ public static void TestClassicSemiProtease() var listOfSortedms2Scans2 = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray2, listOfSortedms2Scans2, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters2, null, null, new List(), writeSpectralLibrary).Run(); @@ -1768,7 +1768,7 @@ public static void TestClassicSearchOneNterminalModifiedPeptideOneScan() CommonParameters commonParameters = new CommonParameters(dissociationType: d, precursorMassTolerance: precursorTolerance, productMassTolerance: productTolerance, digestionParams: testDigestionParams); //Search the scan against the protein - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[1]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[1]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, scans, new List(), new List(), null, null, null, @@ -1842,7 +1842,7 @@ public static void TestTerminalModificationsForSnes() var peptideIndex = indexResults.PeptideIndex; var fragmentIndexDict = indexResults.FragmentIndex; var precursorIndexDict = indexResults.PrecursorIndex; - PeptideSpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; + SpectralMatch[][] allPsmsArrays = new PeptideSpectralMatch[3][]; allPsmsArrays[2] = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; //coisolation index @@ -1855,7 +1855,7 @@ public static void TestTerminalModificationsForSnes() var searchResults = engine.Run(); for (int i = 0; i < listOfSortedms2Scans.Length; i++) { - PeptideSpectralMatch testPsm = allPsmsArrays[2][i]; + SpectralMatch testPsm = allPsmsArrays[2][i]; Assert.IsTrue(testPsm != null); testPsm.ResolveAllAmbiguities(); Assert.IsTrue(psmAnswer[1 - i].Equals(testPsm.FullSequence)); diff --git a/MetaMorpheus/Test/SearchTaskTest.cs b/MetaMorpheus/Test/SearchTaskTest.cs index dc3cb447c..cce514a40 100644 --- a/MetaMorpheus/Test/SearchTaskTest.cs +++ b/MetaMorpheus/Test/SearchTaskTest.cs @@ -447,7 +447,7 @@ public static void TestMzIdentMlWriterWithUniprotResId() string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "ResIdOutput.mzID"); - MzIdentMLWriter.WriteMzIdentMl(new List { psm }, new List(), new List(), + MzIdentMLWriter.WriteMzIdentMl(new List { psm }, new List(), new List(), new List(), new List(), new List(), new PpmTolerance(20), new PpmTolerance(20), 0, path, true); @@ -489,7 +489,7 @@ public static void TestMzIdentMlWriterWithUniprotPsiMod() string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "ResIdOutput.mzID"); - MzIdentMLWriter.WriteMzIdentMl(new List { psm }, new List(), new List(), + MzIdentMLWriter.WriteMzIdentMl(new List { psm }, new List(), new List(), new List(), new List(), new List(), new PpmTolerance(20), new PpmTolerance(20), 0, path, true); @@ -505,7 +505,7 @@ public static void TestMzIdentMlWriterWithUniprotPsiMod() Assert.That(found); // test again w/ NOT appending motifs onto mod names - MzIdentMLWriter.WriteMzIdentMl(new List { psm }, new List(), new List(), + MzIdentMLWriter.WriteMzIdentMl(new List { psm }, new List(), new List(), new List(), new List(), new List(), new PpmTolerance(20), new PpmTolerance(20), 0, path, false); diff --git a/MetaMorpheus/Test/SeqCoverageTest.cs b/MetaMorpheus/Test/SeqCoverageTest.cs index 620fb1c75..81d7bda7c 100644 --- a/MetaMorpheus/Test/SeqCoverageTest.cs +++ b/MetaMorpheus/Test/SeqCoverageTest.cs @@ -74,7 +74,7 @@ public static void TryFailSequenceCoverage() psm3.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); - List newPsms = new List + List newPsms = new List { psm1, psm2, @@ -143,7 +143,7 @@ public static void TestFragmentSequenceCoverage() var psm3 = new PeptideSpectralMatch(pwsm3, 0, 1, 0, scan, new CommonParameters(), new List()); psm3.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); - List newPsms = new List + List newPsms = new List { psm1, psm2, diff --git a/MetaMorpheus/Test/SpectralLibraryReaderTest.cs b/MetaMorpheus/Test/SpectralLibraryReaderTest.cs index 8170c7fc9..25244e2c4 100644 --- a/MetaMorpheus/Test/SpectralLibraryReaderTest.cs +++ b/MetaMorpheus/Test/SpectralLibraryReaderTest.cs @@ -180,7 +180,7 @@ public static void AnotherSpectralLibrarySearchTest() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, commonParameters,null, sl, new List(), writeSpectralLibrary).Run(); @@ -222,7 +222,7 @@ public static void AnotherSpectralLibrarySearchTestDecoy() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, commonParameters, null, sl, new List(), writeSpectralLibrary).Run(); diff --git a/MetaMorpheus/Test/SpectralRecoveryTest.cs b/MetaMorpheus/Test/SpectralRecoveryTest.cs index c26ed855a..e46ca8994 100644 --- a/MetaMorpheus/Test/SpectralRecoveryTest.cs +++ b/MetaMorpheus/Test/SpectralRecoveryTest.cs @@ -14,6 +14,7 @@ using Omics.Modifications; using TaskLayer; using TaskLayer.MbrAnalysis; +using Omics; namespace Test { @@ -23,7 +24,7 @@ public class { private static MyTaskResults searchTaskResults; private static List tsvPsms; - private static List psms; + private static List psms; private static List proteinList; private static MyFileManager myFileManager; private static List rawSlices; @@ -34,10 +35,10 @@ public class [OneTimeSetUp] public void SpectralRecoveryTestSetup() { - // This block of code converts from PsmFromTsv to PeptideSpectralMatch objects + // This block of code converts from PsmFromTsv to SpectralMatch objects string psmtsvPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", @"SpectralRecoveryTest\MSMSids.psmtsv"); tsvPsms = PsmTsvReader.ReadTsv(psmtsvPath, out var warnings); - psms = new List(); + psms = new List(); proteinList = new List(); myFileManager = new MyFileManager(true); @@ -58,7 +59,7 @@ public void SpectralRecoveryTestSetup() PeptideWithSetModifications pwsm = new PeptideWithSetModifications( readPsm.FullSequence, null, p: protein, digestionParams: new DigestionParams(), oneBasedStartResidueInProtein: startResidue, oneBasedEndResidueInProtein: endResidue); - PeptideSpectralMatch psm = new PeptideSpectralMatch(pwsm, 0, readPsm.Score, readPsm.Ms2ScanNumber, ms2Scan, + SpectralMatch psm = new PeptideSpectralMatch(pwsm, 0, readPsm.Score, readPsm.Ms2ScanNumber, ms2Scan, new CommonParameters(), readPsm.MatchedIons); psm.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); if (readPsm.Ms2ScanNumber == 206 && readPsm.BaseSeq.Equals("HADIVTTTTHK")) psm.SetFdrValues(0, 0, 0, 0, 0, 0, 0.0046, 0); // Necessary for to be implemented "original pep" test @@ -224,7 +225,7 @@ public static void MiniClassicSearchEngineTest() Ms2ScanWithSpecificMass[] listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, commonParameters, null, sl, new List(), writeSpectralLibrary).Run(); @@ -238,9 +239,9 @@ public static void MiniClassicSearchEngineTest() SpectralLibrarySearchFunction.CalculateSpectralAngles(sl, allPsmsArray, listOfSortedms2Scans, commonParameters); Assert.That(allPsmsArray[5].SpectralAngle, Is.EqualTo(0.82).Within(0.01)); - foreach (PeptideSpectralMatch psm in allPsmsArray.Where(p => p != null)) + foreach (SpectralMatch psm in allPsmsArray.Where(p => p != null)) { - PeptideWithSetModifications pwsm = psm.BestMatchingPeptides.First().Peptide; + IBioPolymerWithSetMods pwsm = psm.BestMatchingBioPolymersWithSetMods.First().Peptide; MiniClassicSearchEngine mcse = new MiniClassicSearchEngine( listOfSortedms2Scans.OrderBy(p => p.RetentionTime).ToArray(), @@ -249,7 +250,7 @@ public static void MiniClassicSearchEngineTest() sl, null); - PeptideSpectralMatch[] peptideSpectralMatches = + SpectralMatch[] peptideSpectralMatches = mcse.SearchAroundPeak(pwsm, allPsmsArray[5].ScanRetentionTime).ToArray(); Assert.AreEqual(allPsmsArray[5].BaseSequence, peptideSpectralMatches[0].BaseSequence); @@ -363,7 +364,7 @@ public static void SpectralWriterTest() [Test] public static void SpectralRecoveryHeaderTest() { - string psmHeader = PeptideSpectralMatch.GetTabSeparatedHeader().Trim(); + string psmHeader = SpectralMatch.GetTabSeparatedHeader().Trim(); StringBuilder sb = new(); sb.Append(psmHeader); sb.Append('\t'); diff --git a/MetaMorpheus/Test/StefanParsimonyTest.cs b/MetaMorpheus/Test/StefanParsimonyTest.cs index b836d9b30..7fb4ea560 100644 --- a/MetaMorpheus/Test/StefanParsimonyTest.cs +++ b/MetaMorpheus/Test/StefanParsimonyTest.cs @@ -43,7 +43,7 @@ public static void ParsimonyTreatModifiedFormsAsUnique() Assert.That(unmodifiedPeptide.NumMods == 0); // there was no modification on this protein // build PSMs for parsimony - List psmsForParsimony = new List(); + List psmsForParsimony = new List(); MsDataScan fakeScan = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, @@ -51,11 +51,11 @@ public static void ParsimonyTreatModifiedFormsAsUnique() Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(fakeScan, 2, 0, "File", new CommonParameters()); - PeptideSpectralMatch psm1 = new PeptideSpectralMatch(modifiedPeptide, 0, 10, 1, scan, new CommonParameters(), new List()); + SpectralMatch psm1 = new PeptideSpectralMatch(modifiedPeptide, 0, 10, 1, scan, new CommonParameters(), new List()); psm1.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); psm1.ResolveAllAmbiguities(); - PeptideSpectralMatch psm2 = new PeptideSpectralMatch(unmodifiedPeptide, 0, 10, 2, scan, new CommonParameters(), new List()); + SpectralMatch psm2 = new PeptideSpectralMatch(unmodifiedPeptide, 0, 10, 2, scan, new CommonParameters(), new List()); psm2.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); psm2.ResolveAllAmbiguities(); @@ -77,8 +77,8 @@ public static void ParsimonyTreatModifiedFormsAsUnique() // because modified peptides were considered as unique, then there should be two protein groups after parsimony, and one protein accession for each peptide Assert.That(countOfProteinGroups == 2); Assert.That(results.SortedAndScoredProteinGroups.All(p => p.Proteins.Count == 1)); - Assert.That(psm1.ProteinAccession == "accession1"); - Assert.That(psm2.ProteinAccession == "accession2"); + Assert.That(psm1.Accession == "accession1"); + Assert.That(psm2.Accession == "accession2"); } [Test] @@ -110,7 +110,7 @@ public static void ParsimonyDontTreatModifiedFormsAsUnique() Assert.That(unmodifiedPeptide.NumMods == 0); // there was no modification on this protein // build PSMs for parsimony - List psmsForParsimony = new List(); + List psmsForParsimony = new List(); MsDataScan fakeScan = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, @@ -118,11 +118,11 @@ public static void ParsimonyDontTreatModifiedFormsAsUnique() Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(fakeScan, 2, 0, "File", new CommonParameters()); - PeptideSpectralMatch psm1 = new PeptideSpectralMatch(modifiedPeptide, 0, 10, 1, scan, new CommonParameters(), new List()); + SpectralMatch psm1 = new PeptideSpectralMatch(modifiedPeptide, 0, 10, 1, scan, new CommonParameters(), new List()); psm1.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); psm1.ResolveAllAmbiguities(); - PeptideSpectralMatch psm2 = new PeptideSpectralMatch(unmodifiedPeptide, 0, 10, 2, scan, new CommonParameters(), new List()); + SpectralMatch psm2 = new PeptideSpectralMatch(unmodifiedPeptide, 0, 10, 2, scan, new CommonParameters(), new List()); psm2.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); psm2.ResolveAllAmbiguities(); @@ -146,8 +146,8 @@ public static void ParsimonyDontTreatModifiedFormsAsUnique() // and two protein accessions for each peptide Assert.AreEqual(1, countOfProteinGroups); Assert.AreEqual(2, results.SortedAndScoredProteinGroups.First().Proteins.Count); - Assert.IsNull(psm1.ProteinAccession); - Assert.IsNull(psm2.ProteinAccession); + Assert.IsNull(psm1.Accession); + Assert.IsNull(psm2.Accession); } [Test] @@ -173,7 +173,7 @@ public static void ParsimonyWeirdCatch() MatchedFragmentIon mfiC3 = new MatchedFragmentIon(productC3, 0, 0, 1); MatchedFragmentIon mfiC4 = new MatchedFragmentIon(productC4, 0, 0, 1); - List psms = new List + List psms = new List { new PeptideSpectralMatch(pep1,0,1,0, scan, new CommonParameters(), new List() {mfiC3, mfiC4}), }; @@ -222,7 +222,7 @@ public static void TopPickedFdrTest() MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); - List psms = new List + List psms = new List { new PeptideSpectralMatch(fillerPep,0,30,0, scan, new CommonParameters(), new List()), new PeptideSpectralMatch(decoyPep,0,15.11,0, scan, new CommonParameters(), new List()), diff --git a/MetaMorpheus/Test/TestPsm.cs b/MetaMorpheus/Test/TestPsm.cs index e34d4b3a1..f7cba663f 100644 --- a/MetaMorpheus/Test/TestPsm.cs +++ b/MetaMorpheus/Test/TestPsm.cs @@ -18,6 +18,7 @@ using TaskLayer; using UsefulProteomicsDatabases; using PsmFromTsv = EngineLayer.PsmFromTsv; +using Omics; namespace Test { @@ -45,23 +46,23 @@ public static void TestPsmHeader() var theoreticalIons = new List(); pepWithSetMods.Fragment(DissociationType.HCD, FragmentationTerminus.Both, theoreticalIons); var matchedIons = MetaMorpheusEngine.MatchFragmentIons(scan, theoreticalIons, new CommonParameters()); - PeptideSpectralMatch psm = new PeptideSpectralMatch(pepWithSetMods, 1, 2, 3, scan, commonParameters, matchedIons); + SpectralMatch psm = new PeptideSpectralMatch(pepWithSetMods, 1, 2, 3, scan, commonParameters, matchedIons); psm.ResolveAllAmbiguities(); var t = psm.ToString(); - var tabsepheader = PeptideSpectralMatch.GetTabSeparatedHeader(); - Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); + var tabsepheader = SpectralMatch.GetTabSeparatedHeader(); + Assert.AreEqual(psm.ToString().Count(f => f == '\t'), SpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); - Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); + Assert.AreEqual(psm.ToString().Count(f => f == '\t'), SpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); Tolerance fragmentTolerance = new PpmTolerance(10); - new LocalizationEngine(new List { psm }, myMsDataFile, new CommonParameters(productMassTolerance: fragmentTolerance), null, new List()).Run(); + new LocalizationEngine(new List { psm }, myMsDataFile, new CommonParameters(productMassTolerance: fragmentTolerance), null, new List()).Run(); - Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); + Assert.AreEqual(psm.ToString().Count(f => f == '\t'), SpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); psm.SetFdrValues(6, 6, 6, 6, 6, 0, 0, 0); - Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); + Assert.AreEqual(psm.ToString().Count(f => f == '\t'), SpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); } [Test] @@ -116,7 +117,7 @@ public static void TestLongestFragmentIonSequence() ProteinDbLoader.UniprotOrganismRegex, -1); string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\DbForPrunedDb.fasta"); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpetralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, new CommonParameters(), null, null, new List(), writeSpetralLibrary).Run(); @@ -125,13 +126,13 @@ public static void TestLongestFragmentIonSequence() List longestSeriesExpected = new List { 4, 3, 3, 7, 7, 7, 7, 3, 3, 12, 8, 4, 4, 13, 7, 7, 7, 12, 12, 3, 3, 3, 2, 2, 2, 2, 2, 2, 11, 11, 11, 11, 11, 11, 4, 4, 4, 4, 4, 4, 10, 10, 13, 13, 5, 5, 5, 5, 15, 15, 15, 15, 3, 3, 3, 15, 15, 15, 3, 3, 3, 16, 6, 2, 2, 18, 3, 2, 2, 2, 2, 2, 9, 9, 9, 3, 2, 2, 2, 2, 2, 3, 3, 12, 6, 3, }; - foreach (PeptideSpectralMatch psm in allPsmsArray) + foreach (SpectralMatch psm in allPsmsArray) { if (psm != null) { - foreach (var (Notch, Peptide) in psm.BestMatchingPeptides) + foreach (var (Notch, Peptide) in psm.BestMatchingBioPolymersWithSetMods) { - longestSeriesObserved.Add(PeptideSpectralMatch.GetLongestIonSeriesBidirectional(psm.PeptidesToMatchingFragments, Peptide)); + longestSeriesObserved.Add(SpectralMatch.GetLongestIonSeriesBidirectional(psm.BioPolymersWithSetModsToMatchingFragments, Peptide)); } } } @@ -228,16 +229,16 @@ public static void TestPsmMatchingToTargetAndDecoyWithSameSequence() MsDataScan msDataScan = msDataFile.GetOneBasedScan(2); Ms2ScanWithSpecificMass scanWithMass = new Ms2ScanWithSpecificMass(msDataScan, 4, 1, null, commonParameters); - PeptideSpectralMatch psm = new PeptideSpectralMatch(target, 0, 1, 1, scanWithMass, commonParameters, null); + SpectralMatch psm = new PeptideSpectralMatch(target, 0, 1, 1, scanWithMass, commonParameters, null); psm.AddOrReplace(decoy, 1, 0, true, null, 0); - Assert.AreEqual(2, psm.BestMatchingPeptides.Count()); - Assert.That(psm.BestMatchingPeptides.Any(p => p.Peptide.Protein.IsDecoy)); + Assert.AreEqual(2, psm.BestMatchingBioPolymersWithSetMods.Count()); + Assert.That(psm.BestMatchingBioPolymersWithSetMods.Any(p => p.Peptide.Parent.IsDecoy)); psm.ResolveAllAmbiguities(); - Assert.AreEqual(1, psm.BestMatchingPeptides.Count()); - Assert.That(psm.BestMatchingPeptides.All(p => !p.Peptide.Protein.IsDecoy)); + Assert.AreEqual(1, psm.BestMatchingBioPolymersWithSetMods.Count()); + Assert.That(psm.BestMatchingBioPolymersWithSetMods.All(p => !p.Peptide.Parent.IsDecoy)); Assert.That(!psm.IsDecoy); } @@ -254,20 +255,20 @@ public static void TestPsmMatchingToTargetAndDecoyWithDifferentSequences() MsDataScan msDataScan = msDataFile.GetOneBasedScan(2); Ms2ScanWithSpecificMass scanWithMass = new Ms2ScanWithSpecificMass(msDataScan, 4, 1, null, commonParameters); - PeptideSpectralMatch psm = new PeptideSpectralMatch(target, 0, 1, 1, scanWithMass, commonParameters, null); + SpectralMatch psm = new PeptideSpectralMatch(target, 0, 1, 1, scanWithMass, commonParameters, null); psm.AddOrReplace(decoy, 1, 0, true, null, 0); - Assert.AreEqual(2, psm.BestMatchingPeptides.Count()); - Assert.That(psm.BestMatchingPeptides.Any(p => p.Peptide.Protein.IsDecoy)); + Assert.AreEqual(2, psm.BestMatchingBioPolymersWithSetMods.Count()); + Assert.That(psm.BestMatchingBioPolymersWithSetMods.Any(p => p.Peptide.Parent.IsDecoy)); psm.ResolveAllAmbiguities(); - Assert.AreEqual(2, psm.BestMatchingPeptides.Count()); + Assert.AreEqual(2, psm.BestMatchingBioPolymersWithSetMods.Count()); Assert.That(psm.IsDecoy); List<(string fileName, CommonParameters fileSpecificParameters)> fsp = new List<(string fileName, CommonParameters fileSpecificParameters)> { ("filename", commonParameters) }; - new FdrAnalysisEngine(new List { psm }, 1, new CommonParameters(), fsp, new List()).Run(); + new FdrAnalysisEngine(new List { psm }, 1, new CommonParameters(), fsp, new List()).Run(); Assert.AreEqual(0.5, psm.FdrInfo.CumulativeDecoy); } @@ -288,15 +289,15 @@ public static void TestPsmCount() MsDataScan mzLibScan1 = t.GetOneBasedScan(2); Ms2ScanWithSpecificMass scan1 = new Ms2ScanWithSpecificMass(mzLibScan1, 0, 1, null, new CommonParameters()); - PeptideSpectralMatch psm1 = new PeptideSpectralMatch(pep1, 0, 0, 0, scan1, commonParameters, new List()); + SpectralMatch psm1 = new PeptideSpectralMatch(pep1, 0, 0, 0, scan1, commonParameters, new List()); MsDataScan mzLibScan2 = t.GetOneBasedScan(4); Ms2ScanWithSpecificMass scan2 = new Ms2ScanWithSpecificMass(mzLibScan2, 0, 1, null, new CommonParameters()); - PeptideSpectralMatch psm2 = new PeptideSpectralMatch(pep2, 0, 0, 0, scan2, commonParameters, new List()); + SpectralMatch psm2 = new PeptideSpectralMatch(pep2, 0, 0, 0, scan2, commonParameters, new List()); MsDataScan mzLibScan3 = t.GetOneBasedScan(6); Ms2ScanWithSpecificMass scan3 = new Ms2ScanWithSpecificMass(mzLibScan3, 0, 1, null, new CommonParameters()); - PeptideSpectralMatch psm3 = new PeptideSpectralMatch(pep3, 0, 0, 0, scan3, commonParameters, new List()); + SpectralMatch psm3 = new PeptideSpectralMatch(pep3, 0, 0, 0, scan3, commonParameters, new List()); psm1.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); // valid psm psm1.ResolveAllAmbiguities(); @@ -306,7 +307,7 @@ public static void TestPsmCount() psm3.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); // ambiguous psm - var allPsms = new List { psm1, psm2, psm3 }; + var allPsms = new List { psm1, psm2, psm3 }; List<(string fileName, CommonParameters fileSpecificParameters)> fsp = new List<(string fileName, CommonParameters fileSpecificParameters)> { ("filename", new CommonParameters()) }; @@ -378,13 +379,13 @@ public static void TestPsmAddOrReplace() 2, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null), 100, 1, null, new CommonParameters(), null); - PeptideSpectralMatch psm1 = new PeptideSpectralMatch(new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0), 0, 10, 1, scanB, new CommonParameters(), new List(), 0); + SpectralMatch psm1 = new PeptideSpectralMatch(new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0), 0, 10, 1, scanB, new CommonParameters(), new List(), 0); PeptideWithSetModifications pwsm = new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0); psm1.AddOrReplace(pwsm, 11, 1, true, new List(), 0); - Assert.AreEqual(1, psm1.BestMatchingPeptides.Count()); + Assert.AreEqual(1, psm1.BestMatchingBioPolymersWithSetMods.Count()); Assert.AreEqual(11, psm1.Score); @@ -401,17 +402,17 @@ public static void TestComplementaryIons() 2, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null), 100, 1, null, new CommonParameters(), null); - PeptideSpectralMatch psm1 = new PeptideSpectralMatch(new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0), 0, 10, 1, scanB, new CommonParameters(), new List(), 0); + SpectralMatch psm1 = new PeptideSpectralMatch(new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0), 0, 10, 1, scanB, new CommonParameters(), new List(), 0); PeptideWithSetModifications pwsm = new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0); - int count = PeptideSpectralMatch.GetCountComplementaryIons(psm1.PeptidesToMatchingFragments, pwsm); + int count = SpectralMatch.GetCountComplementaryIons(psm1.BioPolymersWithSetModsToMatchingFragments, pwsm); //No Matched Fragment Ions Returns 0 Assert.AreEqual(0, count); - count = PeptideSpectralMatch.GetCountComplementaryIons(null, pwsm); - //PeptidesToMatchingFragments Null Returns 0 + count = SpectralMatch.GetCountComplementaryIons(null, pwsm); + //BioPolymersWithSetModsToMatchingFragments Null Returns 0 Assert.AreEqual(0, count); List myProducts = new List(); @@ -424,11 +425,11 @@ public static void TestComplementaryIons() mfiList.Add(new MatchedFragmentIon(prod, 1, 1, 1)); } - Dictionary> PTMF = new Dictionary>(); + Dictionary> PTMF = new Dictionary>(); PTMF.Add(pwsm, mfiList); - count = PeptideSpectralMatch.GetCountComplementaryIons(PTMF, pwsm); - //PeptidesToMatchingFragments Contains one N and one C ion so intersection Returns 1 + count = SpectralMatch.GetCountComplementaryIons(PTMF, pwsm); + //BioPolymersWithSetModsToMatchingFragments Contains one N and one C ion so intersection Returns 1 Assert.AreEqual(1, count); } @@ -445,15 +446,15 @@ public static void Test_PSM_GetLongestIonSeries_NullChecks() PeptideWithSetModifications pwsm = new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary(), 0); - //PeptidesToMatchingFragments == null returns 1 - longestSeries = PeptideSpectralMatch.GetLongestIonSeriesBidirectional(null, pwsm); + //BioPolymersWithSetModsToMatchingFragments == null returns 1 + longestSeries = SpectralMatch.GetLongestIonSeriesBidirectional(null, pwsm); Assert.AreEqual(1, longestSeries); //matchedFragments == null returns 1 - Dictionary> PeptidesToMatchingFragments = new Dictionary>(); + Dictionary> PeptidesToMatchingFragments = new Dictionary>(); PeptidesToMatchingFragments.Add(pwsm, null); - longestSeries = PeptideSpectralMatch.GetLongestIonSeriesBidirectional(PeptidesToMatchingFragments, pwsm); + longestSeries = SpectralMatch.GetLongestIonSeriesBidirectional(PeptidesToMatchingFragments, pwsm); Assert.AreEqual(1, longestSeries); } @@ -492,7 +493,7 @@ public static void TestPSMFragmentCoverage() List mfis1 = new List { mfiC3, mfiC4, mfiC7, mfiC13, mfiN3, mfiN4, mfiN6, mfiN8, mfiN13}; MsDataScan mzLibScan1 = t.GetOneBasedScan(2); Ms2ScanWithSpecificMass scan1 = new Ms2ScanWithSpecificMass(mzLibScan1, 0, 1, null, new CommonParameters()); - PeptideSpectralMatch psm1 = new PeptideSpectralMatch(pep1, 0, 0, 0, scan1, commonParameters, mfis1); + SpectralMatch psm1 = new PeptideSpectralMatch(pep1, 0, 0, 0, scan1, commonParameters, mfis1); psm1.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); // valid psm psm1.ResolveAllAmbiguities(); psm1.GetAminoAcidCoverage(); @@ -512,7 +513,7 @@ public static void TestPSMFragmentCoverage() Assert.IsFalse(psm1.FragmentCoveragePositionInPeptide.Contains(5)); - PeptideSpectralMatch psm2 = new PeptideSpectralMatch(pep2, 0, 0, 0, scan1, commonParameters, mfis1); + SpectralMatch psm2 = new PeptideSpectralMatch(pep2, 0, 0, 0, scan1, commonParameters, mfis1); psm2.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); // valid psm psm2.ResolveAllAmbiguities(); psm2.GetAminoAcidCoverage(); diff --git a/MetaMorpheus/Test/TestTopDown.cs b/MetaMorpheus/Test/TestTopDown.cs index b99e13262..c76f95057 100644 --- a/MetaMorpheus/Test/TestTopDown.cs +++ b/MetaMorpheus/Test/TestTopDown.cs @@ -47,7 +47,7 @@ public static void TestClassicSearchEngineTopDown() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpetralLibrary = false; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, null, new List(), writeSpetralLibrary).Run(); @@ -79,7 +79,7 @@ public static void TestModernSearchEngineTopDown() var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); - PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; + SpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; var indexEngine = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, null, null, 1, DecoyType.Reverse, CommonParameters, null, 30000, false, new List(), TargetContaminantAmbiguity.RemoveContaminant, new List()); diff --git a/MetaMorpheus/Test/XLTest.cs b/MetaMorpheus/Test/XLTest.cs index aa2568118..fea59a172 100644 --- a/MetaMorpheus/Test/XLTest.cs +++ b/MetaMorpheus/Test/XLTest.cs @@ -203,7 +203,7 @@ public static void XlTest_BSA_DSSO() List<(string fileName, CommonParameters fileSpecificParameters)> fsp = new List<(string fileName, CommonParameters fileSpecificParameters)> { ("filename", commonParameters) }; - FdrAnalysisEngine fdrAnalysisEngine = new FdrAnalysisEngine(newPsms.ToList(), 0, commonParameters, fsp, new List(), ""); + FdrAnalysisEngine fdrAnalysisEngine = new FdrAnalysisEngine(newPsms.ToList(), 0, commonParameters, fsp, new List(), ""); Assert.AreEqual(4, newPsms.Count); Assert.That(newPsms[0].XlProteinPos == 2 && newPsms[0].BetaPeptide.XlProteinPos == 4); //cross @@ -529,9 +529,9 @@ public static void XlTest_MoreComprehensive() Assert.AreEqual(0, deadendTris); Assert.AreEqual(0, unnasignedCrossType); - var fdrResultsXLink = new FdrAnalysisEngine(firstCsmsFromListsOfCsms.Where(c => c.CrossType == PsmCrossType.Inter || c.CrossType == PsmCrossType.Intra).ToList(), 1, CommonParameters, fsp, new List(), "crosslink").Run(); + var fdrResultsXLink = new FdrAnalysisEngine(firstCsmsFromListsOfCsms.Where(c => c.CrossType == PsmCrossType.Inter || c.CrossType == PsmCrossType.Intra).ToList(), 1, CommonParameters, fsp, new List(), "crosslink").Run(); - fdrResultsXLink = new FdrAnalysisEngine(firstCsmsFromListsOfCsms.Where(c => c.CrossType != PsmCrossType.Inter && c.CrossType != PsmCrossType.Intra).ToList(), 1, CommonParameters, fsp, new List(), "standard").Run(); + fdrResultsXLink = new FdrAnalysisEngine(firstCsmsFromListsOfCsms.Where(c => c.CrossType != PsmCrossType.Inter && c.CrossType != PsmCrossType.Intra).ToList(), 1, CommonParameters, fsp, new List(), "standard").Run(); unnasignedCrossType = 0; inter = 0; @@ -634,7 +634,7 @@ public static void XlTest_MoreComprehensive() { Path.GetFileName(intraCsm.FullFilePath), 0 } }; - var intraPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("crosslink", fsp, intraCsm, sequenceToPsmCount, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_unmodified, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_modified, medianFragmentMassError, chargeStateMode, intraCsm.BestMatchingPeptides.First().Peptide, intraCsm.BestMatchingPeptides.First().Notch, !intraCsm.BestMatchingPeptides.First().Peptide.Protein.IsDecoy); + var intraPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("crosslink", fsp, intraCsm, sequenceToPsmCount, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_unmodified, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_modified, medianFragmentMassError, chargeStateMode, intraCsm.BestMatchingBioPolymersWithSetMods.First().Peptide, intraCsm.BestMatchingBioPolymersWithSetMods.First().Notch, !intraCsm.BestMatchingBioPolymersWithSetMods.First().Peptide.Parent.IsDecoy); Assert.That(intraPsmData.AbsoluteAverageFragmentMassErrorFromMedian, Is.EqualTo(1.0).Within(0.1)); Assert.That(intraPsmData.AlphaIntensity, Is.EqualTo(1).Within(0.1)); Assert.AreEqual(intraPsmData.Ambiguity, 0); @@ -660,13 +660,13 @@ public static void XlTest_MoreComprehensive() CrosslinkSpectralMatch singleCsm = firstCsmsFromListsOfCsms.Where(c => c.CrossType == PsmCrossType.Single).OrderBy(c => -c.Score).First(); - List psms = new List(); + List psms = new List(); psms.AddRange(firstCsmsFromListsOfCsms); fileSpecificTimeDependantHydrophobicityAverageAndDeviation_unmodified = PEP_Analysis_Cross_Validation.ComputeHydrophobicityValues(psms, fsp, false); fileSpecificTimeDependantHydrophobicityAverageAndDeviation_modified = PEP_Analysis_Cross_Validation.ComputeHydrophobicityValues(psms, fsp, true); - var singleCsmPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("standard", fsp, singleCsm, sequenceToPsmCount, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_unmodified, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_modified, medianFragmentMassError, chargeStateMode, singleCsm.BestMatchingPeptides.First().Peptide, singleCsm.BestMatchingPeptides.First().Notch, !singleCsm.BestMatchingPeptides.First().Peptide.Protein.IsDecoy); + var singleCsmPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("standard", fsp, singleCsm, sequenceToPsmCount, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_unmodified, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_modified, medianFragmentMassError, chargeStateMode, singleCsm.BestMatchingBioPolymersWithSetMods.First().Peptide, singleCsm.BestMatchingBioPolymersWithSetMods.First().Notch, !singleCsm.BestMatchingBioPolymersWithSetMods.First().Peptide.Parent.IsDecoy); Assert.That(singleCsmPsmData.AbsoluteAverageFragmentMassErrorFromMedian, Is.EqualTo(8).Within(0.1)); Assert.AreEqual(singleCsmPsmData.AlphaIntensity, 0); Assert.AreEqual(singleCsmPsmData.Ambiguity, 0); @@ -692,7 +692,7 @@ public static void XlTest_MoreComprehensive() Assert.That(singleCsmPsmData.TotalMatchingFragmentCount, Is.EqualTo(8).Within(0.1)); CrosslinkSpectralMatch loopCsm = firstCsmsFromListsOfCsms.Where(c => c.CrossType == PsmCrossType.Loop).OrderBy(c => -c.Score).First(); - var loopCsmPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("standard", fsp, loopCsm, sequenceToPsmCount, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_unmodified, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_modified, medianFragmentMassError, chargeStateMode, loopCsm.BestMatchingPeptides.First().Peptide, loopCsm.BestMatchingPeptides.First().Notch, !loopCsm.BestMatchingPeptides.First().Peptide.Protein.IsDecoy); + var loopCsmPsmData = PEP_Analysis_Cross_Validation.CreateOnePsmDataEntry("standard", fsp, loopCsm, sequenceToPsmCount, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_unmodified, fileSpecificTimeDependantHydrophobicityAverageAndDeviation_modified, medianFragmentMassError, chargeStateMode, loopCsm.BestMatchingBioPolymersWithSetMods.First().Peptide, loopCsm.BestMatchingBioPolymersWithSetMods.First().Notch, !loopCsm.BestMatchingBioPolymersWithSetMods.First().Peptide.Parent.IsDecoy); Assert.That(loopCsmPsmData.AbsoluteAverageFragmentMassErrorFromMedian, Is.EqualTo(6).Within(0.1)); Assert.AreEqual(loopCsmPsmData.AlphaIntensity, 0); Assert.AreEqual(loopCsmPsmData.Ambiguity, 0); @@ -1228,11 +1228,11 @@ public static void XLSearchTastWriteFileTest() //check decoy label csmAlpha.BetaPeptide = csmBeta; Crosslinker xlinker = Crosslinker.ParseCrosslinkerFromString("DSSO\tK\tK\tT\tCID|HCD\t158.0038\t54.01056\t85.982635\t176.0143\t175.0303\t279.0777"); - double someSortOfMass = csmAlpha.ScanPrecursorMass - csmAlpha.BetaPeptide.PeptideMonisotopicMass.Value - csmAlpha.PeptideMonisotopicMass.Value - xlinker.TotalMass; + double someSortOfMass = csmAlpha.ScanPrecursorMass - csmAlpha.BetaPeptide.BioPolymerWithSetModsMonoisotopicMass.Value - csmAlpha.BioPolymerWithSetModsMonoisotopicMass.Value - xlinker.TotalMass; string someLongString = "-." + csmAlpha.FullSequence + csmAlpha.LinkPositions.First().ToString(CultureInfo.InvariantCulture) + "--" + csmAlpha.BetaPeptide.FullSequence + csmAlpha.BetaPeptide.LinkPositions.First().ToString(CultureInfo.InvariantCulture) + ".-"; - string someOtherString = csmAlpha.BestMatchingPeptides.First().Peptide.Protein.Accession.ToString(CultureInfo.InvariantCulture) + string someOtherString = csmAlpha.BestMatchingBioPolymersWithSetMods.First().Peptide.Parent.Accession.ToString(CultureInfo.InvariantCulture) + "(" + (csmAlpha.XlProteinPos.HasValue ? csmAlpha.XlProteinPos.Value.ToString(CultureInfo.InvariantCulture) : string.Empty) + ")"; - string lastRandomString = csmAlpha.BetaPeptide.BestMatchingPeptides.First().Peptide.Protein.Accession.ToString(CultureInfo.InvariantCulture) + string lastRandomString = csmAlpha.BetaPeptide.BestMatchingBioPolymersWithSetMods.First().Peptide.Parent.Accession.ToString(CultureInfo.InvariantCulture) + "(" + (csmAlpha.BetaPeptide.XlProteinPos.HasValue ? csmAlpha.BetaPeptide.XlProteinPos.Value.ToString(CultureInfo.InvariantCulture) : string.Empty) + ")"; Assert.AreEqual("NaN", csmAlpha.ScanRetentionTime.ToString(CultureInfo.InvariantCulture)); @@ -1439,7 +1439,7 @@ public static void TestMixedMs2Ms2() && psmFromTsv.ProteinLinkSite == 455 && psmFromTsv.ParentIons.Equals("2;2")); - Assert.That(csm.ProteinAccession == null && csm.BetaPeptide.ProteinAccession == null); + Assert.That(csm.Accession == null && csm.BetaPeptide.Accession == null); Assert.That(psmFromTsv.ProteinAccession == "BSA|BSA2"); Assert.That(psmFromTsv.UniqueSequence, Is.EqualTo(psmFromTsv.FullSequence + psmFromTsv.BetaPeptideFullSequence)); diff --git a/MetaMorpheus/Test/gptmdPrunedBdTests.cs b/MetaMorpheus/Test/gptmdPrunedBdTests.cs index a10baa6f3..1267d3909 100644 --- a/MetaMorpheus/Test/gptmdPrunedBdTests.cs +++ b/MetaMorpheus/Test/gptmdPrunedBdTests.cs @@ -364,7 +364,7 @@ public static void TestProteinPrunedWithModSelection() MzSpectrum spectrum = new MzSpectrum(noiseData); MsDataScan scan = new MsDataScan(spectrum , 1, 1, true, Polarity.Unknown, 2, new MzLibUtil.MzRange(10, 1000), "", MZAnalyzerType.Orbitrap, 10000, null, noiseData, ""); testPostTaskParameters.ProteinList = new List() { protein1, protein2 }; - testPostTaskParameters.AllPsms = new List { new PeptideSpectralMatch(peptideObserved, 0, 20, 1, new Ms2ScanWithSpecificMass(scan, 100, 1, @"", commonParam), commonParam, matchedFragmentIons) }; + testPostTaskParameters.AllPsms = new List { new PeptideSpectralMatch(peptideObserved, 0, 20, 1, new Ms2ScanWithSpecificMass(scan, 100, 1, @"", commonParam), commonParam, matchedFragmentIons) }; testPostTaskParameters.SearchParameters = new SearchParameters(); testPostTaskParameters.SearchParameters.WritePrunedDatabase = true; testPostTaskParameters.SearchParameters.DoLabelFreeQuantification = false; @@ -469,7 +469,7 @@ public static void TestProteinPrunedWithModSelectionAndVariants() MzSpectrum spectrum = new MzSpectrum(noiseData); MsDataScan scan = new MsDataScan(spectrum, 1, 1, true, Polarity.Unknown, 2, new MzLibUtil.MzRange(10, 1000), "", MZAnalyzerType.Orbitrap, 10000, null, noiseData, ""); testPostTaskParameters.ProteinList = proteinList; - testPostTaskParameters.AllPsms = new List { new PeptideSpectralMatch(peptideObserved, 0, 20, 1, new Ms2ScanWithSpecificMass(scan, 100, 1, @"", commonParam), commonParam, matchedFragmentIons) }; + testPostTaskParameters.AllPsms = new List { new PeptideSpectralMatch(peptideObserved, 0, 20, 1, new Ms2ScanWithSpecificMass(scan, 100, 1, @"", commonParam), commonParam, matchedFragmentIons) }; testPostTaskParameters.SearchParameters = new SearchParameters(); testPostTaskParameters.SearchParameters.WritePrunedDatabase = true; testPostTaskParameters.SearchParameters.DoLabelFreeQuantification = false;