예제 #1
0
        public static void LoadThermoTest3()
        {
            ThermoStaticData a = ThermoStaticData.LoadAllStaticData(@"small.RAW");

            Assert.IsTrue(a.GetAllScansList().Where(eb => eb.MsnOrder > 1).Count() > 0);

            Assert.IsTrue(a.GetAllScansList().Where(eb => eb.MsnOrder == 1).Count() > 0);

            Assert.IsFalse(a.ThermoGlobalParams.MonoisotopicselectionEnabled);

            var hehe = a.GetAllScansList().First(b => b.MsnOrder > 1);

            var prec = a.GetOneBasedScan(hehe.OneBasedPrecursorScanNumber.Value);

            Assert.IsNull(hehe.SelectedIonChargeStateGuess);

            Assert.IsNull(hehe.SelectedIonIntensity);

            hehe.ComputeSelectedPeakIntensity(prec.MassSpectrum);

            Assert.AreEqual(1017759, hehe.SelectedIonIntensity, 1);

            Assert.IsNull(hehe.SelectedIonMonoisotopicGuessIntensity);

            hehe.ComputeMonoisotopicPeakIntensity(prec.MassSpectrum);

            Assert.AreEqual(1017759, hehe.SelectedIonMonoisotopicGuessIntensity, 1);
        }
예제 #2
0
        public static void WindowFilteringStaticTest()
        {
            //test window number of 1
            ThermoStaticData a_w = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw");
            ThermoStaticData b_w = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw", filterParams: new FilteringParams(numberOfPeaksToKeepPerWindow: 400, numberOfWindows: 1, applyTrimmingToMs1: true));
            ThermoStaticData c_w = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw", filterParams: new FilteringParams(minimumAllowedIntensityRatioToBasePeak: 0.001, numberOfWindows: 1, applyTrimmingToMs1: true));
            ThermoStaticData d_w = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw", filterParams: new FilteringParams(minimumAllowedIntensityRatioToBasePeak: 0.001, numberOfPeaksToKeepPerWindow: 400, numberOfWindows: 1, applyTrimmingToMs1: true));

            var aLen = a_w.GetOneBasedScan(1).MassSpectrum.Size;
            var bLen = b_w.GetOneBasedScan(1).MassSpectrum.Size;
            var cLen = c_w.GetOneBasedScan(1).MassSpectrum.Size;
            var dLen = d_w.GetOneBasedScan(1).MassSpectrum.Size;

            Assert.AreEqual(Math.Min(bLen, cLen), dLen);

            var aLen2 = a_w.GetOneBasedScan(2).MassSpectrum.Size;
            var bLen2 = b_w.GetOneBasedScan(2).MassSpectrum.Size;
            var cLen2 = c_w.GetOneBasedScan(2).MassSpectrum.Size;
            var dLen2 = d_w.GetOneBasedScan(2).MassSpectrum.Size;

            Assert.AreEqual(Math.Min(bLen2, cLen2), dLen2);

            var aLen3 = a_w.GetOneBasedScan(3).MassSpectrum.Size;
            var bLen3 = b_w.GetOneBasedScan(3).MassSpectrum.Size;
            var cLen3 = c_w.GetOneBasedScan(3).MassSpectrum.Size;
            var dLen3 = d_w.GetOneBasedScan(3).MassSpectrum.Size;

            Assert.AreEqual(Math.Min(bLen3, cLen3), dLen3);
        }
