Ejemplo n.º 1
0
        public Peak1DArray ReadSpectrumPeaks(string spectrumID)
        {
            RaiseDisposed();

            try
            {
                int sampleIndex, experimentIndex, scanIndex;
                Parse(spectrumID, out sampleIndex, out experimentIndex, out scanIndex);

                using (MassSpectrometerSample sample = batch.GetSample(sampleIndex).MassSpectrometerSample)
                    using (MSExperiment msExp = sample.GetMSExperiment(experimentIndex))
                    {
                        Clearcore2.Data.MassSpectrum ms = msExp.GetMassSpectrum(scanIndex);
                        Peak1DArray pa = new Peak1DArray(
                            BinaryDataCompressionType.NoCompression,
                            BinaryDataType.Float32,
                            BinaryDataType.Float32);

                        //Peak1D[] peaks = new Peak1D[ms.NumDataPoints];

                        //for (int i = 0; i < ms.NumDataPoints; i++)
                        //    peaks[i] = new Peak1D(ms.GetYValue(i), ms.GetXValue(i));

                        //pa.Peaks = MzLiteArray.ToMzLiteArray(peaks);

                        pa.Peaks = new WiffPeaksArray(ms);

                        return(pa);
                    }
            }
            catch (Exception ex)
            {
                throw new MzLiteIOException(ex.Message, ex);
            }
        }
Ejemplo n.º 2
0
        public MzLiteModel CreateDefaultModel()
        {
            RaiseDisposed();

            MzLiteModel model = new MzLiteModel(batch.Name);

            string[] sampleNames = batch.GetSampleNames();

            for (int sampleIdx = 0; sampleIdx < sampleNames.Length; sampleIdx++)
            {
                using (Clearcore2.Data.DataAccess.SampleData.Sample wiffSample = batch.GetSample(sampleIdx))
                {
                    if (wiffSample.HasMassSpectrometerData)
                    {
                        string sampleName = sampleNames[sampleIdx].Trim();
                        string sampleID   = ToRunID(sampleIdx);
                        MassSpectrometerSample msSample     = wiffSample.MassSpectrometerSample;
                        MzLite.Model.Sample    mzLiteSample = new MzLite.Model.Sample(
                            sampleID,
                            sampleName);
                        model.Samples.Add(mzLiteSample);

                        string   softwareID = wiffSample.Details.SoftwareVersion.Trim();
                        Software software   = null;

                        if (!model.Software.TryGetItemByKey(softwareID, out software))
                        {
                            software = new Software(softwareID);
                            model.Software.Add(software);
                        }

                        string     instrumentID = msSample.InstrumentName.Trim();
                        Instrument instrument   = null;

                        if (!model.Instruments.TryGetItemByKey(instrumentID, out instrument))
                        {
                            instrument          = new Instrument(instrumentID);
                            instrument.Software = software;
                            model.Instruments.Add(instrument);
                        }

                        string runID = string.Format("sample={0}", sampleIdx);

                        Run run = new Run(runID);
                        run.Sample            = mzLiteSample;
                        run.DefaultInstrument = instrument;
                        model.Runs.Add(run);
                    }
                }
            }

            return(model);
        }
