Пример #1
0
        /// <summary>
        /// The Thermo decon result filename is assumed to be the same as the spectra file name
        /// </summary>
        private static AnnotatedSpecies GetThermoDeconSpecies(string line, StreamReader reader, string fileName)
        {
            string[]   items      = line.Split(ItemDelimiter);
            int        numCharges = int.Parse(items[3]); // TODO: get this from header, not hardcoded
            List <int> chargeList = new List <int>();

            double mass        = double.Parse(items[MonoisotopicMassColumn]);
            string speciesName = items[SpeciesNameColumn] + " (" + mass.ToString("F1") + ")";
            double apexRt      = double.Parse(items[RetentionTimeColumn]);
            string rtRange     = items[FeatureRtStartColumn];
            double rtStart     = double.Parse(rtRange.Split('-')[0].Trim());
            double rtEnd       = double.Parse(rtRange.Split('-')[1].Trim());

            for (int i = 0; i < numCharges + 1; i++)
            {
                var nextLine        = reader.ReadLine();
                var chargeLineSplit = nextLine.Split(ItemDelimiter);

                if (chargeLineSplit[1].Trim().Equals("Charge State", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                chargeList.Add(int.Parse(chargeLineSplit[1]));
            }

            var deconFeature = new DeconvolutionFeature(mass, apexRt, rtStart, rtEnd, chargeList, fileName);
            var species      = new AnnotatedSpecies(deconFeature);

            return(species);
        }
Пример #2
0
        private void SpeciesListView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            AnnotatedSpecies species = ((TreeView)sender).SelectedItem as AnnotatedSpecies;
            MsDataScan       scan    = null;

            var file = SpectraFiles.FirstOrDefault(p => System.IO.Path.GetFileNameWithoutExtension(p.Key)
                                                   == species.DeconvolutionFeature.SpectraFileNameWithoutExtension);

            if (file.Value == null)
            {
                MessageBox.Show("The spectra file '" + species.DeconvolutionFeature.SpectraFileNameWithoutExtension + "' has not been loaded");
            }

            CurrentlySelectedSpectraFile = file;

            for (int i = 1; i < 10000000; i++)
            {
                var theScan = file.Value.GetOneBasedScanFromDynamicConnection(i);

                if (theScan.RetentionTime >= species.DeconvolutionFeature.ApexRt && theScan.MsnOrder == 1)
                {
                    scan = theScan;
                    break;
                }
            }

            PlotSpecies(species, scan);
        }
Пример #3
0
        private static AnnotatedSpecies GetTdPortalSpecies(string line)
        {
            string[] items = line.Split(ItemDelimiter);

            string baseSequence = items[SpeciesNameColumn];
            string modSequence  = items[SpeciesNameColumn];
            double mass         = double.Parse(items[MonoisotopicMassColumn]);
            // TD portal does not report precursor charge

            var id = new Identification(baseSequence, modSequence, mass, -1);

            var species = new AnnotatedSpecies(id);

            return(species);
        }
Пример #4
0
        private static AnnotatedSpecies GetMetaMorpheusSpecies(string line)
        {
            string[] items = line.Split(ItemDelimiter);

            string baseSequence = items[SpeciesNameColumn];
            string modSequence  = items[SpeciesNameColumn];
            double mass         = double.Parse(items[MonoisotopicMassColumn]);
            int    charge       = int.Parse(items[ChargeColumn]);

            var id = new Identification(baseSequence, modSequence, mass, charge);

            var species = new AnnotatedSpecies(id);

            return(species);
        }
Пример #5
0
        private static AnnotatedSpecies GetFlashDeconvSpecies(string line)
        {
            string[] items = line.Split(ItemDelimiter);

            string identifier = items[SpeciesNameColumn];
            double mass       = double.Parse(items[MonoisotopicMassColumn]);

            int    minChargeState = int.Parse(items[MinChargeColumn]);
            int    maxChargeState = int.Parse(items[MaxChargeColumn]);
            var    chargeList     = Enumerable.Range(minChargeState, maxChargeState - minChargeState + 1).ToList();
            double apexRt         = double.Parse(items[RetentionTimeColumn]) / 60;
            double rtStart        = double.Parse(items[FeatureRtStartColumn]) / 60;
            double rtEnd          = double.Parse(items[FeatureRtEndColumn]) / 60;
            string fileName       = items[SpectraFileNameColumn];
            var    deconFeature   = new DeconvolutionFeature(mass, apexRt, rtStart, rtEnd, chargeList, fileName);
            var    species        = new AnnotatedSpecies(deconFeature);

            return(species);
        }
Пример #6
0
        private static AnnotatedSpecies GetProteoformExplorerSpecies(string line, StreamReader reader)
        {
            line = line.Replace("\"", string.Empty);
            string[] items = line.Split(ItemDelimiter);

            string identifier = items[SpeciesNameColumn];
            double mass       = double.Parse(items[MonoisotopicMassColumn]);
            int    charge     = int.Parse(items[ChargeColumn]);
            double apexRt     = double.Parse(items[RetentionTimeColumn]);
            string fileName   = items[SpectraFileNameColumn];
            int    scan       = int.Parse(items[ScanNumberColumn]);
            var    peaks      = items[PeaksListColumn].Split(',').Select(p => double.Parse(p)).ToList();

            var annotEnvelope = new AnnotatedEnvelope(scan, apexRt, charge, peaks);
            var deconFeature  = new DeconvolutionFeature(mass, apexRt, apexRt, apexRt, new List <int> {
                charge
            }, fileName, new List <AnnotatedEnvelope> {
                annotEnvelope
            });
            var species = new AnnotatedSpecies(deconFeature);

            return(species);
        }
Пример #7
0
        public static List <AnnotatedSpecies> ReadSpeciesFromFile(string filePath, out List <string> errors)
        {
            var fileType = InputSourceType.Unknown;

            errors = new List <string>();
            var listOfSpecies = new List <AnnotatedSpecies>();

            // open the file to read
            StreamReader reader;

            try
            {
                reader = new StreamReader(filePath);
            }
            catch (Exception e)
            {
                errors.Add("Error reading file " + filePath + "\n" + e.Message);
                return(listOfSpecies);
            }

            // read the file
            int lineNum = 0;

            while (reader.Peek() > 0)
            {
                string line = reader.ReadLine();
                lineNum++;

                // determine file type from the header
                if (lineNum == 1)
                {
                    fileType = GetFileTypeFromHeader(line);

                    if (fileType == InputSourceType.Unknown)
                    {
                        errors.Add("Could not interpret header labels from file: " + filePath);
                        return(listOfSpecies);
                    }

                    continue;
                }

                // read the line + create the species object
                AnnotatedSpecies species = null;
                switch (fileType)
                {
                case InputSourceType.MetaMorpheus:
                    species = GetMetaMorpheusSpecies(line);
                    break;

                case InputSourceType.FlashDeconv:
                    species = GetFlashDeconvSpecies(line);
                    break;

                case InputSourceType.TDPortal:
                    species = GetTdPortalSpecies(line);
                    break;

                case InputSourceType.ThermoDecon:
                    species = GetThermoDeconSpecies(line, reader, filePath);
                    break;

                case InputSourceType.ProteoformExplorer:
                    species = GetProteoformExplorerSpecies(line, reader);
                    break;
                }

                // add the item to the list
                if (species != null)
                {
                    listOfSpecies.Add(species);
                }
            }

            return(listOfSpecies);
        }
Пример #8
0
        private void PlotSpeciesIsotopeXics(AnnotatedSpecies species, MsDataScan scan, int?charge = null)
        {
            double rtWindowHalfWidth = 2.5;

            MsDataScan startScan = null;

            for (int i = scan.OneBasedScanNumber; i >= 1; i--)
            {
                var theScan = CurrentlySelectedSpectraFile.Value.GetOneBasedScanFromDynamicConnection(i);

                if (theScan.RetentionTime < scan.RetentionTime - rtWindowHalfWidth)
                {
                    break;
                }

                startScan = theScan;
            }

            List <MsDataScan> scans = new List <MsDataScan>();

            for (int i = startScan.OneBasedScanNumber; i < 1000000; i++)
            {
                var theScan = CurrentlySelectedSpectraFile.Value.GetOneBasedScanFromDynamicConnection(i);

                if (theScan.RetentionTime > scan.RetentionTime + rtWindowHalfWidth)
                {
                    break;
                }

                if (theScan.MsnOrder == 1)
                {
                    scans.Add(theScan);
                }
            }

            int z = species.DeconvolutionFeature.Charges[species.DeconvolutionFeature.Charges.Count / 2];

            for (int i = 0; i < 10; i++)
            {
                List <Datum> xicData = new List <Datum>();

                double    isotopeMass = species.DeconvolutionFeature.MonoisotopicMass + i * Constants.C13MinusC12;
                Tolerance t           = new PpmTolerance(5);

                foreach (var item in scans)
                {
                    int index = item.MassSpectrum.GetClosestPeakIndex(isotopeMass.ToMz(z));

                    if (t.Within(item.MassSpectrum.XArray[index], isotopeMass.ToMz(z)))
                    {
                        xicData.Add(new Datum(item.RetentionTime, item.MassSpectrum.YArray[index]));
                    }
                    else
                    {
                        xicData.Add(new Datum(item.RetentionTime, 0));
                    }
                }

                if (i == 0)
                {
                    XicPlot = new LinePlot(topPlotView, xicData);
                }
                else
                {
                    XicPlot.AddLinePlot(xicData);
                }
            }
        }
Пример #9
0
 private void PlotSpecies(AnnotatedSpecies species, MsDataScan scan)
 {
     PlotSpeciesIsotopeXics(species, scan);
     PlotSpeciesInSpectrum(species, scan);
 }
Пример #10
0
        private void PlotSpeciesInSpectrum(AnnotatedSpecies species, MsDataScan scan, int?charge = null)
        {
            // add non-annotated peaks
            List <Datum> spectrumData = new List <Datum>();

            for (int i = 0; i < scan.MassSpectrum.XArray.Length; i++)
            {
                spectrumData.Add(new Datum(scan.MassSpectrum.XArray[i], scan.MassSpectrum.YArray[i]));
            }

            SpectrumPlot = new SpectrumPlot(bottomPlotView, spectrumData);

            // add annotated peaks
            List <Datum> annotatedData = new List <Datum>();
            List <int>   chargesToPlot = new List <int>();

            if (species.DeconvolutionFeature != null)
            {
                double mass = species.DeconvolutionFeature.MonoisotopicMass;

                if (charge == null)
                {
                    chargesToPlot.AddRange(species.DeconvolutionFeature.Charges);
                }
                else
                {
                    chargesToPlot.Add(charge.Value);
                }

                foreach (var z in chargesToPlot)
                {
                    Tolerance t = new PpmTolerance(5);

                    bool peakHasBeenObserved = false;

                    for (int i = 0; i < 20; i++)
                    {
                        double isotopeMass = (mass + i * Constants.C13MinusC12).ToMz(z);
                        int    index       = scan.MassSpectrum.GetClosestPeakIndex(isotopeMass);
                        double expMz       = scan.MassSpectrum.XArray[index];

                        if (t.Within(expMz.ToMass(z), isotopeMass.ToMass(z)))
                        {
                            annotatedData.Add(new Datum(scan.MassSpectrum.XArray[index], scan.MassSpectrum.YArray[index]));
                            peakHasBeenObserved = true;
                        }
                        //else if (peakHasBeenObserved)
                        //{
                        //    break;
                        //}
                    }
                }
            }
            else if (species.Identification != null)
            {
                //TODO
            }

            SpectrumPlot.AddSpectrumPlot(annotatedData, OxyPlot.OxyColors.Blue, 2.0);
            ZoomAxes(annotatedData, SpectrumPlot);
        }