Skip to content

Commit 6e84792

Browse files
only centroid segmented scan data if it's profile
1 parent 3145547 commit 6e84792

File tree

3 files changed

+106
-73
lines changed

3 files changed

+106
-73
lines changed

Query/ProxiSpectrumReader.cs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -161,42 +161,40 @@ public List<ProxiSpectrum> Retrieve()
161161
proxiSpectrum.AddAttribute(accession: "MS:10000512", name: "filter string",
162162
value: scanEvent.ToString());
163163

164-
// Check if the scan has a centroid stream
165-
if (scan.HasCentroidStream && (scanEvent.ScanData == ScanDataType.Centroid ||
166-
(scanEvent.ScanData == ScanDataType.Profile &&
167-
!queryParameters.noPeakPicking)))
164+
if (!queryParameters.noPeakPicking)
168165
{
169-
var centroidStream = rawFile.GetCentroidStream(scanNumber, false);
170-
if (scan.CentroidScan.Length > 0)
166+
proxiSpectrum.AddAttribute(accession: "MS:1000525", name: "spectrum representation",
167+
value: "centroid spectrum", valueAccession: "MS:1000127");
168+
169+
// Check if the scan has a centroid stream
170+
if (scan.HasCentroidStream)
171171
{
172-
proxiSpectrum.AddMz(centroidStream.Masses);
173-
proxiSpectrum.AddIntensities(centroidStream.Intensities);
172+
if (scan.CentroidScan.Length > 0)
173+
{
174+
proxiSpectrum.AddMz(scan.CentroidScan.Masses);
175+
proxiSpectrum.AddIntensities(scan.CentroidScan.Intensities);
176+
}
174177
}
175-
}
176-
// Otherwise take the profile data
177-
else
178-
{
179-
// centroid the profile data by default
180-
var segmentedScan = !queryParameters.noPeakPicking ? Scan.ToCentroid(scan).SegmentedScan : scan.SegmentedScan;
181-
182-
proxiSpectrum.AddMz(segmentedScan.Positions);
183-
proxiSpectrum.AddIntensities(segmentedScan.Intensities);
184-
185-
if (scanEvent.ScanData == ScanDataType.Profile)
178+
else // otherwise take the profile data
186179
{
187-
isCentroid = false;
180+
// Get the segmented (low res and profile) scan data
181+
// if the spectrum is profile perform centroiding
182+
var segmentedScan = scanEvent.ScanData == ScanDataType.Profile
183+
? Scan.ToCentroid(scan).SegmentedScan
184+
: scan.SegmentedScan;
185+
186+
proxiSpectrum.AddMz(segmentedScan.Positions);
187+
proxiSpectrum.AddIntensities(segmentedScan.Intensities);
188188
}
189189
}
190-
191-
if (isCentroid)
192-
{
193-
proxiSpectrum.AddAttribute(accession: "MS:1000525", name: "spectrum representation",
194-
value: "centroid spectrum", valueAccession: "MS:1000127");
195-
}
196-
else
190+
else // use the profile data as is
197191
{
198192
proxiSpectrum.AddAttribute(accession: "MS:1000525", name: "spectrum representation",
199193
value: "profile spectrum", valueAccession: "MS:1000128");
194+
195+
// Get the segmented (low res and profile) scan data
196+
proxiSpectrum.AddMz(scan.SegmentedScan.Positions);
197+
proxiSpectrum.AddIntensities(scan.SegmentedScan.Intensities);
200198
}
201199

202200
resultList.Add(proxiSpectrum);

Writer/MgfSpectrumWriter.cs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,38 +123,53 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
123123
// write the filter string
124124
//Writer.WriteLine($"SCANEVENT={scanEvent.ToString()}");
125125

