Skip to content

Commit 534accb

Browse files
increased version
removed monoisotopic mass userparam when value is zero changed selected ion mz in mzML to monoisotopic mass where available
1 parent 5adf776 commit 534accb

File tree

4 files changed

+81
-67
lines changed

4 files changed

+81
-67
lines changed

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.5.0")]
36-
[assembly: AssemblyFileVersion("1.1.5.0")]
35+
[assembly: AssemblyVersion("1.1.6.0")]
36+
[assembly: AssemblyFileVersion("1.1.6.0")]
3737

3838
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config")]

Writer/MgfSpectrumWriter.cs

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ public class MgfSpectrumWriter : SpectrumWriter
1515

1616
private const string PositivePolarity = "+";
1717
private const string NegativePolarity = "-";
18-
private const double PrecursorMzDelta = 0.0001;
19-
private const double DefaultIsolationWindowLowerOffset = 1.5;
20-
private const double DefaultIsolationWindowUpperOffset = 2.5;
2118

2219
// Precursor scan number for reference in the precursor element of an MS2 spectrum
2320
private int _precursorScanNumber;
@@ -88,7 +85,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
8885
// trailer extra data list
8986
var trailerData = rawFile.GetTrailerExtraInformation(scanNumber);
9087
int? charge = null;
91-
double? monoisotopicMass = null;
88+
double? monoisotopicMz = null;
9289
double? isolationWidth = null;
9390
for (var i = 0; i < trailerData.Length; i++)
9491
{
@@ -99,7 +96,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
9996

10097
if (trailerData.Labels[i] == "Monoisotopic M/Z:")
10198
{
102-
monoisotopicMass = double.Parse(trailerData.Values[i], NumberStyles.Any,
99+
monoisotopicMz = double.Parse(trailerData.Values[i], NumberStyles.Any,
103100
CultureInfo.CurrentCulture);
104101
}
105102

@@ -112,45 +109,10 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
112109

113110
if (reaction != null)
114111
{
115-
var truePrecursorMass = reaction.PrecursorMass;
116-
117-
// take isolation width from the reaction if no value was found in the trailer data
118-
if (isolationWidth == null || isolationWidth < ZeroDelta)
119-
{
120-
isolationWidth = reaction.IsolationWidth;
121-
}
122-
123-
isolationWidth = isolationWidth / 2;
124-
125-
if (monoisotopicMass != null && monoisotopicMass > ZeroDelta
126-
&& Math.Abs(
127-
reaction.PrecursorMass - monoisotopicMass.Value) >
128-
PrecursorMzDelta)
129-
{
130-
truePrecursorMass = monoisotopicMass.Value;
131-
132-
// check if the monoisotopic mass lies in the precursor mass isolation window
133-
// otherwise take the precursor mass
134-
if (isolationWidth <= 2.0)
135-
{
136-
if ((truePrecursorMass <
137-
(reaction.PrecursorMass - DefaultIsolationWindowLowerOffset * 2)) ||
138-
(truePrecursorMass >
139-
(reaction.PrecursorMass + DefaultIsolationWindowUpperOffset)))
140-
{
141-
truePrecursorMass = reaction.PrecursorMass;
142-
}
143-
}
144-
else if ((truePrecursorMass < (reaction.PrecursorMass - isolationWidth)) ||
145-
(truePrecursorMass > (reaction.PrecursorMass + isolationWidth)))
146-
{
147-
truePrecursorMass = reaction.PrecursorMass;
148-
}
149-
}
112+
var selectedIonMz = CalculateSelectedIonMz(reaction, monoisotopicMz, isolationWidth);
150113

151114
Writer.WriteLine("PEPMASS=" +
152-
truePrecursorMass.ToString("0.0000000",
153-
CultureInfo.InvariantCulture));
115+
selectedIonMz.ToString(CultureInfo.InvariantCulture));
154116
}
155117

156118
// charge
@@ -183,7 +145,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
183145
centroidStream.Masses[i].ToString("0.0000000",
184146
CultureInfo.InvariantCulture)
185147
+ " "
186-
+ centroidStream.Intensities[i].ToString("0.0000000",
148+
+ centroidStream.Intensities[i].ToString("0.0000000000",
187149
CultureInfo.InvariantCulture));
188150
}
189151
}

Writer/MzMlSpectrumWriter.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ private SpectrumType ConstructSpectrum(int scanNumber)
814814
// Trailer extra data list
815815
var trailerData = _rawFile.GetTrailerExtraInformation(scanNumber);
816816
int? charge = null;
817-
double? monoisotopicMass = null;
817+
double? monoisotopicMz = null;
818818
double? ionInjectionTime = null;
819819
double? isolationWidth = null;
820820
for (var i = 0; i < trailerData.Length; i++)
@@ -829,7 +829,7 @@ private SpectrumType ConstructSpectrum(int scanNumber)
829829