Ejemplo n.º 3
0
 private static IEnumerable <MzLite.Model.MassSpectrum> Yield(Batch batch, int sampleIndex)
 {
     using (MassSpectrometerSample sample = batch.GetSample(sampleIndex).MassSpectrometerSample)
     {
         for (int experimentIndex = 0; experimentIndex < sample.ExperimentCount; experimentIndex++)
         {
             using (MSExperiment msExp = sample.GetMSExperiment(experimentIndex))
             {
                 for (int scanIndex = 0; scanIndex < msExp.Details.NumberOfScans; scanIndex++)
                 {
                     yield return(GetSpectrum(batch, sample, msExp, sampleIndex, experimentIndex, scanIndex));
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        public MzLite.Model.MassSpectrum ReadMassSpectrum(string spectrumID)
        {
            RaiseDisposed();

            try
            {
                int sampleIndex, experimentIndex, scanIndex;
                Parse(spectrumID, out sampleIndex, out experimentIndex, out scanIndex);

                using (MassSpectrometerSample sample = batch.GetSample(sampleIndex).MassSpectrometerSample)
                    using (MSExperiment msExp = sample.GetMSExperiment(experimentIndex))
                    {
                        return(GetSpectrum(batch, sample, msExp, sampleIndex, experimentIndex, scanIndex));
                    }
            }
            catch (Exception ex)
            {
                throw new MzLiteIOException(ex.Message, ex);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Fills this instance data members with the information read from <paramref name="wiffFile"/>.
        /// </summary>
        /// <param name="wiffFile">A <see cref="Batch"/> instance. The data source.</param>
        private void Initialize(Batch wiffFile)
        {
            Sample sample = wiffFile.GetSample(this.index);

            // retrieve this sample's name
            this.name = sample.Details.SampleName;

            // get the position information for the selected sample the position data exists
            // in a seperate file ( one per sample ) and is read from that file 'manually'
            AppContext.ProgressStart("reading path file");
            try
            {
                // 1) Set the various WiffSample Parameters
                string pathFile = this.wiffFileContent.FileName + " (" + (this.index + 1).ToString(CultureInfo.InvariantCulture) + ").path";

                // Make sure the path file exists
                if (!File.Exists(pathFile))
                {
                    MessageBox.Show(pathFile + " is missing", "Missing File");
                    return;
                }

                var positionStream = new FileStream(@pathFile, FileMode.Open, FileAccess.Read);

                // calculate the count of position entries (12 bytes per position entry)
                this.positionDataLength = positionStream.Length / 12;

                this.x1 = 1e10;
                this.x2 = 0.0;
                this.y1 = 1e10;
                this.y2 = 0.0;

                // the array to hold the position information
                this.positionData = new uint[this.positionDataLength, 3];
                var positionReader = new BinaryReader(positionStream);
                for (long posindex = 0; posindex < this.positionDataLength; posindex++)
                {
                    this.positionData[posindex, 0] = positionReader.ReadUInt32();
                    this.positionData[posindex, 1] = positionReader.ReadUInt32();
                    this.positionData[posindex, 2] = positionReader.ReadUInt32();

                    // hundred progress ticks
                    if (Equals(posindex % (this.positionDataLength / 100.0), 0.0))
                    {
                        AppContext.ProgressSetValue(100.0 * posindex / this.positionDataLength);
                    }

                    if (this.positionData[posindex, 1] < this.x1)
                    {
                        this.x1 = this.positionData[posindex, 1];
                    }

                    if (this.positionData[posindex, 1] > this.x2)
                    {
                        this.x2 = this.positionData[posindex, 1];
                    }

                    if (this.positionData[posindex, 2] < this.y1)
                    {
                        this.y1 = this.positionData[posindex, 2];
                    }

                    if (this.positionData[posindex, 2] > this.y2)
                    {
                        this.y2 = this.positionData[posindex, 2];
                    }
                }

                positionReader.Close();
                positionStream.Close();

                this.x1 /= 1000;
                this.x2 /= 1000;
                this.y1 /= 1000;
                this.y2 /= 1000;

                this.width  = this.x2 - this.x1;
                this.height = this.y2 - this.y1;
            }
            finally
            {
                AppContext.ProgressClear();
            }

            // 2) Get the size of the scan file  set scanfilesize
            string scanpathFile = this.wiffFileContent.FileName + ".scan";
            var    fileinfo     = new FileInfo(scanpathFile);

            this.scanfilesize = fileinfo.Length;

            MassSpectrometerSample massSpecSample = sample.MassSpectrometerSample;
            int numberOfExperiments = massSpecSample.ExperimentCount;

            // 3) Get number of experiments and create WiffExperiments for each
            // loop through the experiments; the index of the experiments is zero based!!
            for (int actExperiment = 0; actExperiment < numberOfExperiments; actExperiment++)
            {
                MSExperiment msexperiment = massSpecSample.GetMSExperiment(actExperiment);

                WiffExperiment experiment = WiffExperimentFactory.CreateWiffExperiment(msexperiment, this);

                this.experiments.Add(experiment);
            }
        }
Ejemplo n.º 6
0
        private static MzLite.Model.MassSpectrum GetSpectrum(
            Batch batch,
            MassSpectrometerSample sample,
            MSExperiment msExp,
            int sampleIndex,
            int experimentIndex,
            int scanIndex)
        {
            MassSpectrumInfo wiffSpectrum = msExp.GetMassSpectrumInfo(scanIndex);

            MzLite.Model.MassSpectrum mzLiteSpectrum = new Model.MassSpectrum(ToSpectrumID(sampleIndex, experimentIndex, scanIndex));

            // spectrum

            mzLiteSpectrum.SetMsLevel(wiffSpectrum.MSLevel);

            if (wiffSpectrum.CentroidMode)
            {
                mzLiteSpectrum.SetCentroidSpectrum();
            }
            else
            {
                mzLiteSpectrum.SetProfileSpectrum();
            }

            // scan

            Scan scan = new Scan();

            scan.SetScanStartTime(wiffSpectrum.StartRT)
            .UO_Minute();

            mzLiteSpectrum.Scans.Add(scan);

            // precursor

            if (wiffSpectrum.IsProductSpectrum)
            {
                Precursor precursor = new Precursor();

                double isoWidth;
                double targetMz;

                if (GetIsolationWindow(wiffSpectrum.Experiment, out isoWidth, out targetMz))
                {
                    precursor.IsolationWindow
                    .SetIsolationWindowTargetMz(targetMz)
                    .SetIsolationWindowUpperOffset(isoWidth)
                    .SetIsolationWindowLowerOffset(isoWidth);
                }

                SelectedIon selectedIon = new SelectedIon();

                selectedIon.SetSelectedIonMz(wiffSpectrum.ParentMZ)
                .SetChargeState(wiffSpectrum.ParentChargeState);

                precursor.SelectedIons.Add(selectedIon);

                precursor.Activation
                .SetCollisionEnergy(wiffSpectrum.CollisionEnergy);

                mzLiteSpectrum.Precursors.Add(precursor);
            }

            return(mzLiteSpectrum);
        }