예제 #3
0
        public static void LoadThermoFiltered2()
        {
            ThermoStaticData a = ThermoStaticData.LoadAllStaticData(@"small.raw");
            ThermoStaticData b = ThermoStaticData.LoadAllStaticData(@"small.raw", filterParams: new FilteringParams(numberOfPeaksToKeepPerWindow: 40, applyTrimmingToMs1: true, applyTrimmingToMsMs: true));
            ThermoStaticData c = ThermoStaticData.LoadAllStaticData(@"small.raw", filterParams: new FilteringParams(minimumAllowedIntensityRatioToBasePeak: 0.1, applyTrimmingToMs1: true, applyTrimmingToMsMs: true));
            ThermoStaticData d = ThermoStaticData.LoadAllStaticData(@"small.raw", filterParams: new FilteringParams(minimumAllowedIntensityRatioToBasePeak: 0.1, numberOfPeaksToKeepPerWindow: 40, applyTrimmingToMs1: true, applyTrimmingToMsMs: true));

            var aLen = a.GetOneBasedScan(1).MassSpectrum.Size;
            var bLen = b.GetOneBasedScan(1).MassSpectrum.Size;
            var cLen = c.GetOneBasedScan(1).MassSpectrum.Size;
            var dLen = d.GetOneBasedScan(1).MassSpectrum.Size;

            Assert.AreEqual(Math.Min(bLen, cLen), dLen);

            var aLen2 = a.GetOneBasedScan(2).MassSpectrum.Size;
            var bLen2 = b.GetOneBasedScan(2).MassSpectrum.Size;
            var cLen2 = c.GetOneBasedScan(2).MassSpectrum.Size;
            var dLen2 = d.GetOneBasedScan(2).MassSpectrum.Size;

            Assert.AreEqual(Math.Min(bLen2, cLen2), dLen2);

            var aLen3 = a.GetOneBasedScan(3).MassSpectrum.Size;
            var bLen3 = b.GetOneBasedScan(3).MassSpectrum.Size;
            var cLen3 = c.GetOneBasedScan(3).MassSpectrum.Size;
            var dLen3 = d.GetOneBasedScan(3).MassSpectrum.Size;

            Assert.AreEqual(Math.Min(bLen3, cLen3), dLen3);
        }
예제 #4
0
        internal IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > LoadFile(string origDataFile, int?topNpeaks, double?minRatio, bool trimMs1Peaks, bool trimMsMsPeaks)
        {
            FilteringParams filter = new FilteringParams(topNpeaks, minRatio, null, trimMs1Peaks, trimMsMsPeaks);

            if (myMsDataFiles.TryGetValue(origDataFile, out IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > 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);
                }
                else
                {
#if NETFRAMEWORK
                    myMsDataFiles[origDataFile] = ThermoStaticData.LoadAllStaticData(origDataFile, filter);
#else
                    Warn("No capability for reading " + origDataFile);
#endif
                }
            return(myMsDataFiles[origDataFile]);
        }
예제 #5
0
        public MsDataFile LoadFile(string origDataFile, int?topNpeaks, double?minRatio, bool trimMs1Peaks, bool trimMsMsPeaks, CommonParameters commonParameters)
        {
            FilteringParams filter = new FilteringParams(topNpeaks, minRatio, 1, trimMs1Peaks, trimMsMsPeaks);

            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]);
            }
        }
예제 #6
0
        public bool Run_TdMzCal(InputFile raw_file, List <TopDownHit> 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);
            }

            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);
            }
            return(true);
        }
예제 #7
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");
        }
예제 #8
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);
        }
예제 #9
0
        public static void LoadThermoFiltered()
        {
            ThermoStaticData a = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw");
            ThermoStaticData b = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw", filterParams: new FilteringParams(numberOfPeaksToKeepPerWindow: 400, applyTrimmingToMs1: true));
            ThermoStaticData c = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw", filterParams: new FilteringParams(minimumAllowedIntensityRatioToBasePeak: 0.001, applyTrimmingToMs1: true));
            ThermoStaticData d = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw", filterParams: new FilteringParams(minimumAllowedIntensityRatioToBasePeak: 0.001, numberOfPeaksToKeepPerWindow: 400, applyTrimmingToMs1: true));

            var aLen = a.GetOneBasedScan(1).MassSpectrum.Size;
            var bLen = b.GetOneBasedScan(1).MassSpectrum.Size;
            var cLen = c.GetOneBasedScan(1).MassSpectrum.Size;
            var dLen = d.GetOneBasedScan(1).MassSpectrum.Size;

            Assert.AreEqual(Math.Min(bLen, cLen), dLen);
        }
예제 #10
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);
        }
