コード例 #1
0
        public void FileTypeTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            // wiff1
            {
                string extWiff = ExtensionTestContext.ExtAbWiff;
                string suffix  = ExtensionTestContext.CanImportAbWiff ? "" : "-test";

                // Do file type checks
                using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("051309_digestion" + suffix + extWiff)))
                {
                    Assert.IsTrue(msData.IsABFile);
                }

                using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("051309_digestion-s3.mzXML")))
                {
                    Assert.IsTrue(msData.IsABFile);
                    Assert.IsTrue(msData.IsMzWiffXml);
                }
            }

            // wiff2
            {
                string extWiff2 = ExtensionTestContext.ExtAbWiff2;
                string suffix   = ExtensionTestContext.CanImportAbWiff2 ? "" : "-sample-centroid";

                // Do file type checks
                using (var msData = new MsDataFileImpl(TestFilesDir.GetVendorTestData(TestFilesDir.VendorDir.ABI, "swath.api" + suffix + extWiff2)))
                {
                    Assert.IsTrue(msData.IsABFile);
                }
            }
        }
コード例 #2
0
        private static IEnumerable <double> ReadChromPrecursorsFromMsd(MsDataFileImpl msd, IProgressMonitor monitor)
        {
            for (var i = 0; i < msd.ChromatogramCount; i++)
            {
                if (monitor.IsCanceled)
                {
                    yield break;
                }

                double?precursor = null;
                try
                {
                    int tmp;
                    var chromKey = ChromKey.FromId(msd.GetChromatogramId(i, out tmp), false);
                    precursor = chromKey.Precursor;
                }
                catch
                {
                    // ignored
                }
                if (precursor.HasValue)
                {
                    yield return(precursor.Value);
                }
            }
        }
コード例 #3
0
        private MsDataFilePath[] GetWiffSubPaths(string filePath)
        {
            using (var longWaitDlg = new LongWaitDlg
            {
                Text = Resources.ImportResultsDlg_GetWiffSubPaths_Sample_Names,
                Message = string.Format(Resources.ImportResultsDlg_GetWiffSubPaths_Reading_sample_names_from__0__,
                                        Path.GetFileName(filePath))
            })
            {
                string[] dataIds = null;
                try
                {
                    longWaitDlg.PerformWork(this, 800, () => dataIds = MsDataFileImpl.ReadIds(filePath));
                }
                catch (Exception x)
                {
                    string message = TextUtil.LineSeparate(
                        string.Format(Resources.ImportResultsDlg_GetWiffSubPaths_An_error_occurred_attempting_to_read_sample_information_from_the_file__0__, filePath),
                        Resources.ImportResultsDlg_GetWiffSubPaths_The_file_may_be_corrupted_missing_or_the_correct_libraries_may_not_be_installed,
                        x.Message);
                    MessageDlg.ShowWithException(this, message, x);
                }

                return(DataSourceUtil.GetWiffSubPaths(filePath, dataIds, ChooseSamples));
            }
        }
