Ejemplo n.º 1
0
        public void Create(string directory, SpectralComparison comparerType, double percent)
        {
            var comparer = SpectralComparerFactory.CreateSpectraComparer(comparerType, percent);

            var spectra = new List <MSSpectra>();
            var files   = Directory.GetFiles(directory, "*.txt");

            foreach (var file in files)
            {
                spectra.Add(ReadSpectrum(file));
            }

            var values = new List <double>();

            for (var i = 0; i < spectra.Count; i++)
            {
                //for (int j = i + 1; j < spectra.Count; j++)
                {
                    //double value = comparer.CompareSpectra(spectra[i], spectra[j]);
                    //values.Add(value);

                    Console.WriteLine("{0}", Path.GetFileNameWithoutExtension(files[i]));

                    //                             Path.GetFileNameWithoutExtension(files[j]));
                    DisplaySpectra(spectra[i], .15, newTitle: "MS/MS Spectra - ");
                }
            }

            var baseName = Path.GetFileName(directory);
            // Console.WriteLine("{0} - {1}", baseName, values.Average());
            // values.ForEach(x => Console.WriteLine("\t{0}", x));
        }
Ejemplo n.º 2
0
        public void TestSpectralSimilarityScore(
            string pathX, int scanX,
            string pathY, int scanY,
            SpectralComparison comparerType,
            SpectraFilters filterType,
            double percent,
            double mzTolerance)
        {
            // Convert relative paths to absolute paths
            pathX = GetPath(pathX);
            pathY = GetPath(pathY);

            var spectrumX = GetSpectrum(pathX, scanX);
            var spectrumY = GetSpectrum(pathY, scanY);
            var comparer  = SpectralComparerFactory.CreateSpectraComparer(comparerType, percent);

            var filter = SpectrumFilterFactory.CreateFilter(filterType);

            spectrumX.Peaks = filter.Threshold(spectrumX.Peaks, percent);
            spectrumY.Peaks = filter.Threshold(spectrumY.Peaks, percent);

            spectrumX.Peaks = XYData.Bin(spectrumX.Peaks,
                                         0,
                                         2000,
                                         mzTolerance);

            spectrumY.Peaks = XYData.Bin(spectrumY.Peaks,
                                         0,
                                         2000,
                                         mzTolerance);

            var value = comparer.CompareSpectra(spectrumX, spectrumY);

            var path      = Path.GetDirectoryName(pathX);
            var plotTitle = string.Format("comparison-{2}-{3}-{0}-{1}_{4:0.000}", scanX, scanY, comparerType, percent,
                                          value);
            var pathCompareImage = Path.Combine(path, plotTitle + ".png");

            DisplayComparisonPlot(spectrumX, spectrumY, mzTolerance, pathCompareImage, plotTitle);
        }
Ejemplo n.º 3
0
        protected static SpectralAnalysis MatchDatasets(SpectralComparison comparerType,
                                                        ISpectraProvider readerX,
                                                        ISpectraProvider readerY,
                                                        SpectralOptions options,
                                                        AlignmentDataset datasetX,
                                                        AlignmentDataset datasetY,
                                                        List <string> names)
        {
            var peptideReader = PeptideReaderFactory.CreateReader(SequenceFileType.MSGF);
            var finder        = new SpectralAnchorPointFinder();
            var validator     = new SpectralAnchorPointValidator();
            var comparer      = SpectralComparerFactory.CreateSpectraComparer(comparerType);
            var filter        = SpectrumFilterFactory.CreateFilter(SpectraFilters.TopPercent);

            var matches = finder.FindAnchorPoints(readerX,
                                                  readerY,
                                                  comparer,
                                                  filter,
                                                  options);

            var peptidesX = peptideReader.Read(datasetX.PeptideFile);
            var peptidesY = peptideReader.Read(datasetY.PeptideFile);

            validator.ValidateMatches(matches,
                                      peptidesX,
                                      peptidesY,
                                      options);

            var analysis = new SpectralAnalysis
            {
                DatasetNames = names,
                Matches      = matches,
                Options      = options
            };

            return(analysis);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Gets the spectral matches
        /// </summary>
        /// <param name="baselineFeatures"></param>
        /// <param name="aligneeFeatures"></param>
        /// <returns></returns>
        private List <SpectralMatch> GetSpectralMatches(List <UMCLight> baselineFeatures,
                                                        List <UMCLight> aligneeFeatures,
                                                        double comparisonCutoff)
        {
            var matches         = new List <SpectralMatch>();
            var baselineSpectra = GetSpectra(baselineFeatures);
            var aligneeSpectra  = GetSpectra(aligneeFeatures);

            // Optimizes the loading of a spectra...
            var map      = new Dictionary <int, MSSpectra>();
            var filter   = SpectrumFilterFactory.CreateFilter(SpectraFilters.TopPercent);
            var comparer = SpectralComparerFactory.CreateSpectraComparer(SpectralComparison.CosineDotProduct);

            var    percent     = .2;
            var    mzTolerance = .5;
            double maxScanDiff = 1500;


            foreach (var baselineSpectrum in baselineSpectra)
            {
                baselineSpectrum.Peaks = filter.Threshold(baselineSpectrum.Peaks, percent);
                baselineSpectrum.Peaks = XYData.Bin(baselineSpectrum.Peaks, 0, 2000, mzTolerance);

                foreach (var aligneeSpectrum in aligneeSpectra)
                {
                    // Only consider spectra that are near each other in mass.
                    var diff = Math.Abs(baselineSpectrum.PrecursorMz - aligneeSpectrum.PrecursorMz);
                    if (diff >= mzTolerance)
                    {
                        continue;
                    }

                    // Only consider spectra that are within some range of another.
                    var scanDiff = Math.Abs(aligneeSpectrum.Scan - baselineSpectrum.Scan);
                    if (scanDiff > maxScanDiff)
                    {
                        continue;
                    }

                    // Bin and threshold the spectra
                    aligneeSpectrum.Peaks = filter.Threshold(aligneeSpectrum.Peaks, percent);
                    aligneeSpectrum.Peaks = XYData.Bin(aligneeSpectrum.Peaks, 0, 2000, mzTolerance);

                    // Compare the spectra
                    var value = comparer.CompareSpectra(baselineSpectrum, aligneeSpectrum);
                    if (double.IsNaN(value))
                    {
                        continue;
                    }

                    if (value > comparisonCutoff)
                    {
                        var match = new SpectralMatch();
                        match.Alignee    = aligneeSpectrum;
                        match.Baseline   = baselineSpectrum;
                        match.Similarity = value;
                        matches.Add(match);
                    }
                }
            }

            return(matches);
        }
Ejemplo n.º 5
0
 public SpectralAligner()
 {
     Options          = new SpectralOptions();
     Filter           = SpectrumFilterFactory.CreateFilter(SpectraFilters.TopPercent);
     SpectralComparer = SpectralComparerFactory.CreateSpectraComparer(SpectralComparison.CosineDotProduct);
 }