public static void TestLookingForAcceptableIsotopicEnvelopes()
        {
            CommonParameters CommonParameters = new CommonParameters();

            MetaMorpheusTask.DetermineAnalyteType(CommonParameters);

            var variableModifications = new List <Modification>();
            var fixedModifications    = new List <Modification>();

            var proteinList = new List <Protein>
            {
                new Protein("AAAHSSLK", ""), new Protein("RQPAQPR", ""), new Protein("EKAEAEAEK", "")
            };
            var myMsDataFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"));


            var searchMode = new SinglePpmAroundZeroSearchMode(5);

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

            var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray();

            var ms2ScanTest = listOfSortedms2Scans[0];

            //test when all the masses are not in the given range

            //test1 when all the masses are too small
            var test1 = ms2ScanTest.GetClosestExperimentalIsotopicEnvelopeList(50, 95);

            Assert.AreEqual(test1, null);
            //test2 when all the masses are too big
            var test2 = ms2ScanTest.GetClosestExperimentalIsotopicEnvelopeList(582, 682);

            Assert.AreEqual(test2, null);
            //test3 when the mass which is bigger than given min mass is bigger than the mass which is smaller than the given max mass
            //for example: the mass array is [1,2,3,4,5], the given min mass is 2.2, the given max mass is 2.8
            var test3 = ms2ScanTest.GetClosestExperimentalIsotopicEnvelopeList(110, 111);

            Assert.AreEqual(test3, null);


            //test normal conditions:look for IsotopicEnvelopes which are in the range of acceptable mass
            var test4 = ms2ScanTest.GetClosestExperimentalIsotopicEnvelopeList(120, 130);

            IsotopicEnvelope[] expected4 = ms2ScanTest.ExperimentalFragments.Skip(15).Take(9).ToArray();
            Assert.That(ms2ScanTest.ExperimentalFragments[15].MonoisotopicMass > 120 && ms2ScanTest.ExperimentalFragments[14].MonoisotopicMass < 120);
            Assert.That(ms2ScanTest.ExperimentalFragments[23].MonoisotopicMass < 130 && ms2ScanTest.ExperimentalFragments[24].MonoisotopicMass > 130);
            Assert.AreEqual(test4, expected4);

            var test5 = ms2ScanTest.GetClosestExperimentalIsotopicEnvelopeList(400, 500);

            IsotopicEnvelope[] expected5 = ms2ScanTest.ExperimentalFragments.Skip(150).Take(7).ToArray();
            Assert.That(ms2ScanTest.ExperimentalFragments[150].MonoisotopicMass > 400 && ms2ScanTest.ExperimentalFragments[149].MonoisotopicMass < 400);
            Assert.That(ms2ScanTest.ExperimentalFragments[156].MonoisotopicMass < 500 && ms2ScanTest.ExperimentalFragments[157].MonoisotopicMass > 500);
            Assert.AreEqual(test5, expected5);
        }
예제 #2
0
        public static void TestXicExtraction()
        {
            string dataFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", "SmallCalibratibleYeast.mzml");
            var    data         = Mzml.LoadAllStaticData(dataFilePath);

            var peptide = new PeptideWithSetModifications("KAPAGGAADAAAK", new Dictionary <string, Modification>());

            var xic = data.ExtractIonChromatogram(peptide.MonoisotopicMass, 2, new PpmTolerance(10), 24.806);

            Assert.That(xic.Data.Count(p => p.Y > 0) == 4);
        }
예제 #3
0
        public static void Test_ChargeDeconv()
        {
            string     FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/2076.mzML");
            MsDataFile file         = Mzml.LoadAllStaticData(FilepathMZML, null);
            var        scans        = file.GetAllScansList();

            DeconvolutionParameter deconvolutionParameter = new DeconvolutionParameter();

            Stopwatch stopwatch0 = new Stopwatch();

            stopwatch0.Start();
            var spectrum = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true);

            stopwatch0.Stop();

            Stopwatch stopwatch_iso = new Stopwatch();

            stopwatch_iso.Start();
            var iso = IsoDecon.MsDeconv_Deconvolute(spectrum, spectrum.Range, deconvolutionParameter);

            stopwatch_iso.Stop();

            Stopwatch stopwatch1 = new Stopwatch();

            stopwatch1.Start();
            var x = ChargeDecon.FindChargesForScan(spectrum, deconvolutionParameter);

            stopwatch1.Stop();

            //Stopwatch stopwatch2 = new Stopwatch();
            //stopwatch2.Start();
            var stopwatch2 = Stopwatch.StartNew();
            var x2         = ChargeDecon.QuickFindChargesForScan(spectrum, deconvolutionParameter);

            stopwatch2.Stop();

            //    Stopwatch stopwatch3 = new Stopwatch();
            //    stopwatch3.Start();
            //    int indUp = spectrum.ExtractIndicesByY().First();
            //    double mass_up = spectrum.XArray[indUp];
            //    var highest = ChargeDecon.FindChargesForPeak(spectrum, indUp, new DeconvolutionParameter());
            //    stopwatch3.Stop();

            //    var Parameters = Program.AddParametersFromFile("");
            //    List<double> masses = highest.Select(p => p.Value.Mz).ToList();
            //    string dynamicTargets;
            //    string dynamicMaxITs;

            //    Stopwatch stopwatch4 = new Stopwatch();
            //    stopwatch4.Start();
            //    var test = BoxCarScan.BuildDynamicBoxString(Parameters, masses, out dynamicTargets, out dynamicMaxITs);
            //    stopwatch4.Stop();
            //    Assert.That(test == "[(400.0,522.8),(524.8,542.2),(544.2,563.1),(565.1,585.6),(587.6,610.0),(612.0,636.5),(638.5,665.4),(667.4,697.1),(699.1,732.0),(734.0,770.5),(772.5,813.3),(815.3,861.1),(863.1,915.0),(917.0,976.0),(978.0,1045.7),(1047.7,1126.1),(1128.1,1200.0)]");
        }