コード例 #4
0
 private bool MoveToNextScan(int direction, bool onlyMs1)
 {
     using (var msDataFileImpl = new MsDataFileImpl(Workspace.GetDataFilePath(MsDataFile.Name)))
     {
         int scanIndex = Math.Min(msDataFileImpl.SpectrumCount - 1, Math.Max(0, ScanIndex));
         if (scanIndex < 0)
         {
             return(false);
         }
         while (true)
         {
             scanIndex += direction;
             if (scanIndex < 0 || scanIndex >= msDataFileImpl.SpectrumCount)
             {
                 return(false);
             }
             if (!onlyMs1 || msDataFileImpl.GetMsLevel(scanIndex) == 1)
             {
                 break;
             }
         }
         ScanIndex = scanIndex;
         return(true);
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: zrolfs/pwiz
        static void Main(string[] args)
        {
            if (1 > args.Length || args.Length > 2)
            {
                Console.Error.WriteLine("Usage: PwizConvert <input file> [output file]");
                Console.Error.WriteLine("       Converts a recognized mass spec data file to mzML");
                return;
            }

            // CONSIDER: If Skyline ever uses this for multi-sample files, it will need
            //           to support converting a single sample by index.
            string inputFile  = args[0];
            string outputFile = args.Length > 1 ? args[1] : Path.ChangeExtension(inputFile, ".mzML");

            try
            {
                var dataFiles = MsDataFileImpl.ReadAll(inputFile);
                if (dataFiles.Length == 1)
                {
                    dataFiles[0].Write(outputFile);
                }
                else
                {
                    foreach (var dataFile in dataFiles)
                    {
                        dataFile.Write(Path.ChangeExtension(outputFile, dataFile.RunId + Path.GetExtension(outputFile)));
                    }
                }
            }
            catch (Exception x)
            {
                Console.Error.WriteLine("ERROR: " + x.Message);
            }
        }
コード例 #6
0
 private MsDataFileImpl GetDataFile(bool ignoreZeroIntensityPoints)
 {
     if (_dataFile == null)
     {
         if (DataFilePath is MsDataFilePath)
         {
             string dataFilePath       = FindDataFilePath();
             var    lockMassParameters = DataFilePath.GetLockMassParameters();
             if (dataFilePath == null)
             {
                 throw new FileNotFoundException(string.Format(
                                                     Resources
                                                     .ScanProvider_GetScans_The_data_file__0__could_not_be_found__either_at_its_original_location_or_in_the_document_or_document_parent_folder_,
                                                     DataFilePath));
             }
             int sampleIndex = SampleHelp.GetPathSampleIndexPart(dataFilePath);
             if (sampleIndex == -1)
             {
                 sampleIndex = 0;
             }
             // Full-scan extraction always uses SIM as spectra
             _dataFile = new MsDataFileImpl(dataFilePath, sampleIndex, lockMassParameters, true,
                                            combineIonMobilitySpectra: DataFilePath.GetCombineIonMobilitySpectra(),
                                            requireVendorCentroidedMS1: DataFilePath.GetCentroidMs1(),
                                            requireVendorCentroidedMS2: DataFilePath.GetCentroidMs2(),
                                            ignoreZeroIntensityPoints: ignoreZeroIntensityPoints);
         }
         else
         {
             _dataFile = DataFilePath.OpenMsDataFile(true, 0, null, ignoreZeroIntensityPoints);
         }
     }
     return(_dataFile);
 }
コード例 #7
0
ファイル: MsDataFile.cs プロジェクト: zrolfs/pwiz
 public void Init(CancellationToken cancellationToken, MsDataFileImpl msDataFileImpl)
 {
     if (Data.Times == null)
     {
         double[] times           = null;
         double[] totalIonCurrent = null;
         byte[]   msLevels        = null;
         if (msDataFileImpl.ChromatogramCount > 0)
         {
             times           = msDataFileImpl.GetScanTimes();
             totalIonCurrent = msDataFileImpl.GetTotalIonCurrent();
         }
         if (times == null || times.Length != msDataFileImpl.SpectrumCount)
         {
             msDataFileImpl.GetScanTimesAndMsLevels(cancellationToken, out times, out msLevels);
         }
         Workspace.RunOnEventQueue(() =>
         {
             var data = Data;
             if (times != null)
             {
                 data = data.SetTimes(times);
             }
             if (totalIonCurrent != null)
             {
                 data = data.SetTotalIonCurrent(totalIonCurrent);
             }
             if (msLevels != null)
             {
                 data = data.SetMsLevels(msLevels);
             }
             Data = data;
         });
     }
 }
コード例 #8
0
        public bool Adopt(IScanProvider other)
        {
            if (!Equals(DocFilePath, other.DocFilePath) || !Equals(DataFilePath, other.DataFilePath))
            {
                return(false);
            }
            var scanProvider = other as ScanProvider;

            if (scanProvider == null)
            {
                return(false);
            }
            MeasuredResults thisMeasuredResults, otherMeasuredResults;

            if (!_measuredResultsReference.TryGetTarget(out thisMeasuredResults) ||
                !scanProvider._measuredResultsReference.TryGetTarget(out otherMeasuredResults))
            {
                return(false);
            }
            if (!ReferenceEquals(thisMeasuredResults, otherMeasuredResults))
            {
                return(false);
            }
            _dataFile              = scanProvider._dataFile;
            _msDataFileScanIds     = scanProvider._msDataFileScanIds;
            _getMsDataFileScanIds  = scanProvider._getMsDataFileScanIds;
            scanProvider._dataFile = null;
            return(true);
        }
コード例 #9
0
        public override bool IsWatersLockmassCorrectionCandidate()
        {
            string filePath = GetFilePath();

            // Has to be a Waters .raw file, not just an mzML translation of one
            if (String.IsNullOrEmpty(filePath))
            {
                return(false);                                      // Not even a file
            }
            if (!GetFilePath().ToLowerInvariant().EndsWith(".raw")) // Not L10N
            {
                return(false);                                      // Return without even opening the file
            }
            if (!Directory.Exists(filePath))
            {
                return(false); // Thermo .raw is a file, Waters .raw is actually a directory
            }
            try
            {
                using (var f = new MsDataFileImpl(filePath))
                    return(f.IsWatersLockmassCorrectionCandidate);
            }
            catch (Exception)
            {
                return(false); // whatever that was, it wasn't a Waters lockmass file
            }
        }
コード例 #10
0
        public ChromatogramDataProvider(MsDataFileImpl dataFile,
                                        ChromFileInfo fileInfo,
                                        ProgressStatus status,
                                        int startPercent,
                                        int endPercent,
                                        IProgressMonitor loader)
            : base(fileInfo, status, startPercent, endPercent, loader)
        {
            _dataFile = dataFile;

            if (_dataFile.IsThermoFile)
            {
                _readMaxMinutes = 4;
            }

            int len = dataFile.ChromatogramCount;

            _chromIndices = new int[len];

            bool   fixCEOptForShimadzu = dataFile.IsShimadzuFile;
            int    indexPrecursor      = -1;
            double lastPrecursor       = 0;

            for (int i = 0; i < len; i++)
            {
                int    index;
                string id = dataFile.GetChromatogramId(i, out index);

                if (!ChromKey.IsKeyId(id))
                {
                    continue;
                }

                var chromKey = ChromKey.FromId(id, fixCEOptForShimadzu);
                if (chromKey.Precursor != lastPrecursor)
                {
                    lastPrecursor = chromKey.Precursor;
                    indexPrecursor++;
                }
                var ki = new KeyValuePair <ChromKey, int>(chromKey, index);
                _chromIndices[index] = indexPrecursor;
                _chromIds.Add(ki);
            }

            // Shimadzu can't do the necessary product m/z stepping for itself.
            // So, they provide the CE values in their IDs and we need to adjust
            // product m/z values for them to support CE optimization.
            if (fixCEOptForShimadzu)
            {
                FixCEOptForShimadzu();
            }

            if (_chromIds.Count == 0)
            {
                throw new NoSrmDataException(dataFile.FilePath);
            }

            SetPercentComplete(50);
        }
コード例 #11
0
 public override void Dispose()
 {
     if (_dataFile != null)
     {
         _dataFile.Dispose();
     }
     _dataFile = null;
 }
コード例 #12
0
        public MsDataFileImplExtAgg(string path)
        {
            try
            {
                _msDataFileImpl = new MsDataFileImpl(path);
            }
            catch (Exception e)
            { }

            _HasBeenRead = true;
        }
コード例 #13
0
 public void Dispose()
 {
     lock (this)
     {
         if (_dataFile != null)
         {
             _dataFile.Dispose();
             _dataFile = null;
         }
     }
 }
コード例 #14
0
ファイル: PwizFileInfoTest.cs プロジェクト: rfellers/pwiz
        public void TestQcTraces()
        {
            const string testZipPath = @"TestData\PressureTracesTest.zip";

            var testFilesDir = new TestFilesDir(TestContext, testZipPath);

            using (var msDataFile = new MsDataFileImpl(testFilesDir.GetTestPath("PressureTrace1" + ExtensionTestContext.ExtAbWiff)))
            {
                var pressureTraces = msDataFile.GetQcTraces();

                VerifyQcTrace(pressureTraces[0], "Column Pressure (channel 1)", 1148, 0, 9.558333, 1470, 210, MsDataFileImpl.QcTraceQuality.Pressure, MsDataFileImpl.QcTraceUnits.PoundsPerSquareInch);
                VerifyQcTrace(pressureTraces[1], "Pump A Flowrate (channel 2)", 1148, 0, 9.558333, 91590, 89120, MsDataFileImpl.QcTraceQuality.FlowRate, MsDataFileImpl.QcTraceUnits.MicrolitersPerMinute);
                VerifyQcTrace(pressureTraces[2], "Pump B Flowrate (channel 3)", 1148, 0, 9.558333, 0, 840, MsDataFileImpl.QcTraceQuality.FlowRate, MsDataFileImpl.QcTraceUnits.MicrolitersPerMinute);
                VerifyQcTrace(pressureTraces[3], "Column Pressure (channel 4)", 3508, 0, 29.225, 1396, 1322, MsDataFileImpl.QcTraceQuality.Pressure, MsDataFileImpl.QcTraceUnits.PoundsPerSquareInch);
                VerifyQcTrace(pressureTraces[4], "Pump A Flowrate (channel 5)", 3508, 0, 29.225, 7038, 7833, MsDataFileImpl.QcTraceQuality.FlowRate, MsDataFileImpl.QcTraceUnits.MicrolitersPerMinute);
                VerifyQcTrace(pressureTraces[5], "Pump B Flowrate (channel 6)", 3508, 0, 29.225, 680, 151, MsDataFileImpl.QcTraceQuality.FlowRate, MsDataFileImpl.QcTraceUnits.MicrolitersPerMinute);

                string      docPath = testFilesDir.GetTestPath("PressureTrace1.sky");
                SrmDocument doc     = ResultsUtil.DeserializeDocument(docPath);
                AssertEx.IsDocumentState(doc, 0, 1, 3, 9);

                using (var docContainer = new ResultsTestDocumentContainer(doc, docPath))
                {
                    const string replicateName = "PressureTrace1";
                    string       extRaw        = ExtensionTestContext.ExtAbWiff;
                    var          chromSets     = new[]
                    {
                        new ChromatogramSet(replicateName, new[]
                                            { new MsDataFilePath(testFilesDir.GetTestPath("PressureTrace1" + extRaw)), }),
                    };
                    var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets));
                    Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
                    docContainer.AssertComplete();
                    docResults = docContainer.Document;

                    var chromCache = docResults.Settings.MeasuredResults.GetChromCacheMinimizer(docResults).ChromatogramCache;
                    var tic        = chromCache.LoadAllIonsChromatogramInfo(ChromExtractor.summed, chromSets[0]);
                    var bpc        = chromCache.LoadAllIonsChromatogramInfo(ChromExtractor.base_peak, chromSets[0]);
                    var qc         = chromCache.LoadAllIonsChromatogramInfo(ChromExtractor.qc, chromSets[0]);

                    Assert.AreEqual(0, tic.Count());    // No longer expect these in SRM data
                    Assert.AreEqual(0, bpc.Count());    // No longer expect these in SRM data
                    var qcNames = qc.Select(o => o.TextId).ToArray();
                    Assert.AreEqual(6, qcNames.Length);
                    CollectionAssert.IsSubsetOf(new [] { "Column Pressure (channel 1)",
                                                         "Pump A Flowrate (channel 2)",
                                                         "Pump B Flowrate (channel 3)",
                                                         "Column Pressure (channel 4)",
                                                         "Pump A Flowrate (channel 5)",
                                                         "Pump B Flowrate (channel 6)" },
                                                qcNames);
                }
            }
        }
