Skip to content

Commit

Permalink
Merge pull request #181 from compomics/1.4.4
Browse files Browse the repository at this point in the history
Release of 1.4.4
  • Loading branch information
ypriverol authored May 9, 2024
2 parents 42131e5 + fb5d7bb commit 29d4e59
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 179 deletions.
32 changes: 17 additions & 15 deletions MainClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class MainClass
private static readonly ILog Log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

public const string Version = "1.4.3";
public const string Version = "1.4.4";
public static void Main(string[] args)
{
// Set Invariant culture as default for all further processing
Expand Down Expand Up @@ -83,15 +83,15 @@ private static void XicParametersParsing(string[] args)
v => parameters.printJsonExample = v != null
},
{
"o=|output=",
"The output directory. Specify this or an output file. Specifying neither writes to the input directory.",
v => outputDirectory = v
},
{
"b=|output_file",
"b=|output=",
"The output file. Specify this or an output directory. Specifying neither writes to the input directory.",
v => outputFile = v
},
{
"o=|output_directory=",
"The output directory. Specify this or an output file. Specifying neither writes to the input directory.",
v => outputDirectory = v
},
{
"6|base64",
"Encodes the content of the xic vectors as base 64 encoded string.",
Expand All @@ -103,7 +103,7 @@ private static void XicParametersParsing(string[] args)
v => parameters.stdout = v != null
},
{
"w|warningsAreErrors", "Return non-zero exit code for warnings; default only for errors",
"w|warningsAreErrors", "Return non-zero exit code for warnings; default only for errors",
v => parameters.Vigilant = v != null
},
{
Expand Down Expand Up @@ -338,7 +338,7 @@ private static void SpectrumQueryParametersParsing(string[] args)
v => parameters.scans = v
},
{
"b=|output_file",
"b=|output=",
"The output file. Specifying none writes the output file to the input file parent directory.",
v => parameters.outputFile = v
},
Expand Down Expand Up @@ -510,15 +510,15 @@ private static void RegularParametersParsing(string[] args)
v => parseInput.RawDirectoryPath = v
},
{
"o=|output=",
"The output directory. Specify this or an output file -b. Specifying neither writes to the input directory.",
v => parseInput.OutputDirectory = v
},
{
"b=|output_file",
"b=|output=",
"The output file. Specify this or an output directory -o. Specifying neither writes to the input directory.",
v => parseInput.OutputFile = v
},
{
"o=|output_directory=",
"The output directory. Specify this or an output file -b. Specifying neither writes to the input directory.",
v => parseInput.OutputDirectory = v
},
{
"s|stdout",
"Write to standard output. Cannot be combined with file or directory output. Implies silent logging, i.e. logging level 0",
Expand Down Expand Up @@ -766,6 +766,8 @@ private static void RegularParametersParsing(string[] args)
if (parseInput.OutputFormat == OutputFormat.IndexMzML) parseInput.OutputFormat = OutputFormat.MzML;
}

parseInput.MaxLevel = parseInput.MsLevel.Max();

if (parseInput.S3Url != null && parseInput.S3AccessKeyId != null &&
parseInput.S3SecretAccessKey != null && parseInput.BucketName != null)
if (Uri.IsWellFormedUriString(parseInput.S3Url, UriKind.Absolute))
Expand Down
3 changes: 3 additions & 0 deletions ParseInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public int Warnings

public HashSet<int> MsLevel { get; set; }

public int MaxLevel { get; set; }

public bool MgfPrecursor { get; set; }

public bool NoiseData { get; set; }
Expand Down Expand Up @@ -136,6 +138,7 @@ public ParseInput()
Vigilant = false;
_errors = 0;
_warnings = 0;
MaxLevel = 10;
}

