Skip to content

Commit 7b96537

Browse files
profile flag addition
1 parent 37ee978 commit 7b96537

3 files changed

Lines changed: 49 additions & 50 deletions

File tree

MainClass.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static void Main(string[] args)
2626
var verbose = false;
2727
string bucketName = null;
2828
var ignoreInstrumentErrors = false;
29+
var alwaysUseProfileData = false;
2930

3031
var help = false;
3132

@@ -83,6 +84,11 @@ public static void Main(string[] args)
8384
{
8485
"e|ignoreInstrumentErrors", "Ignore missing properties by the instrument.",
8586
v => ignoreInstrumentErrors = v != null
87+
},
88+
{
89+
"p|profile",
90+
"Always use profile data, even though in some profile scans centroided data is available.",
91+
v => alwaysUseProfileData = v != null
8692
}
8793
};
8894

@@ -191,7 +197,7 @@ public static void Main(string[] args)
191197
}
192198

193199
var parseInput = new ParseInput(rawFilePath, outputDirectory, outputFormat, gzip, outputMetadataFormat,
194-
s3url, s3AccessKeyId, s3SecretAccessKey, bucketName, ignoreInstrumentErrors);
200+
s3url, s3AccessKeyId, s3SecretAccessKey, bucketName, ignoreInstrumentErrors, alwaysUseProfileData);
195201
RawFileParser.Parse(parseInput);
196202
}
197203
catch (Exception ex)

ParseInput.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ public class ParseInput
5050

5151
public bool IgnoreInstrumentErrors { get; }
5252

53+
public bool AlwaysUseProfileData { get; }
54+
5355
private string bucketName;
5456

