public void findFeatureIn_dataset_with_bad_massCalibration_test1()
        {
            //mass error in this dataset is typically ~50ppm.

            var datasetFile = @"D:\Data\Orbitrap\Subissue01\QC_Shew_10_01-pt5-1_8Feb10_Doc_09-12-24.RAW";

            var massTagFile           = @"\\protoapps\UserData\Slysz\Data\QCShew_MassiveTargeted\MassTags\QCShew_Formic_MassTags_Bin10_first10.txt";
            var workflowParameterFile = @"\\protoapps\UserData\Slysz\Data\QCShew_MassiveTargeted\WorkflowParameterFiles\UnlabelledTargeted_WorkflowParameters_noSum.xml";


            var run = RunUtilities.CreateAndLoadPeaks(datasetFile, datasetFile.Replace(".RAW", "_peaks.txt"));

            RunUtilities.AlignRunUsingAlignmentInfoInFiles(run);

            Assert.IsTrue(run.MassIsAligned);
            Assert.IsTrue(run.NETIsAligned);


            var parameters = new BasicTargetedWorkflowParameters();

            parameters.LoadParameters(workflowParameterFile);
            var workflow = new BasicTargetedWorkflow(parameters);


            workflow.Run = run;

            var mtc        = new TargetCollection();
            var mtimporter = new MassTagFromTextFileImporter(massTagFile);

            mtc = mtimporter.Import();

            var mt1 = (from n in mtc.TargetList where n.ID == 24702 && n.ChargeState == 4 select n).First();

            run.CurrentMassTag = mt1;

            workflow.Execute();

            var repo = new TargetedResultRepository();

            repo.AddResult(workflow.Result);


            Console.WriteLine("theor mono mass = " + mt1.MonoIsotopicMass);
            Console.WriteLine("theorMZ = " + mt1.MZ);
            Console.WriteLine("theorNET = " + mt1.NormalizedElutionTime);
            Console.WriteLine("obsScan = " + repo.Results[0].ScanLC);
            Console.WriteLine("obsNET = " + repo.Results[0].NET);
            Console.WriteLine("NETError = " + repo.Results[0].NETError);
            Console.WriteLine("obsMZ = " + repo.Results[0].MonoMZ);
            Console.WriteLine("monoMass = " + repo.Results[0].MonoMass);
            Console.WriteLine("obsMonoMassCalibrated = " + repo.Results[0].MonoMassCalibrated);

            Console.WriteLine("MassErrorBeforeAlignment = " + (mt1.MZ - repo.Results[0].MonoMZ) / mt1.MZ * 1e6);
            Console.WriteLine("MassErrorAfterAlignment = " + repo.Results[0].MassErrorBeforeCalibration);
        }
        public void ProcessDataset()
        {
            //apply mass calibration and NET alignment from .txt files, if they exist
            PerformAlignment();


            var runIsNotAligned = (!Run.MassIsAligned && !Run.NETIsAligned);     //if one of these two is aligned, the run is considered to be aligned

            //Perform targeted alignment if 1) run is not aligned  2) parameters permit it
            if (runIsNotAligned && this.ExecutorParameters.TargetedAlignmentIsPerformed)
            {
                Check.Ensure(this.MassTagsForTargetedAlignment != null && this.MassTagsForTargetedAlignment.TargetList.Count > 0, "MassTags for targeted alignment have not been defined. Check path within parameter file.");

                ReportGeneralProgress("Performing TargetedAlignment using mass tags from file: " + GetTargetFilePathForIqAlignment());
                ReportGeneralProgress("Total mass tags to be aligned = " + this.MassTagsForTargetedAlignment.TargetList.Count);

                this.TargetedAlignmentWorkflow = new TargetedAlignerWorkflow(this.TargetedAlignmentWorkflowParameters);
                this.TargetedAlignmentWorkflow.SetMassTags(this.MassTagsForTargetedAlignment.TargetList);
                this.TargetedAlignmentWorkflow.Run = Run;
                this.TargetedAlignmentWorkflow.Execute();

                ReportGeneralProgress("Targeted Alignment COMPLETE.");
                ReportGeneralProgress("Targeted Alignment Report: ");
                ReportGeneralProgress(this.TargetedAlignmentWorkflow.GetAlignmentReport1());

                PerformAlignment();     //now perform alignment, based on alignment .txt files that were outputted from the targetedAlignmentWorkflow



                TargetedAlignmentWorkflow.SaveFeaturesToTextfile(_alignmentFolder);
                if (Run.AlignmentInfo != null)
                {
                    TargetedAlignmentWorkflow.SaveAlignmentData(_alignmentFolder);
                }

                ReportGeneralProgress("MassAverage = \t" + this.TargetedAlignmentWorkflow.Aligner.Result.MassAverage.ToString("0.00000"));
                ReportGeneralProgress("MassStDev = \t" + this.TargetedAlignmentWorkflow.Aligner.Result.MassStDev.ToString("0.00000"));
                ReportGeneralProgress("NETAverage = \t" + this.TargetedAlignmentWorkflow.Aligner.Result.NETAverage.ToString("0.00000"));
                ReportGeneralProgress("NETStDev = \t" + this.TargetedAlignmentWorkflow.Aligner.Result.NETStDev.ToString("0.00000"));
                ReportGeneralProgress("---------------- END OF Alignment info -------------");
            }

            this.TargetedWorkflow.Run = Run;


            ResultRepository.Results.Clear();

            var mtCounter    = 0;
            var totalTargets = Targets.TargetList.Count;

            ReportGeneralProgress("Processing...", 0);

            foreach (var massTag in this.Targets.TargetList)
            {
                mtCounter++;

#if DEBUG
                var stopwatch = new System.Diagnostics.Stopwatch();
                stopwatch.Start();
#endif


                Run.CurrentMassTag = massTag;
                try
                {
                    this.TargetedWorkflow.Execute();
                    ResultRepository.AddResult(this.TargetedWorkflow.Result);
                }
                catch (Exception ex)
                {
                    var errorString = "Error on MT\t" + massTag.ID + "\tchargeState\t" + massTag.ChargeState + "\t" + ex.Message + "\t" + ex.StackTrace;
                    ReportGeneralProgress(errorString, mtCounter);

                    throw;
                }

#if DEBUG
                stopwatch.Stop();
                Console.WriteLine(massTag.ID + "\tprocessing time = " + stopwatch.ElapsedMilliseconds);
#endif

                var progressString = "Percent complete = " + ((double)mtCounter / totalTargets * 100.0).ToString("0.0") + "\tTarget " + mtCounter + " of " + totalTargets;


                if (_backgroundWorker != null)
                {
                    if (_backgroundWorker.CancellationPending)
                    {
                        return;
                    }
                }

                ReportProcessingProgress(progressString, mtCounter);
            }

            ReportGeneralProgress("---- PROCESSING COMPLETE ---------------", 100);
        }