コード例 #15
0
        public void ShimadzuFileTypeTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string extRaw = ExtensionTestContext.ExtShimadzuRaw;

            // Do file type check
            using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("BSA-digest__MRM_optimisation_SL_scheduled_001" + extRaw)))
            {
                Assert.IsTrue(msData.IsShimadzuFile);
            }
        }
コード例 #16
0
        public MSAmandaSpectrumParser(string file, List <int> charges, bool mono)
        {
            consideredCharges  = charges;
            spectrumFileReader = new MsDataFileImpl(file,
                                                    requireVendorCentroidedMS2: MsDataFileImpl.SupportsVendorPeakPicking(file),
                                                    ignoreZeroIntensityPoints: true, trimNativeId: false);
            useMonoIsotopicMass = mono;

            msdataRunPath   = new MSDataRunPath(file);
            SpectTitleMap   = new Dictionary <int, string>();
            CurrentSpectrum = 0;
        }
コード例 #17
0
ファイル: PwizFileInfoTest.cs プロジェクト: rfellers/pwiz
        private static void VerifySerialNumber(string path, string serialNumber, int sampleIndex = 0)
        {
            if (!MsDataFileImpl.SupportsMultipleSamples(path))
            {
                sampleIndex = 0;
            }

            using (var msDataFile = new MsDataFileImpl(path, sampleIndex))
            {
                Assert.AreEqual(serialNumber, msDataFile.GetInstrumentSerialNumber());
            }
        }
