-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jgpavek
committed
Aug 5, 2024
1 parent
6720fc5
commit b626f41
Showing
5 changed files
with
101 additions
and
47 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
mzLib/MassSpectrometry/Deconvolution/Algorithms/IsoDecAlgorithm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
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; | ||
|
||
namespace MassSpectrometry | ||
{ | ||
public class IsoDecAlgorithm(DeconvolutionParameters deconParameters) | ||
: DeconvolutionAlgorithm(deconParameters) | ||
{ | ||
[StructLayout(LayoutKind.Sequential, Pack =1)] | ||
public struct MatchedPeak | ||
{ | ||
public float mz; | ||
public int z; | ||
public float monoiso; | ||
public float peakmass; | ||
public float avgmass; | ||
public float area; | ||
public float peakint; | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] | ||
public int[] matchedindsiso; | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] | ||
public int[] matchedindsexp; | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] | ||
public float[] isomz; | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] | ||
public float[] isodist; | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] | ||
public float[] isomass; | ||
public int startindex; | ||
public int endindex; | ||
} | ||
|
||
|
||
[DllImport(@"C:\Python\UniDec3\unidec\IsoDec\src\isodec\x64\Release\isodeclib.dll", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern int process_spectrum(float[] mz, float[] intensity, int len, string modelpath, IntPtr matchedpeaks); | ||
|
||
|
||
public override IEnumerable<IsotopicEnvelope> Deconvolute(MzSpectrum spectrum, MzRange range) | ||
{ | ||
var firstIndex = spectrum.GetClosestPeakIndex(range.Minimum); | ||
var lastIndex = spectrum.GetClosestPeakIndex(range.Maximum); | ||
|
||
var mzs = spectrum.XArray[firstIndex..lastIndex] | ||
.Select(p => (float)p) | ||
.ToArray(); | ||
var intensities = spectrum.YArray[firstIndex..lastIndex] | ||
.Select(p => (float)p) | ||
.ToArray(); | ||
|
||
IntPtr matchedPeaksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MatchedPeak)) * intensities.Length); | ||
|
||
int result = process_spectrum(mzs, intensities, intensities.Length, @"C:\Python\UniDec3\unidec\IsoDec\phase_model.bin", matchedPeaksPtr); | ||
if(result > 0) | ||
{ | ||
MatchedPeak[] matchedpeaks = new MatchedPeak[result]; | ||
for(int i = 0;i<result;i++) | ||
{ | ||
matchedpeaks[i] = Marshal.PtrToStructure<MatchedPeak>(matchedPeaksPtr + i * Marshal.SizeOf(typeof(MatchedPeak))); | ||
} | ||
return ConvertToIsotopicEnvelopes(matchedpeaks, mzs, intensities); | ||
} | ||
|
||
else return new List<IsotopicEnvelope>(); | ||
} | ||
|
||
private List<IsotopicEnvelope> ConvertToIsotopicEnvelopes(MatchedPeak[] matchedpeaks, float[] mzs, float[] intensities) | ||
{ | ||
List<IsotopicEnvelope> result = new List<IsotopicEnvelope>(); | ||
foreach(MatchedPeak peak in matchedpeaks) | ||
{ | ||
List<(double,double)> peaks = new List<(double,double)> (); | ||
List<double> listofratios = new List<double>(); | ||
for(int i = 0;i<peak.matchedindsexp.Length;i++) | ||
{ | ||
if (i > 0 && peak.matchedindsexp[i] == 0) | ||
break; | ||
else | ||
{ | ||
listofratios.Add(peak.isodist[i] / intensities[peak.startindex + i]); | ||
peaks.Add((mzs[peak.startindex + i], intensities[peak.startindex + i])); | ||
} | ||
} | ||
result.Add(new IsotopicEnvelope(peaks, peak.monoiso, peak.z, peak.peakint, Statistics.StandardDeviation(listofratios), 0)); | ||
} | ||
return result; | ||
} | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
mzLib/MassSpectrometry/Deconvolution/Algorithms/JohnnyDeconvolutionAlgorithm.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters