forked from CompOmics/ThermoRawFileParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriterTests.cs
More file actions
289 lines (218 loc) · 11.9 KB
/
WriterTests.cs
File metadata and controls
289 lines (218 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.PeerToPeer.Collaboration;
using System.Xml.Serialization;
using IO.Mgf;
using MzLibUtil;
using NUnit.Framework;
using ThermoRawFileParser;
using ThermoRawFileParser.Writer;
using ThermoRawFileParser.Writer.MzML;
using UsefulProteomicsDatabases;
namespace ThermoRawFileParserTest
{
[TestFixture]
public class WriterTests
{
[Test]
public void TestExtensionsNull()
{
// Get temp path for writing the test files
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(tempFilePath);
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/small.RAW");
var parseInput = new ParseInput();
parseInput.RawFilePath = testRawFile;
parseInput.OutputDirectory = tempFilePath;
//empty filename
parseInput.OutputFormat = OutputFormat.MGF;
RawFileParser.Parse(parseInput);
Assert.IsTrue(File.Exists(Path.Combine(tempFilePath, "small.mgf")));
parseInput.OutputFormat = OutputFormat.MzML;
RawFileParser.Parse(parseInput);
Assert.IsTrue(File.Exists(Path.Combine(tempFilePath, "small.mzML")));
File.Delete(Path.Combine(tempFilePath, "small.mzML"));
parseInput.OutputFormat = OutputFormat.IndexMzML;
RawFileParser.Parse(parseInput);
Assert.IsTrue(File.Exists(Path.Combine(tempFilePath, "small.mzML")));
parseInput.Gzip = true;
RawFileParser.Parse(parseInput);
Assert.IsTrue(File.Exists(Path.Combine(tempFilePath, "small.mzML.gz")));
File.Delete(Path.Combine(tempFilePath, "small.mzML.gz"));
parseInput.OutputFormat = OutputFormat.MGF;
RawFileParser.Parse(parseInput);
Assert.IsTrue(File.Exists(Path.Combine(tempFilePath, "small.mgf.gz")));
parseInput.OutputFormat = OutputFormat.MzML;
RawFileParser.Parse(parseInput);
Assert.IsTrue(File.Exists(Path.Combine(tempFilePath, "small.mzML.gz")));
Directory.Delete(tempFilePath, true);
}
[Test]
public void TestExtensionsFull()
{
// Get temp path for writing the test files
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(tempFilePath);
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/small.RAW");
var parseInput = new ParseInput();
parseInput.RawFilePath = testRawFile;
List<OutputFormat> formats = new List<OutputFormat>();
string userInput;
string expectedOutput;
foreach (string line in File.ReadLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/ExtensionTest.tsv")).Skip(1))
{
string[] words = line.Split('\t');
switch (words[0].ToLower())
{
case "mgf": formats = new List<OutputFormat> { OutputFormat.MGF }; break;
case "mzml": formats = new List<OutputFormat> { OutputFormat.MzML, OutputFormat.IndexMzML }; break;
}
switch (words[1].ToLower())
{
case "true": parseInput.Gzip = true; break;
default: parseInput.Gzip = false; break;
}
userInput = words[2];
expectedOutput = words[3];
parseInput.OutputFile = Path.Combine(tempFilePath, userInput);
foreach (var format in formats)
{
parseInput.OutputFormat = format;
RawFileParser.Parse(parseInput);
Assert.IsTrue(File.Exists(Path.Combine(tempFilePath, expectedOutput)));
File.Delete(Path.Combine(tempFilePath, expectedOutput));
}
}
Directory.Delete(tempFilePath, true);
}
[Test]
public void TestMgf()
{
// Get temp path for writing the test MGF
var tempFilePath = Path.GetTempPath();
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/small.RAW");
var parseInput = new ParseInput(testRawFile, null, tempFilePath, OutputFormat.MGF);
RawFileParser.Parse(parseInput);
var mgfData = Mgf.LoadAllStaticData(Path.Combine(tempFilePath, "small.mgf"));
Assert.AreEqual(34, mgfData.NumSpectra);
}
[Test]
public void TestFolderMgfs()
{
// Get temp path for writing the test MGF
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(tempFilePath);
var testRawFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/TestFolderMgfs");
var parseInput = new ParseInput(null, testRawFolder, tempFilePath, OutputFormat.MGF);
RawFileParser.Parse(parseInput);
var numFiles = Directory.GetFiles(tempFilePath, "*.mgf");
Assert.AreEqual(numFiles.Length, 2);
var mgfData = Mgf.LoadAllStaticData(Path.Combine(tempFilePath, "small1.mgf"));
Assert.AreEqual(34, mgfData.NumSpectra);
var mgfData2 = Mgf.LoadAllStaticData(Path.Combine(tempFilePath, "small2.mgf"));
Assert.AreEqual(34, mgfData2.NumSpectra);
Directory.Delete(tempFilePath, true);
}
[Test]
public void TestMzml()
{
// Get temp path for writing the test mzML
var tempFilePath = Path.GetTempPath();
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/small.RAW");
var parseInput = new ParseInput(testRawFile, null, tempFilePath, OutputFormat.MzML);
RawFileParser.Parse(parseInput);
// Deserialize the mzML file
var xmlSerializer = new XmlSerializer(typeof(mzMLType));
var testMzMl = (mzMLType) xmlSerializer.Deserialize(new FileStream(
Path.Combine(tempFilePath, "small.mzML"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
Assert.AreEqual("48", testMzMl.run.spectrumList.count);
Assert.AreEqual(48, testMzMl.run.spectrumList.spectrum.Length);
Assert.AreEqual("1", testMzMl.run.chromatogramList.count);
Assert.AreEqual(1, testMzMl.run.chromatogramList.chromatogram.Length);
Assert.AreEqual(48, testMzMl.run.chromatogramList.chromatogram[0].defaultArrayLength);
}
[Test]
public void TestProfileMzml()
{
// Get temp path for writing the test mzML
var tempFilePath = Path.GetTempPath();
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/small.RAW");
var parseInput = new ParseInput(testRawFile, null, tempFilePath, OutputFormat.MzML);
parseInput.NoPeakPicking = new HashSet<int> { 1, 2 };
RawFileParser.Parse(parseInput);
// Deserialize the mzML file
var xmlSerializer = new XmlSerializer(typeof(mzMLType));
var testMzMl = (mzMLType)xmlSerializer.Deserialize(new FileStream(
Path.Combine(tempFilePath, "small.mzML"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
Assert.AreEqual("48", testMzMl.run.spectrumList.count);
Assert.AreEqual(48, testMzMl.run.spectrumList.spectrum.Length);
Assert.AreEqual("1", testMzMl.run.chromatogramList.count);
Assert.AreEqual(1, testMzMl.run.chromatogramList.chromatogram.Length);
Assert.AreEqual(48, testMzMl.run.chromatogramList.chromatogram[0].defaultArrayLength);
}
[Test]
public void TestMSLevels()
{
// Get temp path for writing the test mzML
var tempFilePath = Path.GetTempPath();
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/small.RAW");
var parseInput = new ParseInput(testRawFile, null, tempFilePath, OutputFormat.MzML);
parseInput.MsLevel = new HashSet<int> { 1 };
RawFileParser.Parse(parseInput);
// Deserialize the mzML file
var xmlSerializer = new XmlSerializer(typeof(mzMLType));
var testMzMl = (mzMLType)xmlSerializer.Deserialize(new FileStream(
Path.Combine(tempFilePath, "small.mzML"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
Assert.AreEqual("14", testMzMl.run.spectrumList.count);
Assert.AreEqual(14, testMzMl.run.spectrumList.spectrum.Length);
Assert.AreEqual(48, testMzMl.run.chromatogramList.chromatogram[0].defaultArrayLength);
}
[Test]
public void TestIndexedMzML()
{
// Get temp path for writing the test mzML
var tempFilePath = Path.GetTempPath();
Console.WriteLine(tempFilePath);
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/small.RAW");
var parseInput = new ParseInput(testRawFile, null, tempFilePath, OutputFormat.IndexMzML);
RawFileParser.Parse(parseInput);
// Deserialize the mzML file
var xmlSerializer = new XmlSerializer(typeof(indexedmzML));
var testMzMl = (indexedmzML) xmlSerializer.Deserialize(new FileStream(
Path.Combine(tempFilePath, "small.mzML"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
Assert.AreEqual("48", testMzMl.mzML.run.spectrumList.count);
Assert.AreEqual(48, testMzMl.mzML.run.spectrumList.spectrum.Length);
Assert.AreEqual("1", testMzMl.mzML.run.chromatogramList.count);
Assert.AreEqual(1, testMzMl.mzML.run.chromatogramList.chromatogram.Length);
Assert.AreEqual(2, testMzMl.indexList.index.Length);
Assert.AreEqual("spectrum", testMzMl.indexList.index[0].name.ToString());
Assert.AreEqual(48, testMzMl.indexList.index[0].offset.Length);
Assert.AreEqual("chromatogram", testMzMl.indexList.index[1].name.ToString());
Assert.AreEqual(1, testMzMl.indexList.index[1].offset.Length);
}
[Test]
public void TestMzML_MS2()
{
// Get temp path for writing the test mzML
var tempFilePath = Path.GetTempPath();
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/small2.RAW");
var parseInput = new ParseInput(testRawFile, null, tempFilePath, OutputFormat.MzML);
RawFileParser.Parse(parseInput);
// Deserialize the mzML file
var xmlSerializer = new XmlSerializer(typeof(mzMLType));
var testMzMl = (mzMLType)xmlSerializer.Deserialize(new FileStream(
Path.Combine(tempFilePath, "small2.mzML"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
Assert.AreEqual(95, testMzMl.run.spectrumList.spectrum.Length);
var precursor = testMzMl.run.spectrumList.spectrum[16].precursorList.precursor[0].selectedIonList.selectedIon[0];
var selectedMz = Double.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000744").First().value);
Assert.IsTrue(selectedMz - 604.7592 < 0.001);
var selectedZ = int.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000041").First().value);
Assert.AreEqual(selectedZ , 2);
//var selectedI = Double.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000042").First().value);
//Assert.IsTrue(selectedI - 10073 < 1);
Assert.AreEqual(95, testMzMl.run.chromatogramList.chromatogram[0].defaultArrayLength);
}
}
}