Skip to content

Commit 6e133e4

Browse files
authored
Merge pull request #137 from GeorgWa/master
Include Noise and Baseline Data in mzML output
2 parents 7685e26 + f969329 commit 6e133e4

File tree

4 files changed

+194
-1
lines changed

4 files changed

+194
-1
lines changed

MainClass.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ private static void RegularParametersParsing(string[] args)
443443
"Include precursor scan number in MGF file TITLE",
444444
v => parseInput.MgfPrecursor = v != null
445445
},
446+
{
447+
"N|noiseData", "Include noise data in mzML output",
448+
v => parseInput.NoiseData = v != null
449+
},
446450
{
447451
"u:|s3_url:",
448452
"Optional property to write directly the data into S3 Storage.",

ParseInput.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public string RawFilePath
7878

7979
public bool MgfPrecursor { get; set; }
8080

81+
public bool NoiseData { get; set; }
82+
8183
public bool StdOut { get; set; }
8284

8385
private S3Loader S3Loader { get; set; }
@@ -108,6 +110,7 @@ public ParseInput()
108110
MsLevel = AllLevels;
109111
MgfPrecursor = false;
110112
StdOut = false;
113+
NoiseData = false;
111114
}
112115

113116
public ParseInput(string rawFilePath, string rawDirectoryPath, string outputDirectory, OutputFormat outputFormat

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ optional subcommands are xic|query (use [subcommand] -h for more info]):
9090
integers ( 1,2,3 ) and/or intervals ( 1-3 ),
9191
open-end intervals ( 1- ) are allowed
9292
-P, --mgfPrecursor Include precursor scan number in MGF file TITLE
93+
-N, --noiseData Include noise data in mzML output
9394
-u, --s3_url[=VALUE] Optional property to write directly the data into
9495
S3 Storage.
9596
-k, --s3_accesskeyid[=VALUE]

Writer/MzMlSpectrumWriter.cs

Lines changed: 186 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,13 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
349349
}
350350
}
351351

352+
353+
352354
var spectrum = ConstructMSSpectrum(scanNumber);
353355

354356
var level = int.Parse(spectrum.cvParam.Where(p => p.accession == "MS:1000511").First().value);
357+
358+
355359

