Skip to content

Commit c27f2bd

Browse files
Merge branch 'eubic2020hackathon' of https://github.com/compomics/ThermoRawFileParser into eubic2020hackathon
2 parents 94f1945 + 6b6f026 commit c27f2bd

10 files changed

Lines changed: 55 additions & 35 deletions

File tree

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
{
@@ -479,7 +484,10 @@ private static void RegularParametersParsing(string[] args)
479484

480485
if (help)
481486
{
482-
ShowHelp("usage is (use -option=value for the optional arguments):", null,
487+
string helpmessage = String.Format("usage is {0} [subcommand] [options]\nsubcommand is xic|query\n",
488+
Assembly.GetExecutingAssembly().GetName().Name);
489+
ShowHelp(helpmessage +
490+
"(use -option=value for the optional arguments):", null,
483491
optionSet);
484492
return;
485493
}

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/xic_in.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
{
1919
"sequence":"PEPTIDE",
2020
"tolerance":0.5,
21-
"tolerance_unit":"amu"
21+
"tolerance_unit":"amu",
22+
"scan_filter": "ms2"
2223
}
2324
]

XIC/JSONInputUnit.cs

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

94
namespace ThermoRawFileParser.XIC
@@ -37,6 +32,9 @@ public class JSONInputUnit
3732
[JsonProperty("rt_end", DefaultValueHandling = DefaultValueHandling.Populate)]
3833
[DefaultValue(-1)]
3934
public double RtEnd { get; set; }
35+
[JsonProperty("scan_filter", DefaultValueHandling = DefaultValueHandling.Populate)]
36+
[DefaultValue(null)]
37+
public string Filter { get; set; }
4038

4139
public bool HasMzRange()
4240
{

XIC/JSONParser.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.IO;
33
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
74
using Newtonsoft.Json;
85
using ThermoRawFileParser.Util;
96

@@ -23,7 +20,7 @@ public static XicData ParseJSON(string jsonPath)
2320
foreach (JSONInputUnit xic in jsonIn)
2421
{
2522
if (xic.IsAmbigous())
26-
throw new Exception("The defenition of XIC is ambigous");
23+
throw new Exception(String.Format("The defenition of XIC is ambigous\n{0}", JsonConvert.SerializeObject(xic, Formatting.Indented)));
2724

2825
if (xic.HasSequence())
2926
{
@@ -44,12 +41,12 @@ public static XicData ParseJSON(string jsonPath)
4441
default:
4542
throw new Exception(String.Format("Cannot parse tolerance unit: {0}", xic.ToleranceUnit));
4643
}
47-
data.content.Add(new XicUnit(xic.Mz - delta, xic.Mz + delta, xic.RtStart, xic.RtEnd));
44+
data.content.Add(new XicUnit(xic.Mz - delta, xic.Mz + delta, xic.RtStart, xic.RtEnd, xic.Filter));
4845
}
4946

5047
else if (xic.HasMzRange())
5148
{
52-
data.content.Add(new XicUnit(xic.MzStart, xic.MzEnd, xic.RtStart, xic.RtEnd));
49+
data.content.Add(new XicUnit(xic.MzStart, xic.MzEnd, xic.RtStart, xic.RtEnd, xic.Filter));
5350
}
5451
else
5552
{

XIC/XicExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public int run(){
4545
}
4646
return 0;
4747
}
48-
48+
4949
public void StdOutputXicData(XicData outputData){
5050
string outputString = JsonConvert.SerializeObject(outputData);
5151
Console.WriteLine(outputString);

XIC/XicMeta.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
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(-1.0)]
1110
public double MzStart { get; set; }
11+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
12+
[DefaultValue(-1.0)]
1213
public double MzEnd { get; set; }
14+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
15+
[DefaultValue(-1.0)]
1316
public double RtStart { get; set; }
17+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
18+
[DefaultValue(-1.0)]
1419
public double RtEnd { get; set; }
20+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
21+
[DefaultValue(null)]
22+
public string Filter { get; set; }
1523

1624

1725
public XicMeta()
@@ -20,13 +28,15 @@ public XicMeta()
2028
MzEnd = -1;
2129
RtStart = -1;
2230
RtEnd = -1;
31+
Filter = null;
2332
}
2433

2534
public XicMeta(XicMeta copy){
2635
MzStart = copy.MzStart;
2736
MzEnd = copy.MzEnd;
2837
RtStart = copy.RtStart;
2938
RtEnd = copy.RtEnd;
39+
Filter = copy.Filter;
3040
}
3141
}
3242
}

XIC/XicReader.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ namespace ThermoRawFileParser.XIC
1010
{
1111
public class XicReader
1212
{
13-
private const string MsFilter = "ms";
14-
1513
public static void ReadXic(string rawFilePath, bool base64, XicData xicData)
1614
{
1715
IRawDataPlus rawFile;
@@ -65,7 +63,7 @@ public static void ReadXic(string rawFilePath, bool base64, XicData xicData)
6563
{
6664
settings = new ChromatogramTraceSettings(TraceType.MassRange)
6765
{
68-
Filter = MsFilter,
66+
Filter = xicUnit.Meta.Filter ?? "ms",
6967
MassRanges = new[]
7068
{
7169
new Range(xicUnit.Meta.MzStart,
@@ -83,7 +81,7 @@ public static void ReadXic(string rawFilePath, bool base64, XicData xicData)
8381
{
8482
settings = new ChromatogramTraceSettings(TraceType.MassRange)
8583
{
86-
Filter = MsFilter,
84+
Filter = xicUnit.Meta.Filter ?? "ms",
8785
MassRanges = new[]
8886
{
8987
new Range(minMass,
@@ -95,7 +93,7 @@ public static void ReadXic(string rawFilePath, bool base64, XicData xicData)
9593
{
9694
settings = new ChromatogramTraceSettings(TraceType.MassRange)
9795
{
98-
Filter = MsFilter,
96+
Filter = xicUnit.Meta.Filter ?? "ms",
9997
MassRanges = new[]
10098
{
10199
new Range(xicUnit.Meta.MzStart,

XIC/XicUnit.cs

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

83
namespace ThermoRawFileParser.XIC
94
{
@@ -22,13 +17,14 @@ public XicUnit()
2217

2318
}
2419

25-
public XicUnit (double mzstart, double mzend, double rtstart, double rtend)
20+
public XicUnit (double mzstart, double mzend, double rtstart, double rtend, string filter)
2621
{
2722
Meta = new XicMeta();
2823
Meta.MzStart = mzstart;
2924
Meta.MzEnd = mzend;
3025
Meta.RtStart = rtstart;
3126
Meta.RtEnd = rtend;
27+
Meta.Filter = filter;
3228
}
3329

3430
public XicUnit(XicUnit copy)

0 commit comments

Comments
 (0)