コード例 #18
0
ファイル: AgilentMixTest.cs プロジェクト: zrolfs/pwiz
        public void AgilentFileTypeTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string extRaw = ExtensionTestContext.ExtAgilentRaw;

            // Do file type check
            using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("081809_100fmol-MichromMix-05" + extRaw)))
            {
                Assert.IsTrue(msData.IsAgilentFile);
            }
        }
コード例 #19
0
        public void TestMsx(SrmDocument doc, string dataPath)
        {
            // Load the file and check MsDataFileImpl
            using (var file = new MsDataFileImpl(dataPath))
            {
                var filter = new SpectrumFilter(doc, null, null);
                Assert.IsTrue(filter.EnabledMsMs);
                var demultiplexer = new MsxDemultiplexer(file, filter);
                demultiplexer.ForceInitializeFile();

                // Check that the demultiplexer found the correct multiplexing parameters
                Assert.AreEqual(5, demultiplexer.IsoWindowsPerScan);
                Assert.AreEqual(100, demultiplexer.NumIsoWindows);
                Assert.AreEqual(20, demultiplexer.DutyCycleLength);

                var isoMapper = demultiplexer.IsoMapperTest;
                Assert.AreEqual(100, isoMapper.NumWindows);

                // Check the isolation window mapper responsible for mapping each unique isolation
                // window detected in the file to a unique index
                TestIsolationWindowMapper(isoMapper, file, 4.00182);

                var transBinner = new TransitionBinner(filter, isoMapper);

                // Test creation of a transition binner from a spectrum filter
                TestTransitionBinnerFromFilter(transBinner, isoMapper);
                var testSpectrum = file.GetSpectrum(TEST_SPECTRUM);
                // Generate a transition binner containing a lot of tough cases with
                // overlapping transitions and test
                double[] binnedExpected =
                {
                    0.0,         25160.11261, 18254.06375, 18254.06375, 18254.06375,
                    11090.00577, 19780.18628, 19780.18628
                };
                var transBinnerOverlap = TestTransitionBinnerOverlap(testSpectrum, isoMapper, binnedExpected);

                TestSpectrumProcessor(transBinnerOverlap, isoMapper, file, TEST_SPECTRUM);

                TestPeakIntensityCorrection(testSpectrum, isoMapper,
                                            demultiplexer);
                int[]    intensityIndices = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 290, 291, 292, 293, 294, 295, 296 };
                double[] intensityValues  =
                {
                    0.0,        0.0,   0.0, 0.0, 142.95, 349.75,
                    542.87,  511.77, 248.4, 0.0,  49.28,
                    1033.65, 278.56,   0.0, 0.0,    0.0,
                    0.0, 0.0
                };
                // Test demultiplexing of a real spectrum
                TestSpectrumDemultiplex(demultiplexer, TEST_SPECTRUM, testSpectrum, intensityIndices, intensityValues, 0);
            }
        }