5557
public ParseInput(string rawFilePath, string outputDirectory, OutputFormat outputFormat, bool gzip,
5658
MetadataFormat outputMetadata, string s3url, string s3AccessKeyId,
5759
string s3SecretAccessKey, string bucketName,
58-
bool ignoreInstrumentErrors
60+
bool ignoreInstrumentErrors, bool alwaysUseProfileData
5961
)
6062
{
6163
RawFilePath = rawFilePath;
@@ -71,6 +73,7 @@ bool ignoreInstrumentErrors
7173
S3SecretAccessKey = s3SecretAccessKey;
7274
this.bucketName = bucketName;
7375
IgnoreInstrumentErrors = ignoreInstrumentErrors;
76+
AlwaysUseProfileData = alwaysUseProfileData;
7477

7578
if (S3url != null && S3AccessKeyId != null && S3SecretAccessKey != null && bucketName != null)
7679
InitializeS3Bucket();

Writer/MzMlSpectrumWriter.cs

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -868,14 +868,14 @@ private SpectrumType ConstructSpectrum(int scanNumber)
868868

869869
// Keep track of scan number and isolation m/z for precursor reference
870870
var result = Regex.Match(scanEvent.ToString(), FilterStringIsolationMzPattern);
871-
if (result.Success )
871+
if (result.Success)
872872
{
873873
if (!_precursorMs2ScanNumbers.ContainsKey(result.Groups[1].Value))
874874
{
875875
_precursorMs2ScanNumbers.Add(result.Groups[1].Value, scanNumber);
876876
}
877877
else
878-
{
878+
{
879879
// update the existing value
880880
_precursorMs2ScanNumbers[result.Groups[1].Value] = scanNumber;
881881
}
@@ -885,14 +885,6 @@ private SpectrumType ConstructSpectrum(int scanNumber)
885885
var precursorListType = ConstructPrecursorList(scanEvent, charge, scanFilter.MSOrder);
886886
spectrum.precursorList = precursorListType;
887887
break;
888-
case MSOrderType.Ng:
889-
break;
890-
case MSOrderType.Nl:
891-
break;
892-
case MSOrderType.Par:
893-
break;
894-
case MSOrderType.Any:
895-
break;
896888
case MSOrderType.Ms3:
897889
spectrumCvParams.Add(new CVParamType
898890
{
@@ -904,20 +896,6 @@ private SpectrumType ConstructSpectrum(int scanNumber)
904896
precursorListType = ConstructPrecursorList(scanEvent, charge, scanFilter.MSOrder);
905897
spectrum.precursorList = precursorListType;
906898
break;
907-
case MSOrderType.Ms4:
908-
break;
909-
case MSOrderType.Ms5:
910-
break;
911-
case MSOrderType.Ms6:
912-
break;
913-
case MSOrderType.Ms7:
914-
break;
915-
case MSOrderType.Ms8:
916-
break;
917-
case MSOrderType.Ms9:
918-
break;
919-
case MSOrderType.Ms10:
920-
break;
921899
default:
922900
throw new ArgumentOutOfRangeException();
923901
}
@@ -958,15 +936,41 @@ private SpectrumType ConstructSpectrum(int scanNumber)
958936
value = scan.ScanStatistics.TIC.ToString(CultureInfo.InvariantCulture),
959937
cvRef = "MS"
960938
});
939+
940+
// Scan type, centroid or profile
941+
switch (scanEvent.ScanData)
942+
{
943+
case ScanDataType.Centroid:
944+
spectrumCvParams.Add(new CVParamType
945+
{
946+
accession = "MS:1000127",
947+
cvRef = "MS",
948+
name = "centroid spectrum",
949+
value = ""
950+
});
951+
break;
952+
case ScanDataType.Profile:
953+
spectrumCvParams.Add(new CVParamType
954+
{
955+
accession = "MS:1000128",
956+
cvRef = "MS",
957+
name = "profile spectrum",
958+
value = ""
959+
});
960+
break;
961+
}
961962

962963
double? basePeakMass = null;
963964
double? basePeakIntensity = null;
964965
double? lowestObservedMz = null;
965966
double? highestObservedMz = null;
966967
double[] masses = null;
967968
double[] intensities = null;
968-
if (scan.HasCentroidStream)
969-
{
969+
if (scan.HasCentroidStream){
970+
// if (scan.HasCentroidStream && (scanEvent.ScanData == ScanDataType.Centroid ||
971+
// (scanEvent.ScanData == ScanDataType.Profile &&
972+
// !ParseInput.AlwaysUseProfileData)))
973+
// {
970974
var centroidStream = _rawFile.GetCentroidStream(scanNumber, false);
971975
if (scan.CentroidScan.Length > 0)
972976
{
@@ -976,16 +980,6 @@ private SpectrumType ConstructSpectrum(int scanNumber)
976980
highestObservedMz = centroidStream.Masses[centroidStream.Masses.Length - 1];
977981
masses = centroidStream.Masses;
978982
intensities = centroidStream.Intensities;
979-
980-
// Note that although the scan data type is profile,
981-
// centroid data might be available
982-
spectrumCvParams.Add(new CVParamType
983-
{
984-
accession = "MS:1000127",
985-
cvRef = "MS",
986-
name = "centroid spectrum",
987-
value = ""
988-
});
989983
}
990984
}
991985
else
@@ -1003,15 +997,7 @@ private SpectrumType ConstructSpectrum(int scanNumber)
1003997
lowestObservedMz = segmentedScan.Positions[0];
1004998
highestObservedMz = segmentedScan.Positions[segmentedScan.Positions.Length - 1];
1005999
masses = segmentedScan.Positions;
1006-
intensities = segmentedScan.Intensities;
1007-
1008-
spectrumCvParams.Add(new CVParamType
1009-
{
1010-
accession = "MS:1000128",
1011-
cvRef = "MS",
1012-
name = "profile spectrum",
1013-
value = ""
1014-
});
1000+
intensities = segmentedScan.Intensities;
10151001
}
10161002
}
10171003

@@ -1213,15 +1199,19 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int?
12131199
spectrumRef = ConstructSpectrumTitle(_precursorMs1ScanNumber);
12141200
break;
12151201
case MSOrderType.Ms3:
1216-
var precursorMs2ScanNumber = _precursorMs2ScanNumbers.Keys.FirstOrDefault(isolationMz => scanEvent.ToString().Contains(isolationMz));
1202+
var precursorMs2ScanNumber =
1203+
_precursorMs2ScanNumbers.Keys.FirstOrDefault(isolationMz =>
1204+
scanEvent.ToString().Contains(isolationMz));
12171205
if (!precursorMs2ScanNumber.IsNullOrEmpty())
12181206
{
12191207
spectrumRef = ConstructSpectrumTitle(_precursorMs2ScanNumbers[precursorMs2ScanNumber]);
12201208
}
12211209
else
12221210
{
1223-
throw new InvalidOperationException("Couldn't find a MS2 precursor scan for MS3 scan " + scanEvent.ToString());
1224-
}
1211+
throw new InvalidOperationException("Couldn't find a MS2 precursor scan for MS3 scan " +
1212+
scanEvent.ToString());
1213+
}
1214+
12251215
break;
12261216
}
12271217

0 commit comments

Comments
 (0)