-
Notifications
You must be signed in to change notification settings - Fork 33
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
IsoDec Deconvolution Algorithm #791
Open
nbollis
wants to merge
41
commits into
smith-chem-wisc:master
Choose a base branch
from
nbollis:JohnnyDeconv
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
3d7ebd1
Added in foundation for John to use
nbollis ddd03b5
removed charge from johnny decon parameters
nbollis 6720fc5
instantiated johhnydeconparams.decontype
nbollis 73df199
Merge branch 'master' into JohnnyDeconv
trishorts 50b8d9d
Merge branch 'master' into JohnnyDeconv
trishorts b626f41
IsoDec incorporated!
7c5132e
Merge branch 'JohnnyDeconv' of https://github.com/nbollis/mzLib into …
fc0f4bb
Did a little cleanup and made IsoDec run on my device
nbollis 097b4bd
Changed isodec to use the embedded dlls and resources
nbollis ba54e46
changed around assembly references and added IsoDec to Deconvolution …
nbollis 678dbc3
added test for negative mode
nbollis 64d4a4b
updated nuspec to pack isodec resources
nbollis 6ef4447
Updated dll. Now just making monoisotopic errors but getting generall…
1a0bd54
Corrected some IsoDec issues. Not passing tests yet, but getting corr…
963826b
IsoDec passes (updated) tests.
bc1b6a9
began neutral mz spectrum
nbollis a8bba37
Refactor visibility and clean up deconvolution code
455f3c0
Finish NeutralMassSpectrum
0dd9e52
Refactor Deconvoluter and rename NeutralMzSpectrum
09cefc7
added neutral mass file bool
72d8202
Adjsuted and tested neutral mass spectra
nbollis 4277814
Refactor Deconvoluter and add new tests
nbollis 6c124c5
Make FirstX and LastX properties virtual; update tests
nbollis f049ee4
fixed nuspec
nbollis 3c560ee
IsoDecDeconvolutionParameters and Multiple Monoisos
93e4161
Refactor IsoDec classes and enhance parameters
nbollis b97a23d
Merged in NeutralMassSpectrum and reconciled errors
nbollis 492f7e0
Bug Fixes and parameter cleanup
fc32cd2
Fixed broken unit test and assertion structure in test deconvolution
nbollis 2e4a772
Cleaned up isotopic Envelope
nbollis 8ff5883
Refactor IsoDec classes and update parameters
nbollis 302a07a
help me
nbollis e45fb3f
Changed resources from content to none
nbollis cf8b6a3
nuspec edit
nbollis 9aa30a8
Refactor Deconvolute method and update variable handling
nbollis 7cd2639
Fixed memory allocation/deallocation issues
3db9ab4
simple restructure of parameter handling
nbollis 788aa81
merged John and Nic Changes
nbollis 4bacc61
Update namespaces, references, and version number
nbollis 60d7e4e
idk man
nbollis 98a609f
look mom, I did it
nbollis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
185 changes: 110 additions & 75 deletions
185
...econvolution/StandardDeconvolutionTest.cs → ...nDevelopment/StandardDeconvolutionTest.cs
Large diffs are not rendered by default.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
9 changes: 3 additions & 6 deletions
9
mzLib/MassSpectrometry/Deconvolution/Algorithms/ExampleNewDeconvolutionAlgorithmTemplate.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
129 changes: 129 additions & 0 deletions
129
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,129 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using MzLibUtil; | ||
|
||
namespace MassSpectrometry | ||
{ | ||
internal class IsoDecAlgorithm : DeconvolutionAlgorithm | ||
{ | ||
|
||
internal IsoDecAlgorithm(DeconvolutionParameters deconParameters) : base(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 float[] matchedindsiso; | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] | ||
public float[] matchedindsexp; | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] | ||
public float[] isomz; | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] | ||
public float[] isodist; | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] | ||
public float[] isomass; | ||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] | ||
public float[] monoisos; | ||
int startindex; | ||
int endindex; | ||
public float score; | ||
public int realisolength; | ||
} | ||
|
||
[DllImport("isodeclib.dll", EntryPoint = "process_spectrum", CallingConvention = CallingConvention.Cdecl)] | ||
protected static extern int process_spectrum(double[] cmz, float[] cintensity, int c, string fname, IntPtr matchedpeaks, IsoDecDeconvolutionParameters.IsoSettings settings); | ||
|
||
internal override IEnumerable<IsotopicEnvelope> Deconvolute(MzSpectrum spectrum, MzRange range) | ||
{ | ||
var deconParams = DeconvolutionParameters as IsoDecDeconvolutionParameters ?? throw new MzLibException("Deconvolution params and algorithm do not match"); | ||
|
||
var firstIndex = spectrum.GetClosestPeakIndex(range.Minimum); | ||
var lastIndex = spectrum.GetClosestPeakIndex(range.Maximum); | ||
|
||
var mzs = spectrum.XArray[firstIndex..lastIndex] | ||
.Select(p => p) | ||
.ToArray(); | ||
var intensities = spectrum.YArray[firstIndex..lastIndex] | ||
.Select(p => (float)p) | ||
.ToArray(); | ||
|
||
var mpArray = new byte[intensities.Length * Marshal.SizeOf(typeof(MatchedPeak))]; | ||
GCHandle handle = GCHandle.Alloc(mpArray, GCHandleType.Pinned); | ||
try | ||
{ | ||
IntPtr matchedPeaksPtr = (IntPtr)handle.AddrOfPinnedObject(); | ||
IsoDecDeconvolutionParameters.IsoSettings settings = deconParams.ToIsoSettings(); | ||
int result = process_spectrum(mzs, intensities, intensities.Length, null, matchedPeaksPtr, settings); | ||
if (result <= 0) | ||
return Enumerable.Empty<IsotopicEnvelope>(); | ||
|
||
// Handle results | ||
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(deconParams, matchedpeaks, spectrum); | ||
} | ||
finally | ||
{ | ||
handle.Free(); | ||
} | ||
} | ||
|
||
private List<IsotopicEnvelope> ConvertToIsotopicEnvelopes(IsoDecDeconvolutionParameters parameters, MatchedPeak[] matchedpeaks, MzSpectrum spectrum) | ||
{ | ||
List<IsotopicEnvelope> result = new List<IsotopicEnvelope>(); | ||
int currentId = 0; | ||
foreach(MatchedPeak peak in matchedpeaks) | ||
{ | ||
List<(double,double)> peaks = new List<(double,double)> (); | ||
for (int i = 0; i < peak.realisolength; i++) | ||
{ | ||
|
||
List<int> indicesWithinTolerance = spectrum.GetPeakIndicesWithinTolerance(peak.isomz[i], new PpmTolerance(5)); | ||
double maxIntensity = 0; | ||
int maxIndex = -1; | ||
foreach (int index in indicesWithinTolerance) | ||
{ | ||
if (spectrum.YArray[index] > maxIntensity) { maxIntensity = spectrum.YArray[index]; maxIndex = index; } | ||
} | ||
if (maxIndex >= 0) | ||
{ | ||
peaks.Add((spectrum.XArray[maxIndex], spectrum.YArray[maxIndex])); | ||
} | ||
else | ||
{ | ||
peaks.Add((peak.isomz[i], 0)); | ||
} | ||
|
||
} | ||
int charge = peak.z; | ||
if(parameters.Polarity == Polarity.Negative) { charge = -peak.z; } | ||
if(parameters.ReportMulitpleMonoisos) | ||
{ | ||
foreach (float monoiso in peak.monoisos) | ||
{ | ||
if (monoiso > 0) { result.Add(new IsotopicEnvelope(currentId, peaks, (double)monoiso, charge, peak.peakint, peak.score)); } | ||
} | ||
} | ||
else { result.Add(new IsotopicEnvelope(currentId, peaks, (double)peak.monoiso, charge, peak.peakint, peak.score)); } | ||
currentId++; | ||
} | ||
return result; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MassSpectrometry | ||
{ | ||
public enum DeconvolutionType | ||
{ | ||
ClassicDeconvolution, | ||
ExampleNewDeconvolutionTemplate, | ||
IsoDecDeconvolution, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be good to use our standard variable names for these features.