Skip to content

Commit 1aeeb7d

Browse files
Merge branch 'eubic2020hackathon' of https://github.com/compomics/ThermoRawFileParser into jsonvalidation
2 parents 2e5dbf9 + 6b6f026 commit 1aeeb7d

13 files changed

Lines changed: 78 additions & 57 deletions

MainClass.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Reflection;
23
using System.IO;
34
using log4net;
45
using log4net.Core;
@@ -7,6 +8,7 @@
78
using System.Linq;
89
using ThermoRawFileParser.Query;
910
using ThermoRawFileParser.XIC;
11+
using System.Globalization;
1012

1113
namespace ThermoRawFileParser
1214
{
@@ -19,6 +21,9 @@ public static class MainClass
1921

2022
public static void Main(string[] args)
2123
{
24+
//Set Invariant culture as default for all further processing
25+
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
26+
2227
// introduce subcommand for xics and spectra query
2328
if (args.Length > 0)
2429
{
@@ -452,7 +457,10 @@ private static void RegularParametersParsing(string[] args)
452457

453458
if (help)
454459
{
455-
ShowHelp("usage is (use -option=value for the optional arguments):", null,
460+
string helpmessage = String.Format("usage is {0} [subcommand] [options]\nsubcommand is xic|query\n",
461+
Assembly.GetExecutingAssembly().GetName().Name);
462+
ShowHelp(helpmessage +
463+
"(use -option=value for the optional arguments):", null,
456464
optionSet);
457465
return;
458466
}

Query/ProxiSpectrumReader.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ public List<PROXISpectrum> Retrieve()
115115
// trailer extra data list
116116
var trailerData = rawFile.GetTrailerExtraInformation(scanNumber);
117117
int charge = 0;
118-
double? monoisotopicMz = null;
119-
double? isolationWidth = null;
118+
double monoisotopicMz = 0.0;
119+
double isolationWidth = 0.0;
120120
for (var i = 0; i < trailerData.Length; i++)
121121
{
122122
if (trailerData.Labels[i] == "Ion Injection Time (ms):")
@@ -148,10 +148,20 @@ public List<PROXISpectrum> Retrieve()
148148

149149
if (reaction != null)
150150
{
151+
// Store the precursor information
151152
var selectedIonMz =
152153
SpectrumWriter.CalculateSelectedIonMz(reaction, monoisotopicMz, isolationWidth);
153154
proxiSpectrum.AddAttribute(accession: "MS:10000744", name: "selected ion m/z",
154155
value: selectedIonMz.ToString(CultureInfo.InvariantCulture));
156+
proxiSpectrum.AddAttribute(accession: "MS:1000827", name: "isolation window target m/z",
157+
value: selectedIonMz.ToString(CultureInfo.InvariantCulture));
158+
159+
// Store the isolation window information
160+
double isolationHalfWidth = isolationWidth / 2;
161+
proxiSpectrum.AddAttribute(accession: "MS:1000828", name: "isolation window lower offset",
162+
value: isolationHalfWidth.ToString(CultureInfo.InvariantCulture));
163+
proxiSpectrum.AddAttribute(accession: "MS:1000829", name: "isolation window upper offset",
164+
value: isolationHalfWidth.ToString(CultureInfo.InvariantCulture));
155165
}
156166

157167
// scan polarity

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ For running on Windows, omit `mono`. The optional parameters only work in the -o
2626

2727
```
2828
ThermoRawFileParser.exe --help
29-
usage is (use -option=value for the optional arguments):
29+
usage is ThermoRawFileParser [subcommand] [option]
30+
subcommand is xic|query
31+
(use -option=value for the optional arguments):
3032
-h, --help Prints out the options.
3133
--version Prints out the library version.
3234
-i, --input=VALUE The raw file input (Required). Specify this or an

ThermoRawFileParserTest/Data/xic_in.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
{
33
"mz": 488.5384,
44
"tolerance": 2,
5-
"tolerance_unit": "da"
5+
"tolerance_unit": "da",
6+
"filter": "ms2"
67
},
78
{
89
"mz": 570.2413,

ThermoRawFileParserTest/XicReaderTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public void testValidateJson()
8080
{
8181
'mz':488.5384,
8282
'tolerance':10,
83-
'tolerance_unit':'ppm'
83+
'tolerance_unit':'ppm',
84+
'scan_filter':'ms'
8485
},
8586
{
8687
'mz':575.2413,
@@ -171,7 +172,8 @@ public void testParseJson()
171172
{
172173
'mz': 488.5384,
173174
'tolerance':10,
174-
'tolerance_unit':'ppm'
175+
'tolerance_unit':'ppm',
176+
'scan_filter': 'ms2'
175177
},
176178
{
177179
'mz':575.2413,

XIC/JSONInputUnit.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
using System;
21
using System.ComponentModel;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Runtime.Serialization;
6-
using System.Text;
7-
using System.Threading.Tasks;
82
using Newtonsoft.Json;
9-
using Newtonsoft.Json.Serialization;
103

114
namespace ThermoRawFileParser.XIC
125
{
@@ -48,6 +41,10 @@ public class JSONInputUnit
4841
[DefaultValue(null)]
4942
public double? RtEnd { get; set; }
5043

44+
[JsonProperty("scan_filter", DefaultValueHandling = DefaultValueHandling.Populate)]
45+
[DefaultValue(null)]
46+
public string Filter { get; set; }
47+
5148
public bool HasMzRange()
5249
{
5350
return MzStart != null && MzEnd != null;

XIC/JSONParser.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
using System;
2-
using System.IO;
3-
using System.Collections.Generic;
4-
using System.ComponentModel.DataAnnotations;
5-
using System.Globalization;
6-
using System.Linq;
7-
using System.Text;
1+
using System.Collections.Generic;
82
using System.Threading.Tasks;
93
using Newtonsoft.Json;
10-
using Newtonsoft.Json.Linq;
11-
using Newtonsoft.Json.Schema;
124
using NJsonSchema.Validation;
13-
using ThermoFisher.CommonCore.Data;
145
using ThermoRawFileParser.Util;
156

167
namespace ThermoRawFileParser.XIC
@@ -39,7 +30,8 @@ public static class JSONParser
3930
{'required' : ['mz_start','tolerance']},
4031
{'required' : ['mz_end','tolerance']},
4132
]
42-
},
33+
},
34+
'additionalProperties': false,
4335
'properties': {
4436
'mz': {
4537
'$id': '#/items/properties/mz',
@@ -58,13 +50,13 @@ public static class JSONParser
5850
'type': 'string',
5951
'title': 'The Tolerance_unit Schema',
6052
'enum': ['ppm', 'amu', 'mmu', 'da']
61-
},
53+
},
6254
'mz_start': {
6355
'$id': '#/items/properties/mz_start',
6456
'type': 'number',
6557
'minimum': 0,
6658
'title': 'The Mz_start Schema',
67-
},
59+
},
6860
'mz_end': {
6961
'$id': '#/items/properties/mz_end',
7062
'type': 'number',
@@ -87,6 +79,11 @@ public static class JSONParser
8779
'$id': '#/items/properties/sequence',
8880
'type': 'string',
8981
'title': 'The Sequence Schema',
82+
},
83+
'scan_filter': {
84+
'$id': '#/items/properties/scan_filter',
85+
'type': 'string',
86+
'title': 'The Filter Schema',
9087
}
9188
}
9289
}
@@ -139,11 +136,11 @@ public static XicData ParseJSON(string jsonString)
139136
}
140137

141138
xicUnit = new XicUnit(xic.Mz.Value - delta, xic.Mz.Value + delta, xic.RtStart,
142-
xic.RtEnd);
139+
xic.RtEnd, xic.Filter);
143140
}
144141
else if (xic.HasMzRange())
145142
{
146-
xicUnit = new XicUnit(xic.MzStart.Value, xic.MzEnd.Value, xic.RtStart, xic.RtEnd);
143+
xicUnit = new XicUnit(xic.MzStart.Value, xic.MzEnd.Value, xic.RtStart, xic.RtEnd, xic.Filter);
147144
}
148145

149146
if (xicUnit == null || !xicUnit.HasValidRanges())

XIC/XicData.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32

43
namespace ThermoRawFileParser.XIC

XIC/XicMeta.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using System.ComponentModel;
2+
using Newtonsoft.Json;
63

74
namespace ThermoRawFileParser.XIC
85
{
96
public class XicMeta
107
{
8+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
9+
[DefaultValue(null)]
1110
public double? MzStart { get; set; }
11+
12+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
13+
[DefaultValue(null)]
1214
public double? MzEnd { get; set; }
15+
16+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
17+
[DefaultValue(null)]
1318
public double? RtStart { get; set; }
19+
20+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
21+
[DefaultValue(null)]
1422
public double? RtEnd { get; set; }
1523

24+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
25+
[DefaultValue(null)]
26+
public string Filter { get; set; }
27+
1628

1729
public XicMeta()
1830
{
19-
// MzStart = -1;
20-
// MzEnd = -1;
21-
// RtStart = -1;
22-
// RtEnd = -1;
31+
MzStart = null;
32+
MzEnd = null;
33+
RtStart = null;
34+
RtEnd = null;
35+
Filter = null;
2336
}
2437

2538
public XicMeta(XicMeta copy)
@@ -28,6 +41,7 @@ public XicMeta(XicMeta copy)
2841
MzEnd = copy.MzEnd;
2942
RtStart = copy.RtStart;
3043
RtEnd = copy.RtEnd;
44+
Filter = copy.Filter;
3145
}
3246
}
3347
}

XIC/XicOutputMeta.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Newtonsoft.Json;
72

83
namespace ThermoRawFileParser.XIC
94
{
@@ -17,11 +12,11 @@ public XicOutputMeta()
1712
base64 = false;
1813
timeunit = String.Empty;
1914
}
20-
15+
2116
public XicOutputMeta(XicOutputMeta copy)
2217
{
2318
base64 = copy.base64;
2419
timeunit = copy.timeunit;
2520
}
2621
}
27-
}
22+
}

0 commit comments

Comments
 (0)