コード例 #20
0
        public int GetTotalNumberOfSpectra(string spectraFile)
        {
            if (new MSDataRunPath(spectraFile) != msdataRunPath)
            {
                return(0);
            }
            using (var filereader = new MsDataFileImpl(msdataRunPath.Filepath, msdataRunPath.RunIndex, preferOnlyMsLevel: 2))
            {
                TotalSpectra = filereader.SpectrumCount;
            }

            return(TotalSpectra);
        }
コード例 #21
0
        public void TestScanDescription()
        {
            if (Skyline.Program.NoVendorReaders)
            {
                return;
            }

            string path = TestFilesDir.GetVendorTestData(TestFilesDir.VendorDir.Thermo, "IT-HCD-SPS.raw");

            using (var msDataFile = new MsDataFileImpl(path))
            {
                Assert.AreEqual("sps", msDataFile.GetScanDescription(0));
            }
        }
コード例 #22
0
 private static void VerifyInstrumentInfo(string path, string model, string ionization, string analyzer, string detector)
 {
     using (var msDataFile = new MsDataFileImpl(path))
     {
         var instrumentInfoList = msDataFile.GetInstrumentConfigInfoList().ToList();
         Assert.AreEqual(1, instrumentInfoList.Count);
         var instrument = instrumentInfoList[0];
         Assert.IsFalse(instrument.IsEmpty);
         Assert.AreEqual(model, instrument.Model);
         Assert.AreEqual(ionization, instrument.Ionization);
         Assert.AreEqual(analyzer, instrument.Analyzer);
         Assert.AreEqual(detector, instrument.Detector);
     }
 }
