Ejemplo n.º 1
0
        static int Main(string[] args)
        {
            var options = new IqConsoleOptions();

            var datasetList = new List <string>();


            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                return(-1);
            }

            var inputFile = options.InputFile;



            var inputFileIsAListOfDatasets = inputFile.ToLower().EndsWith(".txt");

            if (inputFileIsAListOfDatasets)
            {
                using (var reader = new StreamReader(inputFile))
                {
                    while (reader.Peek() != -1)
                    {
                        var datsetName = reader.ReadLine();
                        datasetList.Add(datsetName);
                    }
                }
            }
            else
            {
                datasetList.Add(options.InputFile);
            }


            var numDatasets    = datasetList.Count;
            var datasetCounter = 0;

            foreach (var dataset in datasetList)
            {
                datasetCounter++;

                var datasetNameContainsPath = dataset.Contains(@"\");

                string currentDatasetPath;

                if (datasetNameContainsPath)
                {
                    currentDatasetPath = dataset;
                }
                else
                {
                    if (string.IsNullOrEmpty(options.TemporaryWorkingFolder))
                    {
                        IqLogger.Log.Fatal("Trying to grab .raw file from DMS, but no temporary working folder was declared. Use option -f. ");
                        break;
                    }


                    if (string.IsNullOrEmpty(options.OutputFolder))
                    {
                        options.OutputFolder = options.TemporaryWorkingFolder;
                    }



                    var datasetutil = new DatasetUtilities();

                    //TODO: figure out how to do this while supporting other file types
                    currentDatasetPath = Path.Combine(datasetutil.GetDatasetPath(dataset), dataset + ".raw");

                    if (currentDatasetPath.ToLower().Contains("purged"))
                    {
                        currentDatasetPath = Path.Combine(datasetutil.GetDatasetPathArchived(dataset), dataset + ".raw");
                    }
                }


                if (!File.Exists(currentDatasetPath))
                {
                    IqLogger.Log.Fatal("!!!!!!!!! Dataset not found! Dataset path = " + currentDatasetPath);
                    return(-2);
                }

                if (string.IsNullOrEmpty(options.OutputFolder))
                {
                    options.OutputFolder = RunUtilities.GetDatasetParentFolder(currentDatasetPath);
                }

                var executorParameters = GetExecutorParameters(options);

                IqLogger.Log.Info("IQ analyzing dataset " + datasetCounter + " of " + numDatasets + ". Dataset = " + dataset);


                if (options.UseOldIq)
                {
                    TargetedWorkflowExecutor executor = new BasicTargetedWorkflowExecutor(executorParameters,
                                                                                          currentDatasetPath);

                    //executor.Targets.TargetList = executor.Targets.TargetList.Take(10).ToList();
                    executor.MsgfFdrScoreCutoff = 0.1;
                    executor.Execute();
                }
                else
                {
                    var run      = new RunFactory().CreateRun(currentDatasetPath);
                    var executor = new IqExecutor(executorParameters, run);

                    executor.LoadAndInitializeTargets(executorParameters.TargetsFilePath);
                    executor.SetupMassAndNetAlignment();
                    executor.DoAlignment();


                    foreach (var iqTarget in executor.Targets)
                    {
                        TargetedWorkflowParameters workflowParameters = new O16O18WorkflowParameters();

                        if (iqTarget.ElutionTimeTheor > 0.7 || iqTarget.ElutionTimeTheor < 0.15)
                        {
                            //TODO: remove the hard-coded value
                            workflowParameters.ChromNETTolerance = 0.1;
                        }
                        else
                        {
                            //TODO: remove the hard-coded value
                            workflowParameters.ChromNETTolerance = 0.025;
                        }

                        if (run.MassAlignmentInfo != null && run.MassAlignmentInfo.StdevPpmShiftData > 0)
                        {
                            workflowParameters.ChromGenTolerance = run.MassAlignmentInfo.StdevPpmShiftData * 3;
                        }

                        //define workflows for parentTarget and childTargets
                        // Note: this is currently hard-coded to user O16O18IqWorkflow
                        var parentWorkflow = new ChromPeakDeciderIqWorkflow(run, workflowParameters);
                        var childWorkflow  = new O16O18IqWorkflow(run, workflowParameters);

                        var workflowAssigner = new IqWorkflowAssigner();
                        workflowAssigner.AssignWorkflowToParent(parentWorkflow, iqTarget);
                        workflowAssigner.AssignWorkflowToChildren(childWorkflow, iqTarget);
                    }

                    executor.Execute();

                    run.Dispose();
                }
            }

            return(0);
        }