コード例 #1
0
        public static void CalibrationTestLowRes()
        {
            CalibrationTask calibrationTask = new CalibrationTask();

            EngineLayer.CommonParameters CommonParameters = new EngineLayer.CommonParameters
                                                                (dissociationType: MassSpectrometry.DissociationType.LowCID,
                                                                scoreCutoff: 1);

            string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestCalibrationLow");
            string myFile       = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\sliced_b6.mzML");
            string myDatabase   = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\LowResSnip_B6_mouse_11700_117500.xml.gz");

            Directory.CreateDirectory(outputFolder);

            calibrationTask.RunTask(outputFolder, new List <DbForTask> {
                new DbForTask(myDatabase, false)
            }, new List <string> {
                myFile
            }, "test");
            Assert.That(File.Exists(Path.Combine(outputFolder, @"sliced_b6-calib.mzML")));
            Assert.That(File.Exists(Path.Combine(outputFolder, @"sliced_b6-calib.toml")));
            var lines      = File.ReadAllLines(Path.Combine(outputFolder, @"sliced_b6-calib.toml"));
            var tolerance  = Regex.Match(lines[0], @"\d+\.\d*").Value;
            var tolerance1 = Regex.Match(lines[1], @"\d+\.\d*").Value;

            Assert.That(double.TryParse(tolerance, out double tol) == true);
            Assert.That(double.TryParse(tolerance1, out double tol1) == true);
            Assert.That(lines[0].Contains("PrecursorMassTolerance"));
            Assert.That(lines[1].Contains("ProductMassTolerance"));
            Directory.Delete(outputFolder, true);
            Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true);
        }
コード例 #2
0
        public static void ExperimentalDesignCalibrationTest(string originalFileName)
        {
            CalibrationTask calibrationTask = new CalibrationTask();
            string          outputFolder    = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestCalibration");
            string          myFile          = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\" + originalFileName);

            File.Copy(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"), myFile, true);

            string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\smalldb.fasta");
            string experimentalDesignFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\ExperimentalDesign.tsv");

            Directory.CreateDirectory(outputFolder);

            using (StreamWriter output = new StreamWriter(experimentalDesignFilePath))
            {
                output.WriteLine("FileName\tCondition\tBiorep\tFraction\tTechrep");
                output.WriteLine(Path.GetFileNameWithoutExtension(myFile) + "\t" + "condition" + "\t" + "1" + "\t" + "1" + "\t" + "1");
            }

            calibrationTask.RunTask(outputFolder, new List <DbForTask> {
                new DbForTask(myDatabase, false)
            }, new List <string> {
                myFile
            }, "test");

            var    expDesignPath = Path.Combine(outputFolder, @"ExperimentalDesign.tsv");
            var    expDesign     = File.ReadAllLines(expDesignPath);
            string expectedCalibratedFileName = Path.GetFileNameWithoutExtension(myFile) + "-calib.mzML";
            string expectedTomlName           = Path.GetFileNameWithoutExtension(myFile) + "-calib.toml";

            Assert.That(expDesign[1].Contains(Path.GetFileNameWithoutExtension(expectedCalibratedFileName)));
            Assert.That(File.Exists(Path.Combine(outputFolder, myFile)));
            Assert.That(File.Exists(Path.Combine(outputFolder, expectedTomlName)));

            var lines      = File.ReadAllLines(Path.Combine(outputFolder, expectedTomlName));
            var tolerance  = Regex.Match(lines[0], @"\d+\.\d*").Value;
            var tolerance1 = Regex.Match(lines[1], @"\d+\.\d*").Value;

            Assert.That(double.TryParse(tolerance, out double tol) == true);
            Assert.That(double.TryParse(tolerance1, out double tol1) == true);
            Assert.That(lines[0].Contains("PrecursorMassTolerance"));
            Assert.That(lines[1].Contains("ProductMassTolerance"));

            File.Delete(experimentalDesignFilePath);
            File.Delete(myFile);
            Directory.Delete(outputFolder, true);
            Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true);
        }
コード例 #3
0
        public static void ExperimentalDesignCalibrationTest(string nonCalibratedFile)
        {
            // set up directories
            string unitTestFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"ExperimentalDesignCalibrationTest");
            string outputFolder   = Path.Combine(unitTestFolder, @"TaskOutput");

            Directory.CreateDirectory(unitTestFolder);
            Directory.CreateDirectory(outputFolder);

            // set up original spectra file (input to calibration)
            string nonCalibratedFilePath = Path.Combine(unitTestFolder, nonCalibratedFile);

            File.Copy(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"), nonCalibratedFilePath, true);

            // protein db
            string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\smalldb.fasta");

            // set up original experimental design (input to calibration)
            SpectraFileInfo fileInfo = new SpectraFileInfo(nonCalibratedFilePath, "condition", 0, 0, 0);
            var             experimentalDesignFilePath = ExperimentalDesign.WriteExperimentalDesignToFile(new List <SpectraFileInfo> {
                fileInfo
            });

            // run calibration
            CalibrationTask calibrationTask = new CalibrationTask();

            calibrationTask.RunTask(outputFolder, new List <DbForTask> {
                new DbForTask(myDatabase, false)
            }, new List <string> {
                nonCalibratedFilePath
            }, "test");

            // test new experimental design written by calibration
            var    newExpDesignPath           = Path.Combine(outputFolder, @"ExperimentalDesign.tsv");
            string expectedCalibratedFileName = Path.GetFileNameWithoutExtension(nonCalibratedFilePath) + "-calib.mzML";
            var    expectedCalibratedFilePath = Path.Combine(outputFolder, expectedCalibratedFileName);
            var    newExperDesign             = ExperimentalDesign.ReadExperimentalDesign(newExpDesignPath, new List <string> {
                expectedCalibratedFilePath
            }, out var errors);

            Assert.That(!errors.Any());
            Assert.That(newExperDesign.Count == 1);

            // test file-specific toml written by calibration w/ suggested ppm tolerances
            string expectedTomlName = Path.GetFileNameWithoutExtension(nonCalibratedFilePath) + "-calib.toml";

            Assert.That(File.Exists(Path.Combine(outputFolder, expectedTomlName)));

            var lines      = File.ReadAllLines(Path.Combine(outputFolder, expectedTomlName));
            var tolerance  = Regex.Match(lines[0], @"\d+\.\d*").Value;
            var tolerance1 = Regex.Match(lines[1], @"\d+\.\d*").Value;

            Assert.That(double.TryParse(tolerance, out double tol) == true);
            Assert.That(double.TryParse(tolerance1, out double tol1) == true);
            Assert.That(lines[0].Contains("PrecursorMassTolerance"));
            Assert.That(lines[1].Contains("ProductMassTolerance"));

            // check that calibrated .mzML exists
            Assert.That(File.Exists(Path.Combine(outputFolder, expectedCalibratedFilePath)));

            // clean up
            Directory.Delete(unitTestFolder, true);
        }