예제 #4
0
        public static void TestSummedMsDataFile()
        {
            ThermoStaticData rawFile = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw");

            // 3 scans

            SummedMsDataFile summed3 = new SummedMsDataFile(rawFile, 3, 10);

            Assert.AreEqual(rawFile.NumSpectra - 2, summed3.NumSpectra);

            var resultingTic        = summed3.GetOneBasedScan(1).TotalIonCurrent;
            var mySummedTic         = rawFile.GetOneBasedScan(1).MassSpectrum.SumOfAllY + rawFile.GetOneBasedScan(2).MassSpectrum.SumOfAllY + rawFile.GetOneBasedScan(3).MassSpectrum.SumOfAllY;
            var instrumentSummedTic = rawFile.GetOneBasedScan(1).TotalIonCurrent + rawFile.GetOneBasedScan(2).TotalIonCurrent + rawFile.GetOneBasedScan(3).TotalIonCurrent;

            // Tics are approximately what they should be
            Assert.IsTrue(Math.Abs(resultingTic - mySummedTic) / mySummedTic < 1e-4);
            Assert.IsTrue(Math.Abs(resultingTic - instrumentSummedTic) / instrumentSummedTic < 1e-1);

            // Equal to representative
            Assert.AreEqual(summed3.GetOneBasedScan(1).RetentionTime, rawFile.GetOneBasedScan(2).RetentionTime);

            Assert.IsTrue(summed3.GetOneBasedScan(1).MassSpectrum.Size <= rawFile.GetOneBasedScan(1).MassSpectrum.Size + rawFile.GetOneBasedScan(2).MassSpectrum.Size + rawFile.GetOneBasedScan(3).MassSpectrum.Size);
            Assert.IsTrue(summed3.GetOneBasedScan(1).MassSpectrum.Size >= rawFile.GetOneBasedScan(1).MassSpectrum.Size);
            Assert.IsTrue(summed3.GetOneBasedScan(1).MassSpectrum.Size >= rawFile.GetOneBasedScan(2).MassSpectrum.Size);
            Assert.IsTrue(summed3.GetOneBasedScan(1).MassSpectrum.Size >= rawFile.GetOneBasedScan(3).MassSpectrum.Size);

            Assert.IsTrue(summed3.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY == rawFile.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY + rawFile.GetOneBasedScan(2).MassSpectrum.YofPeakWithHighestY + rawFile.GetOneBasedScan(3).MassSpectrum.YofPeakWithHighestY);

            // Interval of 893-899 mz

            Assert.AreEqual(2, rawFile.GetOneBasedScan(1).MassSpectrum.NumPeaksWithinRange(893, 899));
            Assert.AreEqual(2, rawFile.GetOneBasedScan(2).MassSpectrum.NumPeaksWithinRange(893, 899));
            Assert.AreEqual(1, rawFile.GetOneBasedScan(3).MassSpectrum.NumPeaksWithinRange(893, 899));

            // One peak persists across the three scans! So instead of 5 see three peaks in summed
            Assert.AreEqual(3, summed3.GetOneBasedScan(1).MassSpectrum.NumPeaksWithinRange(893, 899));

            Assert.AreEqual(summed3.GetOneBasedScan(1).MassSpectrum.FirstX, Math.Min(Math.Min(rawFile.GetOneBasedScan(1).MassSpectrum.FirstX.Value, rawFile.GetOneBasedScan(2).MassSpectrum.FirstX.Value), rawFile.GetOneBasedScan(3).MassSpectrum.FirstX.Value));

            Assert.AreEqual(summed3.GetOneBasedScan(1).MassSpectrum.LastX, Math.Max(Math.Max(rawFile.GetOneBasedScan(1).MassSpectrum.LastX.Value, rawFile.GetOneBasedScan(2).MassSpectrum.LastX.Value), rawFile.GetOneBasedScan(3).MassSpectrum.LastX.Value));

            // 5 scans
            SummedMsDataFile summed5 = new SummedMsDataFile(rawFile, 5, 10);

            Assert.AreEqual(rawFile.NumSpectra - 4, summed5.NumSpectra);

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(summed5, "testSummed.mzML", false);

            var ok = Mzml.LoadAllStaticData("testSummed.mzML");

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(ok, "testSummed2.mzML", false);

            Mzml.LoadAllStaticData("testSummed2.mzML");
        }
예제 #5
0
        public static void WriteIndexedMzmlFromThermoTest()
        {
            var smallThermo = ThermoStaticData.LoadAllStaticData(@"small.raw");

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(smallThermo, Path.Combine(TestContext.CurrentContext.TestDirectory, "Hi.mzML"), true);
            var smallMzml = Mzml.LoadAllStaticData(@"Hi.mzML");

            Assert.AreEqual(smallMzml.NumSpectra, 48);
            Assert.AreEqual(smallMzml.GetOneBasedScan(8).OneBasedScanNumber, 8);
            Assert.AreEqual(smallThermo.GetOneBasedScan(5).RetentionTime, smallMzml.GetOneBasedScan(5).RetentionTime);
        }
예제 #6
0
        public static void Test_RealDataDeconv()
        {
            string     FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/20170802_QEp1_FlMe_SA_BOX0_SILAC_BoxCar_SLICED.mzML");
            MsDataFile file         = Mzml.LoadAllStaticData(FilepathMZML, null);
            var        scans        = file.GetAllScansList();

            var test = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true);


            var ms1scans = scans.Where(p => p.MsnOrder == 1).ToList();
            DeconvolutionParameter deconvolutionParameter = new DeconvolutionParameter();
        }
예제 #7
0
        public static void Test_FragmentMesh()
        {
            string     FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/2076.mzML");
            MsDataFile file         = Mzml.LoadAllStaticData(FilepathMZML, null);
            var        scans        = file.GetAllScansList();

            DeconvolutionParameter deconvolutionParameter = new DeconvolutionParameter();
            var spectrum = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true);

            var CEs = ChargeDecon.FindChargesForScan(spectrum, deconvolutionParameter);

            var mesh = CEs.First().mzs_box;

            Assert.That(mesh.Count() == 3);
        }
예제 #8
0
        public static void BU_dynamicBoxCarRange()
        {
            string     FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/20170802_QEp1_FlMe_SA_BOX0_SILAC_BoxCar_SLICED.mzML");
            MsDataFile file         = Mzml.LoadAllStaticData(FilepathMZML, null);
            var        scans        = file.GetAllScansList();

            var        spectrum   = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true);
            Parameters parameters = Program.AddParametersFromFile("");
            var        isos       = IsoDecon.MsDeconv_Deconvolute(spectrum, spectrum.Range, parameters.DeconvolutionParameter);

            List <List <Tuple <double, double, double> > > Boxes = new List <List <Tuple <double, double, double> > >();

            BoxCarScan.GenerateDynamicBoxes_BU(isos, parameters, Boxes);

            Assert.That(Boxes.Count == 2);
        }
예제 #9
0
파일: TestMzML.cs 프로젝트: dippman/mzLib
        public static void WriteEmptyScan()
        {
            double[]       intensities1 = new double[] { };
            double[]       mz1          = new double[] { };
            MzmlMzSpectrum massSpec1    = new MzmlMzSpectrum(mz1, intensities1, false);

            IMzmlScan[] scans = new IMzmlScan[] {
                new MzmlScan(1, massSpec1, 1, true, Polarity.Positive, 1, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec1.SumOfAllY, null, "1")
            };
            FakeMsDataFile f = new FakeMsDataFile(scans);

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(f, Path.Combine(TestContext.CurrentContext.TestDirectory, "mzmlWithEmptyScan.mzML"), false);

            Mzml ok = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, "mzmlWithEmptyScan.mzML"));

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(ok, Path.Combine(TestContext.CurrentContext.TestDirectory, "mzmlWithEmptyScan2.mzML"), false);
        }
예제 #10
0
파일: TestMzML.cs 프로젝트: NRTDP/mzLib
        public void LoadMzmlAnotherTest()
        {
            Mzml a = Mzml.LoadAllStaticData(@"small.pwiz.1.1.mzML");

            Assert.AreEqual(19914, a.First().MassSpectrum.Size);

            //a = new Mzml(@"small.pwiz.1.1.mzML", 400);
            //a.Open();

            //Assert.AreEqual(400, a.First().MassSpectrum.Size);

            //var cool = a.GetOneBasedScan(6) as MzmlScanWithPrecursor;

            //Assert.AreEqual(1, cool.IsolationWidth);

            //a.Close();
        }
예제 #11
0
        /// <summary>
        /// Tests peak filtering for ThermoRawFileReader
        /// </summary>
        public static void TestPeakFilteringRawFileReader(string infile)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            var filterParams = new FilteringParams(200, 0.01, 0, 1, false, true, true);

            var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", infile);

            var a        = ThermoRawFileReader.LoadAllStaticData(path, filterParams, maxThreads: 1);
            var rawScans = a.GetAllScansList();

            foreach (var scan in rawScans)
            {
                Assert.That(scan.MassSpectrum.XArray.Length <= 200);
            }

            string outfile1 = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", Path.GetFileNameWithoutExtension(infile) + ".mzML");

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(a, outfile1, false);
            var mzml = Mzml.LoadAllStaticData(outfile1, filterParams, maxThreads: 1);

            var mzmlScans = mzml.GetAllScansList();

            for (int i = 0; i < mzmlScans.Count; i++)
            {
                var mzmlScan = mzmlScans[i];
                var rawScan  = rawScans[i];

                for (int j = 0; j < mzmlScan.MassSpectrum.XArray.Length; j++)
                {
                    double roundedMzmlMz = Math.Round(mzmlScan.MassSpectrum.XArray[j], 2);
                    double roundedRawMz  = Math.Round(rawScan.MassSpectrum.XArray[j], 2);

                    Assert.AreEqual(roundedMzmlMz, roundedRawMz);

                    double roundedMzmlIntensity = Math.Round(mzmlScan.MassSpectrum.XArray[j], 0);
                    double roundedRawIntensity  = Math.Round(rawScan.MassSpectrum.XArray[j], 0);

                    Assert.AreEqual(roundedMzmlIntensity, roundedRawIntensity);
                }
            }

            Console.WriteLine($"Analysis time for TestPeakFilteringRawFileReader: {stopwatch.Elapsed.Hours}h " +
                              $"{stopwatch.Elapsed.Minutes}m {stopwatch.Elapsed.Seconds}s");
        }
