Skip to content

Commit 8b9d701

Browse files
committed
Handling missing trailer
1 parent c293d4a commit 8b9d701

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

Writer/MgfSpectrumWriter.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,18 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
108108
$"RTINSECONDS={(retentionTime * 60).ToString(CultureInfo.InvariantCulture)}");
109109

110110
// Trailer extra data list
111-
var trailerData = new ScanTrailer(rawFile.GetTrailerExtraInformation(scanNumber));
111+
ScanTrailer trailerData;
112+
113+
try
114+
{
115+
trailerData = new ScanTrailer(rawFile.GetTrailerExtraInformation(scanNumber));
116+
}
117+
catch (Exception ex)
118+
{
119+
Log.WarnFormat("Cannot load trailer infromation for scan {0} due to following exception\n{1}", scanNumber, ex.Message);
120+
trailerData = new ScanTrailer();
121+
}
122+
112123
int? charge = trailerData.AsPositiveInt("Charge State:");
113124
double? monoisotopicMz = trailerData.AsDouble("Monoisotopic M/Z:");
114125
double? isolationWidth =

Writer/MzMlSpectrumWriter.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,17 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
11991199
};
12001200

12011201
// Trailer extra data list
1202-
var trailerData = new ScanTrailer(_rawFile.GetTrailerExtraInformation(scanNumber));
1202+
ScanTrailer trailerData;
1203+
1204+
try
1205+
{
1206+
trailerData = new ScanTrailer(_rawFile.GetTrailerExtraInformation(scanNumber));
1207+
}
1208+
catch (Exception ex)
1209+
{
1210+
Log.WarnFormat("Cannot load trailer infromation for scan {0} due to following exception\n{1}", scanNumber, ex.Message);
1211+
trailerData = new ScanTrailer();
1212+
}
12031213

12041214
int? charge = trailerData.AsPositiveInt("Charge State:");
12051215
double? monoisotopicMz = trailerData.AsDouble("Monoisotopic M/Z:");

Writer/ScanTrailer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public ScanTrailer(LogEntry trailerData)
3535
}
3636
}
3737

38+
public ScanTrailer()
39+
{
40+
data = new Dictionary<string, string>();
41+
}
42+
3843
/// <summary>
3944
/// Try returning selected trailer element as boolean value,
4045
/// if the element does not exist or cannot be converted to boolean return null

0 commit comments

Comments
 (0)