@@ -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