Skip to content

Commit 2d22606

Browse files
committed
Use trailer precursor scan if possible + docstrings for ScanTrailer
1 parent ddb5c82 commit 2d22606

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

Writer/MzMlSpectrumWriter.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,9 +1170,9 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
11701170
//tune version == 3
11711171
if (trailerData.Has("SPS Masses:"))
11721172
{
1173-
foreach (var label in trailerData.MatchKeys(SPSentry3))
1173+
foreach (var labelvalue in trailerData.MatchValues(SPSentry3))
11741174
{
1175-
foreach (var mass in trailerData.Get(label).Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
1175+
foreach (var mass in labelvalue.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
11761176
{
11771177
SPSMasses.Add(double.Parse(mass));
11781178
}
@@ -1270,6 +1270,10 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
12701270
value = ""
12711271
});
12721272

1273+
//update precursor scan if it is provided in trailer data
1274+
var trailerMasterScan = trailerData.AsPositiveInt("Master Scan Number:");
1275+
if (trailerMasterScan.HasValue) _precursorMs1ScanNumber = trailerMasterScan.Value;
1276+
12731277
// Keep track of scan number and isolation m/z for precursor reference
12741278
var result = FilterStringIsolationMzPattern.Match(scanEvent.ToString());
12751279
if (result.Success)

Writer/ScanTrailer.cs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
4-
using System.Text;
53
using System.Text.RegularExpressions;
6-
using System.Threading.Tasks;
74
using ThermoFisher.CommonCore.Data.Business;
85

96
namespace ThermoRawFileParser.Writer
@@ -16,7 +13,7 @@ public class ScanTrailer
1613

1714
public string[] Values { get => data.Values.ToArray(); }
1815

19-
private Dictionary<string, string> data;
16+
private readonly Dictionary<string, string> data;
2017

2118
public ScanTrailer(LogEntry trailerData)
2219
{
@@ -28,6 +25,11 @@ public ScanTrailer(LogEntry trailerData)
2825
}
2926
}
3027

28+
/// <summary>
29+
/// Try returning selected trailer element as boolean value,
30+
/// if the element does not exist or cannot be converted to boolean return null
31+
/// </summary>
32+
/// <param name="key">name of the element</param>
3133
public bool? AsBool(string key)
3234
{
3335
if(data.ContainsKey(key))
@@ -48,6 +50,11 @@ public ScanTrailer(LogEntry trailerData)
4850
return null;
4951
}
5052

53+
/// <summary>
54+
/// Try returning selected trailer element as double value,
55+
/// if the element does not exist or cannot be converted to double return null
56+
/// </summary>
57+
/// <param name="key">name of the element</param>
5158
public double? AsDouble(string key)
5259
{
5360
if (data.ContainsKey(key))
@@ -57,6 +64,11 @@ public ScanTrailer(LogEntry trailerData)
5764
return null;
5865
}
5966

67+
/// <summary>
68+
/// Try returning selected trailer element as integer value,
69+
/// if the element does not exist or cannot be converted to integer return null
70+
/// </summary>
71+
/// <param name="key">name of the element</param>
6072
public int? AsInt(string key)
6173
{
6274
if (data.ContainsKey(key))
@@ -66,6 +78,11 @@ public ScanTrailer(LogEntry trailerData)
6678
return null;
6779
}
6880

81+
/// <summary>
82+
/// Try returning selected trailer element as strictly positive (non zero) integer value,
83+
/// if the element does not exist or cannot be converted to strictly positive integer return null
84+
/// </summary>
85+
/// <param name="key">name of the element</param>
6986
public int? AsPositiveInt(string key)
7087
{
7188
int? value = AsInt(key);
@@ -75,11 +92,21 @@ public ScanTrailer(LogEntry trailerData)
7592

7693
}
7794

95+
/// <summary>
96+
/// Try returning selected trailer element as string,
97+
/// alias to `Get`
98+
/// </summary>
99+
/// <param name="key">name of the element</param>
78100
public string AsString(string key)
79101
{
80102
return Get(key);
81103
}
82104

105+
/// <summary>
106+
/// Try getting selected trailer element by name,
107+
/// if the element does not exist return null
108+
/// </summary>
109+
/// <param name="key">name of the element</param>
83110
public string Get(string key)
84111
{
85112
if (data.ContainsKey(key))
@@ -89,16 +116,28 @@ public string Get(string key)
89116
return null;
90117
}
91118

119+
/// <summary>
120+
/// Check if selected trailer element exists
121+
/// </summary>
122+
/// <param name="key">name of the element</param>
92123
public bool Has(string key)
93124
{
94125
return data.ContainsKey(key);
95126
}
96127

128+
/// <summary>
129+
/// Return iterator over trailer element names matching regex
130+
/// </summary>
131+
/// <param name="regex">compiled regex object</param>
97132
public IEnumerable<string> MatchKeys(Regex regex)
98133
{
99134
return data.Keys.Where(k => regex.IsMatch(k));
100135
}
101136

137+
/// <summary>
138+
/// Return iterator over trailer element values which names are matching regex
139+
/// </summary>
140+
/// <param name="regex">compiled regex object</param>
102141
public IEnumerable<string> MatchValues(Regex regex)
103142
{
104143
return data.Where(item => regex.IsMatch(item.Key)).Select(item => item.Value);

0 commit comments

Comments
 (0)