예제 #12
0
        public static void LoadCompressedMzml()
        {
            ThermoStaticData a = ThermoStaticData.LoadAllStaticData(@"small.RAW");

            Mzml b = Mzml.LoadAllStaticData(@"smallCentroid.mzML");

            Assert.AreEqual(a.NumSpectra, b.NumSpectra);

            Assert.AreEqual(a.GetOneBasedScan(1).MassSpectrum.XofPeakWithHighestY.Value, b.GetOneBasedScan(1).MassSpectrum.XofPeakWithHighestY.Value, 1e-8);
            Assert.IsTrue(Math.Abs((a.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY.Value - b.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY.Value) / b.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY.Value) < 1e-8);

            Assert.AreEqual(a.GetOneBasedScan(2).MassSpectrum.XofPeakWithHighestY.Value, b.GetOneBasedScan(2).MassSpectrum.XofPeakWithHighestY, 1e-8);
            Assert.IsTrue(Math.Abs((a.GetOneBasedScan(2).MassSpectrum.YofPeakWithHighestY.Value - b.GetOneBasedScan(2).MassSpectrum.YofPeakWithHighestY.Value) / b.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY.Value) < 1e-8);

            Assert.AreEqual(a.GetOneBasedScan(3).MassSpectrum.XofPeakWithHighestY.Value, b.GetOneBasedScan(3).MassSpectrum.XofPeakWithHighestY.Value, 1e-8);
            Assert.IsTrue(Math.Abs((a.GetOneBasedScan(3).MassSpectrum.YofPeakWithHighestY.Value - b.GetOneBasedScan(3).MassSpectrum.YofPeakWithHighestY.Value) / b.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY.Value) < 1e-8);
        }
예제 #13
0
파일: TestMzML.cs 프로젝트: dippman/mzLib
        public void WriteMzmlTest()
        {
            var peptide = new Peptide("GPEAPPPALPAGAPPPCTAVTSDHLNSLLGNILR");
            OldSchoolChemicalFormulaModification carbamidomethylationOfCMod = new OldSchoolChemicalFormulaModification(ChemicalFormula.ParseFormula("H3C2NO"), "carbamidomethylation of C", ModificationSites.C);

            peptide.AddModification(carbamidomethylationOfCMod);

            MzmlMzSpectrum MS1 = CreateSpectrum(peptide.GetChemicalFormula(), 300, 2000, 1);

            MzmlMzSpectrum MS2 = CreateMS2spectrum(peptide.Fragment(FragmentTypes.b | FragmentTypes.y, true), 100, 1500);

            IMzmlScan[] Scans = new IMzmlScan[2];

            Scans[0] = new MzmlScan(1, MS1, 1, true, Polarity.Positive, 1.0, new MzRange(300, 2000), " first spectrum", MZAnalyzerType.Unknown, MS1.SumOfAllY, 1, "scan=1");

            Scans[1] = new MzmlScanWithPrecursor(2, MS2, 2, true, Polarity.Positive, 2.0, new MzRange(100, 1500), " second spectrum", MZAnalyzerType.Unknown, MS2.SumOfAllY, 1134.26091302033, 3, 0.141146966879759, 1134.3, 1, DissociationType.Unknown, 1, 1134.26091302033, 1, "scan=2");

            var myMsDataFile = new FakeMsDataFile(Scans);

            var oldFirstValue = myMsDataFile.GetOneBasedScan(1).MassSpectrum.FirstX;

            var secondScan = myMsDataFile.GetOneBasedScan(2) as IMsDataScanWithPrecursor <MzmlMzSpectrum>;

            Assert.AreEqual(1, secondScan.IsolationRange.Maximum - secondScan.IsolationRange.Minimum);

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, "argh.mzML", false);

            Mzml okay = Mzml.LoadAllStaticData(@"argh.mzML");

            okay.GetOneBasedScan(2);

            Assert.AreEqual(1, okay.GetClosestOneBasedSpectrumNumber(1));
            Assert.AreEqual(2, okay.GetClosestOneBasedSpectrumNumber(2));

            var newFirstValue = okay.GetOneBasedScan(1).MassSpectrum.FirstX;

            Assert.AreEqual(oldFirstValue.Value, newFirstValue.Value, 1e-9);

            var secondScan2 = okay.GetOneBasedScan(2) as IMsDataScanWithPrecursor <MzmlMzSpectrum>;

            Assert.AreEqual(1, secondScan2.IsolationRange.Maximum - secondScan2.IsolationRange.Minimum);

            secondScan2.MassSpectrum.ReplaceXbyApplyingFunction((a) => 44);
            Assert.AreEqual(44, secondScan2.MassSpectrum.LastX);
        }
예제 #14
0
        public static void ProcessXcorrInMzSpectrum()
        {
            Dictionary <string, MsDataFile> MyMsDataFiles = new Dictionary <string, MsDataFile>();
            string          origDataFile = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", "BinGenerationTest.mzML");
            FilteringParams filter       = new FilteringParams(200, 0.01, null, 1, false, false, true);

            MyMsDataFiles[origDataFile] = Mzml.LoadAllStaticData(origDataFile, filter, 1);

            var scans = MyMsDataFiles[origDataFile].GetAllScansList();

            foreach (MsDataScan scan in scans.Where(s => s.MsnOrder > 1))
            {
                scan.MassSpectrum.XCorrPrePreprocessing(0, 1968 * 1.0005079, scan.IsolationMz.Value);
            }

            Assert.AreEqual(6, scans[0].MassSpectrum.XArray.Count());
            Assert.AreEqual(20, scans[1].MassSpectrum.XArray.Count());
        }
예제 #15
0
        /// <summary>
        /// Tests LoadAllStaticData for ThermoRawFileReader
        /// </summary>
        public static void TestLoadAllStaticDataRawFileReader(string infile, string outfile1, string outfile2)
        {
            var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", infile);

            outfile1 = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", outfile1);
            outfile2 = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", outfile2);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            var a = ThermoRawFileReader.LoadAllStaticData(path, maxThreads: 1);

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(a, outfile1, false);
            var aa = Mzml.LoadAllStaticData(outfile1);

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(aa, outfile2, true);
            Mzml.LoadAllStaticData(outfile2);
            Console.WriteLine($"Analysis time for TestLoadAllStaticDataRawFileReader({infile}): {stopwatch.Elapsed.Hours}h {stopwatch.Elapsed.Minutes}m {stopwatch.Elapsed.Seconds}s");
        }
예제 #16
0
파일: TestMzML.cs 프로젝트: NRTDP/mzLib
        public void LoadMzmlTest()
        {
            Mzml a = Mzml.LoadAllStaticData(@"tiny.pwiz.1.1.mzML");

            var ya = a.GetOneBasedScan(1).MassSpectrum;

            Assert.AreEqual(15, ya.Size);
            var ya2 = a.GetOneBasedScan(2).MassSpectrum;

            Assert.AreEqual(10, ya2.Size);
            var ya3 = a.GetOneBasedScan(3).MassSpectrum;

            Assert.AreEqual(0, ya3.Size);
            var ya4 = a.GetOneBasedScan(4).MassSpectrum;

            Assert.AreEqual(15, ya4.Size);

            IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > ok = a;

            Assert.AreEqual(1, ok.GetClosestOneBasedSpectrumNumber(5));
        }
