Skip to content

Commit 472d7ca

Browse files
committed
Precursor intensity for low res scans
1 parent da280b9 commit 472d7ca

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

ThermoRawFileParserTest/WriterTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
4+
using System.Net.PeerToPeer.Collaboration;
35
using System.Xml.Serialization;
46
using IO.Mgf;
7+
using MzLibUtil;
58
using NUnit.Framework;
69
using ThermoRawFileParser;
710
using ThermoRawFileParser.Writer.MzML;
@@ -66,6 +69,8 @@ public void TestMzml()
6669

6770
Assert.AreEqual("1", testMzMl.run.chromatogramList.count);
6871
Assert.AreEqual(1, testMzMl.run.chromatogramList.chromatogram.Length);
72+
73+
Assert.AreEqual(48, testMzMl.run.chromatogramList.chromatogram[0].defaultArrayLength);
6974
}
7075

7176
[Test]
@@ -98,5 +103,36 @@ public void TestIndexedMzML()
98103
Assert.AreEqual("chromatogram", testMzMl.indexList.index[1].name.ToString());
99104
Assert.AreEqual(1, testMzMl.indexList.index[1].offset.Length);
100105
}
106+
107+
[Test]
108+
public void TestMzML_MS2()
109+
{
110+
// Get temp path for writing the test mzML
111+
var tempFilePath = Path.GetTempPath();
112+
113+
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/small2.RAW");
114+
var parseInput = new ParseInput(testRawFile, null, tempFilePath, OutputFormat.MzML);
115+
116+
RawFileParser.Parse(parseInput);
117+
118+
// Deserialize the mzML file
119+
var xmlSerializer = new XmlSerializer(typeof(mzMLType));
120+
var testMzMl = (mzMLType)xmlSerializer.Deserialize(new FileStream(
121+
Path.Combine(tempFilePath, "small2.mzML"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
122+
123+
Assert.AreEqual(95, testMzMl.run.spectrumList.spectrum.Length);
124+
125+
var precursor = testMzMl.run.spectrumList.spectrum[16].precursorList.precursor[0].selectedIonList.selectedIon[0];
126+
var selectedMz = Double.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000744").First().value);
127+
Assert.IsTrue(selectedMz - 604.7592 < 0.001);
128+
129+
var selectedZ = int.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000041").First().value);
130+
Assert.AreEqual(selectedZ , 2);
131+
132+
var selectedI = Double.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000042").First().value);
133+
Assert.IsTrue(selectedI - 10073 < 1);
134+
135+
Assert.AreEqual(95, testMzMl.run.chromatogramList.chromatogram[0].defaultArrayLength);
136+
}
101137
}
102138
}

Writer/SpectrumWriter.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public static IReaction GetReaction(IScanEvent scanEvent, int scanNumber)
178178
double precursorMass)
179179
{
180180
double? precursorIntensity = null;
181+
double tolerance;
181182

182183
// Get the precursor scan from the RAW file
183184
var scan = Scan.FromFile(rawFile, precursorScanNumber);
@@ -190,15 +191,17 @@ public static IReaction GetReaction(IScanEvent scanEvent, int scanNumber)
190191
{
191192
masses = scan.CentroidScan.Masses;
192193
intensities = scan.CentroidScan.Intensities;
194+
tolerance = 0.01; //high resolution scan
193195
}
194196
else
195197
{
196198
masses = scan.SegmentedScan.Positions;
197199
intensities = scan.SegmentedScan.Intensities;
200+
tolerance = 0.5; //low resolution scan
198201
}
199202

200203
//find closest peak in a stream
201-
var bestDelta = Tolerance;
204+
var bestDelta = tolerance;
202205
for (var i = 0; i < masses.Length; i++)
203206
{
204207
var delta = precursorMass - masses[i];
@@ -208,7 +211,7 @@ public static IReaction GetReaction(IScanEvent scanEvent, int scanNumber)
208211
precursorIntensity = intensities[i];
209212
}
210213

211-
if (delta < -1 * Tolerance) break;
214+
if (delta < -1 * tolerance) break;
212215
}
213216

214217
return precursorIntensity;

0 commit comments

Comments
 (0)