830830
if (trailerData.Labels[i] == "Monoisotopic M/Z:")
831831
{
832-
monoisotopicMass = double.Parse(trailerData.Values[i], NumberStyles.Any,
832+
monoisotopicMz = double.Parse(trailerData.Values[i], NumberStyles.Any,
833833
CultureInfo.CurrentCulture);
834834
}
835835

@@ -847,7 +847,7 @@ private SpectrumType ConstructSpectrum(int scanNumber)
847847
}
848848

849849
// Construct and set the scan list element of the spectrum
850-
var scanListType = ConstructScanList(scanNumber, scan, scanFilter, scanEvent, monoisotopicMass,
850+
var scanListType = ConstructScanList(scanNumber, scan, scanFilter, scanEvent, monoisotopicMz,
851851
ionInjectionTime);
852852
spectrum.scanList = scanListType;
853853

@@ -892,7 +892,7 @@ private SpectrumType ConstructSpectrum(int scanNumber)
892892

893893
// Construct and set the precursor list element of the spectrum
894894
var precursorListType =
895-
ConstructPrecursorList(scanEvent, charge, scanFilter.MSOrder, isolationWidth);
895+
ConstructPrecursorList(scanEvent, charge, scanFilter.MSOrder, monoisotopicMz, isolationWidth);
896896
spectrum.precursorList = precursorListType;
897897
break;
898898
case MSOrderType.Ms3:
@@ -903,7 +903,8 @@ private SpectrumType ConstructSpectrum(int scanNumber)
903903
name = "MSn spectrum",
904904
value = ""
905905
});
906-
precursorListType = ConstructPrecursorList(scanEvent, charge, scanFilter.MSOrder, isolationWidth);
906+
precursorListType = ConstructPrecursorList(scanEvent, charge, scanFilter.MSOrder, monoisotopicMz,
907+
isolationWidth);
907908
spectrum.precursorList = precursorListType;
908909
break;
909910
default:
@@ -1191,10 +1192,11 @@ private SpectrumType ConstructSpectrum(int scanNumber)
11911192
/// <param name="scanEvent">the scan event</param>
11921193
/// <param name="charge">the charge</param>
11931194
/// <param name="msLevel">the MS level</param>
1195+
/// <param name="monoisotopicMz">the monoisotopic m/z value</param>
11941196
/// <param name="isolationWidth">the isolation width</param>
11951197
/// <returns>the precursor list</returns>
11961198
private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int? charge, MSOrderType msLevel,
1197-
double? isolationWidth)
1199+
double? monoisotopicMz, double? isolationWidth)
11981200
{
11991201
// Construct the precursor
12001202
var precursorList = new PrecursorListType
@@ -1240,7 +1242,7 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int?
12401242
};
12411243

12421244
IReaction reaction = null;
1243-
var precursorMass = 0.0;
1245+
var precursorMz = 0.0;
12441246
try
12451247
{
12461248
switch (msLevel)
@@ -1253,26 +1255,21 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int?
12531255
break;
12541256
}
12551257

1256-
precursorMass = reaction.PrecursorMass;
1257-
1258-
// take isolation width from the reaction if no value was found in the trailer data
1259-
if (isolationWidth == null || isolationWidth < ZeroDelta)
1260-
{
1261-
isolationWidth = reaction.IsolationWidth;
1262-
}
1258+
precursorMz = reaction.PrecursorMass;
12631259
}
12641260
catch (ArgumentOutOfRangeException exception)
12651261
{
12661262
//do nothing
12671263
}
12681264

