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

Negative Mode and Charge Carriers #114

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -18,18 +18,22 @@
/// <param name="mz">The mz.</param>
/// <param name="intensity">The intensity.</param>
/// <param name="charge">The charge.</param>
public ChargedIsotopicDistribution(double[] mz, double[] intensity, int charge)
/// <param name="chargeCarrier">The charge carrier.</param>
public ChargedIsotopicDistribution(double[] mz, double[] intensity, int charge, double chargeCarrier)
{
_intensity = intensity;
_mz = mz;

this.Charge = charge;
this.ChargeCarrier = chargeCarrier;
}

/// <summary>
/// Gets the charge.
/// </summary>
/// <summary>The charge.</summary>
public int Charge { get; }

/// <summary>The mass of the charge carrier.</summary>
public double ChargeCarrier { get; }

/// <summary>
/// Gets the mz.
/// </summary>
Expand Down Expand Up @@ -68,7 +72,7 @@
{
// Moving any more would only make things less intense ... stop
return new ChargedIsotopicDistribution(_mz.SubSequence(i, i + numberOfPoints - 1).ToArray(),
_intensity.SubSequence(i, i + numberOfPoints - 1).ToArray(), this.Charge);
_intensity.SubSequence(i, i + numberOfPoints - 1).ToArray(), this.Charge, this.ChargeCarrier);
}
}

Expand All @@ -89,7 +93,7 @@
mz[i] = _mz[i] + shiftMz;
}

return new ChargedIsotopicDistribution(mz, (double[])_intensity.Clone(), this.Charge);
return new ChargedIsotopicDistribution(mz, (double[])_intensity.Clone(), this.Charge, this.ChargeCarrier);

Check warning on line 96 in src/TopDownProteomics/MassSpectrometry/ChargedIsotopicDistribution.cs

View check run for this annotation

Codecov / codecov/patch

src/TopDownProteomics/MassSpectrometry/ChargedIsotopicDistribution.cs#L96

Added line #L96 was not covered by tests
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
/// </summary>
public interface IChargedIsotopicDistribution : IMzIntensityData
{
/// <summary>
/// Gets the charge.
/// </summary>
/// <summary>The charge.</summary>
int Charge { get; }

/// <summary>The mass of the charge carrier.</summary>
double ChargeCarrier { get; }

/// <summary>
/// Clones the distribution with a subset of the most intense points.
/// </summary>
Expand All @@ -20,7 +21,7 @@ public interface IChargedIsotopicDistribution : IMzIntensityData
/// <summary>
/// Clones the distribution and shifts it by an m/z (Th) value.
/// </summary>
/// <param name="shiftMz">The shift m/z in thomsons (Th).</param>
/// <param name="shiftMz">The shift m/z in Thomsons (Th).</param>
/// <returns></returns>
IChargedIsotopicDistribution CloneAndShift(double shiftMz);
}
Expand Down
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);
}
34 changes: 32 additions & 2 deletions 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 @@
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,9 +79,26 @@
/// <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)
{
return new ChargedIsotopicDistribution(this.GetMz(charge, positiveCharge), _abundances, charge);
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, Utility.Proton);
}

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

View check run for this annotation

Codecov / codecov/patch

src/TopDownProteomics/MassSpectrometry/IsotopicDistribution.cs#L86-L87

Added lines #L86 - L87 were not covered by tests

/// <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, chargeCarrier);
}

/// <summary>
Expand Down
Loading
Loading