예제 #11
0
        private void AddAFile(string filePath)
        {
            string filename     = Path.GetFileName(filePath);
            string theExtension = Path.GetExtension(filename).ToLowerInvariant();

            switch (theExtension)
            {
            case ".raw":
                if (!ThermoStaticData.CheckForMsFileReader())
                {
                    AddNotification("Warning! Cannot find Thermo MSFileReader (v3.0 SP2 is preferred); a crash may result from searching this .raw file");
                }

                goto case ".mzml";

            case ".mzml":
                SpectraFileForDataGrid spectraFile = new SpectraFileForDataGrid(filePath);
                if (!spectraFilesForDataGrid.Select(f => f.FilePath).Contains(spectraFile.FilePath))
                {
                    spectraFilesForDataGrid.Add(spectraFile);
                }
                if (string.IsNullOrEmpty(OutputFolderTextBox.Text))
                {
                    var pathOfFirstSpectraFile = Path.GetDirectoryName(spectraFilesForDataGrid.First().FilePath);
                    OutputFolderTextBox.Text = Path.Combine(pathOfFirstSpectraFile, @"FlashLFQ_$DATETIME");
                }
                break;

            case ".txt":
            case ".tsv":
            case ".psmtsv":
            case ".tabular":
                IdentificationFileForDataGrid identFile = new IdentificationFileForDataGrid(filePath);
                if (!identFilesForDataGrid.Select(f => f.FilePath).Contains(identFile.FilePath) && !identFile.FileName.Equals("ExperimentalDesign.tsv"))
                {
                    identFilesForDataGrid.Add(identFile);
                }
                break;

            default:
                AddNotification("Unrecognized file type: " + theExtension);
                break;
            }
        }
예제 #12
0
        public static void MultiWindowFiltering()
        {
            //tests for filtering with window
            ThermoStaticData a_w = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw", filterParams: new FilteringParams(numberOfWindows: 1, applyTrimmingToMs1: true));

            Assert.AreEqual(1120, a_w.GetOneBasedScan(1).MassSpectrum.Size);
            //number of 2
            ThermoStaticData b_w = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw", filterParams: new FilteringParams(numberOfPeaksToKeepPerWindow: 200, numberOfWindows: 3, applyTrimmingToMs1: true));

            Assert.AreEqual(600, b_w.GetOneBasedScan(1).MassSpectrum.Size);
            //number of 4
            ThermoStaticData c_w = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw", filterParams: new FilteringParams(numberOfPeaksToKeepPerWindow: 200, numberOfWindows: 4, applyTrimmingToMs1: true));

            Assert.AreEqual(800, c_w.GetOneBasedScan(1).MassSpectrum.Size);
            //number of 6, which doesn't divide 1120
            ThermoStaticData d_w = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw", filterParams: new FilteringParams(numberOfPeaksToKeepPerWindow: 150, numberOfWindows: 6, applyTrimmingToMs1: true));

            Assert.AreEqual(900, d_w.GetOneBasedScan(1).MassSpectrum.Size);
        }
예제 #13
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]);
            }
        }
예제 #14
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);
        }
예제 #15
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");
            }
        }
예제 #16
0
        private void LoadData(string path, FileType fileType)
        {
            if (fileType == FileType.DeconvolutionTSV)
            {
                System.IO.StreamReader reader = new System.IO.StreamReader(path);
                string line;
                int    lineNum = 1;

                while (reader.Peek() > 0)
                {
                    line = reader.ReadLine();
                    List <IsotopicEnvelope> envs = new List <IsotopicEnvelope>();

                    if (lineNum != 1)
                    {
                        var parsedLine = line.Split('\t');
                        var mass       = double.Parse(parsedLine[0]);
                        var apexRt     = double.Parse(parsedLine[10]);

                        var envelopes = parsedLine[17].Split(new string[] { "[", "]" }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var envelope in envelopes)
                        {
                            var    split  = envelope.Split(new string[] { "|", "(", ")" }, StringSplitOptions.RemoveEmptyEntries);
                            int    charge = int.Parse(split[0]);
                            double rt     = double.Parse(split[1]);
                            int    scan   = int.Parse(split[2]);
                            List <MassSpectralPeak> peaks = new List <MassSpectralPeak>();

                            for (int i = 3; i < split.Length; i++)
                            {
                                string[]         sp   = split[i].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                                MassSpectralPeak peak = new MassSpectralPeak(double.Parse(sp[0]), double.Parse(sp[1]));
                                peaks.Add(peak);
                            }

                            IsotopicEnvelope env = new IsotopicEnvelope(rt, charge, peaks);
                            envs.Add(env);
                        }

                        var gsdf = envs.GroupBy(p => p.charge).Where(v => v.Count() > 1);

                        if (gsdf.Any())
                        {
                            var deconvolutedFeature = new ChromatographicPeak(envs, mass, apexRt);
                            if (deconvolutedFeature.GetSignalToBaseline() > 2.0)
                            {
                                DeconvolutedFeatures.Add(deconvolutedFeature);
                            }
                        }
                    }

                    lineNum++;
                }

                reader.Close();
            }
            else if (fileType == FileType.MetaMorpheusPsmTsv)
            {
                System.IO.StreamReader reader = new System.IO.StreamReader(path);
                string line;
                int    lineNum = 1;

                while (reader.Peek() > 0)
                {
                    line = reader.ReadLine();
                    List <IsotopicEnvelope> envs = new List <IsotopicEnvelope>();

                    if (lineNum != 1)
                    {
                        var parsedLine = line.Split('\t');
                    }
                }
            }
            else if (fileType == FileType.RawFile)
            {
                string ext = System.IO.Path.GetExtension(path).ToUpperInvariant();

                if (ext.Equals(".RAW"))
                {
                    rawFile = ThermoStaticData.LoadAllStaticData(path);
                }
                if (ext.Equals(".MZML"))
                {
                    rawFile = Mzml.LoadAllStaticData(path);
                }
                else
                {
                    throw new Exception("Cannot read file format: " + ext);
                }
            }
            else
            {
                throw new Exception("Cannot read file " + path);
            }
        }