public ParseInput(string rawFilePath, string rawDirectoryPath, string outputDirectory, OutputFormat outputFormat
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ optional subcommands are xic|query (use [subcommand] -h for more info]):
-d, --input_directory=VALUE
The directory containing the raw files (Required).
Specify this or an input raw file -i.
-o, --output=VALUE The output directory. Specify this or an output
file -b. Specifying neither writes to the input
directory.
-b, --output_file=VALUE The output file. Specify this or an output
-b, --output=VALUE The output file. Specify this or an output
directory -o. Specifying neither writes to the
input directory.
-o, --output_directory=VALUE
The output directory. Specify this or an output
file -b. Specifying neither writes to the input
directory.
-s, --stdout Write to standard output. Cannot be combined with
file or directory output. Implies silent logging,
i.e. logging level 0
Expand Down Expand Up @@ -137,7 +138,7 @@ usage is:
-h, --help Prints out the options.
-i, --input=VALUE The raw file input (Required).
-n, --scans=VALUE The scan numbers. e.g. "1-5, 20, 25-30"
-b, --output_file=VALUE The output file. Specifying none writes the output
-b, --output=VALUE The output file. Specifying none writes the output
file to the input file parent directory.
-p, --noPeakPicking Don't use the peak picking provided by the native
Thermo library. By default peak picking is
Expand Down Expand Up @@ -169,12 +170,13 @@ ThermoRawFileParser.exe xic --help
Specify this or an input file -i.
-j, --json=VALUE The json input file (Required).
-p, --print_example Show a json input file example.
-o, --output=VALUE The output directory. Specify this or an output
file. Specifying neither writes to the input
directory.
-b, --output_file=VALUE The output file. Specify this or an output
-b, --output=VALUE The output file. Specify this or an output
directory. Specifying neither writes to the
input directory.
-o, --output_directory=VALUE
The output directory. Specify this or an output
file. Specifying neither writes to the input
directory.
-6, --base64 Encodes the content of the xic vectors as base 64
encoded string.
-s, --stdout Pipes the output into standard output. Logging is
Expand Down
16 changes: 15 additions & 1 deletion Util/CVHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ThermoRawFileParser.Writer.MzML;
using System.Collections.Generic;
using ThermoRawFileParser.Writer.MzML;

namespace ThermoRawFileParser.Util
{
Expand All @@ -18,4 +19,17 @@ public static CVParamType Copy (this CVParamType old)
};
}
}

public class CVComparer : IEqualityComparer<CVParamType>
{
public bool Equals(CVParamType cv1, CVParamType cv2)
{
return cv1.accession == cv2.accession;
}

public int GetHashCode(CVParamType cv)
{
return cv.accession.GetHashCode();
}
}
}
116 changes: 54 additions & 62 deletions Writer/MetadataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web.WebSockets;
using log4net;
using Newtonsoft.Json;
using ThermoFisher.CommonCore.Data;
Expand Down Expand Up @@ -122,16 +121,14 @@ public void WriteMetadata(IRawDataPlus rawFile, int firstScanNumber, int lastSca
switch (_parseInput.MetadataFormat)
{
case MetadataFormat.JSON:
_metadataFileName = _parseInput.MetadataOutputFile != null
? _parseInput.MetadataOutputFile
: Path.Combine(_parseInput.OutputDirectory, _parseInput.RawFileNameWithoutExtension) +
_metadataFileName = _parseInput.MetadataOutputFile ??
Path.Combine(_parseInput.OutputDirectory, _parseInput.RawFileNameWithoutExtension) +
"-metadata.json";
WriteJsonMetada(rawFile, firstScanNumber, lastScanNumber);
break;
case MetadataFormat.TXT:
_metadataFileName = _parseInput.MetadataOutputFile != null
? _parseInput.MetadataOutputFile
: Path.Combine(_parseInput.OutputDirectory, _parseInput.RawFileNameWithoutExtension) +
_metadataFileName = _parseInput.MetadataOutputFile ??
Path.Combine(_parseInput.OutputDirectory, _parseInput.RawFileNameWithoutExtension) +
"-metadata.txt";
WriteTextMetadata(rawFile, firstScanNumber, lastScanNumber);
break;
Expand Down Expand Up @@ -176,43 +173,40 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last
metadata.addInstrumentProperty(new CVTerm("AFR:0001259", "AFO", "firmware version",
rawFile.GetInstrumentData().HardwareVersion));
}
}