126-
// Check if the scan has a centroid stream
127-
if (scan.HasCentroidStream && (scanEvent.ScanData == ScanDataType.Centroid ||
128-
(scanEvent.ScanData == ScanDataType.Profile &&
129-
!ParseInput.NoPeakPicking)))
126+
if (!ParseInput.NoPeakPicking)
130127
{
131-
var centroidStream = rawFile.GetCentroidStream(scanNumber, false);
132-
if (scan.CentroidScan.Length > 0)
128+
// Check if the scan has a centroid stream
129+
if (scan.HasCentroidStream)
133130
{
134-
for (var i = 0; i < centroidStream.Length; i++)
131+
if (scan.CentroidScan.Length > 0)
132+
{
133+
for (var i = 0; i < scan.CentroidScan.Length; i++)
134+
{
135+
Writer.WriteLine(
136+
scan.CentroidScan.Masses[i].ToString("0.0000000",
137+
CultureInfo.InvariantCulture)
138+
+ " "
139+
+ scan.CentroidScan.Intensities[i].ToString("0.0000000000",
140+
CultureInfo.InvariantCulture));
141+
}
142+
}
143+
}
144+
else // otherwise take the profile data
145+
{
146+
// Get the segmented (low res and profile) scan data
147+
// if the spectrum is profile perform centroiding
148+
var segmentedScan = scanEvent.ScanData == ScanDataType.Profile
149+
? Scan.ToCentroid(scan).SegmentedScan
150+
: scan.SegmentedScan;
151+
152+
for (var i = 0; i < segmentedScan.Positions.Length; i++)
135153
{
136154
Writer.WriteLine(
137-
centroidStream.Masses[i].ToString("0.0000000",
155+
segmentedScan.Positions[i].ToString("0.0000000",
138156
CultureInfo.InvariantCulture)
139157
+ " "
140-
+ centroidStream.Intensities[i].ToString("0.0000000000",
158+
+ segmentedScan.Intensities[i].ToString("0.0000000000",
141159
CultureInfo.InvariantCulture));
142160
}
143161
}
144162
}
145-
// Otherwise take the profile data
146-
else
163+
else // use the profile data as is
147164
{
148-
// centroid the profile data by default
149-
var segmentedScan = !ParseInput.NoPeakPicking ? Scan.ToCentroid(scan).SegmentedScan : scan.SegmentedScan;
150-
151-
for (var i = 0; i < segmentedScan.Positions.Length; i++)
165+
// Get the segmented (low res and profile) scan data
166+
for (var i = 0; i < scan.SegmentedScan.Positions.Length; i++)
152167
{
153168
Writer.WriteLine(
154-
segmentedScan.Positions[i].ToString("0.0000000",
169+
scan.SegmentedScan.Positions[i].ToString("0.0000000",
155170
CultureInfo.InvariantCulture)
156171
+ " "
157-
+ segmentedScan.Intensities[i].ToString("0.0000000000",
172+
+ scan.SegmentedScan.Intensities[i].ToString("0.0000000000",
158173
CultureInfo.InvariantCulture));
159174
}
160175
}

Writer/MzMlSpectrumWriter.cs

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ private List<ChromatogramType> ConstructChromatograms(int firstScanNumber, int l
692692
};
693693
timesBinaryData.encodedLength =
694694
(4 * Math.Ceiling((double) timesBinaryData
695-
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
695+
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
696696
var timesBinaryDataCvParams = new List<CVParamType>
697697
{
698698
new CVParamType
@@ -745,7 +745,7 @@ private List<ChromatogramType> ConstructChromatograms(int firstScanNumber, int l
745745
};
746746
intensitiesBinaryData.encodedLength =
747747
(4 * Math.Ceiling((double) intensitiesBinaryData
748-
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
748+
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
749749
var intensitiesBinaryDataCvParams = new List<CVParamType>
750750
{
751751
new CVParamType
@@ -969,37 +969,57 @@ private SpectrumType ConstructSpectrum(int scanNumber)
969969
double? highestObservedMz = null;
970970
double[] masses = null;
971971
double[] intensities = null;
972-
if (scan.HasCentroidStream && (scanEvent.ScanData == ScanDataType.Centroid ||
973-
(scanEvent.ScanData == ScanDataType.Profile &&
974-
!ParseInput.NoPeakPicking)))
972+
973+
if (!ParseInput.NoPeakPicking)
975974
{
976-
var centroidStream = _rawFile.GetCentroidStream(scanNumber, false);
977-
if (scan.CentroidScan.Length > 0)
975+
spectrumCvParams.Add(new CVParamType
978976
{
979-
spectrumCvParams.Add(new CVParamType
977+
accession = "MS:1000127",
978+
cvRef = "MS",
979+
name = "centroid spectrum",
980+
value = ""
981+
});
982+
983+
// Check if the scan has a centroid stream
984+
if (scan.HasCentroidStream)
985+
{
986+
if (scan.CentroidScan.Length > 0)
980987
{
981-
accession = "MS:1000127",
982-
cvRef = "MS",
983-
name = "centroid spectrum",
984-
value = ""
985-
});
988+
basePeakMass = scan.CentroidScan.BasePeakMass;
989+
basePeakIntensity = scan.CentroidScan.BasePeakIntensity;
990+
lowestObservedMz = scan.CentroidScan.Masses[0];
991+
highestObservedMz = scan.CentroidScan.Masses[scan.CentroidScan.Masses.Length - 1];
992+
masses = scan.CentroidScan.Masses;
993+
intensities = scan.CentroidScan.Intensities;
994+
}
995+
}
996+
else // otherwise take the profile data
997+
{
998+
basePeakMass = scan.ScanStatistics.BasePeakMass;
999+
basePeakIntensity = scan.ScanStatistics.BasePeakIntensity;
9861000

987-
basePeakMass = centroidStream.BasePeakMass;
988-
basePeakIntensity = centroidStream.BasePeakIntensity;
989-
lowestObservedMz = centroidStream.Masses[0];
990-
highestObservedMz = centroidStream.Masses[centroidStream.Masses.Length - 1];
991-
masses = centroidStream.Masses;
992-
intensities = centroidStream.Intensities;
1001+
// Get the segmented (low res and profile) scan data
1002+
// if the spectrum is profile perform centroiding
1003+
var segmentedScan = scanEvent.ScanData == ScanDataType.Profile
1004+
? Scan.ToCentroid(scan).SegmentedScan
1005+
: scan.SegmentedScan;
1006+
1007+
if (segmentedScan.PositionCount > 0)
1008+
{
1009+
lowestObservedMz = segmentedScan.Positions[0];
1010+
highestObservedMz = segmentedScan.Positions[segmentedScan.PositionCount - 1];
1011+
masses = segmentedScan.Positions;
1012+
intensities = segmentedScan.Intensities;
1013+
}
9931014
}
9941015
}
995-
else
1016+
else // use the profile data as is
9961017
{
9971018
basePeakMass = scan.ScanStatistics.BasePeakMass;
9981019
basePeakIntensity = scan.ScanStatistics.BasePeakIntensity;
9991020

1000-
// centroid the profile data by default
1001-
var segmentedScan = !ParseInput.NoPeakPicking ? Scan.ToCentroid(scan).SegmentedScan : scan.SegmentedScan;
1002-
if (segmentedScan.Positions.Length > 0)
1021+
// Get the segmented (low res and profile) scan data
1022+
if (scan.SegmentedScan.Positions.Length > 0)
10031023
{
10041024
switch (scanEvent.ScanData)
10051025
{
@@ -1023,10 +1043,10 @@ private SpectrumType ConstructSpectrum(int scanNumber)
10231043
break;
10241044
}
10251045

1026-
lowestObservedMz = segmentedScan.Positions[0];
1027-
highestObservedMz = segmentedScan.Positions[segmentedScan.Positions.Length - 1];
1028-
masses = segmentedScan.Positions;
1029-
intensities = segmentedScan.Intensities;
1046+
lowestObservedMz = scan.SegmentedScan.Positions[0];
1047+
highestObservedMz = scan.SegmentedScan.Positions[scan.SegmentedScan.Positions.Length - 1];
1048+
masses = scan.SegmentedScan.Positions;
1049+
intensities = scan.SegmentedScan.Intensities;
10301050
}
10311051
}
10321052

@@ -1109,7 +1129,7 @@ private SpectrumType ConstructSpectrum(int scanNumber)
11091129
};
11101130
massesBinaryData.encodedLength =
11111131
(4 * Math.Ceiling((double) massesBinaryData
1112-
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
1132+
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
11131133
var massesBinaryDataCvParams = new List<CVParamType>
11141134
{
11151135
new CVParamType
@@ -1159,7 +1179,7 @@ private SpectrumType ConstructSpectrum(int scanNumber)
11591179
};
11601180
intensitiesBinaryData.encodedLength =
11611181
(4 * Math.Ceiling((double) intensitiesBinaryData
1162-
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
1182+
.binary.Length / 3)).ToString(CultureInfo.InvariantCulture);
11631183
var intensitiesBinaryDataCvParams = new List<CVParamType>
11641184
{
11651185
new CVParamType

0 commit comments

Comments
 (0)