Skip to content
Permalink
5f15a33a19
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
126 lines (116 sloc) 5.2 KB
using System;
using System.Diagnostics;
using Newtonsoft.Json;
/// <summary>
/// A C# command line tool extracting the meta data from one or more raw files and putting them in a useful shaped json file.
///
/// Due to the design of the RawFileReader (RawFileReader reading tool. Copyright © 2016 by Thermo Fisher Scientific, Inc.) it is running as 64 bit code on Windows only.
/// Compiled in Visual Studio Community 2017 (Version 15.8.7, .net 4.7.03056) on Windows 10 64 bit it was tested for the following Instruments:
/// Thermo EASY-nLC, Q Exactive Plus - Orbitrap MS, Q Exactive HF - Orbitrap MS, Q Exactive - Orbitrap MS, LTQ Orbitrap Velos MS, Orbitrap Fusion.
/// </summary>
namespace MARMoSET
{
public class Program
{
/// <summary>
/// The main routine for this program. It takes a raw file or a directory with raw files as first argument.
/// Then collects their meta data, groups them in a FileSet and writes a JSON file as output, depending on the second argument.
/// </summary>
/// <param name="args"> The command line arguments for this program.
/// The RAW file name or directory should be passed as the first argument.
/// Optionaly the output path as the second.</param>
///
public static void Main(string[] args)
{
// checking time
Stopwatch watch = new Stopwatch();
watch.Start();
// local variable to check if the output was supplied as an argument to the program
bool consoleOut = false;
bool pathShort = false;
string path = string.Empty;
if (args.Length > 0)
{
path = args[0];
}
// check if the first argument was supplied
if (string.IsNullOrEmpty(path))
{
Console.WriteLine("No path specified!");
}
// help
else if (path.Equals("-h") || path.Equals("-H"))
{
Console.WriteLine(
"\n" +
" MARMoSET is extracting the meta data from one or more raw files and putting them in a useful shaped JSON file.\n\n" +
" Usage:\n\n" +
" MARMoSET.exe [input path] [jsonfile name]\n\n" +
" input path : You can specify either a path to a single raw file or a path to a directory containing one or multiple raw files.\n" +
" jsonfile name : You can set an outputfile(.json). It will be saved in the same directory as the input files.\n" +
" For saving with full path set -r in front. If empty the output will be send to the standard output."
);
}
else
{
// Output path
string outName = string.Empty;
if (args.Length > 1)
{ // 2nd argument is path + name
outName = args[1];
if (outName.Equals("-r") || outName.Equals("-R")) // Mode for R Package
{
pathShort = true;
outName = args[2];
}
}
if (string.IsNullOrEmpty(outName))
{ // no 2nd arg -> file on console
consoleOut = true;
}
//___________________________________________________
// main file handling:
var rawFiles = new FileSet(path, consoleOut);
// convert structure to JSON
string json = JsonConvert.SerializeObject(rawFiles, Formatting.Indented) + "\n";
// deleting ":" at the end of keys (tune data and instrument method)
json = json.Replace(":\":", "\":");
string outPath;
string fullOutPath;
// write to standard out or to file
if (consoleOut)
{
Console.WriteLine(json);
}
else
{
if (pathShort)
{
fullOutPath = outName;
}
else
{
// is path to dir or file?
string lowPath = path.ToLower();
if (lowPath.EndsWith(".raw"))
{
outPath = (System.IO.Path.GetDirectoryName(path));
}
else
{
outPath = path;
}
fullOutPath = System.IO.Path.Combine(outPath, outName);
}
System.IO.File.WriteAllText(fullOutPath, json);
}
// print time spend
watch.Stop();
if (!consoleOut)
{
Console.WriteLine("Time spent: " + watch.Elapsed);
}
}
}
}
}