Skip to content

Commit

Permalink
adds support for negative charges and custom charge carriers for merc…
Browse files Browse the repository at this point in the history
…ury7
  • Loading branch information
rfellers committed Apr 10, 2024
1 parent fb4b105 commit 3b92bc9
Show file tree
Hide file tree
Showing 5 changed files with 330 additions and 230 deletions.
71 changes: 40 additions & 31 deletions src/TopDownProteomics/MassSpectrometry/IIsotopicDistribution.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace TopDownProteomics.MassSpectrometry
namespace TopDownProteomics.MassSpectrometry;

/// <summary>
/// Neutral distribution of isotopes in a mass spectrometer.
/// </summary>
public interface IIsotopicDistribution
{
/// <summary>
/// Neutral distribution of isotopes in a mass spectrometer.
/// Gets the length.
/// </summary>
int Length { get; }

/// <summary>
/// Gets the masses.
/// </summary>
public interface IIsotopicDistribution
{
/// <summary>
/// Gets the length.
/// </summary>
int Length { get; }
IList<double> Masses { get; }

/// <summary>
/// Gets the masses.
/// </summary>
IList<double> Masses { get; }
/// <summary>
/// Gets the intensities.
/// </summary>
IList<double> Intensities { get; }

/// <summary>
/// Gets the intensities.
/// </summary>
IList<double> Intensities { get; }
/// <summary>
/// Creates a charged isotopic distribution.
/// </summary>
/// <param name="charge">The charge.</param>
/// <param name="positiveCharge">if set to <c>true</c> [positive charge].</param>
/// <returns>A charged isotopic distribution with the same abundances.</returns>
[Obsolete("Use CreateChargedDistribution(int charge, double chargeCarrier) instead.")]
IChargedIsotopicDistribution CreateChargedDistribution(int charge, bool positiveCharge);

/// <summary>
/// Creates a charged isotopic distribution.
/// </summary>
/// <param name="charge">The charge.</param>
/// <param name="positiveCharge">if set to <c>true</c> [positive charge].</param>
/// <returns>A charged isotopic distribution with the same abundances.</returns>
IChargedIsotopicDistribution CreateChargedDistribution(int charge, bool positiveCharge = true);
/// <summary>
/// Creates a charged isotopic distribution.
/// </summary>
/// <param name="charge">The charge.</param>
/// <param name="chargeCarrier">The charge carrier.</param>
/// <returns>A charged isotopic distribution with the same abundances.</returns>
IChargedIsotopicDistribution CreateChargedDistribution(int charge, double chargeCarrier = Utility.Proton);

/// <summary>
/// Clones the distribution and shifts it by a mass (Da) value.
/// </summary>
/// <param name="shift">The shift mass in daltons (Da).</param>
/// <returns></returns>
IIsotopicDistribution CloneAndShift(double shift);
}
/// <summary>
/// Clones the distribution and shifts it by a mass (Da) value.
/// </summary>
/// <param name="shift">The shift mass in daltons (Da).</param>
/// <returns>The cloned distribution shifted by the specified mass.</returns>
IIsotopicDistribution CloneAndShift(double shift);
}
32 changes: 31 additions & 1 deletion src/TopDownProteomics/MassSpectrometry/IsotopicDistribution.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace TopDownProteomics.MassSpectrometry
Expand Down Expand Up @@ -55,7 +56,19 @@ private double[] GetMz(int charge, bool positiveCharge)
double[] mz = new double[this.Length];

for (int i = 0; i < this.Length; i++)
#pragma warning disable CS0618 // Type or member is obsolete
mz[i] = Utility.ConvertMassToMz(_masses[i], charge, positiveCharge);
#pragma warning restore CS0618 // Type or member is obsolete

return mz;
}

Check warning on line 64 in src/TopDownProteomics/MassSpectrometry/IsotopicDistribution.cs

View check run for this annotation

Codecov / codecov/patch

src/TopDownProteomics/MassSpectrometry/IsotopicDistribution.cs#L63-L64

Added lines #L63 - L64 were not covered by tests

private double[] GetMz(int charge, double chargeCarrier)
{
double[] mz = new double[this.Length];

for (int i = 0; i < this.Length; i++)
mz[i] = Utility.ConvertMassToMz(_masses[i], charge, chargeCarrier);

return mz;
}
Expand All @@ -66,11 +79,28 @@ private double[] GetMz(int charge, bool positiveCharge)
/// <param name="charge">The charge.</param>
/// <param name="positiveCharge">if set to <c>true</c> [positive charge].</param>
/// <returns></returns>
public IChargedIsotopicDistribution CreateChargedDistribution(int charge, bool positiveCharge = true)
public IChargedIsotopicDistribution CreateChargedDistribution(int charge, bool positiveCharge)
{
Debug.Assert(charge > 0, "Charge must be greater than 0.");

Check warning on line 84 in src/TopDownProteomics/MassSpectrometry/IsotopicDistribution.cs

View check run for this annotation

Codecov / codecov/patch

src/TopDownProteomics/MassSpectrometry/IsotopicDistribution.cs#L84

Added line #L84 was not covered by tests

return new ChargedIsotopicDistribution(this.GetMz(charge, positiveCharge), _abundances, charge);
}

/// <summary>
/// Creates a charged isotopic distribution.
/// </summary>
/// <param name="charge">The charge.</param>
/// <param name="chargeCarrier">The charge carrier.</param>
/// <returns>
/// A charged isotopic distribution with the same abundances.
/// </returns>
public IChargedIsotopicDistribution CreateChargedDistribution(int charge, double chargeCarrier = Utility.Proton)
{
Debug.Assert(chargeCarrier > 0, "Charge carrier must be greater than 0.");

return new ChargedIsotopicDistribution(this.GetMz(charge, chargeCarrier), _abundances, charge);
}

/// <summary>
/// Clones the distribution and shifts it by a constant m/z value.
/// </summary>
Expand Down
Loading

0 comments on commit 3b92bc9

Please sign in to comment.