Example #1
0
        public void DataFileTest()
        {
            MsDataScan theSpectrum = new MsDataScan(_mzSpectrumA, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 1000), "fake scan filter", MZAnalyzerType.Unknown, _mzSpectrumA.SumOfAllY, 1, null, "scan=1");

            MsDataScan[] theList = new MsDataScan[1];

            theList[0] = theSpectrum;

            FakeMsDataFile thefile = new FakeMsDataFile(theList);

            var theOneBasedScan = thefile.GetOneBasedScan(1);

            Assert.AreEqual("Scan #1", theOneBasedScan.ToString());

            Assert.AreEqual(15, theOneBasedScan.MassSpectrum.Size);
            Assert.AreEqual(15, theOneBasedScan.MassSpectrum.Size);

            Assert.AreEqual(1, thefile.NumSpectra);
            Assert.AreEqual(1, thefile.NumSpectra);

            Assert.IsTrue(thefile.GetOneBasedScan(1).IsCentroid);

            foreach (var ok in thefile)
            {
                Assert.AreEqual(300, ok.ScanWindowRange.Minimum, 1e-9);
                Assert.AreEqual(1000, ok.ScanWindowRange.Maximum, 1e-9);
            }

            int ok1 = 0;

            foreach (var i in thefile.GetMsScansInTimeRange(0, 2))
            {
                ok1 += 1;
            }

            Assert.AreEqual(1, ok1);

            int ok2 = 0;

            foreach (var i in thefile.GetMsScansInTimeRange(2, 4))
            {
                ok2 += 1;
            }

            Assert.AreEqual(0, ok2);

            int ok3 = 0;

            foreach (var i in thefile.GetMsScansInTimeRange(-4, -2))
            {
                ok3 += 1;
            }

            Assert.AreEqual(0, ok3);
        }
Example #2
0
        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);
        }
Example #3
0
        public void TestAMoreRealFile()
        {
            var theScan = myMsDataFile.GetOneBasedScan(2);

            Assert.AreEqual(1, theScan.IsolationRange.Width);
            Assert.AreEqual(DissociationType.Unknown, theScan.DissociationType);
            Assert.AreEqual(693.99, theScan.IsolationMz);
            Assert.AreEqual(1, theScan.IsolationRange.Maximum - theScan.IsolationRange.Minimum);
            Assert.AreEqual(1, theScan.OneBasedPrecursorScanNumber);
            Assert.AreEqual(3, theScan.SelectedIonChargeStateGuess.Value);

            var precursorScan = myMsDataFile.GetOneBasedScan(theScan.OneBasedPrecursorScanNumber.Value);

            theScan.RefineSelectedMzAndIntensity(precursorScan.MassSpectrum);
            Assert.AreEqual(.32872, theScan.SelectedIonIntensity, 0.01);
            Assert.AreEqual(693.9892, theScan.SelectedIonMZ, 0.01);
            Assert.AreEqual(693.655, theScan.SelectedIonMonoisotopicGuessMz, 0.001);

            Assert.AreNotEqual(0, myMsDataFile.GetOneBasedScan(2).MassSpectrum.FirstX);

            Assert.AreEqual(myMsDataFile.GetOneBasedScan(2).MassSpectrum.CopyTo2DArray()[0, 0], myMsDataFile.GetOneBasedScan(2).MassSpectrum.FirstX);

            Assert.AreNotEqual(0, myMsDataFile.GetOneBasedScan(2).MassSpectrum.LastX);

            theScan.ComputeMonoisotopicPeakIntensity(precursorScan.MassSpectrum);

            theScan.TransformMzs(b => 0, b => 0);

            Assert.AreEqual("Scan #2", myMsDataFile.GetOneBasedScan(2).ToString());

            Assert.AreEqual(0, myMsDataFile.GetOneBasedScan(2).MassSpectrum.FirstX);
            Assert.AreEqual(0, myMsDataFile.GetOneBasedScan(2).MassSpectrum.LastX);
            Assert.AreEqual(0, theScan.SelectedIonMZ);

            List <MsDataScan> a = myMsDataFile.GetAllScansList();

            foreach (var b in a)
            {
                Assert.IsFalse(b.IsCentroid);
            }
            foreach (var b in myMsDataFile)
            {
                Assert.AreEqual(Polarity.Positive, b.Polarity);
            }
        }
Example #4
0
        public void TestCoIsolation()
        {
            Peptide pep1 = new Peptide("AAAAAA");
            Peptide pep2 = new Peptide("AAA[H]AAA");

            var dist1 = IsotopicDistribution.GetDistribution(pep1.GetChemicalFormula(), 0.1, 0.01);

            var dist2 = IsotopicDistribution.GetDistribution(pep2.GetChemicalFormula(), 0.1, 0.01);

            MsDataScan[] Scans          = new MsDataScan[2];
            double[]     ms1intensities = new double[] { 0.8, 0.8, 0.2, 0.02, 0.2, 0.02 };
            double[]     ms1mzs         = dist1.Masses.Concat(dist2.Masses).OrderBy(b => b).Select(b => b.ToMz(1)).ToArray();

            double selectedIonMz = ms1mzs[1];

            MzSpectrum MS1 = new MzSpectrum(ms1mzs, ms1intensities, false);

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

            // Horrible fragmentation, but we don't care about this!
            double[]   ms2intensities = new double[] { 1000 };
            double[]   ms2mzs         = new double[] { 1000 };
            MzSpectrum MS2            = new MzSpectrum(ms2mzs, ms2intensities, false);
            double     isolationMZ    = selectedIonMz;

            Scans[1] = new MsDataScan(MS2, 2, 2, false, Polarity.Positive, 2.0, new MzRange(100, 1500), "second spectrum", MZAnalyzerType.Unknown, MS2.SumOfAllY, null, null, null, selectedIonMz, null, null, isolationMZ, 2.5, DissociationType.HCD, 1, null);

            var myMsDataFile = new FakeMsDataFile(Scans);

            var cool = myMsDataFile.GetAllScansList().Last();

            int       maxAssumedChargeState = 1;
            Tolerance massTolerance         = Tolerance.ParseToleranceString("10 PPM");

            var isolatedMasses = cool.GetIsolatedMassesAndCharges(myMsDataFile.GetOneBasedScan(cool.OneBasedPrecursorScanNumber.Value).MassSpectrum, 1, maxAssumedChargeState, 10, 5).ToList();

            Assert.AreEqual(2, isolatedMasses.Count);
            Assert.AreEqual(2, isolatedMasses.Count(b => b.charge == 1));
            Assert.AreEqual(pep1.MonoisotopicMass, isolatedMasses.Select(b => b.peaks.First().Item1.ToMass(b.charge)).Min(), 1e-9);
            Assert.AreEqual(pep2.MonoisotopicMass, isolatedMasses.Select(b => b.peaks.First().Item1.ToMass(b.charge)).Max(), 1e-9);
            Assert.AreEqual(pep1.MonoisotopicMass, isolatedMasses.Select(b => b.monoisotopicMass.ToMz(b.charge).ToMass(b.charge)).Min(), 1e-9);
            Assert.AreEqual(pep2.MonoisotopicMass, isolatedMasses.Select(b => b.monoisotopicMass.ToMz(b.charge).ToMass(b.charge)).Max(), 1e-9);
        }