Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3 -Spectral Match Generalization #2340

Merged
merged 34 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
831a394
Updated Mzlib and made it so there are no errors on build
nbollis Jan 8, 2024
976ab07
Adjusted digestionparams toml
nbollis Jan 10, 2024
12129f8
fixed indexing engine without having a default product type
nbollis Jan 10, 2024
9e4da0c
Fixed silac test
nbollis Jan 10, 2024
ad5097b
All Tests Pass!
nbollis Jan 10, 2024
c30b67c
Added toml test for new digestionparams
nbollis Jan 11, 2024
92e9842
Merge branch 'master' into mzlibUpdate
nbollis Jan 18, 2024
ff98c77
ope. Switched to proper version of mzLib
nbollis Jan 18, 2024
fc5fa16
Merge branch 'mzlibUpdate' of https://github.com/nbollis/MetaMorpheus…
nbollis Jan 18, 2024
bd1b1e9
Generalized Spectral Match
nbollis Jan 18, 2024
031c962
Added Omics to project.wxs
nbollis Jan 18, 2024
87d9844
Updated ParsimonySequence to use interfaces
nbollis Jan 19, 2024
75d1bc2
a
nbollis Jan 22, 2024
569edd7
Udpated to mzlib pr 757
nbollis Jan 22, 2024
b3a338c
Merge branch 'master' into mzlibUpdate
nbollis Feb 8, 2024
9096c5c
Generalized Deconvolution in MzLIb
nbollis Feb 9, 2024
251e86e
Updated to mzlib after decon generalization
nbollis Feb 9, 2024
dd31b56
Merged in DeconGeneralization
nbollis Feb 9, 2024
16a1a5a
fixed issue caused by merge
nbollis Feb 9, 2024
c1c578f
updated mzlib version
nbollis Feb 14, 2024
41128eb
Updated mzlib
nbollis Feb 14, 2024
cbb2956
Resolved merge conflicts
nbollis Feb 14, 2024
bd379f1
Merge branch 'mzlibUpdate' into DeconGeneralization
nbollis Feb 14, 2024
e7d56b3
Updated nuget
nbollis Feb 14, 2024
03bfbc7
Merged in DeconGeneralizaton
nbollis Feb 14, 2024
8a67256
Resolved final conflicts
nbollis Feb 14, 2024
4316fe9
Merged in Master
nbollis Feb 27, 2024
05ab191
Updated classes after merge
nbollis Feb 27, 2024
fe8ac98
Made changes for code coverage
nbollis Feb 27, 2024
2a24fc2
Added test coverage to the bin class
nbollis Feb 27, 2024
ab456b3
Idk man its like 0.02% coverage
nbollis Feb 27, 2024
04fd9bb
helpme.jpg
nbollis Feb 27, 2024
0837414
Merge branch 'master' into SpectralMatchGeneralization
trishorts Feb 28, 2024
11c8e82
Merge branch 'master' into SpectralMatchGeneralization
trishorts Mar 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public class DataPointAcquisitionEngine : MetaMorpheusEngine
{
private const double FineResolutionForIsotopeDistCalculation = 0.1;

private readonly List<PeptideSpectralMatch> GoodIdentifications;
private readonly List<SpectralMatch> GoodIdentifications;
private readonly List<Ms2ScanWithSpecificMass> GoodScans;
private readonly MsDataFile MyMsDataFile;
private readonly Tolerance PrecursorMassTolerance;
private readonly Tolerance ProductMassTolerance;
private readonly int MinMS1isotopicPeaksNeededForConfirmedIdentification;

public DataPointAcquisitionEngine(
List<PeptideSpectralMatch> goodIdentifications,
List<SpectralMatch> goodIdentifications,
List<Ms2ScanWithSpecificMass> goodScans,
MsDataFile myMsDataFile,
Tolerance precursorMassTolerance,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -126,7 +126,7 @@ protected override MetaMorpheusEngineResults RunSpecific()
);
}

private (List<LabeledDataPoint>, int, int) SearchMS1Spectra(double[] theoreticalMasses, double[] theoreticalIntensities, int ms2spectrumIndex, int direction, int peptideCharge, PeptideSpectralMatch identification)
private (List<LabeledDataPoint>, int, int) SearchMS1Spectra(double[] theoreticalMasses, double[] theoreticalIntensities, int ms2spectrumIndex, int direction, int peptideCharge, SpectralMatch identification)
{
List<LabeledDataPoint> result = new List<LabeledDataPoint>();
int numMs1MassChargeCombinationsConsidered = 0;
Expand Down Expand Up @@ -220,7 +220,7 @@ protected override MetaMorpheusEngineResults RunSpecific()
return (result, numMs1MassChargeCombinationsConsidered, numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks);
}