// MS Data
foreach (KeyValuePair<string, int> entry in msTypes)
{
if (entry.Key.Equals(MSOrderType.Ms.ToString()))
metadata.addMSData(new CVTerm("PRIDE:0000481", "PRIDE", "Number of MS1 spectra",
entry.Value.ToString()));
if (entry.Key.Equals(MSOrderType.Ms2.ToString()))
metadata.addMSData(new CVTerm("PRIDE:0000482", "PRIDE", "Number of MS2 spectra",
entry.Value.ToString()));
if (entry.Key.Equals(MSOrderType.Ms3.ToString()))
metadata.addMSData(new CVTerm("PRIDE:0000483", "PRIDE", "Number of MS3 spectra",
entry.Value.ToString()));
}

metadata.addMSData(new CVTerm("PRIDE:0000472", "PRIDE", "MS min charge",
minCharge.ToString(CultureInfo.InvariantCulture)));
metadata.addMSData(new CVTerm("PRIDE:0000473", "PRIDE", "MS max charge",
maxCharge.ToString(CultureInfo.InvariantCulture)));

metadata.addMSData(new CVTerm("PRIDE:0000474", "PRIDE", "MS min RT",
minTime.ToString(CultureInfo.InvariantCulture)));
metadata.addMSData(new CVTerm("PRIDE:0000475", "PRIDE", "MS max RT",
maxTime.ToString(CultureInfo.InvariantCulture)));

metadata.addMSData(new CVTerm("PRIDE:0000476", "PRIDE", "MS min MZ",
minMz.ToString(CultureInfo.InvariantCulture)));
metadata.addMSData(new CVTerm("PRIDE:0000477", "PRIDE", "MS max MZ",
maxMz.ToString(CultureInfo.InvariantCulture)));

// Scan Settings
// Get the start and end time from the RAW file

if (rawFile.SelectMsData())
{


// MS Data
foreach (KeyValuePair<string, int> entry in msTypes)
{
if (entry.Key.Equals(MSOrderType.Ms.ToString()))
metadata.addMSData(new CVTerm("PRIDE:0000481", "PRIDE", "Number of MS1 spectra",
entry.Value.ToString()));
if (entry.Key.Equals(MSOrderType.Ms2.ToString()))
metadata.addMSData(new CVTerm("PRIDE:0000482", "PRIDE", "Number of MS2 spectra",
entry.Value.ToString()));
if (entry.Key.Equals(MSOrderType.Ms3.ToString()))
metadata.addMSData(new CVTerm("PRIDE:0000483", "PRIDE", "Number of MS3 spectra",
entry.Value.ToString()));
}

metadata.addMSData(new CVTerm("PRIDE:0000472", "PRIDE", "MS min charge",
minCharge.ToString(CultureInfo.InvariantCulture)));
metadata.addMSData(new CVTerm("PRIDE:0000473", "PRIDE", "MS max charge",
maxCharge.ToString(CultureInfo.InvariantCulture)));

metadata.addMSData(new CVTerm("PRIDE:0000474", "PRIDE", "MS min RT",
minTime.ToString(CultureInfo.InvariantCulture)));
metadata.addMSData(new CVTerm("PRIDE:0000475", "PRIDE", "MS max RT",
maxTime.ToString(CultureInfo.InvariantCulture)));

metadata.addMSData(new CVTerm("PRIDE:0000476", "PRIDE", "MS min MZ",
minMz.ToString(CultureInfo.InvariantCulture)));
metadata.addMSData(new CVTerm("PRIDE:0000477", "PRIDE", "MS max MZ",
maxMz.ToString(CultureInfo.InvariantCulture)));

// Scan Settings
// Get the start and end time from the RAW file
var runHeaderEx = rawFile.RunHeaderEx;
var startTime = runHeaderEx.StartTime;
var endTime = runHeaderEx.EndTime;
Expand Down Expand Up @@ -373,21 +367,20 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la
{
output.Add("Firmware version=" + rawFile.GetInstrumentData().HardwareVersion);
}
}