예제 #17
0
파일: TestMzML.cs 프로젝트: dippman/mzLib
        public static void AnotherMzMLtest()
        {
            IMzmlScan[] scans = new IMzmlScan[4];

            double[]       intensities1 = new double[] { 1 };
            double[]       mz1          = new double[] { 50 };
            MzmlMzSpectrum massSpec1    = new MzmlMzSpectrum(mz1, intensities1, false);

            scans[0] = new MzmlScan(1, massSpec1, 1, true, Polarity.Positive, 1, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec1.SumOfAllY, null, "1");

            double[]       intensities2 = new double[] { 1 };
            double[]       mz2          = new double[] { 30 };
            MzmlMzSpectrum massSpec2    = new MzmlMzSpectrum(mz2, intensities2, false);

            scans[1] = new MzmlScanWithPrecursor(2, massSpec2, 2, true, Polarity.Positive, 2, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec2.SumOfAllY,
                                                 50, null, null, 50, 1, DissociationType.CID, 1, null, null, "2");

            double[]       intensities3 = new double[] { 1 };
            double[]       mz3          = new double[] { 50 };
            MzmlMzSpectrum massSpec3    = new MzmlMzSpectrum(mz3, intensities3, false);

            scans[2] = new MzmlScan(3, massSpec3, 1, true, Polarity.Positive, 1, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec1.SumOfAllY, null, "3");

            double[]       intensities4 = new double[] { 1 };
            double[]       mz4          = new double[] { 30 };
            MzmlMzSpectrum massSpec4    = new MzmlMzSpectrum(mz4, intensities4, false);

            scans[3] = new MzmlScanWithPrecursor(4, massSpec4, 2, true, Polarity.Positive, 2, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec2.SumOfAllY,
                                                 50, null, null, 50, 1, DissociationType.CID, 3, null, null, "4");

            FakeMsDataFile f = new FakeMsDataFile(scans);

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(f, Path.Combine(TestContext.CurrentContext.TestDirectory, "what.mzML"), false);

            Mzml ok = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, "what.mzML"));

            var scanWithPrecursor = ok.Last(b => b is IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >;

            Assert.AreEqual(3, scanWithPrecursor.OneBasedPrecursorScanNumber);
        }
예제 #18
0
파일: TestMzML.cs 프로젝트: dippman/mzLib
        public void LoadMzmlFromConvertedMGFTest()
        {
            Mzml a = Mzml.LoadAllStaticData(@"tester.mzML");

            var ya = a.GetOneBasedScan(1).MassSpectrum;

            Assert.AreEqual(192, ya.Size);
            var ya2 = a.GetOneBasedScan(3).MassSpectrum;

            Assert.AreEqual(165, ya2.Size);
            var ya3 = a.GetOneBasedScan(5).MassSpectrum;

            Assert.AreEqual(551, ya3.Size);
            var ya4 = a.GetOneBasedScan(975).MassSpectrum;

            Assert.AreEqual(190, ya4.Size);

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(a, "CreateFileFromConvertedMGF.mzML", false);

            Mzml b = Mzml.LoadAllStaticData(@"CreateFileFromConvertedMGF.mzML");

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(b, "CreateFileFromConvertedMGF2.mzML", false);
        }
예제 #19
0
        public static void TestClassicSearchEngineTopDown()
        {
            CommonParameters CommonParameters = new CommonParameters(
                digestionParams: new DigestionParams(protease: "top-down"),
                scoreCutoff: 1,
                assumeOrphanPeaksAreZ1Fragments: false);

            MetaMorpheusTask.DetermineAnalyteType(CommonParameters);

            // test output file name (should be proteoform and not peptide)
            Assert.That(GlobalVariables.AnalyteType == "Proteoform");

            var variableModifications = new List <Modification>();
            var fixedModifications    = new List <Modification>();
            var proteinList           = new List <Protein>
            {
                new Protein("MPKVYSYQEVAEHNGPENFWIIIDDKVYDVSQFKDEHPGGDEIIMDLGGQDATESFVDIGHSDEALRLLKGLYIGDVDKTSERVSVEKVSTSENQSKGSGTLVVILAILMLGVAYYLLNE", "P40312")
            };

            var myMsDataFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TopDownTestData\slicedTDYeast.mzML"));

            var searchMode = new SinglePpmAroundZeroSearchMode(5);

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

            var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray();

            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            bool writeSpetralLibrary            = false;

            new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, null, new List <string>(), writeSpetralLibrary).Run();

            var psm = allPsmsArray.Where(p => p != null).FirstOrDefault();

            Assert.That(psm.MatchedFragmentIons.Count == 47);
        }
예제 #20
0
        public static List <ScanHeaderInfo> FileScanHeaderInfo(string fullFilePathWithExtension)
        {
            string filename = Path.GetFileName(fullFilePathWithExtension);
            List <ScanHeaderInfo> scanHeaderInfoList = new();

            switch (GetDataFileType(fullFilePathWithExtension))
            {
            case DataFileType.Thermo:
                ThermoRawFileReader staticRaw = ThermoRawFileReader.LoadAllStaticData(fullFilePathWithExtension);
                foreach (MsDataScan item in staticRaw)
                {
                    scanHeaderInfoList.Add(new ScanHeaderInfo(fullFilePathWithExtension, filename, item.OneBasedScanNumber, item.RetentionTime));
                }
                break;

            case DataFileType.mzML:
                List <MsDataScan> mzmlDataScans = Mzml.LoadAllStaticData(fullFilePathWithExtension).GetAllScansList();
                foreach (MsDataScan item in mzmlDataScans)
                {
                    scanHeaderInfoList.Add(new ScanHeaderInfo(fullFilePathWithExtension, filename, item.OneBasedScanNumber, item.RetentionTime));
                }
                break;

            case DataFileType.mgf:
                List <MsDataScan> mgfDataScans = Mgf.LoadAllStaticData(fullFilePathWithExtension).GetAllScansList();
                foreach (MsDataScan item in mgfDataScans)
                {
                    scanHeaderInfoList.Add(new ScanHeaderInfo(fullFilePathWithExtension, filename, item.OneBasedScanNumber, item.RetentionTime));
                }
                break;

            case DataFileType.unknown:
            default:
                break;
            }
            return(scanHeaderInfoList);
        }
예제 #21
0
        public MsDataFile LoadFile(string origDataFile, int?topNpeaks, double?minRatio, bool trimMs1Peaks, bool trimMsMsPeaks, CommonParameters commonParameters)
        {
            FilteringParams filter = new FilteringParams(topNpeaks, minRatio, null, 1, false, trimMs1Peaks, trimMsMsPeaks);

            if (commonParameters.DissociationType == DissociationType.LowCID || commonParameters.ChildScanDissociationType == DissociationType.LowCID)
            {
                filter = null;
            }

            if (MyMsDataFiles.TryGetValue(origDataFile, out MsDataFile value) && value != null)
            {
                return(value);
            }

            // By now know that need to load this file!!!
            lock (FileLoadingLock) // Lock because reading is sequential
            {
                if (Path.GetExtension(origDataFile).Equals(".mzML", StringComparison.OrdinalIgnoreCase))
                {
                    MyMsDataFiles[origDataFile] = Mzml.LoadAllStaticData(origDataFile, filter, commonParameters.MaxThreadsToUsePerFile);
                }
                else if (Path.GetExtension(origDataFile).Equals(".mgf", StringComparison.OrdinalIgnoreCase))
                {
                    MyMsDataFiles[origDataFile] = Mgf.LoadAllStaticData(origDataFile, filter);
                }
                else
                {
#if NETFRAMEWORK
                    MyMsDataFiles[origDataFile] = ThermoStaticData.LoadAllStaticData(origDataFile, filter);
#else
                    Warn("No capability for reading " + origDataFile);
#endif
                }

                return(MyMsDataFiles[origDataFile]);
            }
        }
