static int Main(string[] args)
        {
            try
            {

                // Handles a bug in .NET console applications
                var handle = Process.GetCurrentProcess().MainWindowHandle;
                SetConsoleMode(handle, ENABLE_EXTENDED_FLAGS);

                // Get the version number
                var assembly = Assembly.GetExecutingAssembly();
                var assemblyVersion = assembly.GetName().Version.ToString();

                Console.WriteLine("CrossLinkingIMS Console Application Version " + assemblyVersion);

                var commandLineUtil = new CommandLineUtil(caseSensitiveSwitchNames: false);

                // Make sure we have parameters. If not, then show the user the proper syntax
                var doParametersExist = commandLineUtil.ParseCommandLine();
                if (!doParametersExist)
                {
                    ShowSyntax();
                    return -1;
                }

                // Get the Feature File Location
                string featureFileLocation;
                if (!commandLineUtil.RetrieveValueForParameter("f", out featureFileLocation))
                {
                    Console.WriteLine("-f switch is missing");
                    ShowSyntax();
                    return -2;
                }

                if (!FileExists(featureFileLocation))
                {
                    return -4;
                }

                var featureFile = new FileInfo(featureFileLocation);

                // Get the Peaks File Location
                string peaksFileLocation;
                if (!commandLineUtil.RetrieveValueForParameter("p", out peaksFileLocation))
                {
                    Console.WriteLine("-p switch is missing");
                    ShowSyntax();
                    return -2;
                }

                if (!FileExists(peaksFileLocation))
                {
                    return -4;
                }

                var peaksFile = new FileInfo(peaksFileLocation);

                // Get the FastA File Location
                string fastAFileLocation;
                if (!commandLineUtil.RetrieveValueForParameter("fasta", out fastAFileLocation))
                {
                    Console.WriteLine("-fasta switch is missing");
                    ShowSyntax();
                    return -2;
                }

                if (!FileExists(fastAFileLocation))
                {
                    return -4;
                }

                var fastAFile = new FileInfo(fastAFileLocation);

                // Get the PPM Mass Tolerance
                string massToleranceString;
                if (!commandLineUtil.RetrieveValueForParameter("ppm", out massToleranceString))
                {
                    Console.WriteLine("-ppm switch is missing");
                    ShowSyntax();
                    return -2;
                }

                var massTolerance = double.Parse(massToleranceString);

                // Get the Max Missed Cleavages
                string maxMissedCleavagesString;
                commandLineUtil.RetrieveValueForParameter("c", out maxMissedCleavagesString);

                if (string.IsNullOrEmpty(maxMissedCleavagesString))
                    maxMissedCleavagesString = "1";

                var maxMissedCleavages = int.Parse(maxMissedCleavagesString);

                // Get the Partially Tryptic Flag
                string trypticString;
                commandLineUtil.RetrieveValueForParameter("t", out trypticString);

                string staticDeltaMassString;
                var staticDeltaMass = 0.0;
                if (commandLineUtil.RetrieveValueForParameter("static", out staticDeltaMassString))
                {
                    double.TryParse(staticDeltaMassString, out staticDeltaMass);
                }

                var useC13 = true;
                var useN15 = true;

                if (commandLineUtil.IsParameterPresent("c13off"))
                    useC13 = false;

                if (commandLineUtil.IsParameterPresent("n15off"))
                    useN15 = false;

                if (!(useC13 || useN15) && Math.Abs(staticDeltaMass) < float.Epsilon)
                {
                    Console.WriteLine("If you use both -C13off and -N15off, you must use -Static:MassDiff to specify a static mass difference");
                    Thread.Sleep(1500);
                    return -3;
                }

                var settings = new CrossLinkSettings(massTolerance, maxMissedCleavages, trypticString, useC13, useN15, staticDeltaMass);

                // Get the Output File Location
                string outputFileLocation;
                if (!commandLineUtil.RetrieveValueForParameter("o", out outputFileLocation))
                {
                    if (featureFile.DirectoryName != null && featureFile.DirectoryName == peaksFile.DirectoryName)
                        outputFileLocation = Path.Combine(featureFile.DirectoryName, "crossLinkResults.csv");
                    else
                        outputFileLocation = "crossLinkResults.csv";
                }

                // Run the cross-linking application
                Console.WriteLine("Executing...");
                var crossLinkResults = CrossLinkingImsController.Execute(settings, fastAFile, featureFile, peaksFile);

                var outputFileInfo = new FileInfo(outputFileLocation);

                // Output the results
                Console.WriteLine("Outputting " + crossLinkResults.Count().ToString("#,##0") + " results to \n" + outputFileInfo.FullName);
                CrossLinkUtil.OutputCrossLinkResults(crossLinkResults, outputFileInfo);

                return 0;
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine("=========================================");
                Console.WriteLine("Error: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine("=========================================");

                Thread.Sleep(2000);
                return -10;
            }
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            try
            {
                // Handles a bug in .NET console applications
                var handle = Process.GetCurrentProcess().MainWindowHandle;
                SetConsoleMode(handle, ENABLE_EXTENDED_FLAGS);

                // Get the version number
                var assembly        = Assembly.GetExecutingAssembly();
                var assemblyVersion = assembly.GetName().Version.ToString();

                Console.WriteLine("CrossLinkingIMS Console Application Version " + assemblyVersion);

                var commandLineUtil = new CommandLineUtil(caseSensitiveSwitchNames: false);

                // Make sure we have parameters. If not, then show the user the proper syntax
                var doParametersExist = commandLineUtil.ParseCommandLine();
                if (!doParametersExist)
                {
                    ShowSyntax();
                    return(-1);
                }

                // Get the Feature File Location
                string featureFileLocation;
                if (!commandLineUtil.RetrieveValueForParameter("f", out featureFileLocation))
                {
                    Console.WriteLine("-f switch is missing");
                    ShowSyntax();
                    return(-2);
                }

                if (!FileExists(featureFileLocation))
                {
                    return(-4);
                }

                var featureFile = new FileInfo(featureFileLocation);

                // Get the Peaks File Location
                string peaksFileLocation;
                if (!commandLineUtil.RetrieveValueForParameter("p", out peaksFileLocation))
                {
                    Console.WriteLine("-p switch is missing");
                    ShowSyntax();
                    return(-2);
                }

                if (!FileExists(peaksFileLocation))
                {
                    return(-4);
                }

                var peaksFile = new FileInfo(peaksFileLocation);

                // Get the FastA File Location
                string fastAFileLocation;
                if (!commandLineUtil.RetrieveValueForParameter("fasta", out fastAFileLocation))
                {
                    Console.WriteLine("-fasta switch is missing");
                    ShowSyntax();
                    return(-2);
                }

                if (!FileExists(fastAFileLocation))
                {
                    return(-4);
                }

                var fastAFile = new FileInfo(fastAFileLocation);

                // Get the PPM Mass Tolerance
                string massToleranceString;
                if (!commandLineUtil.RetrieveValueForParameter("ppm", out massToleranceString))
                {
                    Console.WriteLine("-ppm switch is missing");
                    ShowSyntax();
                    return(-2);
                }

                var massTolerance = double.Parse(massToleranceString);

                // Get the Max Missed Cleavages
                string maxMissedCleavagesString;
                commandLineUtil.RetrieveValueForParameter("c", out maxMissedCleavagesString);

                if (string.IsNullOrEmpty(maxMissedCleavagesString))
                {
                    maxMissedCleavagesString = "1";
                }

                var maxMissedCleavages = int.Parse(maxMissedCleavagesString);

                // Get the Partially Tryptic Flag
                string trypticString;
                commandLineUtil.RetrieveValueForParameter("t", out trypticString);

                string staticDeltaMassString;
                var    staticDeltaMass = 0.0;
                if (commandLineUtil.RetrieveValueForParameter("static", out staticDeltaMassString))
                {
                    double.TryParse(staticDeltaMassString, out staticDeltaMass);
                }

                var useC13 = true;
                var useN15 = true;

                if (commandLineUtil.IsParameterPresent("c13off"))
                {
                    useC13 = false;
                }

                if (commandLineUtil.IsParameterPresent("n15off"))
                {
                    useN15 = false;
                }

                if (!(useC13 || useN15) && Math.Abs(staticDeltaMass) < float.Epsilon)
                {
                    Console.WriteLine("If you use both -C13off and -N15off, you must use -Static:MassDiff to specify a static mass difference");
                    Thread.Sleep(1500);
                    return(-3);
                }

                var settings = new CrossLinkSettings(massTolerance, maxMissedCleavages, trypticString, useC13, useN15, staticDeltaMass);

                // Get the Output File Location
                string outputFileLocation;
                if (!commandLineUtil.RetrieveValueForParameter("o", out outputFileLocation))
                {
                    if (featureFile.DirectoryName != null && featureFile.DirectoryName == peaksFile.DirectoryName)
                    {
                        outputFileLocation = Path.Combine(featureFile.DirectoryName, "crossLinkResults.csv");
                    }
                    else
                    {
                        outputFileLocation = "crossLinkResults.csv";
                    }
                }

                // Run the cross-linking application
                Console.WriteLine("Executing...");
                var crossLinkResults = CrossLinkingImsController.Execute(settings, fastAFile, featureFile, peaksFile);

                var outputFileInfo = new FileInfo(outputFileLocation);

                // Output the results
                Console.WriteLine("Outputting " + crossLinkResults.Count().ToString("#,##0") + " results to \n" + outputFileInfo.FullName);
                CrossLinkUtil.OutputCrossLinkResults(crossLinkResults, outputFileInfo);

                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine("=========================================");
                Console.WriteLine("Error: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine("=========================================");

                Thread.Sleep(2000);
                return(-10);
            }
        }