Ejemplo n.º 1
0
        private void WriteXmlScan(StreamWriter sw, int scan, List <Pair <int, long> > scanIndeies)
        {
            sw.Flush();
            scanIndeies.Add(new Pair <int, long>(scan, sw.BaseStream.Position));

            var rcf = new RawScanFilter();

            rcf.Filter = this.rawFile.GetFilterForScanNum(scan);
            double          retentionTime = this.rawFile.ScanToRetentionTime(scan);
            PeakList <Peak> pkl           = this.rawFile.GetMassListFromScanNum(scan, this.doCentroid);

            /* scan header info begin */
            int    numPakets         = 0;
            double RT                = 0;
            double lowMass           = 0;
            double highMass          = 0;
            double TIC               = 0;
            double basePeakMass      = 0;
            double basePeakIntensity = 0;
            int    channel           = 0;
            int    uniformTime       = 0;
            double frequency         = 0;

            this.rawFile.GetScanHeaderInfoForScanNum(
                scan,
                ref numPakets,
                ref RT,
                ref lowMass,
                ref highMass,
                ref TIC,
                ref basePeakMass,
                ref basePeakIntensity,
                ref channel,
                ref uniformTime,
                ref frequency);

            sw.Write(MyConvert.Format("  <scan num=\"{0}\"" + lf
                                      + "        msLevel=\"{1}\"" + lf
                                      + "        peaksCount=\"{2}\"" + lf
                                      + "        polarity=\"{3}\"" + lf
                                      + "        scanType=\"{4}\"" + lf
                                      + "        retentionTime=\"PT{5:0.00}S\"" + lf,
                                      scan,
                                      rcf.MsLevel,
                                      pkl.Count,
                                      rcf.Polarity,
                                      rcf.ScanType,
                                      retentionTime * 60));
            if (rcf.MsLevel > 1)
            {
                sw.Write("        collisionEnergy=\"{0:0}\"" + lf, rcf.CollisionEnergy);
            }

            sw.Write(MyConvert.Format("        lowMz=\"{0:0}\"" + lf
                                      + "        highMz=\"{1:0}\"" + lf
                                      + "        basePeakMz=\"{2:0.000}\"" + lf
                                      + "        basePeakIntensity=\"{3:0}\"" + lf
                                      + "        totIonCurrent=\"{4}\">" + lf,
                                      lowMass,
                                      highMass,
                                      basePeakMass,
                                      basePeakIntensity,
                                      TIC));

            if (rcf.MsLevel > 1)
            {
                this.rawFile.GetPeakListInfo(scan, pkl);
                sw.Write(MyConvert.Format("    <precursorMz precursorIntensity=\"{0:0.#####}\"", pkl.PrecursorIntensity));

                if (pkl.PrecursorCharge > 0)
                {
                    sw.Write(" precursorCharge=\"" + pkl.PrecursorCharge + "\"");
                }

                sw.Write(">");
                sw.Write(MyConvert.Format("{0:0.######}</precursorMz>" + lf, pkl.PrecursorMZ));
            }
            /* scan header info end */

            /* peak list info begin */
            sw.Write("    <peaks precision=\"32\"" + lf
                     + "           byteOrder=\"network\"" + lf
                     + "           pairOrder=\"m/z-int\">");
            sw.Write(MzxmlHelper.PeakListToBase64(pkl) + "</peaks>" + lf);
            /* peak list info end */

            //I don't care if this scan is an child of last scan, just close it
            sw.Write("  </scan>" + lf);
        }
        protected override void DoWritePeakList(IRawFile rawFile, PeakList <Peak> pkl, string rawFileName, List <string> result)
        {
            sw.Flush();
            scanIndeies.Add(new Pair <int, long>(pkl.ScanTimes[0].Scan, sw.BaseStream.Position));

            int scan          = pkl.ScanTimes[0].Scan;
            var retentionTime = pkl.ScanTimes[0].RetentionTime;

            var activationMethod = string.Empty;

            var intent = GetScanIntent(pkl.MsLevel);

            if (rawFile is RawFileImpl)
            {
                var impl = rawFile as RawFileImpl;

                var rcf = new RawScanFilter();
                rcf.Filter       = impl.GetFilterForScanNum(scan);
                activationMethod = rcf.ActivationMethod.ToUpper();

                /* scan header info begin */
                int    numPakets         = 0;
                double RT                = 0;
                double lowMass           = 0;
                double highMass          = 0;
                double TIC               = 0;
                double basePeakMass      = 0;
                double basePeakIntensity = 0;
                int    channel           = 0;
                int    uniformTime       = 0;
                double frequency         = 0;

                impl.GetScanHeaderInfoForScanNum(
                    scan,
                    ref numPakets,
                    ref RT,
                    ref lowMass,
                    ref highMass,
                    ref TIC,
                    ref basePeakMass,
                    ref basePeakIntensity,
                    ref channel,
                    ref uniformTime,
                    ref frequency);

                lowMass  = pkl.First().Mz;
                highMass = pkl.Last().Mz;

                sw.Write(MyConvert.Format(intent + "<scan num=\"{0}\"" + lf
                                          + intent + " msLevel=\"{1}\"" + lf
                                          + intent + " peaksCount=\"{2}\"" + lf
                                          + intent + " polarity=\"{3}\"" + lf
                                          + intent + " scanType=\"{4}\"" + lf
                                          + intent + " filterLine=\"{5}\"" + lf
                                          + intent + " retentionTime=\"PT{6:G6}S\"" + lf,
                                          scan,
                                          rcf.MsLevel,
                                          pkl.Count,
                                          rcf.Polarity,
                                          rcf.ScanType,
                                          rcf.Filter,
                                          retentionTime * 60));

                sw.Write(MyConvert.Format(intent + " lowMz=\"{0:G6}\"" + lf
                                          + intent + " highMz=\"{1:G6}\"" + lf
                                          + intent + " basePeakMz=\"{2:G6}\"" + lf
                                          + intent + " basePeakIntensity=\"{3:e5}\"" + lf
                                          + intent + " totIonCurrent=\"{4:e5}\" >" + lf,
                                          lowMass,
                                          highMass,
                                          basePeakMass,
                                          basePeakIntensity,
                                          TIC));

                if (rcf.MsLevel > 1)
                {
                    sw.Write(intent + " collisionEnergy=\"{0:0}\"" + lf, rcf.CollisionEnergy);
                }

                pkl.PrecursorIntensity = impl.GetPrecursorPeak(scan).Intensity;
            }
            else
            {
                sw.Write(MyConvert.Format(intent + "<scan num=\"{0}\"" + lf
                                          + intent + " msLevel=\"{1}\"" + lf
                                          + intent + " peaksCount=\"{2}\"" + lf
                                          + intent + " scanType=\"{3}\"" + lf
                                          + intent + " retentionTime=\"PT{4:G8}S\"" + lf,
                                          scan,
                                          pkl.MsLevel,
                                          pkl.Count,
                                          pkl.ScanMode,
                                          retentionTime * 60));

                var basePeak = pkl.FindMaxIntensityPeak();
                var TIC      = pkl.Sum(m => m.Intensity);

                sw.Write(MyConvert.Format(intent + " lowMz=\"{0:0}\"" + lf
                                          + intent + " highMz=\"{1:0}\"" + lf
                                          + intent + " basePeakMz=\"{2:G6}\"" + lf
                                          + intent + " basePeakIntensity=\"{3:e5}\"" + lf
                                          + intent + " totIonCurrent=\"{4:e5}\" >" + lf,
                                          pkl.First().Mz,
                                          pkl.Last().Mz,
                                          basePeak.Mz,
                                          basePeak.Intensity,
                                          TIC));
            }

            if (pkl.MsLevel > 1)
            {
                sw.Write(MyConvert.Format(intent + " <precursorMz precursorIntensity=\"{0:0.#####}\"", pkl.PrecursorIntensity));

                if (!string.IsNullOrEmpty(activationMethod))
                {
                    sw.Write(" activationMethod=\"{0}\"", activationMethod);
                }
                if (pkl.PrecursorCharge > 0)
                {
                    sw.Write(" precursorCharge=\"{0}\"", pkl.PrecursorCharge);
                }

                sw.Write(" >");
                sw.Write(MyConvert.Format("{0:0.######}</precursorMz>" + lf, pkl.PrecursorMZ));
            }
            /* scan header info end */

            /* peak list info begin */
            sw.WriteLine(intent + " <peaks precision=\"32\"");
            sw.WriteLine(intent + "  byteOrder=\"network\"");
            sw.WriteLine(intent + "  contentType=\"m/z-int\"");
            sw.WriteLine(intent + "  compressionType=\"none\"");
            sw.WriteLine(intent + "  compressedLen=\"0\" >" + MzxmlHelper.PeakListToBase64(pkl) + "</peaks>");
            /* peak list info end */
        }