コード例 #23
0
ファイル: PwizFileInfoTest.cs プロジェクト: rfellers/pwiz
        private static void VerifyTicChromatogram(string path, int count, double maxIntensity, int sampleIndex = 0)
        {
            if (!MsDataFileImpl.SupportsMultipleSamples(path))
            {
                sampleIndex = 0;
            }

            using (var msDataFile = new MsDataFileImpl(path, sampleIndex))
            {
                var tic = msDataFile.GetTotalIonCurrent();
                Assert.AreEqual(count, tic.Length);
                Assert.AreEqual(maxIntensity, tic.Max());
            }
        }
コード例 #24
0
        public void TestOverlap(SrmDocument doc, string dataPath)
        {
            // Load the file and check MsDataFileImpl
            using (var file = new MsDataFileImpl(dataPath))
            {
                var filter = new SpectrumFilter(doc, null, null);
                Assert.IsTrue(filter.EnabledMsMs);
                var demultiplexer = new OverlapDemultiplexer(file, filter);
                demultiplexer.ForceInitializeFile();

                // Check that the demultiplexer found the correct multiplexing parameters
                Assert.AreEqual(1, demultiplexer.IsoWindowsPerScan);
                Assert.AreEqual(40, demultiplexer.NumIsoWindows);
                Assert.AreEqual(41, demultiplexer.NumDeconvRegions);

                var isoMapper = demultiplexer.IsoMapperTest;

                // Basic checks of IsolationWindowMapper
                TestIsolationWindowMapper(isoMapper, file, 20.009);
                // Checks of overlap-specific functionality in IsolationWindowMapper
                TestOverlapIsolationWindowMapper(isoMapper, file);
                var transBinner = new TransitionBinner(filter, isoMapper);

                // Test creation of a transition binner from a spectrum filter
                TestTransitionBinnerFromFilter(transBinner, isoMapper);
                var testSpectrum = file.GetSpectrum(TEST_SPECTRUM_OVERLAP);
                // Generate a transition binner containing a lot of tough cases with
                // overlapping transitions and test
                double[] binnedExpected =
                {
                    0.0, 0.0, 0.0, 0.0, 0.0,
                    0.0, 0.0, 0.0
                };
                var transBinnerOverlap = TestTransitionBinnerOverlap(testSpectrum, isoMapper, binnedExpected);

                TestSpectrumProcessor(transBinnerOverlap, isoMapper, file, TEST_SPECTRUM_OVERLAP);
                int[]    intensityIndices = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 290, 291, 292, 293, 294, 295, 296 };
                double[] intensityValues  =
                {
                    0.0,           0.0,      0.0,      0.0,  4545.85, 15660.49,
                    35050.01, 56321.66, 62715.75, 43598.31, 23179.42,
                    2745.94,   3870.54,  4060.16,  3148.17,  1656.38,
                    0.0, 0.0
                };
                // Test demultiplexing of a real spectrum
                TestSpectrumDemultiplex(demultiplexer, TEST_SPECTRUM_OVERLAP, testSpectrum, intensityIndices,
                                        intensityValues, 0);
            }
        }