예제 #22
0
        public MsDataFile LoadFile(string origDataFile, CommonParameters commonParameters)
        {
            FilteringParams filter = new FilteringParams(commonParameters.NumberOfPeaksToKeepPerWindow, commonParameters.MinimumAllowedIntensityRatioToBasePeak, commonParameters.WindowWidthThomsons, commonParameters.NumberOfWindows, commonParameters.NormalizePeaksAccrossAllWindows, commonParameters.TrimMs1Peaks, commonParameters.TrimMsMsPeaks);

            if (commonParameters.DissociationType == DissociationType.LowCID || commonParameters.ChildScanDissociationType == DissociationType.LowCID)
            {
                filter = null;
            }

            if (MyMsDataFiles.TryGetValue(origDataFile, out MsDataFile value) && value != null)
            {
                return(value);
            }

            // By now know that need to load this file!!!
            lock (FileLoadingLock) // Lock because reading is sequential
            {
                if (Path.GetExtension(origDataFile).Equals(".mzML", StringComparison.OrdinalIgnoreCase))
                {
                    MyMsDataFiles[origDataFile] = Mzml.LoadAllStaticData(origDataFile, filter, commonParameters.MaxThreadsToUsePerFile);
                }
                else if (Path.GetExtension(origDataFile).Equals(".mgf", StringComparison.OrdinalIgnoreCase))
                {
                    MyMsDataFiles[origDataFile] = Mgf.LoadAllStaticData(origDataFile, filter);
                }
                else
                {
#if NETFRAMEWORK
                    MyMsDataFiles[origDataFile] = ThermoStaticData.LoadAllStaticData(origDataFile, filter);
#else
                    Warn("No capability for reading " + origDataFile);
#endif
                }

                return(MyMsDataFiles[origDataFile]);
            }
        }
예제 #23
0
        public static void LoadThermoTest2()
        {
            ThermoStaticData a = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw");

            Assert.AreEqual(360, a.NumSpectra);
            Assert.GreaterOrEqual(1000, a.GetOneBasedScan(1).MassSpectrum.Extract(0, 500).Last().Mz);
            Assert.AreEqual(2, a.GetOneBasedScan(1).MassSpectrum.FilterByY(5e6, double.MaxValue).Count());
            var ye = a.GetOneBasedScan(1).MassSpectrum.CopyTo2DArray();

            Assert.AreEqual(77561752, a.GetOneBasedScan(1).TotalIonCurrent);
            Assert.AreEqual(144, a.GetClosestOneBasedSpectrumNumber(2));

            MzSpectrum newSpectrum = new MzSpectrum(a.GetOneBasedScan(51).MassSpectrum.XArray, a.GetOneBasedScan(51).MassSpectrum.YArray, true);

            Assert.AreEqual(1120, a.GetOneBasedScan(1).MassSpectrum.Size);

            var newDeconvolution = a.GetOneBasedScan(1).MassSpectrum.Deconvolute(new MzRange(double.MinValue, double.MaxValue), 1, 10, 1, 4).ToList();

            Assert.IsTrue(newDeconvolution.Any(b => Math.Abs(b.peaks.First().mz.ToMass(b.charge) - 523.257) < 0.001));

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(a, Path.Combine(TestContext.CurrentContext.TestDirectory, "convertedThermo.mzML"), false);

            var sdafaf = a.Deconvolute(null, null, 1, 30, 10, 3, 10, b => true).OrderByDescending(b => b.NumPeaks).First();

            Assert.IsTrue(Math.Abs(262.64 - sdafaf.Mass.ToMz(2)) <= 0.01);

            using (ThermoDynamicData dynamicThermo = ThermoDynamicData.InitiateDynamicConnection(@"05-13-16_cali_MS_60K-res_MS.raw"))
            {
                Assert.AreEqual(136, dynamicThermo.GetClosestOneBasedSpectrumNumber(1.89));
                dynamicThermo.ClearCachedScans();
            }

            Mzml readCovertedMzmlFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, "convertedThermo.mzML"));

            Assert.AreEqual(a.GetAllScansList().First().Polarity, readCovertedMzmlFile.GetAllScansList().First().Polarity);
        }
예제 #24
0
        public static void ReadWriteReadEtc()
        {
            {
                ThermoStaticData a = ThermoStaticData.LoadAllStaticData(@"testFileWMS2.raw");

                MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(a, "a.mzML", false);

                var aa = Mzml.LoadAllStaticData("a.mzML");

                MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(aa, "aa.mzML", true);

                Mzml.LoadAllStaticData("aa.mzML");
            }
            {
                ThermoStaticData a = ThermoStaticData.LoadAllStaticData(@"small.raw");

                MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(a, "a.mzML", false);

                var aa = Mzml.LoadAllStaticData("a.mzML");

                MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(aa, "aa.mzML", true);

                Mzml.LoadAllStaticData("aa.mzML");
            }
            {
                ThermoStaticData a = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw");

                MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(a, "a.mzML", false);

                var aa = Mzml.LoadAllStaticData("a.mzML");

                MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(aa, "aa.mzML", true);

                Mzml.LoadAllStaticData("aa.mzML");
            }
        }