// MS Data
output.Add("#MsData");
foreach (KeyValuePair<string, int> entry in msTypes)
{
if (entry.Key.Equals(MSOrderType.Ms.ToString()))
output.Add("Number of MS1 spectra=" + entry.Value);
if (entry.Key.Equals(MSOrderType.Ms2.ToString()))
output.Add("Number of MS2 spectra=" + entry.Value);
if (entry.Key.Equals(MSOrderType.Ms3.ToString()))
output.Add("Number of MS3 spectra=" + entry.Value);
}

output.AddRange(new List<string>
// MS Data
output.Add("#MsData");
foreach (KeyValuePair<string, int> entry in msTypes)
{
if (entry.Key.Equals(MSOrderType.Ms.ToString()))
output.Add("Number of MS1 spectra=" + entry.Value);
if (entry.Key.Equals(MSOrderType.Ms2.ToString()))
output.Add("Number of MS2 spectra=" + entry.Value);
if (entry.Key.Equals(MSOrderType.Ms3.ToString()))
output.Add("Number of MS3 spectra=" + entry.Value);
}

output.AddRange(new List<string>
{
$"MS min charge={minCharge.ToString(CultureInfo.InvariantCulture)}",
$"MS max charge={maxCharge.ToString(CultureInfo.InvariantCulture)}",
Expand All @@ -396,11 +389,9 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la
$"MS min MZ={minMz.ToString(CultureInfo.InvariantCulture)}",
$"MS max MZ={maxMz.ToString(CultureInfo.InvariantCulture)}"
}
);
);

// Scan Settings
if (rawFile.SelectMsData())
{
// Scan Settings
// Get the start and end time from the RAW file
var startTime = rawFile.RunHeaderEx.StartTime;
var endTime = rawFile.RunHeaderEx.EndTime;
Expand All @@ -410,7 +401,7 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la
$"Scan start time={startTime.ToString(CultureInfo.InvariantCulture)}",
$"Expected runtime={rawFile.RunHeaderEx.ExpectedRunTime.ToString(CultureInfo.InvariantCulture)}",
$"Mass resolution=[MS, MS:1000011, mass resolution, {rawFile.RunHeaderEx.MassResolution.ToString(CultureInfo.InvariantCulture)}]",
"Units=" + rawFile.GetInstrumentData().Units,
$"Units={rawFile.GetInstrumentData().Units}",
$"Number of scans={rawFile.RunHeaderEx.SpectraCount}",
$"Scan range={firstScanNumber};{lastScanNumber}",
$"Time range={startTime.ToString(CultureInfo.InvariantCulture)};{endTime.ToString(CultureInfo.InvariantCulture)}",
Expand All @@ -419,6 +410,7 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la
}
);
}

// Sample Data
output.Add("#SampleData");

Expand Down
2 changes: 0 additions & 2 deletions Writer/MgfSpectrumWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
using System.Reflection;
using System.Text.RegularExpressions;
using log4net;
using ThermoFisher.CommonCore.Data;
using ThermoFisher.CommonCore.Data.Business;
using ThermoFisher.CommonCore.Data.FilterEnums;
using ThermoFisher.CommonCore.Data.Interfaces;
using ThermoRawFileParser.Util;

namespace ThermoRawFileParser.Writer
{
Expand Down
Loading

0 comments on commit 29d4e59

Please sign in to comment.