public override IEnumerable <string> Process()
        {
            IsobaricResult result = BuildIsobaricResult();

            Progress.SetMessage("Saving data to {0} ...", options.OutputFile);
            IsobaricResultFileFormatFactory.GetXmlFormat().WriteToFile(options.OutputFile, result);

            Progress.SetMessage("Done.");
            return(new[] { options.OutputFile });
        }
Пример #2
0
        /// <summary>
        /// 从isobaricFile中读取spectra对应的isobaric labelling信息。
        /// </summary>
        /// <param name="spectra"></param>
        /// <param name="isobaricFile"></param>
        /// <param name="progress"></param>
        public static void Load(List <IIdentifiedSpectrum> spectra, string isobaricFile, bool readPeaks = false, IProgressCallback progress = null)
        {
            if (progress == null)
            {
                progress = new EmptyProgressCallback();
            }

            var fileNames = new HashSet <string>(from s in spectra
                                                 let fs = s.Query.FileScan
                                                          select fs.Experimental + "," + fs.FirstScan.ToString());

            using (var reader = IsobaricResultFileFormatFactory.GetXmlReader(true, readPeaks))
            {
                var usedChannels = IsobaricScanXmlUtils.GetUsedChannels(isobaricFile);

                reader.Open(isobaricFile);

                progress.SetMessage("Reading Isobaric from {0} ...", isobaricFile);
                progress.SetRange(1, spectra.Count);

                foreach (var spectrum in spectra)
                {
                    if (progress.IsCancellationPending())
                    {
                        throw new UserTerminatedException();
                    }

                    progress.Increment(1);

                    var fs = spectrum.Query.FileScan;
                    if (reader.Has(fs.Experimental, fs.FirstScan))
                    {
                        spectrum.SetIsobaricItem(reader.Read(fs.Experimental, fs.FirstScan, usedChannels));
                    }
                    else
                    {
                        spectrum.SetIsobaricItem(null);
                    }
                }
            }
        }
        public virtual IsobaricResult BuildIsobaricResult()
        {
            Progress.SetMessage("Processing " + options.InputFile + " ...");

            string experimental = Path.GetFileNameWithoutExtension(options.InputFile);

            var format = IsobaricResultFileFormatFactory.GetXmlFormat();

            format.Progress     = this.Progress;
            format.HasReporters = false;

            IsobaricResult result = null;

            var reader = options.Reader;

            if (!File.Exists(options.OriginalXmlFileName))
            {
                reader.Progress = this.Progress;

                Progress.SetMessage("Reading isobaric tag channels from " + new FileInfo(options.InputFile).Name + "...");
                var pkls = reader.ReadFromFile(options.InputFile);
                Progress.SetMessage("Reading isobaric tag channels finished.");

                if (pkls.Count == 0)
                {
                    throw new Exception(MyConvert.Format("No isobaric tag information readed from file {0}, contact with author.", options.InputFile));
                }

                result = new IsobaricResult(pkls);
                result.Comments["Mode"]            = reader.ToString();
                result.PlexType                    = options.PlexType;
                result.ForEach(m => m.Experimental = experimental);

                format.WriteToFile(options.OriginalXmlFileName, result);
            }
            else
            {
                Progress.SetMessage("Reading xml information from " + options.OriginalXmlFileName + " ...");
                result = format.ReadFromFile(options.OriginalXmlFileName);
            }

            result.UsedChannels = (from ucha in options.UsedChannels
                                   let cha = options.PlexType.Channels[ucha.Index]
                                             select new UsedChannel()
            {
                Index = ucha.Index, Name = cha.Name, Mz = cha.Mz, MinMz = cha.Mz - IsobaricConsts.MAX_SHIFT, MaxMz = cha.Mz + IsobaricConsts.MAX_SHIFT
            }).ToList();

            if (options.PerformMassCalibration)
            {
                Progress.SetMessage("Performing mass calibration ...");
                var calPeaks = result.GetMassCalibrationPeaks();
                result.UsedChannels.CalibrateMass(calPeaks, options.OutputFile + ".calibration");
                result.Comments["PerformMassCalibration"] = true.ToString();
            }

            foreach (var channel in result.UsedChannels)
            {
                var mztolerance = PrecursorUtils.ppm2mz(channel.Mz, options.ProductPPMTolerance);
                channel.MinMz = channel.Mz - mztolerance;
                channel.MaxMz = channel.Mz + mztolerance;
            }

            Progress.SetMessage("Building isobaric result ...");
            result.ForEach(m => m.DetectReporter(result.UsedChannels));
            result.RemoveAll(m => m.PeakCount() < options.MinPeakCount);
            result.Comments["RequiredChannels"] = (from c in options.RequiredChannels select c.Name).Merge(",");

            if (options.RequiredChannels.Count > 0)
            {
                options.RequiredChannels.ForEach(m => m.Index = result.UsedChannels.FindIndex(l => l.Name.Equals(m.Name)));
                result.RemoveAll(m =>
                {
                    foreach (var channel in options.RequiredChannels)
                    {
                        if (channel.GetValue(m) <= IsobaricConsts.NULL_INTENSITY)
                        {
                            return(true);
                        }
                    }

                    return(false);
                });
            }

            if (options.PerformPurityCorrection)
            {
                Progress.SetMessage("Performing purity correction ...");
                var tempFilename = options.OutputFile + ".csv";
                new IsobaricPurityCorrectionRCalculator(options.PlexType, result.UsedChannels, options.RExecute, options.PerformPurityCorrection, true).Calculate(result, tempFilename);
                result.ForEach(m => m.Reporters.ForEach(p =>
                {
                    if (p.Intensity < IsobaricConsts.NULL_INTENSITY)
                    {
                        p.Intensity = IsobaricConsts.NULL_INTENSITY;
                    }
                }));
                result.Comments["PerformPurityCorrection"] = true.ToString();
            }

            result.RemoveAll(m => m.PeakCount() < options.MinPeakCount);

            Progress.SetMessage("Calculating precursor percentage ...");
            result.ForEach(m => m.PrecursorPercentage = m.PeakInIsolationWindow.GetPrecursorPercentage(options.PrecursorPPMTolerance));

            return(result);
        }