Skip to content

Commit

Permalink
Refactor IsoDec classes and enhance parameters
Browse files Browse the repository at this point in the history
Updated IsoDecAlgorithm to use generic DeconvolutionParameters.
Enhanced IsoDecDeconvolutionParameters with new properties.
Refactored constructor to use camelCase parameter names.
Removed unused using directives from IsoDecAlgorithm.cs.
Ensured correct casting in IsoDecAlgorithm.
Renamed Css_Threshold to CssThreshold for consistency.
  • Loading branch information
nbollis committed Oct 28, 2024
1 parent 3c560ee commit 93e4161
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using MassSpectrometry.MzSpectra;
using MzLibUtil;
using MathNet.Numerics.Statistics;
using System.Reflection.Metadata.Ecma335;

namespace MassSpectrometry
{
public class IsoDecAlgorithm(IsoDecDeconvolutionParameters deconParameters)
public class IsoDecAlgorithm(DeconvolutionParameters deconParameters)
: DeconvolutionAlgorithm(deconParameters)
{
private static string _phaseModelPath;
Expand Down Expand Up @@ -96,7 +90,7 @@ public override IEnumerable<IsotopicEnvelope> Deconvolute(MzSpectrum spectrum, M
.ToArray();

IntPtr matchedPeaksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MatchedPeak)) * intensities.Length);
IsoSettings settings = DeconParametersToIsoSettings(deconParameters);
IsoSettings settings = DeconParametersToIsoSettings(DeconvolutionParameters as IsoDecDeconvolutionParameters);
int result = process_spectrum(mzs, intensities, intensities.Length, _phaseModelPath , matchedPeaksPtr, settings);
if(result > 0)
{
Expand All @@ -105,7 +99,7 @@ public override IEnumerable<IsotopicEnvelope> Deconvolute(MzSpectrum spectrum, M
{
matchedpeaks[i] = Marshal.PtrToStructure<MatchedPeak>(matchedPeaksPtr + i * Marshal.SizeOf(typeof(MatchedPeak)));
}
return ConvertToIsotopicEnvelopes(deconParameters, matchedpeaks, spectrum);
return ConvertToIsotopicEnvelopes(DeconvolutionParameters as IsoDecDeconvolutionParameters, matchedpeaks, spectrum);
}

else return new List<IsotopicEnvelope>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,134 @@ namespace MassSpectrometry
public class IsoDecDeconvolutionParameters : DeconvolutionParameters
{
public override DeconvolutionType DeconvolutionType { get; protected set; } = DeconvolutionType.IsoDecDeconvolution;

/// <summary>
/// Precision of encoding matrix
/// </summary>
public int PhaseRes { get; protected set; } = 8;

/// <summary>
/// Verbose output
/// </summary>
public int Verbose { get; protected set; } = 0;

/// <summary>
/// Peak Detection Window
/// </summary>
public int PeakWindow { get; protected set; } = 80;

/// <summary>
/// Peak Detection Threshold
/// </summary>
public float PeakThreshold { get; protected set; } = (float)0.0001;

/// <summary>
/// Minimum Peaks for an allowed peak
/// </summary>
public int MinPeaks { get; protected set; } = 3;
public float Css_Threshold { get; set; } = (float)0.7;

/// <summary>
/// Minimum cosine similarity score for isotope distribution
/// </summary>
public float CssThreshold { get; set; } = (float)0.7;

/// <summary>
/// Match Tolerance for peak detection in ppm
/// </summary>
public float MatchTolerance { get; set; } = (float)5;

/// <summary>
/// Maximum shift allowed for isotope distribution
/// </summary>
public int MaxShift { get; protected set; } = 3;

/// <summary>
/// MZ Window for isotope distribution
/// </summary>
public float[] MzWindow { get; set; } = new float[] { (float)-1.05, (float)2.05 };

/// <summary>
/// Plus One Intensity range. Will be used for charge state 1
/// </summary>
public float[] PlusOneIntWindow { get; protected set; } = new float[] { (float)0.1, (float)0.6 };

/// <summary>
/// Number of knockdown rounds
/// </summary>
public int KnockdownRounds { get; set; } = 5;

/// <summary>
/// Minimum score difference for isotope distribution to allow missed monoisotopic peaks
/// </summary>
public float MinScoreDiff { get; set; } = (float)0.1;

/// <summary>
/// Minimum area covered by isotope distribution. Use in or with css_thresh
/// </summary>
public float MinAreaCovered { get; set; } = (float)0.15;

/// <summary>
/// Isotope Distribution Length
/// </summary>
public int IsoLength { get; protected set; } = 64;

/// <summary>
/// Mass difference between isotopes
/// </summary>
public double MassDiffC { get; protected set; } = 1.0033;

/// <summary>
/// Adduct Mass
/// </summary>
public float AdductMass { get; set; } = (float)1.00727276467;

/// <summary>
/// Use set the -1 isotope as 0 to help force better alignments
/// </summary>
public int MinusOneAreasZero { get; set; } = 1;

/// <summary>
/// Threshold for isotope distribution. Will remove relative intensities below this.
/// </summary>
public float IsotopeThreshold { get; set; } = (float)0.01;

/// <summary>
/// Threshold for data. Will remove relative intensities below this relative to max intensity in each cluster
/// </summary>
public float DataThreshold { get; set; } = (float)0.05;

/// <summary>
/// Ratio above which a secondary charge state prediction will be returned.
/// </summary>
public float ZScoreThreshold { get; protected set; } = (float)0.95;

/// <summary>
/// Report multiple monoisotopic peaks
/// </summary>
public bool ReportMulitpleMonoisos { get; set; } = true;

public IsoDecDeconvolutionParameters(
int phaseres = 8,
bool reportmultiplemonoisos = true,
float css_threshold = (float)0.7,
float match_tolerance = (float)5,
int maxshift = 3,
float[] mzwindow = null,
int knockdown_rounds = 5,
float min_area_covered = (float)0.20,
int phaseRes = 8,
bool reportMultipleMonoisos = true,
float cssThreshold = (float)0.7,
float matchTolerance = (float)5,
int maxShift = 3,
float[] mzWindow = null,
int knockdownRounds = 5,
float minAreaCovered = (float)0.20,
float relativedatathreshold = (float)0.05)
: base(1,50,Polarity.Positive)
: base(1, 50, Polarity.Positive)
{
this.PhaseRes = phaseres;
this.ReportMulitpleMonoisos = reportmultiplemonoisos;
this.Css_Threshold = css_threshold;
this.MatchTolerance = match_tolerance;
this.MaxShift = maxshift;
if (mzwindow != null)
this.MzWindow = mzwindow;
this.PhaseRes = phaseRes;
this.ReportMulitpleMonoisos = reportMultipleMonoisos;
this.CssThreshold = cssThreshold;
this.MatchTolerance = matchTolerance;
this.MaxShift = maxShift;
if (mzWindow != null)
this.MzWindow = mzWindow;
else this.MzWindow = new float[] { (float)-1.05, (float)2.05 };
this.KnockdownRounds = knockdown_rounds;
this.MinAreaCovered = min_area_covered;
this.KnockdownRounds = knockdownRounds;
this.MinAreaCovered = minAreaCovered;
}
}
}

0 comments on commit 93e4161

Please sign in to comment.