356360
if (spectrum != null && ParseInput.MsLevel.Contains(level)) //applying MS level filter
357361
{
@@ -1431,6 +1435,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
14311435
{
14321436
basePeakMass = scan.CentroidScan.BasePeakMass;
14331437
basePeakIntensity = scan.CentroidScan.BasePeakIntensity;
1438+
14341439
masses = scan.CentroidScan.Masses;
14351440
intensities = scan.CentroidScan.Intensities;
14361441

@@ -1489,7 +1494,6 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
14891494
masses = scan.SegmentedScan.Positions;
14901495
intensities = scan.SegmentedScan.Intensities;
14911496

1492-
14931497
if (scan.SegmentedScan.Positions.Length > 0)
14941498
{
14951499
lowestObservedMz = scan.SegmentedScan.Positions[0];
@@ -1591,6 +1595,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
15911595
},
15921596
new CVParamType {accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = ""}
15931597
};
1598+
15941599
if (!ParseInput.NoZlibCompression)
15951600
{
15961601
massesBinaryDataCvParams.Add(
@@ -1680,6 +1685,186 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
16801685
binaryData.Add(intensitiesBinaryData);
16811686
}
16821687

1688+
// Include optional noise data
1689+
if (ParseInput.NoiseData)
1690+
{
1691+
double[] baselineData;
1692+
double[] noiseData;
1693+
double[] massData;
1694+
1695+
baselineData = scan.PreferredBaselines;
1696+
noiseData = scan.PreferredNoises;
1697+
massData = scan.PreferredMasses;
1698+
1699+
// Noise Data
1700+
if ((baselineData != null) && (noiseData != null) && (massData != null))
1701+
{
1702+
// Set the spectrum default array length if necessary
1703+
if (spectrum.defaultArrayLength == 0)
1704+
{
1705+
spectrum.defaultArrayLength = noiseData.Length;
1706+
}
1707+
1708+
var baselineBinaryData =
1709+
new BinaryDataArrayType
1710+
{
1711+
binary = ParseInput.NoZlibCompression
1712+
? Get64BitArray(baselineData)
1713+
: GetZLib64BitArray(baselineData)
1714+
};
1715+
baselineBinaryData.encodedLength =
1716+
(4 * Math.Ceiling((double)baselineBinaryData
1717+
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
1718+
1719+
var baselineBinaryDataCvParams = new List<CVParamType>
1720+
{
1721+
new CVParamType
1722+
{
1723+
accession = "MS:1002745",
1724+
name = "sampled noise baseline array",
1725+
cvRef = "MS",
1726+
value = ""
1727+
},
1728+
new CVParamType {accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = ""}
1729+
};
1730+
1731+
if (!ParseInput.NoZlibCompression)
1732+
{
1733+
baselineBinaryDataCvParams.Add(
1734+
new CVParamType
1735+
{
1736+
accession = "MS:1000574",
1737+
name = "zlib compression",
1738+
cvRef = "MS",
1739+
value = ""
1740+
});
1741+
}
1742+
else
1743+
{
1744+
baselineBinaryDataCvParams.Add(
1745+
new CVParamType
1746+
{
1747+
accession = "MS:1000576",
1748+
name = "no compression",
1749+
cvRef = "MS",
1750+
value = ""
1751+
});
1752+
}
1753+
1754+
baselineBinaryData.cvParam = baselineBinaryDataCvParams.ToArray();
1755+
1756+
binaryData.Add(baselineBinaryData);
1757+
1758+
var noiseBinaryData =
1759+
new BinaryDataArrayType
1760+
{
1761+
binary = ParseInput.NoZlibCompression
1762+
? Get64BitArray(noiseData)
1763+
: GetZLib64BitArray(noiseData)
1764+
};
1765+
noiseBinaryData.encodedLength =
1766+
(4 * Math.Ceiling((double)noiseBinaryData
1767+
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
1768+
1769+
var noiseBinaryDataCvParams = new List<CVParamType>
1770+
{
1771+
new CVParamType
1772+
{
1773+
accession = "MS:1002744",
1774+
name = "sampled noise intensity array",
1775+
cvRef = "MS",
1776+
unitCvRef = "MS",
1777+
unitAccession = "MS:1000131",
1778+
unitName = "number of detector counts",
1779+
value = ""
1780+
},
1781+
new CVParamType {accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = ""}
1782+
};
1783+
1784+
1785+
if (!ParseInput.NoZlibCompression)
1786+
{
1787+
noiseBinaryDataCvParams.Add(
1788+
new CVParamType
1789+
{
1790+
accession = "MS:1000574",
1791+
name = "zlib compression",
1792+
cvRef = "MS",
1793+
value = ""
1794+
});
1795+
}
1796+
else
1797+
{
1798+
noiseBinaryDataCvParams.Add(
1799+
new CVParamType
1800+
{
1801+
accession = "MS:1000576",
1802+
name = "no compression",
1803+
cvRef = "MS",
1804+
value = ""
1805+
});
1806+
}
1807+
1808+
noiseBinaryData.cvParam = noiseBinaryDataCvParams.ToArray();
1809+
1810+
binaryData.Add(noiseBinaryData);
1811+
1812+
var massBinaryData =
1813+
new BinaryDataArrayType
1814+
{
1815+
binary = ParseInput.NoZlibCompression
1816+
? Get64BitArray(massData)
1817+
: GetZLib64BitArray(massData)
1818+
};
1819+
massBinaryData.encodedLength =
1820+
(4 * Math.Ceiling((double)massBinaryData
1821+
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
1822+
1823+
var massBinaryDataCvParams = new List<CVParamType>
1824+
{
1825+
new CVParamType
1826+
{
1827+
accession = "MS:1002743",
1828+
name = "sampled noise m/z array",
1829+
cvRef = "MS",
1830+
unitCvRef = "MS",
1831+
unitAccession = "MS:1000040",
1832+
unitName = "m/z",
1833+
value = ""
1834+
},
1835+
new CVParamType {accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = ""}
1836+
};
1837+
1838+
1839+
if (!ParseInput.NoZlibCompression)
1840+
{
1841+
massBinaryDataCvParams.Add(
1842+
new CVParamType
1843+
{
1844+
accession = "MS:1000574",
1845+
name = "zlib compression",
1846+
cvRef = "MS",
1847+
value = ""
1848+
});
1849+
}
1850+
else
1851+
{
1852+
massBinaryDataCvParams.Add(
1853+
new CVParamType
1854+
{
1855+
accession = "MS:1000576",
1856+
name = "no compression",
1857+
cvRef = "MS",
1858+
value = ""
1859+
});
1860+
}
1861+
1862+
massBinaryData.cvParam = massBinaryDataCvParams.ToArray();
1863+
1864+
binaryData.Add(massBinaryData);
1865+
}
1866+
}
1867+
16831868
if (!binaryData.IsNullOrEmpty())
16841869
{
16851870
spectrum.binaryDataArrayList = new BinaryDataArrayListType

0 commit comments

Comments
 (0)