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

Monoisotopic mass and m/z on isotopic envelopes #115

Merged
merged 3 commits into from
Oct 28, 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
147 changes: 71 additions & 76 deletions src/TopDownProteomics/MassSpectrometry/ChargedIsotopicDistribution.cs
Original file line number Diff line number Diff line change
@@ -1,99 +1,94 @@
using System;
using System.Linq;

namespace TopDownProteomics.MassSpectrometry
{
/// <summary>
/// Isotopic Distribution with a given charge.
/// </summary>
/// <seealso cref="IMzIntensityData" />
public class ChargedIsotopicDistribution : IMzIntensityData, IChargedIsotopicDistribution
{
private readonly double[] _intensity;
private readonly double[] _mz;
namespace TopDownProteomics.MassSpectrometry;

/// <summary>
/// Initializes a new instance of the <see cref="ChargedIsotopicDistribution"/> class.
/// </summary>
/// <param name="mz">The mz.</param>
/// <param name="intensity">The intensity.</param>
/// <param name="charge">The charge.</param>
/// <param name="chargeCarrier">The charge carrier.</param>
public ChargedIsotopicDistribution(double[] mz, double[] intensity, int charge, double chargeCarrier)
{
_intensity = intensity;
_mz = mz;
/// <summary>
/// Isotopic Distribution with a given charge.
/// </summary>
/// <seealso cref="IMzIntensityData" />
/// <remarks>
/// Initializes a new instance of the <see cref="ChargedIsotopicDistribution"/> class.
/// </remarks>
/// <param name="monoMz">The mono m/z.</param>
/// <param name="mz">The mz.</param>
/// <param name="intensity">The intensity.</param>
/// <param name="charge">The charge.</param>
/// <param name="chargeCarrier">The charge carrier.</param>
public class ChargedIsotopicDistribution(double monoMz, double[] mz, double[] intensity, int charge, double chargeCarrier) : IMzIntensityData, IChargedIsotopicDistribution
{
private readonly double[] _intensity = intensity;
private readonly double[] _mz = mz;

this.Charge = charge;
this.ChargeCarrier = chargeCarrier;
}
/// <summary>The charge.</summary>
public int Charge { get; } = charge;

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

/// <summary>The mass of the charge carrier.</summary>
public double ChargeCarrier { get; }
/// <summary>
/// Gets the mz.
/// </summary>
public double[] GetMz() => _mz;

/// <summary>
/// Gets the mz.
/// </summary>
public double[] GetMz() => _mz;
/// <summary>
/// Gets the first m/z.
/// </summary>
public double FirstMz => _mz[0];

/// <summary>
/// Gets the first m/z.
/// </summary>
public double FirstMz => _mz[0];
/// <summary>The monoisotopic m/z.</summary>
public double MonoisotopicMz { get; } = monoMz;

/// <summary>
/// Gets the last m/z.
/// </summary>
public double LastMz => _mz[_mz.Length - 1];
/// <summary>
/// Gets the last m/z.
/// </summary>
public double LastMz => _mz[_mz.Length - 1];

/// <summary>
/// Gets the intensity.
/// </summary>
public double[] GetIntensity() => _intensity;
/// <summary>
/// Gets the intensity.
/// </summary>
public double[] GetIntensity() => _intensity;

/// <summary>
/// Gets the length.
/// </summary>
public int Length => _mz.Length;
/// <summary>
/// Gets the length.
/// </summary>
public int Length => _mz.Length;

/// <summary>
/// Clones the distribution with a subset of the most intense points.
/// </summary>
/// <param name="numberOfPoints">The number of points to keep.</param>
/// <returns></returns>
public IChargedIsotopicDistribution CloneWithMostIntensePoints(int numberOfPoints)
/// <summary>
/// Clones the distribution with a subset of the most intense points.
/// </summary>
/// <param name="numberOfPoints">The number of points to keep.</param>
/// <returns></returns>
public IChargedIsotopicDistribution CloneWithMostIntensePoints(int numberOfPoints)
{
for (int i = 0; i < _mz.Length - numberOfPoints; i++)
{
for (int i = 0; i < _mz.Length - numberOfPoints; i++)
if (_intensity[i] > _intensity[i + numberOfPoints])
{
if (_intensity[i] > _intensity[i + numberOfPoints])
{
// 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, this.ChargeCarrier);
}
// Moving any more would only make things less intense ... stop
return new ChargedIsotopicDistribution(this.MonoisotopicMz, _mz.SubSequence(i, i + numberOfPoints - 1).ToArray(),
_intensity.SubSequence(i, i + numberOfPoints - 1).ToArray(), this.Charge, this.ChargeCarrier);
}

throw new Exception($"Cannot find most {numberOfPoints} intense points.");
}

/// <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>
/// <returns></returns>
public IChargedIsotopicDistribution CloneAndShift(double shiftMz)
{
double[] mz = new double[this.Length];
throw new Exception($"Cannot find most {numberOfPoints} intense points.");

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

View check run for this annotation

Codecov / codecov/patch

src/TopDownProteomics/MassSpectrometry/ChargedIsotopicDistribution.cs#L74

Added line #L74 was not covered by tests
}

for (int i = 0; i < this.Length; i++)
{
mz[i] = _mz[i] + shiftMz;
}
/// <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>
/// <returns></returns>
public IChargedIsotopicDistribution CloneAndShift(double shiftMz)
{
double[] mz = new double[this.Length];
double monoMz = this.MonoisotopicMz + shiftMz;

return new ChargedIsotopicDistribution(mz, (double[])_intensity.Clone(), this.Charge, this.ChargeCarrier);
for (int i = 0; i < this.Length; i++)
{
mz[i] = _mz[i] + shiftMz;
}

return new ChargedIsotopicDistribution(monoMz, mz, (double[])_intensity.Clone(), this.Charge, this.ChargeCarrier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public interface IChargedIsotopicDistribution : IMzIntensityData
/// <summary>The mass of the charge carrier.</summary>
double ChargeCarrier { get; }

/// <summary>Gets the monoisotopic m/z.</summary>
double MonoisotopicMz { get; }

/// <summary>
/// Clones the distribution with a subset of the most intense points.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public interface IIsotopicDistribution
/// </summary>
int Length { get; }

/// <summary>The monoisotopic mass.</summary>
double MonoisotopicMass { get; }

/// <summary>
/// Gets the masses.
/// </summary>
Expand Down
Loading
Loading