Skip to content

Commit

Permalink
Merge branch 'master' into eliminateExtraTabFromChromatographicPeak
Browse files Browse the repository at this point in the history
  • Loading branch information
trishorts authored Dec 6, 2023
2 parents 55b7896 + 74e2005 commit 8f6990b
Show file tree
Hide file tree
Showing 69 changed files with 8,794 additions and 272 deletions.
5 changes: 4 additions & 1 deletion mzLib/MassSpectrometry/MsDataScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace MassSpectrometry
Expand All @@ -28,7 +29,7 @@ public class MsDataScan
{
public MsDataScan(MzSpectrum massSpectrum, int oneBasedScanNumber, int msnOrder, bool isCentroid, Polarity polarity, double retentionTime, MzRange scanWindowRange, string scanFilter, MZAnalyzerType mzAnalyzer,
double totalIonCurrent, double? injectionTime, double[,] noiseData, string nativeId, double? selectedIonMz = null, int? selectedIonChargeStateGuess = null, double? selectedIonIntensity = null, double? isolationMZ = null,
double? isolationWidth = null, DissociationType? dissociationType = null, int? oneBasedPrecursorScanNumber = null, double? selectedIonMonoisotopicGuessMz = null, string hcdEnergy = null)
double? isolationWidth = null, DissociationType? dissociationType = null, int? oneBasedPrecursorScanNumber = null, double? selectedIonMonoisotopicGuessMz = null, string hcdEnergy = null, string scanDescription = null)
{
OneBasedScanNumber = oneBasedScanNumber;
MsnOrder = msnOrder;
Expand All @@ -52,6 +53,7 @@ public MsDataScan(MzSpectrum massSpectrum, int oneBasedScanNumber, int msnOrder,
SelectedIonChargeStateGuess = selectedIonChargeStateGuess;
SelectedIonMonoisotopicGuessMz = selectedIonMonoisotopicGuessMz;
HcdEnergy = hcdEnergy;
ScanDescription = scanDescription;
}

/// <summary>
Expand Down Expand Up @@ -84,6 +86,7 @@ public MsDataScan(MzSpectrum massSpectrum, int oneBasedScanNumber, int msnOrder,
public double? SelectedIonMonoisotopicGuessIntensity { get; private set; } // May be refined
public double? SelectedIonMonoisotopicGuessMz { get; private set; } // May be refined
public string HcdEnergy { get; private set; }
public string ScanDescription { get; private set; }

private MzRange isolationRange;

Expand Down
17 changes: 17 additions & 0 deletions mzLib/Omics/Fragmentation/FragmentationTerminus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Omics.Fragmentation
{
public enum FragmentationTerminus
{
Both, //N- and C-terminus
N, //N-terminus only
C, //C-terminus only
None //used for internal fragments, could be used for top down intact mass?
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Chemistry;
using System.Text;

namespace Proteomics.Fragmentation
namespace Omics.Fragmentation
{
public class MatchedFragmentIon
{
Expand All @@ -13,14 +13,13 @@ public class MatchedFragmentIon
/// <summary>
/// Constructs a new MatchedFragmentIon given information about a theoretical and an experimental fragment mass spectral peak
/// </summary>
public MatchedFragmentIon(ref Product neutralTheoreticalProduct, double experMz, double experIntensity, int charge)
public MatchedFragmentIon(Product neutralTheoreticalProduct, double experMz, double experIntensity, int charge)
{
NeutralTheoreticalProduct = neutralTheoreticalProduct;
Mz = experMz;
Intensity = experIntensity;
Charge = charge;
}

public double MassErrorDa
{
get
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Chemistry;
using Easy.Common.Extensions;
using MassSpectrometry;
using System.Collections.Generic;
using System.Linq;
using Omics.Fragmentation;

namespace Proteomics.Fragmentation
namespace Omics.Fragmentation.Peptide
{
public class DissociationTypeCollection
{
Expand All @@ -31,7 +29,7 @@ public static List<ProductType> GetTerminusSpecificProductTypesFromDissociation(
lock (TerminusSpecificProductTypesFromDissociation)
{
var productCollection = TerminusSpecificProductTypes.ProductIonTypesFromSpecifiedTerminus[fragmentationTerminus]
.Intersect(DissociationTypeCollection.ProductsFromDissociationType[dissociationType]);
.Intersect(ProductsFromDissociationType[dissociationType]);

if (!TerminusSpecificProductTypesFromDissociation.TryGetValue((dissociationType, fragmentationTerminus), out productTypes))

Check warning on line 34 in mzLib/Omics/Fragmentation/Peptide/DissociationTypeCollection.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

Check warning on line 34 in mzLib/Omics/Fragmentation/Peptide/DissociationTypeCollection.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Proteomics.Fragmentation
namespace Omics.Fragmentation.Peptide
{
public class TerminusSpecificProductTypes
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
using System;
using System.Text;
using System.Text;
using Chemistry;

namespace Proteomics.Fragmentation
namespace Omics.Fragmentation
{
public struct Product
public class Product : IHasMass
{
public readonly double NeutralMass;
public readonly ProductType ProductType;
public readonly double NeutralLoss;
public readonly FragmentationTerminus Terminus;
public readonly int FragmentNumber;
public readonly int AminoAcidPosition;
public readonly ProductType? SecondaryProductType; //used for internal fragment ions
public readonly int SecondaryFragmentNumber; //used for internal fragment ions
public double NeutralMass { get; }
public ProductType ProductType { get; }
public double NeutralLoss { get; }
public FragmentationTerminus Terminus { get; }
public int FragmentNumber { get; }
public int ResiduePosition { get; }
public int AminoAcidPosition => ResiduePosition;
public ProductType? SecondaryProductType { get; } //used for internal fragment ions
public int SecondaryFragmentNumber { get; } //used for internal fragment ions
public double MonoisotopicMass => NeutralMass;

/// <summary>
/// A product is the individual neutral fragment from an MS dissociation. A fragmentation product here contains one of the two termini (N- or C-).
/// The ProductType describes where along the backbone the fragmentaiton occurred (e.g. b-, y-, c-, zdot-). The neutral loss mass (if any) that
/// occurred from a mod on the fragment is listed as a mass. Finally the neutral mass of the whole fragment is provided.
/// </summary>
public Product(ProductType productType, FragmentationTerminus terminus, double neutralMass,
int fragmentNumber, int aminoAcidPosition, double neutralLoss, ProductType? secondaryProductType = null, int secondaryFragmentNumber = 0)
int fragmentNumber, int residuePosition, double neutralLoss, ProductType? secondaryProductType = null,
int secondaryFragmentNumber = 0)
{
NeutralMass = neutralMass;
ProductType = productType;
NeutralLoss = neutralLoss;
Terminus = terminus;
FragmentNumber = fragmentNumber;
AminoAcidPosition = aminoAcidPosition;
ResiduePosition = residuePosition;
SecondaryProductType = secondaryProductType;
SecondaryFragmentNumber = secondaryFragmentNumber;
}
Expand Down Expand Up @@ -70,29 +73,35 @@ public override string ToString()
{
if (SecondaryProductType == null)
{
return ProductType + "" + FragmentNumber + ";" + NeutralMass.ToString("F5") + "-" + string.Format("{0:0.##}", NeutralLoss);
return ProductType + "" + FragmentNumber + ";" + NeutralMass.ToString("F5") + "-" +
string.Format("{0:0.##}", NeutralLoss);
}
else
{
return ProductType + "I" + SecondaryProductType.Value + "[" + FragmentNumber + "-" + SecondaryFragmentNumber + "]" + ";" + NeutralMass.ToString("F5") + "-" + string.Format("{0:0.##}", NeutralLoss);
return ProductType + "I" + SecondaryProductType.Value + "[" + FragmentNumber + "-" +
SecondaryFragmentNumber + "]" + ";" + NeutralMass.ToString("F5") + "-" +
string.Format("{0:0.##}", NeutralLoss);
}
}

public override bool Equals(object obj)

Check warning on line 87 in mzLib/Omics/Fragmentation/Product.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 87 in mzLib/Omics/Fragmentation/Product.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).
{
Product other = (Product)obj;
return obj is Product other && Equals(other);
}

return this.ProductType == other.ProductType
&& this.NeutralMass == other.NeutralMass
&& this.FragmentNumber == other.FragmentNumber
&& this.NeutralLoss == other.NeutralLoss
&& this.SecondaryFragmentNumber == other.SecondaryFragmentNumber
&& this.SecondaryProductType == other.SecondaryProductType;
public bool Equals(Product product)
{
return this.ProductType.Equals(product.ProductType)
&& this.NeutralMass.Equals(product.NeutralMass)
&& this.FragmentNumber == product.FragmentNumber
&& this.NeutralLoss.Equals(product.NeutralLoss)
&& this.SecondaryFragmentNumber == product.SecondaryFragmentNumber
&& this.SecondaryProductType == product.SecondaryProductType;
}

public override int GetHashCode()
{
return NeutralMass.GetHashCode();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
using System.Collections.Generic;

namespace Proteomics.Fragmentation
namespace Omics.Fragmentation
{
public enum ProductType
{
//Ion Type Neutral Mr
//a [N]+[M]-CHO
//a* a-NH3
//a° a-H2O
//a° a-H2O
//b [N]+[M]-H
//b* b-NH3
//b° b-H2O
//b° b-H2O
//c [N]+[M]+NH2
//d a – partial side chain
//v y – complete side chain
//w z – partial side chain
//d a – partial side chain
//v y – complete side chain
//w z – partial side chain
//x [C]+[M]+CO-H
//y [C]+[M]+H
//y* y-NH3
//y° y-H2O
//y° y-H2O
//z [C]+[M]-NH2

a,
Expand All @@ -40,5 +38,4 @@ public enum ProductType
Ycore, //Glyco core Y ions // [pep] + Neutral core Glycan mass (such as: [pep] + [N]) //Which already consider the loss of H2O and H-transfer
Y //Glyco Y ions // [pep] + other Glycan mass
}

}
}
15 changes: 15 additions & 0 deletions mzLib/Omics/Omics.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Platforms>x64</Platforms>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Chemistry\Chemistry.csproj" />
<ProjectReference Include="..\MassSpectrometry\MassSpectrometry.csproj" />
</ItemGroup>

</Project>
93 changes: 93 additions & 0 deletions mzLib/Omics/SpectrumMatch/LibrarySpectrum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System.Text;
using Easy.Common.Extensions;
using MassSpectrometry;
using MassSpectrometry.MzSpectra;
using Omics.Fragmentation;

namespace Omics.SpectrumMatch
{
public class LibrarySpectrum : MzSpectrum
{
public string Sequence { get; set; }
public double? RetentionTime { get; set; }
public double PrecursorMz { get; set; }
public int ChargeState { get; set; }
public List<MatchedFragmentIon> MatchedFragmentIons { get; set; }
public bool IsDecoy { get; set; }

public string Name
{
get { return Sequence + "/" + ChargeState; }
}

public LibrarySpectrum(string sequence, double precursorMz, int chargeState, List<MatchedFragmentIon> peaks, double? rt, bool isDecoy = false) : base(peaks.Select(p => p.Mz).ToArray(), peaks.Select(p => p.Intensity).ToArray(), false)
{
Sequence = sequence;
PrecursorMz = precursorMz;
MatchedFragmentIons = peaks;
ChargeState = chargeState;
IsDecoy = isDecoy;
RetentionTime = rt;
Array.Sort(XArray, YArray);
}

/// <summary>
/// This function enables the spectrum angle to be computed between an individual experimental spectrum and the loaded library spectrum within MetaDraw
/// </summary>
/// <param name="librarySpectrum"></param>
/// <returns></returns>
public string CalculateSpectralAngleOnTheFly(List<MatchedFragmentIon> spectrumMatchFragments)
{
if (!spectrumMatchFragments.Any())
{
return "N/A";
}

if (spectrumMatchFragments.IsNotNullOrEmpty()) { }
SpectralSimilarity spectraComparison = new SpectralSimilarity(
spectrumMatchFragments.Select(f => f.Mz).ToArray(),
spectrumMatchFragments.Select(f => f.Intensity).ToArray(),
MatchedFragmentIons.Select(f => f.Mz).ToArray(),
MatchedFragmentIons.Select(f => f.Intensity).ToArray(),
SpectralSimilarity.SpectrumNormalizationScheme.mostAbundantPeak,
toleranceInPpm: 20,
allPeaks: true);
double? spectralContrastAngle = spectraComparison.SpectralContrastAngle();

return spectralContrastAngle == null
? "N/A"
: ((double)spectralContrastAngle).ToString("F4");
}

public override string ToString()
{
StringBuilder spectrum = new StringBuilder();
spectrum.Append("Name: " + Name);
spectrum.Append("\nMW: " + PrecursorMz);
spectrum.Append("\nComment: ");
spectrum.Append("Parent=" + PrecursorMz);
spectrum.Append(" RT=" + RetentionTime);
spectrum.Append("\nNum peaks: " + MatchedFragmentIons.Count);

double maxIntensity = MatchedFragmentIons.Select(b => b.Intensity).Max();

foreach (MatchedFragmentIon matchedIon in MatchedFragmentIons)
{
double intensityFraction = matchedIon.Intensity / maxIntensity;

string neutralLoss = null;
if (matchedIon.NeutralTheoreticalProduct.NeutralLoss != 0)
{
neutralLoss = "-" + matchedIon.NeutralTheoreticalProduct.NeutralLoss;
}

spectrum.Append("\n" + matchedIon.Mz + "\t" + intensityFraction + "\t" + "\"" +
matchedIon.NeutralTheoreticalProduct.ProductType.ToString() +
matchedIon.NeutralTheoreticalProduct.FragmentNumber.ToString() + "^" +
matchedIon.Charge + neutralLoss + "/" + 0 + "ppm" + "\"");
}

return spectrum.ToString();
}
}
}
Loading

0 comments on commit 8f6990b

Please sign in to comment.