예제 #25
0
        public static void TestReverseDecoyGenerationDuringSearch()
        {
            CommonParameters CommonParameters = new CommonParameters();

            MetaMorpheusTask.DetermineAnalyteType(CommonParameters);

            var variableModifications = new List <Modification>();
            var fixedModifications    = new List <Modification>();

            var proteinList = new List <Protein>
            {
                new Protein("KKAEDGINK", ""), new Protein("AVNSISLK", ""), new Protein("EKAEAEAEK", ""), new Protein("DITANLR", ""), new Protein("QNAIGTAK", ""),
                new Protein("FHKSQLNK", ""), new Protein("KQVAQWNK", ""), new Protein("NTRIEELK", ""), new Protein("RQPAQPR", ""),
            };
            var myMsDataFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"));


            var searchMode = new SinglePpmAroundZeroSearchMode(5);

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

            var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray();


            var path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\myPrositLib.msp");

            var testLibrary = new SpectralLibrary(new List <string> {
                path
            });



            //test when doing spectral library search without generating library
            PeptideSpectralMatch[] allPsmsArray1 = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray1, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, testLibrary, new List <string>(), false).Run();
            var psm1 = allPsmsArray1.Where(p => p != null).ToList();

            Assert.That(psm1[0].IsDecoy == false && psm1[0].FullSequence == "DITANLR");
            Assert.That(psm1[1].IsDecoy == true && psm1[1].FullSequence == "LSISNVAK");
            Assert.That(psm1[2].IsDecoy == true && psm1[2].FullSequence == "LSISNVAK");
            Assert.That(psm1[3].IsDecoy == false && psm1[3].FullSequence == "RQPAQPR");
            Assert.That(psm1[4].IsDecoy == false && psm1[4].FullSequence == "KKAEDGINK");
            Assert.That(psm1[5].IsDecoy == false && psm1[5].FullSequence == "EKAEAEAEK");
            Assert.That(psm1[6].IsDecoy == false && psm1[6].FullSequence == "EKAEAEAEK");


            proteinList.Add(new Protein("LSISNVAK", "", isDecoy: true));
            //test when doing spectral library search with generating library; non spectral search won't generate decoy by "decoy on the fly" , so proteinlist used by non spectral library search would contain decoys
            PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray2, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, testLibrary, new List <string>(), true).Run();
            var psm2 = allPsmsArray2.Where(p => p != null).ToList();

            Assert.That(psm2[0].IsDecoy == false && psm2[0].FullSequence == "DITANLR");
            Assert.That(psm2[1].IsDecoy == true && psm2[1].FullSequence == "LSISNVAK");
            Assert.That(psm2[2].IsDecoy == true && psm2[2].FullSequence == "LSISNVAK");
            Assert.That(psm2[3].IsDecoy == false && psm2[3].FullSequence == "RQPAQPR");
            Assert.That(psm2[4].IsDecoy == false && psm2[4].FullSequence == "KKAEDGINK");
            Assert.That(psm2[5].IsDecoy == false && psm2[5].FullSequence == "EKAEAEAEK");
            Assert.That(psm2[6].IsDecoy == false && psm2[6].FullSequence == "EKAEAEAEK");

            //test when doing non spectral library search without generating library
            PeptideSpectralMatch[] allPsmsArray3 = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray3, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, null, new List <string>(), false).Run();
            var psm3 = allPsmsArray3.Where(p => p != null).ToList();

            Assert.That(psm3[0].IsDecoy == false && psm3[0].FullSequence == "DITANLR");
            Assert.That(psm3[1].IsDecoy == true && psm3[1].FullSequence == "LSISNVAK");
            Assert.That(psm3[2].IsDecoy == true && psm3[2].FullSequence == "LSISNVAK");
            Assert.That(psm3[3].IsDecoy == false && psm3[3].FullSequence == "RQPAQPR");
            Assert.That(psm3[4].IsDecoy == false && psm3[4].FullSequence == "KKAEDGINK");
            Assert.That(psm3[5].IsDecoy == false && psm3[5].FullSequence == "EKAEAEAEK");
            Assert.That(psm3[6].IsDecoy == false && psm3[6].FullSequence == "EKAEAEAEK");


            //test when doing non spectral library search with generating library
            PeptideSpectralMatch[] allPsmsArray4 = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray4, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, null, new List <string>(), true).Run();
            var psm4 = allPsmsArray4.Where(p => p != null).ToList();

            Assert.That(psm4[0].IsDecoy == false && psm4[0].FullSequence == "DITANLR");
            Assert.That(psm4[1].IsDecoy == true && psm4[1].FullSequence == "LSISNVAK");
            Assert.That(psm4[2].IsDecoy == true && psm4[2].FullSequence == "LSISNVAK");
            Assert.That(psm4[3].IsDecoy == false && psm4[3].FullSequence == "RQPAQPR");
            Assert.That(psm4[4].IsDecoy == false && psm4[4].FullSequence == "KKAEDGINK");
            Assert.That(psm4[5].IsDecoy == false && psm4[5].FullSequence == "EKAEAEAEK");
            Assert.That(psm4[6].IsDecoy == false && psm4[6].FullSequence == "EKAEAEAEK");


            //compare psm's target/decoy results in 4 conditions. they should be same as new decoy methods shouldn't change the t/d results
            for (int i = 0; i < psm1.Count; i++)
            {
                Assert.That(psm1[i].FullSequence == psm2[i].FullSequence && psm3[i].FullSequence == psm3[i].FullSequence && psm2[i].FullSequence == psm3[i].FullSequence);
                Assert.That(psm1[i].IsDecoy == psm2[i].IsDecoy && psm3[i].IsDecoy == psm3[i].IsDecoy && psm2[i].IsDecoy == psm3[i].IsDecoy);
            }

            //compare MetaMorpheus scores in 4 conditions; for some psms, they should have a little higher score when "generating library" as they switch to all charges ions matching function
            for (int j = 0; j < psm1.Count; j++)
            {
                if (psm1[j].FullSequence == psm2[j].FullSequence && psm1[j].MatchedFragmentIons.Count != psm2[j].MatchedFragmentIons.Count)
                {
                    Assert.That(psm1[j].Score < psm2[j].Score);
                }
            }
        }
예제 #26
0
        public static void TestMatchIonsOfAllChargesBottomUp()
        {
            CommonParameters CommonParameters = new CommonParameters();

            MetaMorpheusTask.DetermineAnalyteType(CommonParameters);

            var variableModifications = new List <Modification>();
            var fixedModifications    = new List <Modification>();

            var proteinList = new List <Protein>
            {
                new Protein("AAAHSSLK", ""), new Protein("RQPAQPR", ""), new Protein("EKAEAEAEK", "")
            };
            var myMsDataFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"));


            var searchMode = new SinglePpmAroundZeroSearchMode(5);

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

            var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray();

            //search by new method of looking for all charges
            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];

            new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, null, new List <string>(), true).Run();
            var psm = allPsmsArray.Where(p => p != null).ToList();

            Assert.That(psm[1].MatchedFragmentIons.Count == 14);
            //there are ions with same product type and same fragment number but different charges
            Assert.That(psm[1].MatchedFragmentIons[8].NeutralTheoreticalProduct.ProductType == psm[1].MatchedFragmentIons[9].NeutralTheoreticalProduct.ProductType &&
                        psm[1].MatchedFragmentIons[8].NeutralTheoreticalProduct.FragmentNumber == psm[1].MatchedFragmentIons[9].NeutralTheoreticalProduct.FragmentNumber &&
                        psm[1].MatchedFragmentIons[8].Charge != psm[1].MatchedFragmentIons[9].Charge);
            Assert.That(psm[2].MatchedFragmentIons.Count == 14);
            Assert.That(psm[4].MatchedFragmentIons.Count == 16);

            //search by old method of looking for only one charge
            PeptideSpectralMatch[] allPsmsArray_oneCharge = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray_oneCharge, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, null, new List <string>(), false).Run();
            var psm_oneCharge = allPsmsArray_oneCharge.Where(p => p != null).ToList();

            //compare 2 scores , they should have same integer part but new search has a little higher score than old search
            Assert.That(psm[1].Score > psm_oneCharge[1].Score);
            Assert.AreEqual(Math.Truncate(psm[1].Score), 12);
            Assert.AreEqual(Math.Truncate(psm_oneCharge[1].Score), 12);

            //compare 2 results and evaluate the different matched ions
            var peptideTheorProducts = new List <Product>();

            Assert.That(psm_oneCharge[1].MatchedFragmentIons.Count == 12);
            var differences = psm[1].MatchedFragmentIons.Except(psm_oneCharge[1].MatchedFragmentIons);

            psm[1].BestMatchingPeptides.First().Peptide.Fragment(CommonParameters.DissociationType, CommonParameters.DigestionParams.FragmentationTerminus, peptideTheorProducts);
            foreach (var ion in differences)
            {
                foreach (var product in peptideTheorProducts)
                {
                    if (product.Annotation.ToString().Equals(ion.NeutralTheoreticalProduct.Annotation.ToString()))
                    {
                        //to see if the different matched ions are qualified
                        Assert.That(CommonParameters.ProductMassTolerance.Within(ion.Mz.ToMass(ion.Charge), product.NeutralMass));
                    }
                }
            }

            //test specific condition: unknown fragment mass; this only happens rarely for sequences with unknown amino acids
            var myMsDataFile1          = new TestDataFile();
            var variableModifications1 = new List <Modification>();
            var fixedModifications1    = new List <Modification>();
            var proteinList1           = new List <Protein> {
                new Protein("QXQ", null)
            };
            var productMassTolerance = new AbsoluteTolerance(0.01);
            var searchModes          = new OpenSearchMode();

            Tolerance DeconvolutionMassTolerance1 = new PpmTolerance(5);

            var listOfSortedms2Scans1 = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray();

            List <DigestionMotif> motifs = new List <DigestionMotif> {
                new DigestionMotif("K", null, 1, null)
            };
            Protease protease = new Protease("Custom Protease3", CleavageSpecificity.Full, null, null, motifs);

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);

            CommonParameters CommonParameters1 = new CommonParameters(
                digestionParams: new DigestionParams(protease: protease.Name, maxMissedCleavages: 0, minPeptideLength: 1),
                scoreCutoff: 1,
                addCompIons: false);
            var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>();

            fsp.Add(("", CommonParameters));
            PeptideSpectralMatch[] allPsmsArray1 = new PeptideSpectralMatch[listOfSortedms2Scans.Length];

            bool writeSpectralLibrary = true;

            new ClassicSearchEngine(allPsmsArray1, listOfSortedms2Scans1, variableModifications1, fixedModifications1, null, null, null,
                                    proteinList1, searchModes, CommonParameters1, fsp, null, new List <string>(), writeSpectralLibrary).Run();

            var psm1 = allPsmsArray1.Where(p => p != null).ToList();

            Assert.AreEqual(psm1.Count, 222);
        }
