Skip to content

Commit d763546

Browse files
committed
trailerData class
1 parent 6b31ea9 commit d763546

File tree

3 files changed

+142
-4
lines changed

3 files changed

+142
-4
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: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,12 +1142,37 @@ 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));
11461146
int? charge = null;
11471147
double? monoisotopicMz = null;
11481148
double? ionInjectionTime = null;
11491149
double? FAIMSCV = null;
11501150
List<double> SPSMasses = new List<double>();
1151+
1152+
charge = trailerData.AsPositiveInt("Charge State:");
1153+
monoisotopicMz = trailerData.AsDouble("Monoisotopic M/Z:");
1154+
ionInjectionTime = trailerData.AsDouble("Ion Injection Time (ms):");
1155+
if (trailerData.AsBool("FAIMS Voltage On:").GetValueOrDefault(false))
1156+
FAIMSCV = trailerData.AsDouble("FAIMS CV:");
1157+
1158+
//tune version < 3 produced trailer entry like "SPS Mass #", one entry per mass
1159+
foreach (var label in trailerData.MatchKeys(SPSentry))
1160+
{
1161+
var mass = trailerData.AsDouble(label).GetValueOrDefault(0);
1162+
if (mass > 0) SPSMasses.Add((double)mass); //zero means mass does not exist
1163+
}
1164+
1165+
//tune version == 3 produces trailer entry "SPS Masses", comma separated list of masses
1166+
foreach (var label in trailerData.MatchKeys(SPSentry3))
1167+
{
1168+
foreach (var mass in trailerData.Get(label).Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
1169+
{
1170+
SPSMasses.Add(double.Parse(mass));
1171+
}
1172+
1173+
}
1174+
1175+
/*var trailerData = _rawFile.GetTrailerExtraInformation(scanNumber);
11511176
for (var i = 0; i < trailerData.Length; i++)
11521177
{
11531178
if (trailerData.Labels[i] == "Charge State:")
@@ -1192,13 +1217,15 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
11921217
}
11931218
11941219
}
1195-
}
1220+
}*/
11961221

11971222
// Construct and set the scan list element of the spectrum
11981223
var scanListType = ConstructScanList(scanNumber, scan, scanFilter, scanEvent, monoisotopicMz,
11991224
ionInjectionTime);
12001225
spectrum.scanList = scanListType;
12011226

1227+
int? trailerMasterScan;
1228+
12021229
switch (scanFilter.MSOrder)
12031230
{
12041231
case MSOrderType.Ms:
@@ -1211,7 +1238,8 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
12111238
});
12121239

12131240
// Keep track of scan number for precursor reference
1214-
_precursorMs1ScanNumber = scanNumber;
1241+
trailerMasterScan = trailerData.AsInt("Master Scan Number:");
1242+
_precursorMs1ScanNumber = trailerMasterScan.HasValue ? trailerMasterScan.Value : scanNumber;
12151243

12161244
break;
12171245
case MSOrderType.Ms2:
@@ -1232,7 +1260,9 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
12321260
_precursorMs2ScanNumbers.Remove(result.Groups[1].Value);
12331261
}
12341262

1235-
_precursorMs2ScanNumbers.Add(result.Groups[1].Value, scanNumber);
1263+
trailerMasterScan = trailerData.AsInt("Master Scan Number:");
1264+
_precursorMs2ScanNumbers.Add(result.Groups[1].Value,
1265+
trailerMasterScan.HasValue ? trailerMasterScan.Value : scanNumber);
12361266
}
12371267

12381268
// Construct and set the precursor list element of the spectrum

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)