Example #1
0
        /// <summary>
        /// Gets full heat map data from the <see cref="DataReader"/> that the UIMF is open in.
        /// </summary>
        /// <param name="uimf">
        /// The uimf that data is to be fetched from.
        /// </param>
        /// <param name="frameNumber">
        /// The frame number that data is to be fetched.
        /// </param>
        /// <returns>
        /// The 2d array of doubles with the heat map data.
        /// </returns>
        private double[,] GetFullHeatmapData(DataReader uimf, int frameNumber)
        {
            var global  = uimf.GetGlobalParams();
            var endScan = uimf.GetFrameParams(frameNumber).Scans;
            var endBin  = global.Bins;

            return(uimf.AccumulateFrameData(frameNumber, frameNumber, false, 1, endScan, 1, endBin, 1, 1));
        }
Example #2
0
        public void ReadAllFramesAndScans()
        {
            if (!File.Exists(mTestUIMFFilePath))
            {
                reportProgress("UIMFFile not found. Input file path was: " + mTestUIMFFilePath);
                return;
            }

            var datareader = new DataReader(mTestUIMFFilePath);

            //--------------------------------------------------------------------------Get Global parameters

            var gp = datareader.GetGlobalParams();

            reportProgress();
            reportProgress();
            reportProgress("Displaying some global parameters...");

#pragma warning disable 618
            var legacyGlobalParams = datareader.GetGlobalParameters();
#pragma warning restore 618

            reportProgress("DateStarted_Legacy= " + legacyGlobalParams.DateStarted);

            reportProgress("DateStarted= " + gp.GetValue(GlobalParamKeyType.DateStarted));

            reportProgress("NumBins= " + gp.Bins);
            reportProgress("NumFrames= " + gp.NumFrames);

            reportProgress("Pre-caching all frame parameters...");
            datareader.PreCacheAllFrameParams();

            int frameCountWithError = 0;

            for (var frameNum = 1; frameNum <= gp.NumFrames; frameNum++)
            {
                var fp = datareader.GetFrameParams(frameNum);

                if (fp == null)
                {
                    continue;
                }

                if (fp.CalibrationSlope <= 0.0001)
                {
                    Console.WriteLine("Frame " + frameNum + ", Slope is 0 (or negative)");
                }

                if (Math.Abs(fp.CalibrationIntercept) < Single.Epsilon)
                {
                    Console.WriteLine("Frame " + frameNum + ", Intercept is 0");
                }

                var startScan       = 0;
                var endScan         = fp.GetValueInt32(FrameParamKeyType.Scans);
                var startBin        = 1;
                var endBin          = gp.Bins;
                var valuesPerPixelX = 100;
                var valuesPerPixelY = 100;

                // Note that AccumulateFrameData is used by the UimfViewer and by Atreyu
                var frameData = datareader.AccumulateFrameData(frameNum, frameNum, false, startScan, endScan, startBin, endBin, valuesPerPixelX, valuesPerPixelY);

                var topIndex1    = frameData.GetUpperBound(0);
                var topIndex2    = frameData.GetUpperBound(1);
                var nonZeroCount = 0;

                for (var i = 0; i <= topIndex1; i++)
                {
                    for (var j = 0; j <= topIndex2; j++)
                    {
                        if (frameData[i, j] > 0)
                        {
                            // Console.Write(frameData[i, j] + " ");
                            nonZeroCount++;
                        }
                    }
                }

                if (frameNum % 25 == 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("Frame " + frameNum + " has " + nonZeroCount + " non-zero points");
                }

                if (nonZeroCount == 0)
                {
                    Console.WriteLine("  - Error, all points have an intensity of zero; this should not happen");
                    frameCountWithError++;
                }

                var frameScanInfo = datareader.GetFrameScans(frameNum);

                if (frameNum % 25 == 0)
                {
                    foreach (var scanInfo in frameScanInfo)
                    {
                        if (scanInfo.Scan % 100 == 0)
                        {
                            Console.WriteLine("  Scan " + scanInfo.Scan.ToString().PadLeft(3) + " has BPI = " +
                                              scanInfo.BPI + " at " +
                                              scanInfo.BPI_MZ.ToString("0.0") + " m/z, TIC = " + scanInfo.TIC +
                                              " and drift time " + scanInfo.DriftTime.ToString("0.0") + " msec");
                        }
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine("Loaded data from " + gp.NumFrames + " frames; count with error: " + frameCountWithError);
        }
        private void WriteRun(XmlWriter writer, string outputPath, DataReader reader, VoltageGroup voltageGroup)
        {
            writer.WriteStartElement("run");
            string dataset = Path.GetFileNameWithoutExtension(outputPath);
            writer.WriteAttributeString("id", dataset);
            writer.WriteAttributeString("defaultInstrumentConfigurationRef", "IC");
            writer.WriteAttributeString("startTimeStamp", this.dateTime);

            writer.WriteStartElement("spectrumList");
            writer.WriteAttributeString("count", this.scans.ToString(CultureInfo.InvariantCulture));

            int startingFrame = voltageGroup.FirstFrameNumber;
            int endingFrame = voltageGroup.LastFrameNumber;
            Console.Write("Summing frame[{0} - {1}]...    ", startingFrame, endingFrame);

            double[,] summedIntensities = reader.AccumulateFrameData(startingFrame, endingFrame, false, 1, this.scans, 1, this.bins, -1, -1);

            // Use dirft time scan as LC scan to massage skyline
            for (int lcScan = 1; lcScan <= this.scans; lcScan++)
            {
                float[] mzArray;
                float[] intensityArray;

                this.GetMzIntensityArrayAtScan(summedIntensities, lcScan, out mzArray, out intensityArray);

                double mzLow = mzArray[0];
                double mzHigh = mzArray[mzArray.Count()-1];

                // Write the bins as mass spectrum
                writer.WriteStartElement("spectrum");
                writer.WriteAttributeString("index", String.Format("{0}", lcScan - 1));
                writer.WriteAttributeString("id", String.Format("frame={0} scan={1} frameType={2}", 1, lcScan, 1));
                writer.WriteAttributeString("defaultArrayLength", mzArray.Count().ToString(CultureInfo.InvariantCulture));

                writer.WriteStartElement("cvParam");
                writer.WriteAttributeString("cvRef", "MS");
                writer.WriteAttributeString("accession", "MS:1000511");
                writer.WriteAttributeString("name", "ms level");
                writer.WriteAttributeString("value", "1");
                writer.WriteEndElement();

                writer.WriteStartElement("cvParam");
                writer.WriteAttributeString("cvRef", "MS");
                writer.WriteAttributeString("accession", "MS:1000579");
                writer.WriteAttributeString("name", "MS1 spectrum");
                writer.WriteAttributeString("value", "");
                writer.WriteEndElement();

                writer.WriteStartElement("cvParam");
                writer.WriteAttributeString("cvRef", "MS");
                writer.WriteAttributeString("accession", "MS:1000128");
                writer.WriteAttributeString("name", "profile spectrum");
                writer.WriteAttributeString("value", "");
                writer.WriteEndElement();

                writer.WriteStartElement("scanList");
                writer.WriteAttributeString("count", "1");

                writer.WriteStartElement("cvParam");
                writer.WriteAttributeString("cvRef", "MS");
                writer.WriteAttributeString("accession", "MS:1000795");
                writer.WriteAttributeString("name", "no combination");
                writer.WriteAttributeString("value", "");
                writer.WriteEndElement();

                writer.WriteStartElement("scan");

                writer.WriteStartElement("cvParam");
                writer.WriteAttributeString("cvRef", "MS");
                writer.WriteAttributeString("accession", "MS:1000016");
                writer.WriteAttributeString("name", "scan start time");
                writer.WriteAttributeString("value", reader.GetDriftTime(voltageGroup.FirstFrameNumber, lcScan, true).ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("unitCvRef", "UO");
                writer.WriteAttributeString("unitAccession", "UO:0000031");
                writer.WriteAttributeString("unitName", "minute");

                writer.WriteEndElement();

                writer.WriteStartElement("scanWindowList");
                writer.WriteAttributeString("count", "1");

                writer.WriteStartElement("scanWindow");

                writer.WriteStartElement("cvParam");
                writer.WriteAttributeString("cvRef", "MS");
                writer.WriteAttributeString("accession", "MS:1000501");
                writer.WriteAttributeString("name", "scan window lower limit");
                writer.WriteAttributeString("value", mzLow.ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("unitCvRef", "MS");
                writer.WriteAttributeString("unitAccession", "MS:1000040");
                writer.WriteAttributeString("unitName", "m/z");
                writer.WriteEndElement();

                writer.WriteStartElement("cvParam");
                writer.WriteAttributeString("cvRef", "MS");
                writer.WriteAttributeString("accession", "MS:1000500");
                writer.WriteAttributeString("name", "scan window upper limit");
                writer.WriteAttributeString("value", mzHigh.ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("unitCvRef", "MS");
                writer.WriteAttributeString("unitAccession", "MS:1000040");
                writer.WriteAttributeString("unitName", "m/z");
                writer.WriteEndElement();

                // scan window
                writer.WriteEndElement();

                // scan window list
                writer.WriteEndElement();

                // scan
                writer.WriteEndElement();

                // scan list
                writer.WriteEndElement();

                this.WriteBinaryDataArrays(mzArray, intensityArray, writer);

                // spectrum
                writer.WriteEndElement();
            }

            // spectrum list
            writer.WriteEndElement();

            // run
            writer.WriteEndElement();
        }