Skip to content

Commit e059d0a

Browse files
committed
Merge branch '1.4.0'
2 parents 410ff00 + ccecc0e commit e059d0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+87870
-376
lines changed

MainClass.cs

Lines changed: 51 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class MainClass
1919
private static readonly ILog Log =
2020
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
2121

22-
public const string Version = "1.3.4";
22+
public const string Version = "1.4.0";
2323

2424
public static void Main(string[] args)
2525
{
@@ -390,11 +390,11 @@ private static void RegularParametersParsing(string[] args)
390390
},
391391
{
392392
"f=|format=",
393-
"The spectra output format: 0 for MGF, 1 for mzML, 2 for indexed mzML, 3 for Parquet. Defaults to indexed mzML if no format is specified.",
393+
"The spectra output format: 0 for MGF, 1 for mzML, 2 for indexed mzML, 3 for Parquet; both numeric and text (case insensitive) value recognized. Defaults to indexed mzML if no format is specified.",
394394
v => outputFormatString = v
395395
},
396396
{
397-
"m=|metadata=", "The metadata output format: 0 for JSON, 1 for TXT.",
397+
"m=|metadata=", "The metadata output format: 0 for JSON, 1 for TXT; both numeric and text (case insensitive) value recognized",
398398
v => metadataFormatString = v
399399
},
400400
{
@@ -422,15 +422,15 @@ private static void RegularParametersParsing(string[] args)
422422
v => parseInput.AllDetectors = v != null
423423
},
424424
{
425-
"l=|logging=", "Optional logging level: 0 for silent, 1 for verbose.",
425+
"l=|logging=", "Optional logging level: 0 for silent, 1 for verbose; both numeric and text (case insensitive) value recognized.",
426426
v => logFormatString = v
427427
},
428428
{
429429
"e|ignoreInstrumentErrors", "Ignore missing properties by the instrument.",
430430
v => parseInput.IgnoreInstrumentErrors = v != null
431431
},
432432
{
433-
"x|includeExceptionData", "Include reference and exception data",
433+
"x|excludeExceptionData", "Exclude reference and exception data",
434434
v => parseInput.ExData = v != null
435435
},
436436
{
@@ -585,54 +585,12 @@ private static void RegularParametersParsing(string[] args)
585585

586586
if (outputFormatString != null)
587587
{
588-
int outPutFormatInt;
589-
try
590-
{
591-
outPutFormatInt = int.Parse(outputFormatString);
592-
}
593-
catch (FormatException)
594-
{
595-
throw new OptionException(
596-
"unknown output format value (0 for MGF, 1 for mzML, 2 for indexed mzML, 3 for Parquet)",
597-
"-f, --format");
598-
}
599-
600-
if (Enum.IsDefined(typeof(OutputFormat), outPutFormatInt) &&
601-
((OutputFormat) outPutFormatInt) != OutputFormat.NONE)
602-
{
603-
parseInput.OutputFormat = (OutputFormat) outPutFormatInt;
604-
}
605-
else
606-
{
607-
throw new OptionException(
608-
"unknown output format value (0 for MGF, 1 for mzML, 2 for indexed mzML, 3 for Parquet)",
609-
"-f, --format");
610-
}
588+
parseInput.OutputFormat = (OutputFormat)ParseToEnum(typeof(OutputFormat), outputFormatString, "-f, --format");
611589
}
612590

613591
if (metadataFormatString != null)
614592
{
615-
int metadataInt;
616-
try
617-
{
618-
metadataInt = int.Parse(metadataFormatString);
619-
}
620-
catch (FormatException)
621-
{
622-
throw new OptionException("unknown metadata format value (0 for JSON, 1 for TXT)",
623-
"-m, --metadata");
624-
}
625-
626-
if (Enum.IsDefined(typeof(MetadataFormat), metadataInt) &&
627-
((MetadataFormat) metadataInt) != MetadataFormat.NONE)
628-
{
629-
parseInput.MetadataFormat = (MetadataFormat) metadataInt;
630-
}
631-
else
632-
{
633-
throw new OptionException("unknown metadata format value (0 for JSON, 1 for TXT)",
634-
"-m, --metadata");
635-
}
593+
parseInput.MetadataFormat = (MetadataFormat)ParseToEnum(typeof(MetadataFormat), metadataFormatString, "-m, --metadata");
636594
}
637595

638596
if (parseInput.MetadataOutputFile != null && Directory.Exists(parseInput.MetadataOutputFile))
@@ -657,29 +615,7 @@ private static void RegularParametersParsing(string[] args)
657615

658616
if (logFormatString != null)
659617
{
660-
int logFormatInt;
661-
try
662-
{
663-
logFormatInt = int.Parse(logFormatString);
664-
}
665-
catch (FormatException)
666-
{
667-
throw new OptionException("unknown log format value (0 for silent, 1 for verbose)",
668-
"-l, --logging");
669-
}
670-
671-
if (Enum.IsDefined(typeof(LogFormat), logFormatInt))
672-
{
673-
if ((LogFormat) logFormatInt != LogFormat.NONE)
674-
{
675-
parseInput.LogFormat = (LogFormat) logFormatInt;
676-
}
677-
}
678-
else
679-
{
680-
throw new OptionException("unknown log format value (0 for silent, 1 for verbose)",
681-
"-l, --logging");
682-
}
618+
parseInput.LogFormat = (LogFormat)ParseToEnum(typeof(LogFormat), logFormatString, "-l, --logging");
683619
}
684620

685621
if (parseInput.StdOut)
@@ -796,6 +732,49 @@ private static void ShowHelp(string message, OptionException optionException, Op
796732
Environment.Exit(-1);
797733
}
798734

735+
private static string GetValidEnumLevels(Type enumType)
736+
{
737+
List<string> output = new List<string>();
738+
foreach (int v in Enum.GetValues(enumType))
739+
{
740+
output.Add(String.Format("{0} ({1})", Enum.GetName(enumType, v), v));
741+
}
742+
743+
return String.Join("\n", output);
744+
}
745+
746+
private static int ParseToEnum(Type enumType, string formatString, string keyName)
747+
{
748+
if (int.TryParse(formatString, out var formatInt)) //can be parsed as int
749+
{
750+
if (Enum.IsDefined(enumType, formatInt))
751+
{
752+
return formatInt;
753+
}
754+
else
755+
{
756+
throw new OptionException(
757+
String.Format("unknown format value, the following values recognized (case insensitive)\n{0}", GetValidEnumLevels(enumType)),
758+
keyName);
759+
}
760+
761+
}
762+
else //try parse as a string
763+
{
764+
try
765+
{
766+
return (int)Enum.Parse(enumType, formatString, true);
767+
}
768+
769+
catch (Exception)
770+
{
771+
throw new OptionException(
772+
String.Format("unknown format value, the following values recognized (case insensitive)\n{0}", GetValidEnumLevels(enumType)),
773+
keyName);
774+
}
775+
}
776+
}
777+
799778
private static HashSet<int> ParseMsLevel(string inputString)
800779
{
801780
HashSet<int> result = new HashSet<int>();

RawFileParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private static void ProcessFile(ParseInput parseInput)
112112
// selected instrument to the MS instrument, first instance of it
113113
rawFile.SelectInstrument(Device.MS, 1);
114114

115-
rawFile.IncludeReferenceAndExceptionData = parseInput.ExData;
115+
rawFile.IncludeReferenceAndExceptionData = !parseInput.ExData;
116116

117117
// Get the first and last scan from the RAW file
118118
var firstScanNumber = rawFile.RunHeaderEx.FirstSpectrum;

ThermoRawFileParser.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="packages\NUnit3TestAdapter.4.1.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('packages\NUnit3TestAdapter.4.1.0\build\net35\NUnit3TestAdapter.props')" />
34
<Import Project="packages\NUnit.3.13.1\build\NUnit.props" Condition="Exists('packages\NUnit.3.13.1\build\NUnit.props')" />
45
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
56
<PropertyGroup>
@@ -14,6 +15,8 @@
1415
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1516
<FileAlignment>512</FileAlignment>
1617
<LangVersion>7.2</LangVersion>
18+
<NuGetPackageImportStamp>
19+
</NuGetPackageImportStamp>
1720
</PropertyGroup>
1821
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1922
<PlatformTarget>x64</PlatformTarget>
@@ -194,7 +197,9 @@
194197
<Compile Include="RawFileParserException.cs" />
195198
<Compile Include="RawFileParser.cs" />
196199
<Compile Include="Util\LimitedSizeDictionary.cs" />
200+
<Compile Include="Util\MZArray.cs" />
197201
<Compile Include="Util\Peptide.cs" />
202+
<Compile Include="Writer\PrecursorInfo.cs" />
198203
<Compile Include="Writer\ScanTrailer.cs" />
199204
<Compile Include="XIC\JSONInputUnit.cs" />
200205
<Compile Include="XIC\JSONParser.cs" />
@@ -242,6 +247,7 @@
242247
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
243248
</PropertyGroup>
244249
<Error Condition="!Exists('packages\NUnit.3.13.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\NUnit.3.13.1\build\NUnit.props'))" />
250+
<Error Condition="!Exists('packages\NUnit3TestAdapter.4.1.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\NUnit3TestAdapter.4.1.0\build\net35\NUnit3TestAdapter.props'))" />
245251
</Target>
246252
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
247253
Other similar extension points exist, see Microsoft.Common.targets.
@@ -250,4 +256,4 @@
250256
<Target Name="AfterBuild">
251257
</Target>
252258
-->
253-
</Project>
259+
</Project>

ThermoRawFileParserTest/ThermoRawFileParserTest.csproj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\NUnit.3.13.1\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.13.1\build\NUnit.props')" />
3+
<Import Project="..\packages\NUnit.3.13.2\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.13.2\build\NUnit.props')" />
4+
<Import Project="..\packages\NUnit3TestAdapter.4.1.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.4.1.0\build\net35\NUnit3TestAdapter.props')" />
45
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
56
<PropertyGroup>
67
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -14,9 +15,11 @@
1415
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1516
<FileAlignment>512</FileAlignment>
1617
<LangVersion>7.2</LangVersion>
18+
<NuGetPackageImportStamp>
19+
</NuGetPackageImportStamp>
1720
</PropertyGroup>
1821
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19-
<PlatformTarget>AnyCPU</PlatformTarget>
22+
<PlatformTarget>x64</PlatformTarget>
2023
<DebugSymbols>true</DebugSymbols>
2124
<DebugType>full</DebugType>
2225
<Optimize>false</Optimize>
@@ -108,9 +111,8 @@
108111
<HintPath>..\packages\NJsonSchema.10.4.0\lib\net45\NJsonSchema.dll</HintPath>
109112
<Private>True</Private>
110113
</Reference>
111-
<Reference Include="nunit.framework, Version=3.13.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb">
112-
<HintPath>..\packages\NUnit.3.13.1\lib\net45\nunit.framework.dll</HintPath>
113-
<Private>True</Private>
114+
<Reference Include="nunit.framework, Version=3.13.2.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
115+
<HintPath>..\packages\NUnit.3.13.2\lib\net45\nunit.framework.dll</HintPath>
114116
</Reference>
115117
<Reference Include="OpenMcdf, Version=2.2.1.9, Culture=neutral, PublicKeyToken=fdbb1629d7c00800, processorArchitecture=MSIL">
116118
<HintPath>..\packages\OpenMcdf.2.2.1.9\lib\net40\OpenMcdf.dll</HintPath>
@@ -229,8 +231,9 @@
229231
<PropertyGroup>
230232
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
231233
</PropertyGroup>
232-
<Error Condition="!Exists('..\packages\NUnit.3.13.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.13.1\build\NUnit.props'))" />
233234
<Error Condition="!Exists('..\packages\mzLib.1.0.450\build\net471\mzLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\mzLib.1.0.450\build\net471\mzLib.targets'))" />
235+
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.4.1.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.4.1.0\build\net35\NUnit3TestAdapter.props'))" />
236+
<Error Condition="!Exists('..\packages\NUnit.3.13.2\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.13.2\build\NUnit.props'))" />
234237
</Target>
235238
<Import Project="..\packages\mzLib.1.0.450\build\net471\mzLib.targets" Condition="Exists('..\packages\mzLib.1.0.450\build\net471\mzLib.targets')" />
236239
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

ThermoRawFileParserTest/packages.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
<package id="Namotion.Reflection" version="1.0.18" targetFramework="net472" />
1212
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
1313
<package id="NJsonSchema" version="10.4.0" targetFramework="net472" />
14-
<package id="NUnit" version="3.13.1" targetFramework="net472" />
14+
<package id="NUnit" version="3.13.2" targetFramework="net472" />
15+
<package id="NUnit3TestAdapter" version="4.1.0" targetFramework="net472" />
1516
<package id="OpenMcdf" version="2.2.1.9" targetFramework="net472" />
1617
<package id="OpenMcdf.Extensions" version="2.2.1.4" targetFramework="net472" />
1718
<package id="PSI_Interface" version="2.3.2" targetFramework="net472" />

Util/MZArray.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace ThermoRawFileParser.Util
2+
{
3+
struct MZArray
4+
{
5+
public double[] Masses { get; set; }
6+
public double[] Intensities { get; set; }
7+
}
8+
}

Writer/MgfSpectrumWriter.cs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,16 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
139139
// Write the filter string
140140
//Writer.WriteLine($"SCANEVENT={scanEvent.ToString()}");
141141

142+
double[] masses;
143+
double[] intensities;
144+
142145
if (!ParseInput.NoPeakPicking.Contains((int) scanFilter.MSOrder))
143146
{
144147
// Check if the scan has a centroid stream
145148
if (scan.HasCentroidStream)
146149
{
147-
if (scan.CentroidScan.Length > 0)
148-
{
149-
for (var i = 0; i < scan.CentroidScan.Length; i++)
150-
{
151-
Writer.WriteLine(
152-
scan.CentroidScan.Masses[i].ToString("0.0000000",
153-
CultureInfo.InvariantCulture)
154-
+ " "
155-
+ scan.CentroidScan.Intensities[i].ToString("0.0000000000",
156-
CultureInfo.InvariantCulture));
157-
}
158-
}
150+
masses = scan.CentroidScan.Masses;
151+
intensities = scan.CentroidScan.Intensities;
159152
}
160153
else // Otherwise take segmented (low res) scan data
161154
{
@@ -164,27 +157,23 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
164157
? Scan.ToCentroid(scan).SegmentedScan
165158
: scan.SegmentedScan;
166159

167-
for (var i = 0; i < segmentedScan.Positions.Length; i++)
168-
{
169-
Writer.WriteLine(
170-
segmentedScan.Positions[i].ToString("0.0000000",
171-
CultureInfo.InvariantCulture)
172-
+ " "
173-
+ segmentedScan.Intensities[i].ToString("0.0000000000",
174-
CultureInfo.InvariantCulture));
175-
}
160+
masses = segmentedScan.Positions;
161+
intensities = segmentedScan.Intensities;
176162
}
177163
}
178164
else // Use the segmented data as is
179165
{
180-
for (var i = 0; i < scan.SegmentedScan.Positions.Length; i++)
166+
masses = scan.SegmentedScan.Positions;
167+
intensities = scan.SegmentedScan.Intensities;
168+
}
169+
170+
if (!(masses is null) && masses.Length > 0)
171+
{
172+
Array.Sort(masses, intensities);
173+
174+
for (var i = 0; i < masses.Length; i++)
181175
{
182-
Writer.WriteLine(
183-
scan.SegmentedScan.Positions[i].ToString("0.0000000",
184-
CultureInfo.InvariantCulture)
185-
+ " "
186-
+ scan.SegmentedScan.Intensities[i].ToString("0.0000000000",
187-
CultureInfo.InvariantCulture));
176+
Writer.WriteLine(String.Format("{0:f5} {1:f3}", masses[i], intensities[i]));
188177
}
189178
}
190179

0 commit comments

Comments
 (0)