Skip to content

Commit 239d526

Browse files
committed
Correct fileContent
1 parent 89ad1c5 commit 239d526

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

Writer/MzMlSpectrumWriter.cs

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.Specialized;
4+
using System.Diagnostics;
5+
using System.Diagnostics.Eventing.Reader;
46
using System.Globalization;
57
using System.IO;
68
using System.IO.Compression;
@@ -141,32 +143,34 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
141143
_writer.WriteStartElement("fileDescription");
142144
// fileContent
143145
_writer.WriteStartElement("fileContent");
146+
147+
//accumulating different types of file content
148+
HashSet<CVParamType> content = new HashSet<CVParamType>();
149+
144150
if (_rawFile.HasMsData)
145151
{
152+
var nMS1 = rawFile.GetFilteredScanEnumerator("ms").Count();
153+
var nMS = rawFile.RunHeaderEx.SpectraCount;
146154
// MS1
147-
SerializeCvParam(new CVParamType
155+
if(ParseInput.MsLevel.Contains(1) && nMS1 > 0)
156+
content.Add(new CVParamType
148157
{
149158
accession = "MS:1000579",
150159
name = "MS1 spectrum",
151160
cvRef = "MS",
152161
value = ""
153162
});
154163
// MSn
155-
SerializeCvParam(new CVParamType
164+
if(ParseInput.MsLevel.Any(n => n > 1) && nMS > nMS1)
165+
content.Add(new CVParamType
156166
{
157167
accession = "MS:1000580",
158168
name = "MSn spectrum",
159169
cvRef = "MS",
160170
value = ""
161171
});
162172
// Ion current chromatogram
163-
SerializeCvParam(new CVParamType
164-
{
165-
accession = "MS:1000810",
166-
name = "ion current chromatogram",
167-
cvRef = "MS",
168-
value = ""
169-
});
173+
content.Add(OntologyMapping.chromatogramTypes["current"]);
170174
}
171175

172176
// Other detector data
@@ -175,7 +179,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
175179
// PDA spectrum
176180
if (_rawFile.GetInstrumentCountOfType(Device.Pda) > 0)
177181
{
178-
SerializeCvParam(new CVParamType
182+
content.Add(new CVParamType
179183
{
180184
accession = "MS:1000806",
181185
name = "absorption spectrum",
@@ -188,15 +192,39 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
188192
if (_rawFile.GetInstrumentCountOfType(Device.Pda) > 0 ||
189193
_rawFile.GetInstrumentCountOfType(Device.UV) > 0)
190194
{
191-
SerializeCvParam(new CVParamType
195+
content.Add(OntologyMapping.chromatogramTypes["absorption"]);
196+
}
197+
//non-standard chromatograms pressure, flow, FID, etc
198+
foreach (var deviceType in new Device[2] { Device.Analog, Device.MSAnalog })
199+
{
200+
for (int nrI = 1; nrI < _rawFile.GetInstrumentCountOfType(deviceType) + 1; nrI++)
192201
{
193-
accession = "MS:1000812",
194-
name = "absorption chromatogram",
195-
cvRef = "MS",
196-
value = ""
197-
});
202+
_rawFile.SelectInstrument(deviceType, nrI);
203+
204+
var instData = _rawFile.GetInstrumentData();
205+
206+
for (int channel = 0; channel < instData.ChannelLabels.Length; channel++)
207+
{
208+
var channelName = instData.ChannelLabels[channel];
209+
if (channelName.ToLower().Contains("pressure"))
210+
content.Add(OntologyMapping.chromatogramTypes["pressure"]);
211+
else if (channelName.ToLower().Contains("flow"))
212+
content.Add(OntologyMapping.chromatogramTypes["flow"]);
213+
214+
else if (channelName.ToLower().Contains("fid"))
215+
content.Add(OntologyMapping.chromatogramTypes["current"]);
216+
else
217+
content.Add(OntologyMapping.chromatogramTypes["unknown"]);
218+
}
219+
}
198220
}
199-
//TODO non-standard chromatograms pressure, flow, FID, etc
221+
_rawFile.SelectMsData();
222+
}
223+
224+
//write content
225+
foreach (var item in content)
226+
{
227+
SerializeCvParam(item);
200228
}
201229

202230
_writer.WriteEndElement(); // fileContent

0 commit comments

Comments
 (0)