コード例 #25
0
        public void ShimadzuFileTypeTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string extRaw = ExtensionTestContext.ExtShimadzuRaw;

            // Do file type check
            using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("BSA-digest__MRM_optimisation_SL_scheduled_001" + extRaw)))
            {
                Assert.IsTrue(msData.IsShimadzuFile);

                // check time is minutes
                msData.GetChromatogram(msData.ChromatogramCount - 1, out _, out float[] times, out _);
                Assert.AreEqual(new KeyValuePair <float, float>(5.908167f, 8.905833f), new KeyValuePair <float, float>(times.First(), times.Last()));
            }
        }
コード例 #26
0
 private void ComboChromatogramOnDropDown(object sender, EventArgs e)
 {
     if (_chromatogramDatas != null)
     {
         return;
     }
     comboChromatogram.Items.Clear();
     using (var msDataFileImpl = new MsDataFileImpl(Workspace.GetDataFilePath(MsDataFile.Name)))
     {
         _chromatogramDatas = new ChromatogramData[msDataFileImpl.ChromatogramCount];
         for (int i = 0; i < _chromatogramDatas.Length; i++)
         {
             int indexId;
             comboChromatogram.Items.Add(msDataFileImpl.GetChromatogramId(i, out indexId));
         }
     }
 }
コード例 #27
0
        private static MsDataFilePath[] GetWiffSubPaths(string filePath)
        {
            string[] dataIds;
            try
            {
                dataIds = MsDataFileImpl.ReadIds(filePath);
            }
            catch (Exception x)
            {
                var message = TextUtil.LineSeparate(
                    string.Format(Resources.DataSourceUtil_GetWiffSubPaths_An_error_occurred_attempting_to_read_sample_information_from_the_file__0__, filePath),
                    Resources.DataSourceUtil_GetWiffSubPaths_The_file_may_be_corrupted_missing_or_the_correct_libraries_may_not_be_installed,
                    x.Message);
                throw new IOException(message);
            }

            return(GetWiffSubPaths(filePath, dataIds, null));
        }
コード例 #28
0
        public bool Adopt(IScanProvider other)
        {
            if (!Equals(DocFilePath, other.DocFilePath) || !Equals(DataFilePath, other.DataFilePath))
            {
                return(false);
            }
            var scanProvider = other as ScanProvider;

            if (scanProvider == null)
            {
                return(false);
            }
            _dataFile              = scanProvider._dataFile;
            _msDataFileScanIds     = scanProvider._msDataFileScanIds;
            _getMsDataFileScanIds  = scanProvider._getMsDataFileScanIds;
            scanProvider._dataFile = null;
            return(true);
        }
コード例 #29
0
ファイル: MidasLibrary.cs プロジェクト: tomas-pluskal/pwiz
        private static IEnumerable <DbSpectrum> ReadDbSpectraFromMsd(MsDataFileImpl msd, IProgressMonitor monitor)
        {
            for (var i = 0; i < msd.SpectrumCount; i++)
            {
                if (monitor.IsCanceled)
                {
                    yield break;
                }

                var spectrum = msd.GetSpectrum(i);
                if (!spectrum.Precursors.Any())
                {
                    continue;
                }
                var precursor = spectrum.Precursors.First();
                yield return(new DbSpectrum(new DbResultsFile(msd.FilePath), precursor.PrecursorMz.GetValueOrDefault(),
                                            null, spectrum.RetentionTime.GetValueOrDefault(), spectrum.Mzs, spectrum.Intensities));
            }
        }
コード例 #30
0
        public void FileTypeTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string extWiff = ExtensionTestContext.ExtAbWiff;
            string suffix  = ExtensionTestContext.CanImportAbWiff ? "" : "-test";

            // Do file type checks
            using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("051309_digestion" + suffix + extWiff)))
            {
                Assert.IsTrue(msData.IsABFile);
            }

            using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("051309_digestion-s3.mzXML")))
            {
                Assert.IsTrue(msData.IsABFile);
                Assert.IsTrue(msData.IsMzWiffXml);
            }
        }
