public void Write(SpectralAnalysis analysis) { Open(); WriteLine("[Test]"); WriteLine("[Datasets]"); foreach (var name in analysis.DatasetNames) { WriteLine(name); } WriteLine("[Histogram]"); var falseMatches = MatchCountHistogramBuilder.SimilarityScore(0, 1, .05, analysis.Matches.Where(x => x.IsValidMatch == AnchorPointMatchType.FalseMatch)); var trueMatches = MatchCountHistogramBuilder.SimilarityScore(0, 1, .05, analysis.Matches.Where(x => x.IsValidMatch == AnchorPointMatchType.TrueMatch)); var allMatches = MatchCountHistogramBuilder.SimilarityScore(0, 1, .05, analysis.Matches); WriteLine("Value\t False Matches\t True Matches\t All"); for (var i = 0; i < falseMatches.Bins.Count; i++) { var score = falseMatches.Bins[i]; WriteLine(string.Format("{0}\t{1}\t{2}\t{3}", score, falseMatches.Data[i], trueMatches.Data[i], allMatches.Data[i])); } // Determine how many matches we have WriteLine(); }
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); }
protected static void AlignMatches(SpectralAnalysis analysis, ISpectralAnalysisWriter writer) { var netXvalues = new List <double>(); var netYvalues = new List <double>(); var massXvalues = new List <double>(); var massYvalues = new List <double>(); var matches = analysis.Matches.OrderBy(x => x.AnchorPointX.Net); // 1. Find the best matches // 2. Find only matches that have been made once. var bestMatches = new Dictionary <int, SpectralAnchorPointMatch>(); foreach (var match in matches) { var scan = match.AnchorPointX.Scan; if (bestMatches.ContainsKey(scan)) { if (bestMatches[scan].SimilarityScore < match.SimilarityScore) { bestMatches[scan] = match; } } else { bestMatches.Add(scan, match); } } // 2. Find only those matched once var all = new Dictionary <int, SpectralAnchorPointMatch>(); foreach (var match in bestMatches.Values) { var scan = match.AnchorPointY.Scan; if (all.ContainsKey(scan)) { if (all[scan].SimilarityScore < match.SimilarityScore) { all[scan] = match; } } else { all.Add(scan, match); } } // Write the analysis writer.Write(analysis); // Then generate the NET Alignment using R1 var anchorPoints = all.Values.OrderBy(x => x.AnchorPointX.Net).ToList(); foreach (var match in anchorPoints) { netXvalues.Add(match.AnchorPointX.Net); netYvalues.Add(match.AnchorPointY.Net); } Func <double, double, double> netFunc = (x, y) => x - y; Func <double, double, double> massFunc = FeatureLight.ComputeMassPPMDifference; InterpolateDimension("NET-R1", writer, netXvalues, netYvalues, anchorPoints, netFunc); // Then generate the Mass Alignment using R1 // We also have to resort the matches based on mass now too anchorPoints = all.Values.OrderBy(x => x.AnchorPointX.Mz).ToList(); foreach (var match in anchorPoints) { massXvalues.Add(match.AnchorPointX.Mz); massYvalues.Add(match.AnchorPointY.Mz); } InterpolateDimension("Mass-R1", writer, massXvalues, massYvalues, anchorPoints, massFunc); }
/// <summary> /// Serializes the data provided. /// </summary> /// <param name="analysis"></param> public void Write(SpectralAnalysis analysis) { WriteLine(string.Format("NET,{0}", analysis.Options.NetTolerance)); WriteLine(string.Format("Mass,{0}", analysis.Options.MzTolerance)); }
protected static void AlignMatches(SpectralAnalysis analysis, ISpectralAnalysisWriter writer) { var netXvalues = new List<double>(); var netYvalues = new List<double>(); var massXvalues = new List<double>(); var massYvalues = new List<double>(); var matches = analysis.Matches.OrderBy(x => x.AnchorPointX.Net); // 1. Find the best matches // 2. Find only matches that have been made once. var bestMatches = new Dictionary<int, SpectralAnchorPointMatch>(); foreach (var match in matches) { var scan = match.AnchorPointX.Scan; if (bestMatches.ContainsKey(scan)) { if (bestMatches[scan].SimilarityScore < match.SimilarityScore) { bestMatches[scan] = match; } } else { bestMatches.Add(scan, match); } } // 2. Find only those matched once var all = new Dictionary<int, SpectralAnchorPointMatch>(); foreach (var match in bestMatches.Values) { var scan = match.AnchorPointY.Scan; if (all.ContainsKey(scan)) { if (all[scan].SimilarityScore < match.SimilarityScore) { all[scan] = match; } } else { all.Add(scan, match); } } // Write the analysis writer.Write(analysis); // Then generate the NET Alignment using R1 var anchorPoints = all.Values.OrderBy(x => x.AnchorPointX.Net).ToList(); foreach (var match in anchorPoints) { netXvalues.Add(match.AnchorPointX.Net); netYvalues.Add(match.AnchorPointY.Net); } Func<double, double, double> netFunc = (x, y) => x - y; Func<double, double, double> massFunc = FeatureLight.ComputeMassPPMDifference; InterpolateDimension("NET-R1", writer, netXvalues, netYvalues, anchorPoints, netFunc); // Then generate the Mass Alignment using R1 // We also have to resort the matches based on mass now too anchorPoints = all.Values.OrderBy(x => x.AnchorPointX.Mz).ToList(); foreach (var match in anchorPoints) { massXvalues.Add(match.AnchorPointX.Mz); massYvalues.Add(match.AnchorPointY.Mz); } InterpolateDimension("Mass-R1", writer, massXvalues, massYvalues, anchorPoints, massFunc); }
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 Write(SpectralAnalysis analysis) { Open(); WriteLine("[Test]"); WriteLine("[Datasets]"); foreach (var name in analysis.DatasetNames) { WriteLine(name); } WriteLine("[Histogram]"); var falseMatches = MatchCountHistogramBuilder.SimilarityScore(0, 1, .05, analysis.Matches.Where(x => x.IsValidMatch == AnchorPointMatchType.FalseMatch)); var trueMatches = MatchCountHistogramBuilder.SimilarityScore(0, 1, .05, analysis.Matches.Where(x => x.IsValidMatch == AnchorPointMatchType.TrueMatch)); var allMatches = MatchCountHistogramBuilder.SimilarityScore(0, 1, .05, analysis.Matches); WriteLine("Value\t False Matches\t True Matches"); for (var i = 0; i < falseMatches.Bins.Count; i++) { var score = falseMatches.Bins[i]; WriteLine(string.Format("{0}\t{1}\t{2}\t{3}", score, falseMatches.Data[i], trueMatches.Data[i], allMatches.Data[i])); } // Determine how many matches we have WriteLine("[Matches]"); var datasetX = new Dictionary <int, List <SpectralAnchorPoint> >(); // Here we tally the number of matches foreach (var match in analysis.Matches) { var scanX = match.AnchorPointX.Scan; if (!datasetX.ContainsKey(scanX)) { datasetX.Add(scanX, new List <SpectralAnchorPoint>()); } // making sure to attribute true positive matches match.AnchorPointX.IsTrue = match.IsValidMatch == AnchorPointMatchType.TrueMatch; datasetX[scanX].Add(match.AnchorPointX); } var maxMatch = 0; var matchCount = new Dictionary <int, int>(); var multipleTrue = new Dictionary <int, int>(); foreach (var points in datasetX.Values) { // Then we go through the list... // count the number of true matches var total = points.Count; var totalTrue = points.Count(x => x.IsTrue); // first time to see this match total...then make a new list maxMatch = Math.Max(maxMatch, total); if (!matchCount.ContainsKey(total)) { matchCount.Add(total, 0); } // if we have more than one entry for this spectrum // and we have more than one true positive...lets add him up if (total >= 1 && totalTrue > 0) { if (!multipleTrue.ContainsKey(totalTrue)) { multipleTrue.Add(totalTrue, 0); } multipleTrue[totalTrue]++; } matchCount[total]++; } WriteLine("Num Matches\tTotal\tTotal True"); for (var i = 1; i < maxMatch; i++) { var totalTrue = 0; var total = 0; if (multipleTrue.ContainsKey(i)) { totalTrue = multipleTrue[i]; } if (matchCount.ContainsKey(i)) { total = matchCount[i]; } WriteLine(string.Format("{0}\t{1}\t{2}", i, total, totalTrue)); } WriteLine(); Close(); }
public void Write(SpectralAnalysis analysis) { Open(); WriteLine("[Test]"); WriteLine("[Datasets]"); foreach (var name in analysis.DatasetNames) { WriteLine(name); } WriteLine("[Histogram]"); var falseMatches = MatchCountHistogramBuilder.SimilarityScore(0, 1, .05, analysis.Matches.Where(x => x.IsValidMatch == AnchorPointMatchType.FalseMatch)); var trueMatches = MatchCountHistogramBuilder.SimilarityScore(0, 1, .05, analysis.Matches.Where(x => x.IsValidMatch == AnchorPointMatchType.TrueMatch)); var allMatches = MatchCountHistogramBuilder.SimilarityScore(0, 1, .05, analysis.Matches); WriteLine("Value\t False Matches\t True Matches"); for (var i = 0; i < falseMatches.Bins.Count; i++) { var score = falseMatches.Bins[i]; WriteLine(string.Format("{0}\t{1}\t{2}\t{3}", score, falseMatches.Data[i], trueMatches.Data[i], allMatches.Data[i])); } // Determine how many matches we have WriteLine("[Matches]"); var datasetX = new Dictionary<int, List<SpectralAnchorPoint>>(); // Here we tally the number of matches foreach (var match in analysis.Matches) { var scanX = match.AnchorPointX.Scan; if (!datasetX.ContainsKey(scanX)) datasetX.Add(scanX, new List<SpectralAnchorPoint>()); // making sure to attribute true positive matches match.AnchorPointX.IsTrue = match.IsValidMatch == AnchorPointMatchType.TrueMatch; datasetX[scanX].Add(match.AnchorPointX); } var maxMatch = 0; var matchCount = new Dictionary<int, int>(); var multipleTrue = new Dictionary<int, int>(); foreach (var points in datasetX.Values) { // Then we go through the list... // count the number of true matches var total = points.Count; var totalTrue = points.Count(x => x.IsTrue); // first time to see this match total...then make a new list maxMatch = Math.Max(maxMatch, total); if (!matchCount.ContainsKey(total)) matchCount.Add(total, 0); // if we have more than one entry for this spectrum // and we have more than one true positive...lets add him up if (total >= 1 && totalTrue > 0) { if (!multipleTrue.ContainsKey(totalTrue)) multipleTrue.Add(totalTrue, 0); multipleTrue[totalTrue]++; } matchCount[total]++; } WriteLine("Num Matches\tTotal\tTotal True"); for (var i = 1; i < maxMatch; i++) { var totalTrue = 0; var total = 0; if (multipleTrue.ContainsKey(i)) totalTrue = multipleTrue[i]; if (matchCount.ContainsKey(i)) total = matchCount[i]; WriteLine(string.Format("{0}\t{1}\t{2}", i, total, totalTrue)); } WriteLine(); Close(); }