Skip to content

Commit ddb5c82

Browse files
committed
ScanTrailer as object
1 parent ae7b0b0 commit ddb5c82

File tree

3 files changed

+150
-3
lines changed

3 files changed

+150
-3
lines changed

ThermoRawFileParser.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
<Compile Include="RawFileParser.cs" />
156156
<Compile Include="Util\LimitedSizeDictionary.cs" />
157157
<Compile Include="Util\Peptide.cs" />
158+
<Compile Include="Writer\ScanTrailer.cs" />
158159
<Compile Include="XIC\JSONInputUnit.cs" />
159160
<Compile Include="XIC\JSONParser.cs" />
160161
<Compile Include="XIC\XicData.cs" />

Writer/MzMlSpectrumWriter.cs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class MzMlSpectrumWriter : SpectrumWriter
3131

3232
//tune version < 3 produces multiple trailer entry like "SPS Mass [number]"
3333
private readonly Regex SPSentry = new Regex(@"SPS Mass\s+\d+:");
34-
//tune version == 3 produces trailer entry "SPS Masses/Continued"
34+
//tune version == 3 produces trailer entry "SPS Masses (Continued)"
3535
private readonly Regex SPSentry3 = new Regex(@"SPS Masses(?:\s+Continued)?:");
3636

3737
private IRawDataPlus _rawFile;
@@ -1142,7 +1142,46 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
11421142
};
11431143

11441144
// Trailer extra data list
1145-
var trailerData = _rawFile.GetTrailerExtraInformation(scanNumber);
1145+
var trailerData = new ScanTrailer(_rawFile.GetTrailerExtraInformation(scanNumber));
1146+
int? charge;
1147+
double? monoisotopicMz;
1148+
double? ionInjectionTime;
1149+
double? isolationWidth;
1150+
double? FAIMSCV = null;
1151+
List<double> SPSMasses = new List<double>();
1152+
1153+
charge = trailerData.AsPositiveInt("Charge State:");
1154+
monoisotopicMz = trailerData.AsDouble("Monoisotopic M/Z:");
1155+
ionInjectionTime = trailerData.AsDouble("Ion Injection Time (ms):");
1156+
isolationWidth = trailerData.AsDouble("MS" + (int)scanFilter.MSOrder + " Isolation Width:");
1157+
if (trailerData.AsBool("FAIMS Voltage On:").GetValueOrDefault(false))
1158+
FAIMSCV = trailerData.AsDouble("FAIMS CV:");
1159+
1160+
//tune version < 3
1161+
if (trailerData.Has("SPS Mass 1:"))
1162+
{
1163+
foreach (var label in trailerData.MatchKeys(SPSentry))
1164+
{
1165+
var mass = trailerData.AsDouble(label).GetValueOrDefault(0);
1166+
if (mass > 0) SPSMasses.Add((double)mass); //zero means mass does not exist
1167+
}
1168+
}
1169+
1170+
//tune version == 3
1171+
if (trailerData.Has("SPS Masses:"))
1172+
{
1173+
foreach (var label in trailerData.MatchKeys(SPSentry3))
1174+
{
1175+
foreach (var mass in trailerData.Get(label).Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
1176+
{
1177+
SPSMasses.Add(double.Parse(mass));
1178+
}
1179+
1180+
}
1181+
}
1182+
1183+
//Older iterative version that works with trailer directly, can be removed if the new object version is better
1184+
/*var trailerData = _rawFile.GetTrailerExtraInformation(scanNumber);
11461185
int? charge = null;
11471186
double? monoisotopicMz = null;
11481187
double? ionInjectionTime = null;
@@ -1200,7 +1239,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
12001239
}
12011240
12021241
}
1203-
}
1242+
}*/
12041243

12051244
// Construct and set the scan list element of the spectrum
12061245
var scanListType = ConstructScanList(scanNumber, scan, scanFilter, scanEvent, monoisotopicMz,

Writer/ScanTrailer.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.RegularExpressions;
6+
using System.Threading.Tasks;
7+
using ThermoFisher.CommonCore.Data.Business;
8+
9+
namespace ThermoRawFileParser.Writer
10+
{
11+
public class ScanTrailer
12+
{
13+
public int Length { get => data.Count; }
14+
15+
public string[] Labels { get => data.Keys.ToArray(); }
16+
17+
public string[] Values { get => data.Values.ToArray(); }
18+
19+
private Dictionary<string, string> data;
20+
21+
public ScanTrailer(LogEntry trailerData)
22+
{
23+
data = new Dictionary<string, string>();
24+
25+
for (int i = 0; i < trailerData.Length; i++)
26+
{
27+
data[trailerData.Labels[i]] = trailerData.Values[i].Trim();
28+
}
29+
}
30+
31+
public bool? AsBool(string key)
32+
{
33+
if(data.ContainsKey(key))
34+
{
35+
var stringValue = data[key].ToLower();
36+
37+
switch (stringValue)
38+
{
39+
case "on":
40+
case "true":
41+
case "yes":
42+
return true;
43+
default:
44+
return false;
45+
}
46+
}
47+
48+
return null;
49+
}
50+
51+
public double? AsDouble(string key)
52+
{
53+
if (data.ContainsKey(key))
54+
{
55+
if (double.TryParse(data[key], out var result)) return result;
56+
}
57+
return null;
58+
}
59+
60+
public int? AsInt(string key)
61+
{
62+
if (data.ContainsKey(key))
63+
{
64+
if (int.TryParse(data[key], out var result)) return result;
65+
}
66+
return null;
67+
}
68+
69+
public int? AsPositiveInt(string key)
70+
{
71+
int? value = AsInt(key);
72+
73+
if (value != null && value > 0) return value;
74+
else return null;
75+
76+
}
77+
78+
public string AsString(string key)
79+
{
80+
return Get(key);
81+
}
82+
83+
public string Get(string key)
84+
{
85+
if (data.ContainsKey(key))
86+
{
87+
return data[key];
88+
}
89+
return null;
90+
}
91+
92+
public bool Has(string key)
93+
{
94+
return data.ContainsKey(key);
95+
}
96+
97+
public IEnumerable<string> MatchKeys(Regex regex)
98+
{
99+
return data.Keys.Where(k => regex.IsMatch(k));
100+
}
101+
102+
public IEnumerable<string> MatchValues(Regex regex)
103+
{
104+
return data.Where(item => regex.IsMatch(item.Key)).Select(item => item.Value);
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)