/// <summary> /// Creates a spectral comparer based on the comparison type. /// </summary> /// <param name="comparisonType"></param> /// <returns></returns> public static ISpectralComparer CreateSpectraComparer(SpectralComparison comparisonType, double percent = .4) { ISpectralComparer comparer = null; switch (comparisonType) { case SpectralComparison.DotProduct: comparer = new SpectralDotProductComprarer(percent); break; case SpectralComparison.NormalizedDotProduct: comparer = new SpectralNormalizedDotProductComparer(percent); break; case SpectralComparison.BinaryDotProduct: comparer = new BinaryDotProduct(percent); break; case SpectralComparison.CosineDotProduct: comparer = new SpectralCosineComparer(); break; case SpectralComparison.PeakCounts: comparer = new SpectralPeakCountComparer(); break; case SpectralComparison.SteinDotProduct: comparer = new SteinDotProduct(); break; default: break; } return(comparer); }
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)); }
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)); }
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); }
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); }
public void GenerateFigure4_MetaMatches(string directory, SpectralComparison comparerType, double mzBinSize, double mzTolerance, double netTolerance, double similarityScoreCutoff, double peptideScore, double peptideFdr, double ionPercent, int numberOfRequiredPeaks, string name) { AlignmentAnalysisWriterFactory.BasePath = @"M:\doc\papers\paperAlignment\Data\figure4"; Console.WriteLine(@"Post-Pre Tests For {0}", directory); var cacheFiles = Directory.GetFiles(directory, "*.mscache"); Console.WriteLine(@"Building data cache"); var data = cacheFiles.Select(path => new FigureBase.PathCache { Cache = path }).ToList(); // The options for the analysis var options = new SpectralOptions { MzBinSize = mzBinSize, MzTolerance = mzTolerance, NetTolerance = netTolerance, SimilarityCutoff = similarityScoreCutoff, TopIonPercent = ionPercent, IdScore = peptideScore, ComparerType = comparerType, Fdr = peptideFdr, RequiredPeakCount = numberOfRequiredPeaks }; var comparison = 0; for (var i = 0; i < data.Count; i++) { var cachex = data[i]; // Get the raw path stored in the cache file... // then get the dataset object var rawPathX = ScanSummaryCache.ReadPath(cachex.Cache); var datasetX = new AlignmentDataset(rawPathX, "", cachex.Msgf); // create a raw file reader for the datasets using (var readerX = new InformedProteomicsReader()) { // wrap it in the cached object so we can load scan meta-data var cacheReaderX = new RawLoaderCache(readerX); var cacheDataX = ScanSummaryCache.ReadCache(cachex.Cache); readerX.AddDataFile(rawPathX, 0); cacheReaderX.AddCache(0, cacheDataX); for (var j = i + 1; j < data.Count; j++) { var cachey = data[j]; // Get the raw path stored in the cache file... // then get the dataset object var rawPathY = ScanSummaryCache.ReadPath(cachey.Cache); var datasetY = new AlignmentDataset(rawPathY, "", cachey.Msgf); // create a raw file reader for the datasets using (var readerY = new InformedProteomicsReader()) { // Then the writer for creating a report var writer = AlignmentAnalysisWriterFactory.Create(AlignmentFigureType.Figure3, name + comparison); comparison++; // wrap it in the cached object so we can load scan meta-data var cacheReaderY = new RawLoaderCache(readerY); var cacheDataY = ScanSummaryCache.ReadCache(cachey.Cache); cacheReaderY.AddCache(0, cacheDataY); readerY.AddDataFile(rawPathY, 0); var names = new List <string> { data[i].Cache, data[j].Cache }; var analysis = MatchDatasets(comparerType, readerX, readerY, options, datasetX, datasetY, names); AlignMatches(analysis, writer); writer.Close(); } } } } }
public void GenerateFigure3_Matches(string directory, SpectralComparison comparerType, double mzBinSize, double mzTolerance, double netTolerance, double similarityScoreCutoff, double peptideScore, double peptideFdr, double ionPercent, int numberOfRequiredPeaks) { AlignmentAnalysisWriterFactory.BasePath = @"M:\doc\papers\paperAlignment\Data\figure4"; Console.WriteLine(@"Post-Pre Tests For {0}", directory); var cacheFiles = Directory.GetFiles(directory, "*.mscache"); var msgfFiles = Directory.GetFiles(directory, "*_msgfdb_fht.txt"); Console.WriteLine(@"Building data cache"); var map = cacheFiles.ToDictionary<string, string, FigureBase.PathCache>(path => path.ToLower(), path => null); var data = (from path in msgfFiles let name = path.ToLower().Replace("_msgfdb_fht.txt", ".mscache") let newName = Path.Combine(directory, name) let features = Path.Combine(directory, name) where map.ContainsKey(newName) select new FigureBase.PathCache { Cache = newName, Msgf = path, Features = features }).ToList(); // The options for the analysis var options = new SpectralOptions { MzBinSize = mzBinSize, MzTolerance = mzTolerance, NetTolerance = netTolerance, SimilarityCutoff = similarityScoreCutoff, TopIonPercent = ionPercent, IdScore = peptideScore, ComparerType = comparerType, Fdr = peptideFdr, RequiredPeakCount = numberOfRequiredPeaks }; Console.WriteLine(@"{0}", data.Count); var comparison = 0; for (var i = 0; i < data.Count; i++) { var cachex = data[i]; // Get the raw path stored in the cache file... // then get the dataset object var rawPathX = ScanSummaryCache.ReadPath(cachex.Cache); var datasetX = new AlignmentDataset(rawPathX, "", cachex.Msgf); // create a raw file reader for the datasets using (var readerX = RawLoaderFactory.CreateFileReader(datasetX.RawFile)) { // wrap it in the cached object so we can load scan meta-data var cacheReaderX = new RawLoaderCache(readerX); var cacheDataX = ScanSummaryCache.ReadCache(cachex.Cache); readerX.AddDataFile(rawPathX, 0); cacheReaderX.AddCache(0, cacheDataX); for (var j = i + 1; j < data.Count; j++) { // Then the writer for creating a report var writer = AlignmentAnalysisWriterFactory.Create(AlignmentFigureType.Figure3, "results-figure3-largeScale" + comparison); comparison++; var cachey = data[j]; // Get the raw path stored in the cache file... // then get the dataset object var rawPathY = ScanSummaryCache.ReadPath(cachey.Cache); var datasetY = new AlignmentDataset(rawPathY, "", cachey.Msgf); // create a raw file reader for the datasets using (var readerY = RawLoaderFactory.CreateFileReader(datasetY.RawFile)) { // wrap it in the cached object so we can load scan meta-data var cacheReaderY = new RawLoaderCache(readerY); var cacheDataY = ScanSummaryCache.ReadCache(cachey.Cache); cacheReaderY.AddCache(0, cacheDataY); readerY.AddDataFile(rawPathY, 0); var names = new List<string> { data[i].Cache, data[j].Cache }; // Write the results var analysis = MatchDatasets(comparerType, cacheReaderX, cacheReaderY, options, datasetX, datasetY, names); AlignMatches(analysis, writer); } } } } }
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; }
public void GenerateFigure3_Matches(string directory, SpectralComparison comparerType, double mzBinSize, double mzTolerance, double netTolerance, double similarityScoreCutoff, double peptideScore, double peptideFdr, double ionPercent, int numberOfRequiredPeaks) { AlignmentAnalysisWriterFactory.BasePath = @"M:\doc\papers\paperAlignment\Data\figure4"; Console.WriteLine(@"Post-Pre Tests For {0}", directory); var cacheFiles = Directory.GetFiles(directory, "*.mscache"); var msgfFiles = Directory.GetFiles(directory, "*_msgfdb_fht.txt"); Console.WriteLine(@"Building data cache"); var map = cacheFiles.ToDictionary <string, string, FigureBase.PathCache>(path => path.ToLower(), path => null); var data = (from path in msgfFiles let name = path.ToLower().Replace("_msgfdb_fht.txt", ".mscache") let newName = Path.Combine(directory, name) let features = Path.Combine(directory, name) where map.ContainsKey(newName) select new FigureBase.PathCache { Cache = newName, Msgf = path, Features = features }).ToList(); // The options for the analysis var options = new SpectralOptions { MzBinSize = mzBinSize, MzTolerance = mzTolerance, NetTolerance = netTolerance, SimilarityCutoff = similarityScoreCutoff, TopIonPercent = ionPercent, IdScore = peptideScore, ComparerType = comparerType, Fdr = peptideFdr, RequiredPeakCount = numberOfRequiredPeaks }; Console.WriteLine(@"{0}", data.Count); var comparison = 0; for (var i = 0; i < data.Count; i++) { var cachex = data[i]; // Get the raw path stored in the cache file... // then get the dataset object var rawPathX = ScanSummaryCache.ReadPath(cachex.Cache); var datasetX = new AlignmentDataset(rawPathX, "", cachex.Msgf); // create a raw file reader for the datasets using (var readerX = new InformedProteomicsReader()) { // wrap it in the cached object so we can load scan meta-data var cacheReaderX = new RawLoaderCache(readerX); var cacheDataX = ScanSummaryCache.ReadCache(cachex.Cache); readerX.AddDataFile(rawPathX, 0); cacheReaderX.AddCache(0, cacheDataX); for (var j = i + 1; j < data.Count; j++) { // Then the writer for creating a report var writer = AlignmentAnalysisWriterFactory.Create(AlignmentFigureType.Figure3, "results-figure3-largeScale" + comparison); comparison++; var cachey = data[j]; // Get the raw path stored in the cache file... // then get the dataset object var rawPathY = ScanSummaryCache.ReadPath(cachey.Cache); var datasetY = new AlignmentDataset(rawPathY, "", cachey.Msgf); // create a raw file reader for the datasets using (var readerY = new InformedProteomicsReader()) { // wrap it in the cached object so we can load scan meta-data var cacheReaderY = new RawLoaderCache(readerY); var cacheDataY = ScanSummaryCache.ReadCache(cachey.Cache); cacheReaderY.AddCache(0, cacheDataY); readerY.AddDataFile(rawPathY, 0); var names = new List <string> { data[i].Cache, data[j].Cache }; // Write the results var analysis = MatchDatasets(comparerType, cacheReaderX, cacheReaderY, options, datasetX, datasetY, names); AlignMatches(analysis, writer); } } } } }
public void GenerateFigure4_MetaMatches(string directory, SpectralComparison comparerType, double mzBinSize, double mzTolerance, double netTolerance, double similarityScoreCutoff, double peptideScore, double peptideFdr, double ionPercent, int numberOfRequiredPeaks, string name) { AlignmentAnalysisWriterFactory.BasePath = @"M:\doc\papers\paperAlignment\Data\figure4"; Console.WriteLine(@"Post-Pre Tests For {0}", directory); var cacheFiles = Directory.GetFiles(directory, "*.mscache"); Console.WriteLine(@"Building data cache"); var data = cacheFiles.Select(path => new FigureBase.PathCache { Cache = path }).ToList(); // The options for the analysis var options = new SpectralOptions { MzBinSize = mzBinSize, MzTolerance = mzTolerance, NetTolerance = netTolerance, SimilarityCutoff = similarityScoreCutoff, TopIonPercent = ionPercent, IdScore = peptideScore, ComparerType = comparerType, Fdr = peptideFdr, RequiredPeakCount = numberOfRequiredPeaks }; var comparison = 0; for (var i = 0; i < data.Count; i++) { var cachex = data[i]; // Get the raw path stored in the cache file... // then get the dataset object var rawPathX = ScanSummaryCache.ReadPath(cachex.Cache); var datasetX = new AlignmentDataset(rawPathX, "", cachex.Msgf); // create a raw file reader for the datasets using (var readerX = RawLoaderFactory.CreateFileReader(datasetX.RawFile)) { // wrap it in the cached object so we can load scan meta-data var cacheReaderX = new RawLoaderCache(readerX); var cacheDataX = ScanSummaryCache.ReadCache(cachex.Cache); readerX.AddDataFile(rawPathX, 0); cacheReaderX.AddCache(0, cacheDataX); for (var j = i + 1; j < data.Count; j++) { var cachey = data[j]; // Get the raw path stored in the cache file... // then get the dataset object var rawPathY = ScanSummaryCache.ReadPath(cachey.Cache); var datasetY = new AlignmentDataset(rawPathY, "", cachey.Msgf); // create a raw file reader for the datasets using (var readerY = RawLoaderFactory.CreateFileReader(datasetY.RawFile)) { // Then the writer for creating a report var writer = AlignmentAnalysisWriterFactory.Create(AlignmentFigureType.Figure3, name + comparison); comparison++; // wrap it in the cached object so we can load scan meta-data var cacheReaderY = new RawLoaderCache(readerY); var cacheDataY = ScanSummaryCache.ReadCache(cachey.Cache); cacheReaderY.AddCache(0, cacheDataY); readerY.AddDataFile(rawPathY, 0); var names = new List<string> { data[i].Cache, data[j].Cache }; var analysis = MatchDatasets(comparerType, readerX, readerY, options, datasetX, datasetY, names); AlignMatches(analysis, writer); writer.Close(); } } } } }