12691265
// Selected ion MZ
1266+
var selectedIonMz = CalculateSelectedIonMz(reaction, monoisotopicMz, isolationWidth);
12701267
var ionCvParams = new List<CVParamType>
12711268
{
12721269
new CVParamType
12731270
{
12741271
name = "selected ion m/z",
1275-
value = precursorMass.ToString(CultureInfo.InvariantCulture),
1272+
value = selectedIonMz.ToString(CultureInfo.InvariantCulture),
12761273
accession = "MS:1000744",
12771274
cvRef = "MS",
12781275
unitCvRef = "MS",
@@ -1320,7 +1317,7 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int?
13201317
{
13211318
accession = "MS:1000827",
13221319
name = "isolation window target m/z",
1323-
value = precursorMass.ToString(CultureInfo.InvariantCulture),
1320+
value = precursorMz.ToString(CultureInfo.InvariantCulture),
13241321
cvRef = "MS",
13251322
unitCvRef = "MS",
13261323
unitAccession = "MS:1000040",
@@ -1534,7 +1531,7 @@ private ScanListType ConstructScanList(int scanNumber, Scan scan, IScanFilter sc
15341531
};
15351532

15361533
// Monoisotopic mass
1537-
if (monoisotopicMass.HasValue)
1534+
if (monoisotopicMass.HasValue && monoisotopicMass.Value > ZeroDelta)
15381535
{
15391536
scanType.userParam = new UserParamType[1];
15401537
scanType.userParam[0] = new UserParamType

Writer/SpectrumWriter.cs

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ namespace ThermoRawFileParser.Writer
99
{
1010
public abstract class SpectrumWriter : ISpectrumWriter
1111
{
12-
private const double Tolerance = 0.01;
12+
private const double Tolerance = 0.01;
1313
protected const double ZeroDelta = 0.0001;
14+
private const double PrecursorMzDelta = 0.0001;
15+
private const double DefaultIsolationWindowLowerOffset = 1.5;
16+
private const double DefaultIsolationWindowUpperOffset = 2.5;
1417

1518
/// <summary>
1619
/// The parse input object
@@ -45,21 +48,23 @@ protected void ConfigureWriter(string extension)
4548
var fullExtension = ParseInput.Gzip ? extension + ".gzip" : extension;
4649
if (!ParseInput.Gzip || ParseInput.OutputFormat == OutputFormat.IndexMzML)
4750
{
48-
Writer = File.CreateText(ParseInput.OutputDirectory + "//" + ParseInput.RawFileNameWithoutExtension +
51+
Writer = File.CreateText(ParseInput.OutputDirectory + "//" +
52+
ParseInput.RawFileNameWithoutExtension +
4953
extension);
5054
}
5155
else
5256
{
53-
var fileStream = File.Create(ParseInput.OutputDirectory + "//" + ParseInput.RawFileNameWithoutExtension + fullExtension);
57+
var fileStream = File.Create(ParseInput.OutputDirectory + "//" +
58+
ParseInput.RawFileNameWithoutExtension + fullExtension);
5459
var compress = new GZipStream(fileStream, CompressionMode.Compress);
5560
Writer = new StreamWriter(compress);
56-
}
61+
}
5762
}
5863
else
5964
{
6065
if (!ParseInput.Gzip || ParseInput.OutputFormat == OutputFormat.IndexMzML)
6166
{
62-
Writer = File.CreateText(ParseInput.OutputFile);
67+
Writer = File.CreateText(ParseInput.OutputFile);
6368
}
6469
else
6570
{
@@ -86,6 +91,56 @@ protected static string ConstructSpectrumTitle(int scanNumber)
8691
return "controllerType=0 controllerNumber=1 scan=" + scanNumber;
8792
}
8893

94+
/// <summary>
95+
/// Calculate the selected ion m/z value. This is necessary because the precursor mass found in the reaction
96+
/// isn't always the monoisotopic mass.
97+
/// https://github.com/ProteoWizard/pwiz/blob/master/pwiz/data/vendor_readers/Thermo/SpectrumList_Thermo.cpp#L564-L574
98+
/// </summary>
99+
/// <param name="reaction">the scan event reaction</param>
100+
/// <param name="monoisotopicMz">the monoisotopic m/z value</param>
101+
/// <param name="isolationWidth">the scan event reaction</param>
102+
protected static double CalculateSelectedIonMz(IReaction reaction, double? monoisotopicMz,
103+
double? isolationWidth)
104+
{
105+
var selectedIonMz = reaction.PrecursorMass;
106+
107+
// take the isolation width from the reaction if no value was found in the trailer data
108+
if (isolationWidth == null || isolationWidth < ZeroDelta)
109+
{
110+
isolationWidth = reaction.IsolationWidth;
111+
}
112+
113+
isolationWidth = isolationWidth / 2;
114+
115+
if (monoisotopicMz != null && monoisotopicMz > ZeroDelta
116+
&& Math.Abs(
117+
reaction.PrecursorMass - monoisotopicMz.Value) >
118+
PrecursorMzDelta)
119+
{
120+
selectedIonMz = monoisotopicMz.Value;
121+
122+
// check if the monoisotopic mass lies in the precursor mass isolation window
123+
// otherwise take the precursor mass
124+
if (isolationWidth <= 2.0)
125+
{
126+
if ((selectedIonMz <
127+
(reaction.PrecursorMass - DefaultIsolationWindowLowerOffset * 2)) ||
128+
(selectedIonMz >
129+
(reaction.PrecursorMass + DefaultIsolationWindowUpperOffset)))
130+
{
131+
selectedIonMz = reaction.PrecursorMass;
132+
}
133+
}
134+
else if ((selectedIonMz < (reaction.PrecursorMass - isolationWidth)) ||
135+
(selectedIonMz > (reaction.PrecursorMass + isolationWidth)))
136+
{
137+
selectedIonMz = reaction.PrecursorMass;
138+
}
139+
}
140+
141+
return selectedIonMz;
142+
}
143+
89144
/// <summary>
90145
/// Get the spectrum intensity.
91146
/// </summary>

0 commit comments

Comments
 (0)