예제 #17
0
        public static void ThermoReaderNotInstalled()
        {
            bool check = ThermoStaticData.CheckForMsFileReader();

            Assert.IsTrue(check);
        }
예제 #18
0
 public static void ThermoLoadError()
 {
     Assert.Throws <FileNotFoundException>(() => ThermoStaticData.LoadAllStaticData(@"aaa.RAW"));
 }
예제 #19
0
        private static void DoFileDecon(string[] args)
        {
            var p = new FluentCommandLineParser <ApplicationArguments>();

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

            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.AverageScans)
            .As("AverageScans");

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

            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)
            {
                MsDataFile myMsDataFile;
                if (Path.GetExtension(p.Object.FilePath).Equals(".mzML", StringComparison.OrdinalIgnoreCase))
                {
                    myMsDataFile = Mzml.LoadAllStaticData(p.Object.FilePath);
                }
                else
                {
                    myMsDataFile = ThermoStaticData.LoadAllStaticData(p.Object.FilePath);
                }

                if (p.Object.AverageScans > 1)
                {
                    myMsDataFile = new SummedMsDataFile(myMsDataFile, p.Object.AverageScans, p.Object.DeconvolutionTolerancePpm);
                }

                using (StreamWriter output = new StreamWriter(@"DeconvolutionOutput-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss", CultureInfo.InvariantCulture) + ".tsv"))
                {
                    output.WriteLine("Mass\tScore\tNumPeaks\tNumScans\tMinScan\tMaxScan\tElutionStart\tElutionEnd\tTotalNormalizedIntensity\tObservedCharges\tMostIntenseElutionTime\tMostIntenseCharge\tMostIntenseMz\tNumPeaksInMostIntenseEnvelope\tMostIntenseEnvelopeIntensity\tElutionOfMostIntenseCharge");

                    foreach (var nice in myMsDataFile.Deconvolute(p.Object.MinScan, p.Object.MaxScan, p.Object.MinAssumedChargeState, p.Object.MaxAssumedChargeState, p.Object.DeconvolutionTolerancePpm, p.Object.IntensityRatioLimit, p.Object.AggregationTolerancePpm, b => b.MsnOrder == 1).OrderByDescending(b => b.Score))
                    {
                        if ((nice.MaxScanIndex - nice.MinScanIndex + 1) >= p.Object.NumScansRequired)
                        {
                            output.WriteLine(nice.OneLineString());
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("BAD PARAMETERS");
                Console.WriteLine(result.ErrorText);
            }
        }
예제 #20
0
파일: Program.cs 프로젝트: NRTDP/mzLib
        private static void Main(string[] args)
        {
            DoubleRange r = new DoubleRange(-187, double.PositiveInfinity);

            Console.WriteLine(r);
            Console.WriteLine(r.ToString());

            //Loaders.LoadElements("elements2.dat");
            //Dictionary<string, Modification> um;
            //ProteinDbLoader.LoadProteinXML(@"C:\Users\stepa\Desktop\01012017_MM_ONLYGPTMD.xml", true, new List<Modification>(), false, new List<string> { "GO", "EnsemblFungi" }, null, out um);

            //ThermoStaticData.LoadAllStaticData(@"C:\Users\stepa\Desktop\PrecursorProblems\2016_080902_SMC_EC_Glyco_EThcD.raw");

            //Mzml.LoadAllStaticData(@"C:\Users\stepa\Source\Repos\MetaMorpheus\Test\bin\Debug\ok.mzML");
            //var oddk = ThermoDynamicData.InitiateDynamicConnection(@"C:\Users\stepa\Data\CalibrationPaperData\Jurkat\120426_Jurkat_highLC_Frac1.raw");
            //ThermoStaticData.LoadAllStaticData(@"C:\Users\stepa\Desktop\yeast_tmt\m04667.raw");
            //ThermoStaticData.LoadAllStaticData(@"C:\Users\stepa\Desktop\human_spike\C14-11130.raw");
            //ThermoStaticData.LoadAllStaticData(@"C:\Users\stepa\Data\CalibrationPaperData\Jurkat\120426_Jurkat_highLC_Frac18.raw");
            ThermoStaticData.LoadAllStaticData(@"C:\Users\stepa\Desktop\CoIsolation\05-11-17_YL_25iso.raw");

            //var hheh = oddk.GetMsScansInTimeRange(47.2469, 47.25693).ToList();

            //Mzml.LoadAllStaticData(@"C:\Users\stepa\Data\CalibrationPaperData\Jurkat\120426_Jurkat_highLC_Frac28.mzML");
            //var okff = ThermoStaticData.LoadAllStaticData(@"C:\Users\stepa\Data\CalibrationPaperData\Jurkat\120426_Jurkat_highLC_Frac28.raw");
            //var okff = ThermoStaticData.LoadAllStaticData(@"C:\Users\stepa\Data\ForRyan\golden.raw");
            //MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(okff, @"C:\Users\stepa\Data\ForRyan\adsfjk.mzML");

            //Mzml.LoadAllStaticData(@"C:\Users\stepa\Desktop\02-15-17_Cys-tag_light\02-14-17_Cl-1_rep1.mzML");
            //using (var nice = ThermoDynamicData.InitiateDynamicConnection(@"C:\Users\stepa\Desktop\02-15-17_Cys-tag_light\02-14-17_Cl-1_rep1.raw"))
            //{
            //    Console.WriteLine(nice.GetOneBasedScan(1000).RetentionTime);
            //}

            //// OLD MASS SPEC
            //var theFiles = new List<string>{
            //    //@"C:\Users\stepa\Data\CalibrationPaperData\Jurkat\120426_Jurkat_highLC_Frac17.raw",
            //    //@"C:\Users\stepa\Data\CalibrationPaperData\Mouse\04-30-13_CAST_Frac5_4uL.raw",
            //    //@"C:\Users\stepa\Data\CalibrationPaperData\Yeast\12-10-16_A17A_yeast_BU_fract9_rep1_8uL.raw",
            //    //@"C:\Users\stepa\Desktop\MvsMM\04-21-17_Lys_1-200_rep1.raw",
            //    //@"C:\Users\stepa\Desktop\MvsMM\04-21-17_Lys_1-200_rep1.mzML",
            //    @"C:\Users\stepa\Data\CalibrationPaperData\Mouse\04-29-13_B6_Frac7_5uL.raw"
            //};

            //// Params
            //var tols = new List<Tolerance> { new Tolerance("5 PPM") };
            //var isotopeRatios = new List<int> { 4 };
            //var maxAssumedChargeState = 10;

            //foreach (var theFile in theFiles)
            //{
            //    var okff = ThermoStaticData.LoadAllStaticData(theFile);
            //    //var okff = Mzml.LoadAllStaticData(theFile);

            //    int countScans = 0;
            //    int totalHaveMMandCharge = 0;

            //    var totalHaveMyMass = new int[1, 1];
            //    var totalMatch = new int[1, 1];
            //    //foreach (var scanWithPrec in okff.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>())
            //    var scanWithPrec = okff.GetOneBasedScan(11042) as IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>;
            //    {
            //        countScans++;

            //        Console.WriteLine("Scan " + scanWithPrec.OneBasedScanNumber + " ; isolation=" + scanWithPrec.IsolationMz + " ; mm=" + scanWithPrec.SelectedIonMonoisotopicGuessMz + " ; charge=" + scanWithPrec.SelectedIonChargeStateGuess);

            //        if (scanWithPrec.SelectedIonMonoisotopicGuessMz.HasValue && scanWithPrec.SelectedIonChargeStateGuess.HasValue)
            //        {
            //            totalHaveMMandCharge++;
            //        }

            //        for (int i = 0; i < tols.Count; i++)
            //        {
            //            var tol = tols[i];
            //            for (int j = 0; j < isotopeRatios.Count; j++)
            //            {
            //                var isotopeRatio = isotopeRatios[j];
            //                var mzEnvelopesWithCharges = scanWithPrec.GetIsolatedMassesAndCharges(okff.GetOneBasedScan(scanWithPrec.OneBasedPrecursorScanNumber).MassSpectrum, maxAssumedChargeState, tol, isotopeRatio).ToList();

            //                if (mzEnvelopesWithCharges.Count() > 0)
            //                    totalHaveMyMass[i, j]++;

            //                if (scanWithPrec.SelectedIonMonoisotopicGuessMz.HasValue && scanWithPrec.SelectedIonChargeStateGuess.HasValue)
            //                {
            //                    if (mzEnvelopesWithCharges.Any(bd => tol.Within(bd.Item1.First().Mz.ToMass(bd.Item2), scanWithPrec.SelectedIonMonoisotopicGuessMz.Value.ToMass(scanWithPrec.SelectedIonChargeStateGuess.Value))))
            //                    {
            //                        totalMatch[i, j]++;
            //                        Console.WriteLine("Match!");
            //                    }
            //                    else
            //                    {
            //                        Console.WriteLine(string.Join(Environment.NewLine, mzEnvelopesWithCharges.Select(b => "\t" + b.Item2 + " : " + string.Join(",", b.Item1))));
            //                    }
            //                }
            //                else
            //                {
            //                    Console.WriteLine(string.Join(Environment.NewLine, mzEnvelopesWithCharges.Select(b => "\t" + b.Item2 + " : " + string.Join(",", b.Item1))));
            //                }
            //            }
            //        }
            //    }

            //    Console.WriteLine("countScans: " + countScans);
            //    Console.WriteLine("totalHaveMMandCharge: " + totalHaveMMandCharge);

            //    for (int i = 0; i < tols.Count; i++)
            //    {
            //        var tol = tols[i];
            //        for (int j = 0; j < isotopeRatios.Count; j++)
            //        {
            //            Console.WriteLine("i = " + i + " j = " + j);
            //            Console.WriteLine("totalHaveMyMass: " + totalHaveMyMass[i, j]);
            //            Console.WriteLine("totalMatch: " + totalMatch[i, j]);
            //        }
            //    }
            //}

            //using (var nice = ThermoDynamicData.InitiateDynamicConnection(@"C:\Users\stepa\Data\CalibrationPaperData\Mouse\04-30-13_CAST_Frac5_4uL.raw"))
            ////{
            //using (var nice = ThermoDynamicData.InitiateDynamicConnection(@"C:\Users\stepa\Data\CalibrationPaperData\Jurkat\120426_Jurkat_highLC_Frac17.raw"))
            //{
            //var hehdfe = nice.GetOneBasedScan(168) as IMsDataScanWithPrecursor<ThermoSpectrum>;
            //Console.WriteLine("Scan " + hehdfe.OneBasedScanNumber + " ; isolation=" + hehdfe.IsolationMz + " ; mm=" + hehdfe.SelectedIonMonoisotopicGuessMz);

            //var fdf = hehdfe.GetIsolatedMassesAndCharges(nice.GetOneBasedScan(hehdfe.OneBasedPrecursorScanNumber).MassSpectrum, 10, new Tolerance("20 PPM"), 10, 1);

            //Console.WriteLine(fdf.Count() + ";" + hehdfe.SelectedIonMonoisotopicGuessMz.HasValue);

            //Console.WriteLine(string.Join(Environment.NewLine, fdf.Select(b => "\t" + b.Item1 + "; " + b.Item2 + "; " + b.Item1.First())));

            //    Console.WriteLine();

            //    int totalHaveMM = 0;
            //    int totalHaveMMandMatch = 0;
            //    int totalHaveMyMass = 0;
            //    int totalHaveMMandMatchAll = 0;
            //    int totalHaveMyMassAll = 0;
            //    foreach (var hehdfe in nice.OfType<IMsDataScanWithPrecursor<ThermoSpectrum>>())
            //    {
            //        Console.WriteLine("Scan " + hehdfe.OneBasedScanNumber + " ; isolation=" + hehdfe.IsolationMz + " ; mm=" + hehdfe.SelectedIonMonoisotopicGuessMz + " ; charge=" + hehdfe.SelectedIonChargeStateGuess);

            //        //var fdf = hehdfe.GetIsolatedMassesAndCharges(nice.GetOneBasedScan(hehdfe.OneBasedPrecursorScanNumber).MassSpectrum, 10, tol, 10, 1).ToList();

            //        //if (fdf.Count() > 0)
            //        //    totalHaveMyMass++;

            //        //if (hehdfe.SelectedIonMonoisotopicGuessMz.HasValue)
            //        //{
            //        //    totalHaveMM++;
            //        //    if (fdf.Any(bd => tol.Within(bd.Item1.First().ToMass(bd.Item2), hehdfe.SelectedIonMonoisotopicGuessMz.Value.ToMass(hehdfe.SelectedIonChargeStateGuess.Value))))
            //        //        totalHaveMMandMatch++;
            //        //}

            //        if (fdfAll.Count() > 0)
            //            totalHaveMyMassAll++;
            //        Console.WriteLine(fdfAll.Count() + ";" + hehdfe.SelectedIonMonoisotopicGuessMz.HasValue);

            //        if (hehdfe.SelectedIonMonoisotopicGuessMz.HasValue)
            //        {
            //            totalHaveMM++;
            //            var massFromScan = hehdfe.SelectedIonMonoisotopicGuessMz.Value.ToMass(hehdfe.SelectedIonChargeStateGuess.Value);
            //            if (fdfAll.Any(bd => tol.Within(bd.Item1.First().ToMass(bd.Item2), massFromScan)))
            //                totalHaveMMandMatchAll++;

            //            if (totalHaveMMandMatchAll - totalHaveMyMassAll < -6)
            //                    Console.WriteLine(totalHaveMMandMatchAll + " not equal " + totalHaveMyMassAll);
            //        }

            //        Console.WriteLine();
            //    }
            //}

            //using (var nice = ThermoDynamicData.InitiateDynamicConnection(@"C:\Users\stepa\Data\CalibrationPaperData\Jurkat\120426_Jurkat_highLC_Frac17.raw"))
            //{
            //    var ok = nice.GetOneBasedScan(24676);
            //    var hm = ok as IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>;
            //    hm.RecomputeSelectedPeak(nice.GetOneBasedScan(hm.OneBasedPrecursorScanNumber).MassSpectrum);
            //}

            //using (var nice = ThermoDynamicData.InitiateDynamicConnection(@"C:\Users\stepa\Desktop\02-15-17_Cys-tag_light\02-14-17_Cl-1_rep1.raw"))
            //{
            //    var ok = nice.GetOneBasedScan(71291);
            //    var hm = ok as IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>;

            //    var prevSpectrum = nice.GetOneBasedScan(hm.OneBasedPrecursorScanNumber).MassSpectrum;

            //    Console.WriteLine(hm.SelectedIonGuessChargeStateGuess + Environment.NewLine
            //        + hm.SelectedIonGuessMZ + Environment.NewLine
            //        + hm.SelectedIonGuessIntensity + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicMZ + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicIntensity + Environment.NewLine);

            //    hm.RecomputeChargeState(prevSpectrum, 0.01, 4);

            //    Console.WriteLine(hm.SelectedIonGuessChargeStateGuess + Environment.NewLine
            //        + hm.SelectedIonGuessMZ + Environment.NewLine
            //        + hm.SelectedIonGuessIntensity + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicMZ + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicIntensity + Environment.NewLine);

            //    hm.ComputeSelectedPeakIntensity(prevSpectrum);

            //    Console.WriteLine(hm.SelectedIonGuessChargeStateGuess + Environment.NewLine
            //        + hm.SelectedIonGuessMZ + Environment.NewLine
            //        + hm.SelectedIonGuessIntensity + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicMZ + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicIntensity + Environment.NewLine);

            //    hm.ComputeMonoisotopicPeakIntensity(prevSpectrum);

            //    Console.WriteLine(hm.SelectedIonGuessChargeStateGuess + Environment.NewLine
            //        + hm.SelectedIonGuessMZ + Environment.NewLine
            //        + hm.SelectedIonGuessIntensity + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicMZ + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicIntensity + Environment.NewLine);

            //    hm.RecomputeSelectedPeak(prevSpectrum);

            //    Console.WriteLine(hm.SelectedIonGuessChargeStateGuess + Environment.NewLine
            //        + hm.SelectedIonGuessMZ + Environment.NewLine
            //        + hm.SelectedIonGuessIntensity + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicMZ + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicIntensity + Environment.NewLine);

            //    hm.RecomputeMonoisotopicPeak(prevSpectrum, 0.01, 0.3);

            //    Console.WriteLine(hm.SelectedIonGuessChargeStateGuess + Environment.NewLine
            //        + hm.SelectedIonGuessMZ + Environment.NewLine
            //        + hm.SelectedIonGuessIntensity + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicMZ + Environment.NewLine
            //        + hm.SelectedIonGuessMonoisotopicIntensity + Environment.NewLine);

            //    hm.RecomputeSelectedPeak(nice.GetOneBasedScan(hm.OneBasedPrecursorScanNumber).MassSpectrum);
            //}

            PopulatePeriodicTable();

            BenchmarkFormula();
            Console.WriteLine("");
            BenchmarkFormula2();
            Console.WriteLine("");
            BenchmarkTimeGettingElementFromPeriodicTable();
            Console.WriteLine("");
            BenchmarkGettingIsotopes();
            Console.WriteLine("");
            BenchmarkIsotopicDistribution();
            Loaders.LoadElements(@"elements.tmp");
            Console.WriteLine("");
            BenchmarkDatabaseLoadWrite();
        }
예제 #21
0
        public static void TestExternalPassedFile()
        {
            Console.WriteLine("UNIT TEST - Entering unit test");
            string[] filePaths  = Directory.GetFiles(TestContext.CurrentContext.TestDirectory).Where(f => f.Substring(f.IndexOf('.')).ToUpper().Equals(".RAW")).ToArray();
            var      thermoFile = ThermoStaticData.LoadAllStaticData(filePaths[0]);

            string elements = Path.Combine(TestContext.CurrentContext.TestDirectory, "elements.dat");
            string ident    = Path.Combine(TestContext.CurrentContext.TestDirectory, "aggregatePSMs_5ppmAroundZero.psmtsv");

            FlashLFQEngine engine = new FlashLFQEngine();

            Console.WriteLine("UNIT TEST - About to load elements");
            Loaders.LoadElements(elements);
            Console.WriteLine("UNIT TEST - Finished loading elements");

            engine.PassFilePaths(filePaths);
            Assert.That(engine.ParseArgs(new string[] {
                "--ppm 5",
                "--sil false",
                "--pau false",
                "--mbr true"
            }
                                         ));
            Console.WriteLine("UNIT TEST - Done making engine");
            engine.globalStopwatch.Start();
            engine.SetParallelization(1);

            Console.WriteLine("UNIT TEST - Adding identifications");
            var ids       = File.ReadAllLines(ident);
            int lineCount = 1;

            foreach (var line in ids)
            {
                if (lineCount != 1)
                {
                    var splitLine = line.Split('\t');
                    engine.AddIdentification(Path.GetFileNameWithoutExtension(splitLine[0]), splitLine[20], splitLine[21], double.Parse(splitLine[27]), double.Parse(splitLine[2]), (int)double.Parse(splitLine[6]), new List <string> {
                        splitLine[14]
                    });
                }
                lineCount++;
            }
            Console.WriteLine("UNIT TEST - Finished adding IDs");

            engine.ConstructIndexTemplateFromIdentifications();
            Console.WriteLine("UNIT TEST - Finished constructing bins");
            Assert.That(engine.observedMzsToUseForIndex.Count > 0);
            Assert.That(engine.baseSequenceToIsotopicDistribution.Count > 0);
            Console.WriteLine("UNIT TEST - Bins are OK");

            for (int i = 0; i < engine.filePaths.Length; i++)
            {
                Console.WriteLine("UNIT TEST - Quantifying file " + (i + 1));
                try
                {
                    Assert.That(engine.Quantify(thermoFile, engine.filePaths[i]));
                }
                catch (AssertionException)
                {
                    Console.WriteLine("UNIT TEST - Could not quantify file \"" + engine.filePaths[i] + "\"");
                }
            }

            //if (engine.mbr)
            //    engine.RetentionTimeCalibrationAndErrorCheckMatchedFeatures();

            Console.WriteLine("UNIT TEST - Quantifying proteins ");
            engine.QuantifyProteins();

            Console.WriteLine("UNIT TEST - Asserting results");
            Assert.That(engine.SumFeatures(engine.allFeaturesByFile.SelectMany(p => p), true).Any());
            Assert.That(engine.SumFeatures(engine.allFeaturesByFile.SelectMany(p => p), false).Any());

            Assert.That(engine.allFeaturesByFile[0].First().intensity > 0);

            Assert.That(!engine.allFeaturesByFile[0].First().isMbrFeature);
            Console.WriteLine("UNIT TEST - All passed");
        }
예제 #22
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);
            }
        }
예제 #23
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);
        }