예제 #27
0
        public static void TestMatchIonsOfAllChargesTopDown()
        {
            CommonParameters CommonParameters = new CommonParameters(
                digestionParams: new DigestionParams(protease: "top-down"),
                scoreCutoff: 1,
                assumeOrphanPeaksAreZ1Fragments: false);

            MetaMorpheusTask.DetermineAnalyteType(CommonParameters);

            // test output file name (should be proteoform and not peptide)
            Assert.That(GlobalVariables.AnalyteType == "Proteoform");

            var variableModifications = new List <Modification>();
            var fixedModifications    = new List <Modification>();
            var proteinList           = new List <Protein>
            {
                new Protein("MPKVYSYQEVAEHNGPENFWIIIDDKVYDVSQFKDEHPGGDEIIMDLGGQDATESFVDIGHSDEALRLLKGLYIGDVDKTSERVSVEKVSTSENQSKGSGTLVVILAILMLGVAYYLLNE", "P40312")
            };

            var myMsDataFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TopDownTestData\slicedTDYeast.mzML"));

            var searchMode = new SinglePpmAroundZeroSearchMode(5);

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

            var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray();

            //search by new method of looking for all charges
            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, null, new List <string>(), true).Run();

            var psm = allPsmsArray.Where(p => p != null).FirstOrDefault();

            Assert.That(psm.MatchedFragmentIons.Count == 62);


            //search by old method of looking for only one charge
            PeptideSpectralMatch[] allPsmsArray_oneCharge = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray_oneCharge, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, null, new List <string>(), false).Run();

            var psm_oneCharge = allPsmsArray_oneCharge.Where(p => p != null).FirstOrDefault();

            Assert.That(psm_oneCharge.MatchedFragmentIons.Count == 47);

            //compare 2 scores , they should have same integer but new search has a little higher score than old search
            Assert.That(psm.Score > psm_oneCharge.Score);
            Assert.AreEqual(Math.Truncate(psm.Score), 47);
            Assert.AreEqual(Math.Truncate(psm_oneCharge.Score), 47);

            //compare 2 results and evaluate the different matched ions
            var peptideTheorProducts = new List <Product>();
            var differences          = psm.MatchedFragmentIons.Except(psm_oneCharge.MatchedFragmentIons);

            psm.BestMatchingPeptides.First().Peptide.Fragment(CommonParameters.DissociationType, CommonParameters.DigestionParams.FragmentationTerminus, peptideTheorProducts);
            foreach (var ion in differences)
            {
                foreach (var product in peptideTheorProducts)
                {
                    if (product.Annotation.ToString().Equals(ion.NeutralTheoreticalProduct.Annotation.ToString()))
                    {
                        //to see if the different matched ions are qualified
                        Assert.That(CommonParameters.ProductMassTolerance.Within(ion.Mz.ToMass(ion.Charge), product.NeutralMass));
                    }
                }
            }
        }