private static List<LabeledDataPoint> SearchMS2Spectrum(Ms2ScanWithSpecificMass ms2DataScan, PeptideSpectralMatch identification, Tolerance ms2Tolerance)
private static List<LabeledDataPoint> SearchMS2Spectrum(Ms2ScanWithSpecificMass ms2DataScan, SpectralMatch identification, Tolerance ms2Tolerance)
{
List<LabeledDataPoint> result = new List<LabeledDataPoint>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class DataPointAquisitionResults : MetaMorpheusEngineResults
{
public DataPointAquisitionResults(
MetaMorpheusEngine dataPointAcquisitionEngine,
List<PeptideSpectralMatch> psms,
List<SpectralMatch> psms,
List<LabeledDataPoint> ms1List,
List<LabeledDataPoint> ms2List,
int numMs1MassChargeCombinationsConsidered,
Expand Down Expand Up @@ -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();

Expand All @@ -67,7 +67,7 @@ public DataPointAquisitionResults(
public readonly double PsmProductMedianPpmError;
public readonly double PsmPrecursorIqrPpmError;
public readonly double PsmProductIqrPpmError;
public readonly List<PeptideSpectralMatch> Psms;
public readonly List<SpectralMatch> Psms;

public int Count { get { return Ms1List.Count + Ms2List.Count; } }

Expand Down
4 changes: 2 additions & 2 deletions MetaMorpheus/EngineLayer/Calibration/LabeledDataPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public class ClassicSearchEngine : MetaMorpheusEngine
private readonly List<Modification> VariableModifications;
private readonly List<SilacLabel> 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<Modification> variableModifications, List<Modification> fixedModifications, List<SilacLabel> silacLabels, SilacLabel startLabel, SilacLabel endLabel,
List<Protein> proteinList, MassDiffAcceptor searchMode, CommonParameters commonParameters, List<(string FileName, CommonParameters Parameters)> fileSpecificParameters,
SpectralLibrary spectralLibrary, List<string> nestedIds, bool writeSpectralLibrary)
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MassSpectrometry;
using MassSpectrometry.MzSpectra;
using MzLibUtil;
using Omics;
using Omics.Fragmentation;
using Proteomics.ProteolyticDigestion;
using System;
Expand Down Expand Up @@ -42,7 +43,7 @@ public MiniClassicSearchEngine(
/// <param name="donorPwsm"> Ms2 scans in window are searched for matches to this donor peptide</param>
/// <param name="peakApexRT"> The center of the 2 minute window where the search occurs</param>
/// <returns></returns>
public IEnumerable<PeptideSpectralMatch> SearchAroundPeak(PeptideWithSetModifications donorPwsm, double peakApexRT)
public IEnumerable<SpectralMatch> SearchAroundPeak(IBioPolymerWithSetMods donorPwsm, double peakApexRT)
{
var targetFragmentsForEachDissociationType = new Dictionary<DissociationType, List<Product>>();

Expand All @@ -66,7 +67,7 @@ public IEnumerable<PeptideSpectralMatch> SearchAroundPeak(PeptideWithSetModifica
return null;
}

List<PeptideSpectralMatch> acceptablePsms = new();
List<SpectralMatch> acceptablePsms = new();
foreach (ScanWithIndexAndNotchInfo scan in acceptableScans)
{
var dissociationType = FileSpecificParameters.DissociationType == DissociationType.Autodetect ?
Expand Down Expand Up @@ -95,8 +96,8 @@ public IEnumerable<PeptideSpectralMatch> SearchAroundPeak(PeptideWithSetModifica
acceptablePsms.Add(new PeptideSpectralMatch(donorPwsm, scan.Notch, thisScore, scan.ScanIndex, scan.TheScan, FileSpecificParameters, matchedIons, 0));
}

IEnumerable<PeptideSpectralMatch> matchedSpectra = acceptablePsms.Where(p => p != null);
foreach (PeptideSpectralMatch psm in matchedSpectra)
IEnumerable<SpectralMatch> matchedSpectra = acceptablePsms.Where(p => p != null);
foreach (SpectralMatch psm in matchedSpectra)
{
psm.ResolveAllAmbiguities();
}
Expand All @@ -106,7 +107,7 @@ public IEnumerable<PeptideSpectralMatch> 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)
Expand All @@ -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<double> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ private List<MatchedFragmentIon> 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);

Expand Down Expand Up @@ -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);
Expand Down
Loading