コード例 #31
0
        private void GenerateChromatograms(MsDataFile msDataFile, List<AnalysisChromatograms> analyses)
        {
            int totalAnalyses = analyses.Count;
            if (totalAnalyses == 0)
            {
                return;
            }
            if (!UpdateProgress(0))
            {
                return;
            }
            analyses = new List<AnalysisChromatograms>(analyses);
            using (var pwizMsDataFileImpl = new MsDataFileImpl(msDataFile.Path))
            {
                var completeAnalyses = new List<AnalysisChromatograms>();
                int totalScanCount = pwizMsDataFileImpl.SpectrumCount;
                double minTime = msDataFile.GetTime(msDataFile.GetSpectrumCount() - 1);
                double maxTime = msDataFile.GetTime(0);
                foreach (var analysis in analyses)
                {
                    minTime = Math.Min(minTime, analysis.FirstTime);
                    maxTime = Math.Max(maxTime, analysis.LastTime);
                }
                int firstScan = msDataFile.FindScanIndex(minTime);
                for (int iScan = firstScan; analyses.Count > 0 && iScan < totalScanCount; iScan++)
                {
                    double time = msDataFile.GetTime(iScan);
                    int progress = (int)(100 * (time - minTime) / (maxTime - minTime));
                    progress = Math.Min(progress, 100);
                    progress = Math.Max(progress, 0);
                    if (!UpdateProgress(progress))
                    {
                        return;
                    }

                    List<AnalysisChromatograms> activeAnalyses = new List<AnalysisChromatograms>();
                    double nextTime = Double.MaxValue;
                    if (msDataFile.GetMsLevel(iScan, pwizMsDataFileImpl) != 1)
                    {
                        continue;
                    }
                    foreach (var analysis in analyses)
                    {
                        nextTime = Math.Min(nextTime, analysis.FirstTime);
                        if (analysis.FirstTime <= time)
                        {
                            activeAnalyses.Add(analysis);
                        }
                    }
                    if (activeAnalyses.Count == 0)
                    {
                        int nextScan = msDataFile.FindScanIndex(nextTime);
                        iScan = Math.Max(iScan, nextScan - 1);
                        continue;
                    }
                    double[] mzArray, intensityArray;
                    pwizMsDataFileImpl.GetSpectrum(iScan, out mzArray, out intensityArray);
                    foreach (var analysis in activeAnalyses)
                    {
                        var points = new List<MsDataFileUtil.ChromatogramPoint>();
                        foreach (var chromatogram in analysis.Chromatograms)
                        {
                            points.Add(MsDataFileUtil.GetIntensity(chromatogram.Mz, mzArray, intensityArray));
                        }
                        analysis.AddPoints(iScan, time, points);
                    }
                    var incompleteAnalyses = new List<AnalysisChromatograms>();
                    foreach (var analysis in analyses)
                    {
                        if (analysis.LastTime <= time)
                        {
                            completeAnalyses.Add(analysis);
                        }
                        else
                        {
                            incompleteAnalyses.Add(analysis);
                        }
                    }
                    if (completeAnalyses.Count > 10)
                    {
                        SaveChromatograms(completeAnalyses, null);
                        completeAnalyses.Clear();
                    }
                    analyses = incompleteAnalyses;
                }
                completeAnalyses.AddRange(analyses);
                SaveChromatograms(completeAnalyses, msDataFile);
                lock(this)
                {
                    _activePeptideFileAnalysisIds.Clear();
                }
            }
        }
コード例 #32
0
ファイル: MsDataFiles.cs プロジェクト: lgatto/proteowizard
        public static bool TryInitMsDataFile(Workspace workspace, MsDataFile msDataFile, String path, out String message)
        {
            if (path == null)
            {
                message = "Location of data file has never been specified.";
                return false;
            }
            if (!File.Exists(path))
            {
                message = "File does not exist.";
                return false;
            }

            if (msDataFile.HasTimes())
            {
                message = "File exists and has been read before.";
                return true;
            }
            try
            {
                using(var cMsDataFile = new MsDataFileImpl(path))
                {
                    msDataFile.Init(path, cMsDataFile);
                    using (var session = workspace.OpenWriteSession())
                    {
                        session.BeginTransaction();
                        msDataFile.Save(session);
                        session.Transaction.Commit();
                        message = "Success";
                        return true;
                    }
                }
            }
            catch (Exception exception)
            {
                Console.Out.Write(exception);
                message =
                    "An exception occurred while trying to open the file.  Either the file is corrupted, or the necessary libraries to read this file type have not been installed.";
                return false;
            }
        }