Skip to content

Commit 994a800

Browse files
Merge branch 'mzidentmlrefactoring'
2 parents e79b58d + ebedd98 commit 994a800

11 files changed

Lines changed: 137 additions & 139 deletions

OutputFormat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
{
33
public enum OutputFormat
44
{
5-
Mgf,
6-
Mzml,
5+
MGF,
6+
MzML,
77
IndexMzML,
88
Parquet,
99
MGFNoProfileData,

ParseInput.cs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.ComponentModel;
2-
using System.IO;
3-
using NUnit.Framework.Constraints;
1+
using System.IO;
42
using ThermoRawFileParser.Writer;
53

64
namespace ThermoRawFileParser
@@ -42,23 +40,17 @@ public class ParseInput
4240
/// </summary>
4341
public string RawFileNameWithoutExtension { get; }
4442

45-
public S3Loader S3loader { get; set; }
43+
private S3Loader S3Loader { get; set; }
4644

47-
public string S3AccessKeyId { get; set; }
45+
private string S3AccessKeyId { get; }
4846

49-
public string S3SecretAccessKey { get; set; }
47+
private string S3SecretAccessKey { get; }
5048

51-
public string S3url { get; set; }
49+
private string S3url { get; }
5250

53-
private string bucketName;
54-
private bool ignoreInstrumentErrors;
55-
56-
public bool IgnoreInstrumentErrors
57-
{
58-
get => ignoreInstrumentErrors;
59-
set => ignoreInstrumentErrors = value;
60-
}
51+
public bool IgnoreInstrumentErrors { get; }
6152

53+
private string bucketName;
6254

6355
public ParseInput(string rawFilePath, string outputDirectory, OutputFormat outputFormat, bool gzip,
6456
MetadataFormat outputMetadata, string s3url, string s3AccessKeyId,
@@ -73,20 +65,20 @@ bool ignoreInstrumentErrors
7365
OutputDirectory = outputDirectory;
7466
OutputFormat = outputFormat;
7567
Gzip = gzip;
76-
OutputMetadata = outputMetadata;
68+
OutputMetadata = outputMetadata;
7769
S3url = s3url;
7870
S3AccessKeyId = s3AccessKeyId;
7971
S3SecretAccessKey = s3SecretAccessKey;
8072
this.bucketName = bucketName;
81-
this.ignoreInstrumentErrors = ignoreInstrumentErrors;
73+
IgnoreInstrumentErrors = ignoreInstrumentErrors;
8274

83-
if (S3url != null && S3AccessKeyId != null && S3SecretAccessKey != null)
84-
InitializeS3Bucket(s3url, s3AccessKeyId, s3SecretAccessKey, bucketName);
75+
if (S3url != null && S3AccessKeyId != null && S3SecretAccessKey != null && bucketName != null)
76+
InitializeS3Bucket();
8577
}
8678

87-
private void InitializeS3Bucket(string s3url, string s3AccessKeyId, string s3SecretAccessKey, string bucketName)
79+
private void InitializeS3Bucket()
8880
{
89-
S3loader = new S3Loader(s3url, s3AccessKeyId, s3SecretAccessKey, bucketName);
81+
S3Loader = new S3Loader(S3url, S3AccessKeyId, S3SecretAccessKey, bucketName);
9082
}
9183
}
9284
}

RawFileParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public static void Parse(ParseInput parseInput)
8282
SpectrumWriter spectrumWriter;
8383
switch (parseInput.OutputFormat)
8484
{
85-
case OutputFormat.Mgf:
85+
case OutputFormat.MGF:
8686
case OutputFormat.MGFNoProfileData:
8787
spectrumWriter = new MgfSpectrumWriter(parseInput);
8888
spectrumWriter.Write(rawFile, firstScanNumber, lastScanNumber);
8989
break;
90-
case OutputFormat.Mzml:
90+
case OutputFormat.MzML:
9191
case OutputFormat.IndexMzML:
9292
spectrumWriter = new MzMlSpectrumWriter(parseInput);
9393
spectrumWriter.Write(rawFile, firstScanNumber, lastScanNumber);

ThermoRawFileParserTest/Tests.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
using System;
22
using System.IO;
3-
using System.Security.Cryptography;
43
using System.Xml.Serialization;
54
using IO.Mgf;
6-
using IO.MzML;
75
using NUnit.Framework;
86
using ThermoRawFileParser;
97
using ThermoRawFileParser.Writer.MzML;
8+
using UsefulProteomicsDatabases;
109

1110
namespace ThermoRawFileParserTest
1211
{
1312
[TestFixture]
1413
public class Tests
1514
{
16-
private static readonly log4net.ILog Log =
17-
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
18-
1915
[Test]
2016
public void TestMgf()
2117
{
2218
// Get temp path for writing the test MGF
2319
var tempFilePath = Path.GetTempPath();
2420

2521
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"small.RAW");
26-
var parseInput = new ParseInput(testRawFile, tempFilePath, OutputFormat.Mgf, false, MetadataFormat.NONE,
22+
var parseInput = new ParseInput(testRawFile, tempFilePath, OutputFormat.MGF, false, MetadataFormat.NONE,
2723
null, null, null, null, false);
2824

2925
RawFileParser.Parse(parseInput);
3026

3127
// Do this for the mzLib library issue
3228
var tempFileName = Path.GetTempPath() + "elements.dat";
33-
UsefulProteomicsDatabases.Loaders.LoadElements(tempFileName);
29+
Loaders.LoadElements(tempFileName);
3430

3531
var mgfData = Mgf.LoadAllStaticData(Path.Combine(tempFilePath, "small.mgf"));
3632
Assert.AreEqual(34, mgfData.NumSpectra);
@@ -44,7 +40,7 @@ public void TestMzml()
4440
var tempFilePath = Path.GetTempPath();
4541

4642
var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"small.RAW");
47-
var parseInput = new ParseInput(testRawFile, tempFilePath, OutputFormat.Mzml, false, MetadataFormat.NONE,
43+
var parseInput = new ParseInput(testRawFile, tempFilePath, OutputFormat.MzML, false, MetadataFormat.NONE,
4844
null, null, null, null, false);
4945

5046
RawFileParser.Parse(parseInput);

Writer/Metadata.cs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Collections.ObjectModel;
4-
using ThermoRawFileParser.Writer.MzML;
1+
using System.Collections.Generic;
52

63
namespace ThermoRawFileParser.Writer
74
{
85
public class Metadata
96
{
107
/** The general Path properties contains: RAW path , RAW file version **/
11-
private readonly List<CVTerm> fileProperties = new List<CVTerm>();
128

13-
/** The Instruments properties contains the information of the instrument **/
14-
private readonly List<CVTerm> instrumentProperties = new List<CVTerm>();
9+
/** The Instruments properties contains the information of the instrument **/
1510

1611
/** Scan Settings **/
17-
private readonly List<CVTerm> scanSettings = new List<CVTerm>();
1812

1913
/** MS and MS data including number of MS and MS/MS **/
20-
private readonly List<CVTerm> msData = new List<CVTerm>();
21-
22-
private readonly List<CVTerm> sampleData = new List<CVTerm>();
23-
14+
2415
/**
2516
* Default constructor
2617
*/
@@ -30,59 +21,59 @@ public Metadata(List<CVTerm> fileProperties,
3021
List<CVTerm> instrumentProperties,
3122
List<CVTerm> msData)
3223
{
33-
this.fileProperties = fileProperties;
34-
this.instrumentProperties = instrumentProperties;
35-
this.msData = msData;
24+
FileProperties = fileProperties;
25+
InstrumentProperties = instrumentProperties;
26+
MsData = msData;
3627
}
3728

38-
public List<CVTerm> FileProperties => fileProperties;
29+
public List<CVTerm> FileProperties { get; } = new List<CVTerm>();
3930

40-
public List<CVTerm> InstrumentProperties => instrumentProperties;
31+
public List<CVTerm> InstrumentProperties { get; } = new List<CVTerm>();
4132

42-
public List<CVTerm> MsData => msData;
33+
public List<CVTerm> MsData { get; } = new List<CVTerm>();
4334

44-
public List<CVTerm> SampleData => sampleData;
35+
public List<CVTerm> SampleData { get; } = new List<CVTerm>();
4536

46-
public List<CVTerm> ScanSettings => scanSettings;
37+
public List<CVTerm> ScanSettings { get; } = new List<CVTerm>();
4738

4839
/**
4940
* Add a File property to the fileProperties
5041
*/
5142
public void addFileProperty(CVTerm value)
5243
{
53-
fileProperties.Add(value);
44+
FileProperties.Add(value);
5445
}
5546

5647
public void addInstrumentProperty( CVTerm value)
5748
{
58-
instrumentProperties.Add(value);
49+
InstrumentProperties.Add(value);
5950
}
6051

6152
public void addScanSetting(CVTerm value)
6253
{
63-
scanSettings.Add(value);
54+
ScanSettings.Add(value);
6455
}
6556

6657
public void addScanSetting(ICollection<CVTerm> value)
6758
{
68-
scanSettings.AddRange(value);
59+
ScanSettings.AddRange(value);
6960
}
7061

7162

7263

7364
public void addMSData(CVTerm value)
7465
{
75-
msData.Add(value);
66+
MsData.Add(value);
7667
}
7768

7869
public void addMSData(HashSet<CVTerm> value)
7970
{
80-
msData.AddRange(value);
71+
MsData.AddRange(value);
8172
}
8273

8374
public void addSampleProperty(CVTerm value)
8475
{
85-
sampleData.Add(value);
76+
SampleData.Add(value);
8677
}
8778
}
8879

Writer/MetadataWriter.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Reflection;
5+
using log4net;
46
using Newtonsoft.Json;
57
using ThermoFisher.CommonCore.Data.FilterEnums;
68
using ThermoFisher.CommonCore.Data.Interfaces;
@@ -9,8 +11,8 @@ namespace ThermoRawFileParser.Writer
911
{
1012
public class MetadataWriter
1113
{
12-
private static readonly log4net.ILog Log =
13-
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
14+
private static readonly ILog Log =
15+
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
1416

1517
private readonly string _outputDirectory;
1618
private readonly string _rawFileNameWithoutExtension;
@@ -170,11 +172,11 @@ public void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int lastS
170172
for (var i = 0; i < trailerData.Length; i++)
171173
{
172174
if (trailerData.Labels[i] == "Charge State:")
173-
{ if (Int32.Parse(trailerData.Values[i]) > maxCharge)
174-
maxCharge = Int32.Parse(trailerData.Values[i]);
175+
{ if (int.Parse(trailerData.Values[i]) > maxCharge)
176+
maxCharge = int.Parse(trailerData.Values[i]);
175177

176-
if (Int32.Parse(trailerData.Values[i]) < minCharge)
177-
maxCharge = Int32.Parse(trailerData.Values[i]);
178+
if (int.Parse(trailerData.Values[i]) < minCharge)
179+
maxCharge = int.Parse(trailerData.Values[i]);
178180

179181
}
180182
}

Writer/MgfSpectrumWriter.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System;
2+
using System.Globalization;
3+
using System.Reflection;
4+
using log4net;
25
using ThermoFisher.CommonCore.Data.Business;
36
using ThermoFisher.CommonCore.Data.FilterEnums;
47
using ThermoFisher.CommonCore.Data.Interfaces;
@@ -7,8 +10,8 @@ namespace ThermoRawFileParser.Writer
710
{
811
public class MgfSpectrumWriter : SpectrumWriter
912
{
10-
private static readonly log4net.ILog Log =
11-
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
13+
private static readonly ILog Log =
14+
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
1215

1316
// Precursor scan number for reference in the precursor element of an MS2 spectrum
1417
private int _precursorScanNumber;
@@ -53,17 +56,19 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
5356
Writer.WriteLine("BEGIN IONS");
5457
Writer.WriteLine($"TITLE={ConstructSpectrumTitle(scanNumber)}");
5558
Writer.WriteLine($"SCAN={scanNumber}");
56-
Writer.WriteLine($"RTINSECONDS={time * 60}");
59+
Writer.WriteLine($"RTINSECONDS={(time * 60).ToString(CultureInfo.InvariantCulture)}");
5760
// Get the reaction information for the first precursor
5861
try
5962
{
6063
var reaction = scanEvent.GetReaction(0);
6164
var precursorMass = reaction.PrecursorMass;
62-
var precursorIntensity = 0.0;
65+
Writer.WriteLine("PEPMASS=" +
66+
precursorMass.ToString("0.0000000", CultureInfo.InvariantCulture));
67+
//var precursorIntensity = 0.0;
6368
//GetPrecursorIntensity(rawFile, _precursorScanNumber, precursorMass);
64-
Writer.WriteLine(precursorIntensity != null
65-
? $"PEPMASS={precursorMass:F7} {precursorIntensity}"
66-
: $"PEPMASS={precursorMass:F7}");
69+
//Writer.WriteLine(precursorIntensity != null
70+
// ? $"PEPMASS={precursorMass:F7} {precursorIntensity}"
71+
// : $"PEPMASS={precursorMass:F7}");
6772
}
6873
catch (ArgumentOutOfRangeException exception)
6974
{
@@ -95,7 +100,11 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
95100
for (var i = 0; i < centroidStream.Length; i++)
96101
{
97102
Writer.WriteLine(
98-
$"{centroidStream.Masses[i]:F7} {centroidStream.Intensities[i]:F10}");
103+
centroidStream.Masses[i].ToString("0.0000000",
104+
CultureInfo.InvariantCulture)
105+
+ " "
106+
+ centroidStream.Intensities[i].ToString("0.0000000",
107+
CultureInfo.InvariantCulture));
99108
}
100109
}
101110
}
@@ -111,7 +120,11 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
111120
for (var i = 0; i < segmentedScan.Positions.Length; i++)
112121
{
113122
Writer.WriteLine(
114-
$"{segmentedScan.Positions[i]:F7} {segmentedScan.Intensities[i]:F10}");
123+
segmentedScan.Positions[i].ToString("0.0000000",
124+
CultureInfo.InvariantCulture)
125+
+ " "
126+
+ segmentedScan.Intensities[i].ToString("0.0000000000",
127+
CultureInfo.InvariantCulture));
115128
}
116129
}
117130

0 commit comments

Comments
 (0)