public void LoadCalibrationDataTest1()
        {
            var testFile =
                @"\\protoapps\UserData\Slysz\Standard_Testing\Targeted_FeatureFinding\AlignmentInfo\LNA_A_Stat_Sample_SC_23_LNA_ExpA_Expo_Stat_SeattleBioMed_15Feb13_Cougar_12-12-35_MassAndGANETErrors_BeforeRefinement.txt";

            var loader = new ViperMassCalibrationLoader(testFile);

            var calibrationData = loader.ImportMassCalibrationData();

            Console.WriteLine(calibrationData.MassError);
        }
Esempio n. 2
0
        public void LoadAndApplyMassAlignmentFromViperDataTest1()
        {
            var testFile = @"\\protoapps\UserData\Slysz\DeconTools_TestFiles\QC_Shew_08_04-pt5-2_11Jan09_Sphinx_08-11-18.RAW";
            var run      = new RunFactory().CreateRun(testFile);

            var viperMassAlignmentFile =
                @"\\protoapps\UserData\Slysz\Standard_Testing\Targeted_FeatureFinding\AlignmentInfo\QC_Shew_08_04-pt5-2_11Jan09_Sphinx_08-11-18_MassAndGANETErrors_BeforeRefinement.txt";
            var loader = new ViperMassCalibrationLoader(viperMassAlignmentFile);

            /*
             * From unit test: targetedWorkflow_alignUsingDataFromFiles
             *      TargetID =  24702
             *      ChargeState =   3
             *      theor monomass=     2920.5319802
             *      theor m/z=  974.517936556667
             *      obs monomass=   2920.49120230408
             *      obs m/z=    974.504343924692
             *      ppmError before=    13.9597398284934
             *      ppmError after=     10.8899784905986
             *      calibrated mass=    2920.50017566955
             *      calibrated mass2=   2920.50017566955
             *      Database NET= 0.4197696
             *      Result NET= 0.42916464805603
             *      Result NET Error= -0.00934833288192749
             *      NumChromPeaksWithinTol= 3
             *
             *
             */


            var calibrationData = loader.ImportMassCalibrationData();

            var massAlignmentInfo = new MassAlignmentInfoLcmsWarp();

            massAlignmentInfo.SetMassAlignmentData(calibrationData);

            run.MassAlignmentInfo = massAlignmentInfo;

            var testMZ    = 974.504343924692;
            var alignedMZ = run.GetAlignedMZ(testMZ);
            var ppmDiff   = (testMZ - alignedMZ) / testMZ * 1e6;

            Console.WriteLine("input m/z= " + testMZ);
            Console.WriteLine("aligned m/z= " + alignedMZ);
            Console.WriteLine("ppmDiff= " + ppmDiff);

            Assert.AreEqual(-3.6, (decimal)Math.Round(ppmDiff, 1));
        }