예제 #28
0
파일: Program.cs 프로젝트: dippman/mzLib
        private static void Main(string[] args)
        {
            Loaders.LoadElements("elements.dat");

            var p = new FluentCommandLineParser <ApplicationArguments>();

            p.Setup(arg => arg.DeconvolutionTolerancePpm)
            .As("DeconvolutionTolerancePpm");

            p.Setup(arg => arg.MinScan)
            .As("MinScan");

            p.Setup(arg => arg.MaxScan)
            .As("MaxScan");

            p.Setup(arg => arg.MinAssumedChargeState)
            .As("MinAssumedChargeState");

            p.Setup(arg => arg.MaxAssumedChargeState)
            .As("MaxAssumedChargeState");

            p.Setup(arg => arg.IntensityRatioLimit)
            .As("IntensityRatioLimit");

            p.Setup(arg => arg.FilePath)
            .As("FilePath").
            Required();

            var result = p.Parse(args);

            Console.WriteLine("Running deconvolution using the following parameters:");
            Console.WriteLine(p.Object);

            if (result.HasErrors == false)
            {
                IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile;
                if (Path.GetExtension(p.Object.FilePath).Equals(".mzML", StringComparison.OrdinalIgnoreCase))
                {
                    myMsDataFile = Mzml.LoadAllStaticData(p.Object.FilePath);
                }
                else
                {
                    myMsDataFile = ThermoStaticData.LoadAllStaticData(p.Object.FilePath);
                }

                using (StreamWriter output = new StreamWriter(@"MS2DeconvolutionOutput-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss", CultureInfo.InvariantCulture) + ".tsv"))
                {
                    output.WriteLine("Mass\tNumPeaks\tNumScans\tMinScan\tMaxScan\tAverageElutionTime\tIntensity\tObservedCharges\tMostIntenseCharge\tMostIntenseMz\tNumPeaksInMostIntenseEnvelope");

                    foreach (var ok in myMsDataFile.OfType <IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > >())
                    {
                        if ((!p.Object.MinScan.HasValue || ok.OneBasedScanNumber >= p.Object.MinScan) && (!p.Object.MaxScan.HasValue || ok.OneBasedScanNumber <= p.Object.MaxScan))
                        {
                            var hmm = ok.MassSpectrum.Deconvolute(new MzRange(0, double.PositiveInfinity), p.Object.MinAssumedChargeState, p.Object.MaxAssumedChargeState, p.Object.DeconvolutionTolerancePpm, p.Object.IntensityRatioLimit).ToList();

                            List <DeconvolutionFeatureWithMassesAndScans> currentListOfGroups = new List <DeconvolutionFeatureWithMassesAndScans>();

                            foreach (var isotopicEnvelope in hmm)
                            {
                                DeconvolutionFeatureWithMassesAndScans matchingGroup = null;
                                var mass = isotopicEnvelope.monoisotopicMass;
                                foreach (var possibleGroup in currentListOfGroups)
                                {
                                    var possibleGroupMass = possibleGroup.Mass;
                                    if (Math.Abs(mass - possibleGroupMass) / possibleGroupMass * 1e6 <= p.Object.AggregationTolerancePpm ||
                                        Math.Abs(mass + 1.002868314 - possibleGroupMass) / possibleGroupMass * 1e6 <= p.Object.AggregationTolerancePpm ||
                                        Math.Abs(mass + 2.005408917 - possibleGroupMass) / possibleGroupMass * 1e6 <= p.Object.AggregationTolerancePpm ||
                                        Math.Abs(mass + 3.007841294 - possibleGroupMass) / possibleGroupMass * 1e6 <= p.Object.AggregationTolerancePpm ||
                                        Math.Abs(mass - 1.002868314 - possibleGroupMass) / possibleGroupMass * 1e6 <= p.Object.AggregationTolerancePpm ||
                                        Math.Abs(mass - 2.005408917 - possibleGroupMass) / possibleGroupMass * 1e6 <= p.Object.AggregationTolerancePpm ||
                                        Math.Abs(mass - 3.007841294 - possibleGroupMass) / possibleGroupMass * 1e6 <= p.Object.AggregationTolerancePpm)
                                    {
                                        matchingGroup = possibleGroup;
                                        matchingGroup.AddEnvelope(isotopicEnvelope, ok.OneBasedScanNumber, ok.RetentionTime);
                                        break;
                                    }
                                }

                                if (matchingGroup == null)
                                {
                                    var newGroupScans = new DeconvolutionFeatureWithMassesAndScans();
                                    newGroupScans.AddEnvelope(isotopicEnvelope, ok.OneBasedScanNumber, ok.RetentionTime);
                                    currentListOfGroups.Add(newGroupScans);
                                }
                            }
                            foreach (var ook in currentListOfGroups)
                            {
                                output.WriteLine(ook.OneLineString());
                            }
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("BAD PARAMETERS");
                Console.WriteLine(result.ErrorText);
            }
        }
예제 #29
0
        public static void TestFlashLFQWithPassedFile()
        {
            // read periodic table - needed to open the raw files
            PeriodicTableLoader.Load(Path.Combine(TestContext.CurrentContext.TestDirectory, @"elements.dat"));

            // get the raw files
            string rawPath  = Path.Combine(TestContext.CurrentContext.TestDirectory, @"sliced-raw.raw");
            string mzmlPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"sliced-mzml.mzml");

            var rawFile  = ThermoDynamicData.InitiateDynamicConnection(rawPath);
            var mzmlFile = Mzml.LoadAllStaticData(mzmlPath);

            RawFileInfo raw  = new RawFileInfo(rawPath, rawFile);
            RawFileInfo mzml = new RawFileInfo(mzmlPath, mzmlFile);

            // create some PSMs
            Identification id1 = new Identification(raw, "EGFQVADGPLYR", "EGFQVADGPLYR", 1350.65681, 94.12193, 2, new List <string> {
                "MyProtein"
            });
            Identification id2 = new Identification(raw, "EGFQVADGPLYR", "EGFQVADGPLYR", 1350.65681, 94.05811, 2, new List <string> {
                "MyProtein"
            });
            Identification id3 = new Identification(mzml, "EGFQVADGPLYR", "EGFQVADGPLYR", 1350.65681, 94.12193, 2, new List <string> {
                "MyProtein"
            });
            Identification id4 = new Identification(mzml, "EGFQVADGPLYR", "EGFQVADGPLYR", 1350.65681, 94.05811, 2, new List <string> {
                "MyProtein"
            });

            // create the FlashLFQ engine
            FlashLFQEngine engine = new FlashLFQEngine(new List <Identification> {
                id1, id2, id3, id4
            });

            // run the engine
            var results = engine.Run();

            // check raw results
            Assert.That(results.peaks[raw].Count == 1);
            Assert.That(results.peaks[raw].First().intensity > 0);
            Assert.That(!results.peaks[raw].First().isMbrFeature);
            Assert.That(results.peptideBaseSequences["EGFQVADGPLYR"].intensities[raw] > 0);
            Assert.That(results.peptideModifiedSequences["EGFQVADGPLYR"].intensities[raw] > 0);
            Assert.That(results.proteinGroups["MyProtein"].intensities[raw] > 0);

            // check mzml results
            Assert.That(results.peaks[mzml].Count == 1);
            Assert.That(results.peaks[mzml].First().intensity > 0);
            Assert.That(!results.peaks[mzml].First().isMbrFeature);
            Assert.That(results.peptideBaseSequences["EGFQVADGPLYR"].intensities[mzml] > 0);
            Assert.That(results.peptideModifiedSequences["EGFQVADGPLYR"].intensities[mzml] > 0);
            Assert.That(results.proteinGroups["MyProtein"].intensities[mzml] > 0);

            // test peak output
            List <string> output = new List <string>()
            {
                FlashLFQ.ChromatographicPeak.TabSeparatedHeader
            };

            foreach (var peak in results.peaks.SelectMany(p => p.Value))
            {
                output.Add(peak.ToString());
            }
            Assert.That(output.Count == 3);

            // test peptide base sequence output
            output = new List <string>()
            {
                Peptide.TabSeparatedHeader
            };
            foreach (var pep in results.peptideBaseSequences)
            {
                output.Add(pep.Value.ToString());
            }
            Assert.That(output.Count == 2);

            // test peptide mod sequence output
            output = new List <string>()
            {
                Peptide.TabSeparatedHeader
            };
            foreach (var pep in results.peptideModifiedSequences)
            {
                output.Add(pep.Value.ToString());
            }
            Assert.That(output.Count == 2);

            // test protein output
            output = new List <string>()
            {
                ProteinGroup.TabSeparatedHeader
            };
            foreach (var protein in results.proteinGroups)
            {
                output.Add(protein.Value.ToString());
            }
            Assert.That(output.Count == 2);
        }
예제 #30
0
        public bool Run_TdMzCal(InputFile raw_file, List <SpectrumMatch> topdown_hits)
        {
            all_topdown_hits = topdown_hits.Where(h => h.score > 0).ToList();
            //need to reset m/z in case same td hits used for multiple calibration raw files...
            Parallel.ForEach(all_topdown_hits, h => h.mz = h.reported_mass.ToMz(h.charge));

            high_scoring_topdown_hits = all_topdown_hits.Where(h => h.score >= 40).ToList();
            this.raw_file             = raw_file;

            if (high_scoring_topdown_hits.Count < 5)
            {
                return(false);
            }

            myMsDataFile = Path.GetExtension(raw_file.complete_path) == ".raw" ?
                           ThermoStaticData.LoadAllStaticData(raw_file.complete_path) :
                           null;
            if (myMsDataFile == null)
            {
                myMsDataFile = Mzml.LoadAllStaticData(raw_file.complete_path);
            }
            if (myMsDataFile == null)
            {
                return(false);
            }

            DataPointAquisitionResults dataPointAcquisitionResult = GetDataPoints();

            if (dataPointAcquisitionResult.Ms1List.Count < 10)
            {
                return(false);
            }

            if (Sweet.lollipop.mass_calibration)
            {
                var myMs1DataPoints = new List <(double[] xValues, double yValue)>();

                for (int i = 0; i < dataPointAcquisitionResult.Ms1List.Count; i++)
                {
                    //x values
                    var explanatoryVariables = new double[4];
                    explanatoryVariables[0] = dataPointAcquisitionResult.Ms1List[i].mz;
                    explanatoryVariables[1] = dataPointAcquisitionResult.Ms1List[i].retentionTime;
                    explanatoryVariables[2] = dataPointAcquisitionResult.Ms1List[i].logTotalIonCurrent;
                    explanatoryVariables[3] = dataPointAcquisitionResult.Ms1List[i].logInjectionTime;

                    //yvalue
                    double mzError = dataPointAcquisitionResult.Ms1List[i].massError;

                    myMs1DataPoints.Add((explanatoryVariables, mzError));
                }

                var ms1Model = GetRandomForestModel(myMs1DataPoints);

                CalibrateHitsAndComponents(ms1Model);
                if (Sweet.lollipop.calibrate_raw_files)
                {
                    MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile,
                                                                          raw_file.directory + "\\" + raw_file.filename + "_calibrated.mzML", false);
                }
            }

            if (Sweet.lollipop.retention_time_calibration)
            {
                var myMs1DataPoints = new List <(double[] xValues, double yValue)>();
                List <SpectrumMatch> firstElutingTopDownHit = new List <SpectrumMatch>();
                List <string>        PFRs = high_scoring_topdown_hits.Select(h => h.pfr_accession).Distinct().ToList();
                foreach (var PFR in PFRs)
                {
                    var firstHitWithPFR = high_scoring_topdown_hits
                                          .Where(h => h.pfr_accession == PFR).OrderBy(h => h.ms2_retention_time).First();
                    firstElutingTopDownHit.Add(firstHitWithPFR);
                }

                for (int i = 0; i < dataPointAcquisitionResult.Ms1List.Count; i++)
                {
                    if (firstElutingTopDownHit.Contains(dataPointAcquisitionResult.Ms1List[i].identification))
                    {
                        //x values
                        var explanatoryVariables = new double[1];
                        explanatoryVariables[0] = dataPointAcquisitionResult.Ms1List[i].retentionTime;

                        //yvalue
                        double RTError = dataPointAcquisitionResult.Ms1List[i].RTError;

                        myMs1DataPoints.Add((explanatoryVariables, RTError));
                    }
                }

                if (myMs1DataPoints.Count < 10)
                {
                    return(false);
                }

                var ms1Model = GetRandomForestModel(myMs1DataPoints);

                foreach (Component c in Sweet.lollipop.calibration_components.Where(h => h.input_file.lt_condition == raw_file.lt_condition && h.input_file.biological_replicate == raw_file.biological_replicate && h.input_file.fraction == raw_file.fraction && h.input_file.technical_replicate == raw_file.technical_replicate))
                {
                    c.rt_apex = c.rt_apex - ms1Model.Predict(new double[] { c.rt_apex });
                }
            }
            return(true);
        }