Esempio n. 3
0
        public static bool AlignRunUsingAlignmentInfoInFiles(Run run, string alignmentDataFolder = "")
        {
            bool alignmentSuccessful;


            string basePath;

            if (string.IsNullOrEmpty(alignmentDataFolder))
            {
                basePath = run.DataSetPath;
            }
            else
            {
                if (Directory.Exists(alignmentDataFolder))
                {
                    basePath = alignmentDataFolder;
                }
                else
                {
                    throw new DirectoryNotFoundException(
                              "Cannot align dataset. Source alignment folder does not exist. Alignment folder = " +
                              alignmentDataFolder);
                }
            }



            var expectedMZAlignmentFile  = Path.Combine(basePath, run.DatasetName + "_MZAlignment.txt");
            var expectedNETAlignmentFile = Path.Combine(basePath, run.DatasetName + "_NETAlignment.txt");

            //first will try to load the multiAlign alignment info
            if (File.Exists(expectedMZAlignmentFile))
            {
                var importer = new MassAlignmentInfoFromTextImporter(expectedMZAlignmentFile);

                var massAlignmentData = importer.Import();

                var massAlignmentInfo = new MassAlignmentInfoLcmsWarp();
                massAlignmentInfo.SetMassAlignmentData(massAlignmentData);
                run.MassAlignmentInfo = massAlignmentInfo;
            }

            if (File.Exists(expectedNETAlignmentFile))
            {
                var netAlignmentInfoImporter = new NETAlignmentFromTextImporter(expectedNETAlignmentFile);
                var scanNETList = netAlignmentInfoImporter.Import();

                NetAlignmentInfo netAlignmentInfo = new NetAlignmentInfoBasic(run.MinLCScan, run.MaxLCScan);
                netAlignmentInfo.SetScanToNETAlignmentData(scanNETList);

                run.NetAlignmentInfo = netAlignmentInfo;
            }

            //if still not aligned, try to get the NET alignment from UMCs file. (this is the older way to do it)
            if (run.NETIsAligned)
            {
                alignmentSuccessful = true;
            }
            else
            {
                var alignmentDirInfo = new DirectoryInfo(basePath);
                var umcFileInfo      = alignmentDirInfo.GetFiles("*_umcs.txt");

                var umcFileCount = umcFileInfo.Count();

                if (umcFileCount == 1)
                {
                    var targetUmcFileName = umcFileInfo.First().FullName;

                    var importer = new UMCFileImporter(targetUmcFileName, '\t');
                    var umcs     = importer.Import();

                    var scannetPairs = umcs.GetScanNETLookupTable();

                    NetAlignmentInfo netAlignmentInfo = new NetAlignmentInfoBasic(run.MinLCScan, run.MaxLCScan);
                    netAlignmentInfo.SetScanToNETAlignmentData(scannetPairs);

                    run.NetAlignmentInfo = netAlignmentInfo;


                    Console.WriteLine(run.DatasetName + " aligned.");
                    alignmentSuccessful = true;
                }
                else if (umcFileCount > 1)
                {
                    var expectedUMCName = Path.Combine(basePath, run.DatasetName + "_UMCs.txt");

                    if (File.Exists(expectedUMCName))
                    {
                        var importer = new UMCFileImporter(expectedUMCName, '\t');
                        var umcs     = importer.Import();

                        var scannetPairs = umcs.GetScanNETLookupTable();

                        NetAlignmentInfo netAlignmentInfo = new NetAlignmentInfoBasic(run.MinLCScan, run.MaxLCScan);
                        netAlignmentInfo.SetScanToNETAlignmentData(scannetPairs);

                        run.NetAlignmentInfo = netAlignmentInfo;

                        Console.WriteLine(run.DatasetName + " NET aligned using UMC file: " + expectedUMCName);

                        alignmentSuccessful = true;
                    }
                    else
                    {
                        throw new FileNotFoundException("Trying to align dataset: " + run.DatasetName +
                                                        " but UMC file not found.");
                    }
                }
                else
                {
                    Console.WriteLine(run.DatasetName + " is NOT NET aligned.");
                    alignmentSuccessful = false;
                }
            }

            //mass is still not aligned... use data in viper output file: _MassAndGANETErrors_BeforeRefinement.txt
            if (run.MassIsAligned == false)
            {
                var expectedViperMassAlignmentFile = Path.Combine(basePath, run.DatasetName + "_MassAndGANETErrors_BeforeRefinement.txt");

                if (File.Exists(expectedViperMassAlignmentFile))
                {
                    var importer             = new ViperMassCalibrationLoader(expectedViperMassAlignmentFile);
                    var viperCalibrationData = importer.ImportMassCalibrationData();

                    var massAlignmentInfo = new MassAlignmentInfoLcmsWarp();
                    massAlignmentInfo.SetMassAlignmentData(viperCalibrationData);
                    run.MassAlignmentInfo = massAlignmentInfo;


                    Console.WriteLine(run.DatasetName + "- mass aligned using file: " + expectedViperMassAlignmentFile);

                    alignmentSuccessful = true;
                }
                else
                {
                    Console.WriteLine(run.DatasetName + " is NOT mass aligned");
                }
            }


            return(alignmentSuccessful);
        }