/// <summary> /// Creates the final analysis plots. /// </summary> public void CreateChargePlots(Dictionary <int, int> chargeMap) { Logger.PrintMessage("Creating Charge State Plots"); var report = Config.Report; report.PushTextHeader("Cluster Charge States"); report.PushStartTable(); var path = Path.Combine(Config.AnalysisPath, PlotPath, "clusters_chargestates.png"); var histogram = HistogramFactory.CreateHistogram(chargeMap, "Charge States", "Charge States"); PlotImageUtility.SaveImage(histogram, path); report.PushImageColumn(path); report.PushEndTable(); }
public void CreateMassTagPlot(MassTagsLoadedEventArgs e) { Logger.PrintMessage("Creating Mass Tag Plot."); if (e.Database == null) { return; } if (e.MassTags == null) { return; } var feature = ScatterPlotFactory.CreateFeatureMassScatterPlot(e.MassTags); var name = e.Database.Name; var directory = Path.Combine(Config.AnalysisPath, name); PlotImageUtility.SaveImage(feature, directory + "_mtdb.png"); }
public void CreateClusterPlots(FeaturesClusteredEventArgs args) { // Plots: // Dataset member // Total members // Cluster scatter plot var clusters = args.Clusters; var report = Config.Report; Logger.PrintMessage("Creating Charge State Plots"); report.PushStartTable(); report.PushStartTableRow(); report.PushTextHeader("Cluster Statistics"); report.PushEndTableRow(); report.PushStartTableRow(); var path = Path.Combine(Config.AnalysisPath, PlotPath, "clusters_scatterplot.png"); var clusterScatterPlot = ScatterPlotFactory.CreateClusterMassScatterPlot(clusters); PlotImageUtility.SaveImage(clusterScatterPlot, path); report.PushImageColumn(path, WIDTH, HEIGHT); report.PushEndTableRow(); report.PushStartTableRow(); path = Path.Combine(Config.AnalysisPath, PlotPath, "clusters_datasetMembersHistogram.png"); var datasetMemberHistogram = HistogramFactory.CreateHistogram(clusters.CreateClusterDatasetMemberSizeHistogram(), "Dataset Members", "Dataset Count"); PlotImageUtility.SaveImage(datasetMemberHistogram, path); report.PushImageColumn(path, WIDTH, HEIGHT); path = Path.Combine(Config.AnalysisPath, PlotPath, "clusters_clusterSizeHistogram.png"); var clusterSizeHistogram = HistogramFactory.CreateHistogram(clusters.CreateClusterSizeHistogram(), "Cluster Members", "Cluster Size"); PlotImageUtility.SaveImage(clusterSizeHistogram, path); report.PushImageColumn(path, WIDTH, HEIGHT); report.PushEndTableRow(); report.PushEndTable(); }
/// <summary> /// Creates images for the HTML output for baseline data /// </summary> /// <param name="e"></param> public void CreateBaselinePlots(BaselineFeaturesLoadedEventArgs e) { var baselineInfo = e.DatasetInformation; if (baselineInfo == null) { return; } var feature = ScatterPlotFactory.CreateFeatureMassScatterPlot(e.Features); var name = e.DatasetInformation.DatasetName; var directory = Path.Combine(Config.AnalysisPath, PlotPath, name); var report = Config.Report; report.PushTextHeader("Baseline Features"); report.PushStartTableRow(); Config.Report.PushImageColumn(directory + "_features.png", WIDTH, HEIGHT); PlotImageUtility.SaveImage(feature, directory + "_features.png"); report.PushEndTableRow(); }
public void TestMsFeatureScatterPlot(string path1, string path2, string pngPath) { // Convert relative paths to absolute paths path1 = GetPath(path1); path2 = GetPath(path2); pngPath = GetPath(pngPath); var fiOutput = new FileInfo(pngPath); var didirectory = fiOutput.Directory; if (didirectory == null) { throw new DirectoryNotFoundException(pngPath); } if (!didirectory.Exists) { didirectory.Create(); } var aligner = new LcmsWarpFeatureAligner(new LcmsWarpAlignmentOptions()); var isosFilterOptions = new DeconToolsIsosFilterOptions(); var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1, isosFilterOptions); var aligneeMs = UmcLoaderFactory.LoadMsFeatureData(path2, isosFilterOptions); var finder = FeatureFinderFactory.CreateFeatureFinder(FeatureFinderType.TreeBased); var tolerances = new FeatureTolerances { FragmentationWindowSize = .5, Mass = 13, DriftTime = .3, Net = .01 }; var options = new LcmsFeatureFindingOptions(tolerances); options.MaximumNetRange = .002; var baseline = finder.FindFeatures(baselineMs, options, null); var alignee = finder.FindFeatures(aligneeMs, options, null); var alignmentResults = aligner.Align(baseline, alignee); var plotModel1 = new PlotModel { Subtitle = "Interpolated, cartesian axes", Title = "HeatMapSeries" }; var palette = OxyPalettes.Hot(200); var linearColorAxis1 = new LinearColorAxis { InvalidNumberColor = OxyColors.Gray, Position = AxisPosition.Right, Palette = palette }; plotModel1.Axes.Add(linearColorAxis1); // linearColorAxis1. var linearAxis1 = new LinearAxis { Position = AxisPosition.Bottom }; plotModel1.Axes.Add(linearAxis1); var linearAxis2 = new LinearAxis(); plotModel1.Axes.Add(linearAxis2); var heatMapSeries1 = new HeatMapSeries { X0 = 0, X1 = 1, Y0 = 0, Y1 = 1, FontSize = .2 }; var scores = alignmentResults.HeatScores; var width = scores.GetLength(0); var height = scores.GetLength(1); heatMapSeries1.Data = new double[width, height]; var seriesData = heatMapSeries1.Data; for (var i = 0; i < width; i++) { for (var j = 0; j < height; j++) { seriesData[i, j] = Convert.ToDouble(scores[i, j]); } } plotModel1.Series.Add(heatMapSeries1); var svg = new SvgExporter(); var svgString = svg.ExportToString(plotModel1); var xml = new XmlDocument(); xml.LoadXml(svgString); var x = SvgDocument.Open(xml); // Svg.SvgDocument(); var bmp = x.Draw(); bmp.Save(pngPath); var heatmap = HeatmapFactory.CreateAlignedHeatmap(alignmentResults.HeatScores, false); var netHistogram = HistogramFactory.CreateHistogram(alignmentResults.NetErrorHistogram, "NET Error", "NET Error"); var massHistogram = HistogramFactory.CreateHistogram(alignmentResults.MassErrorHistogram, "Mass Error", "Mass Error (ppm)"); var baseName = Path.Combine(didirectory.FullName, Path.GetFileNameWithoutExtension(fiOutput.Name)); var encoder = new SvgEncoder(); PlotImageUtility.SaveImage(heatmap, baseName + "_heatmap.svg", encoder); PlotImageUtility.SaveImage(netHistogram, baseName + "_netHistogram.svg", encoder); PlotImageUtility.SaveImage(massHistogram, baseName + "_massHistogram.svg", encoder); }
/// <summary> /// Creates alignment plots for the HTML output. /// </summary> public void CreateAlignmentPlots(FeaturesAlignedEventArgs e) { var name = e.AligneeDatasetInformation.DatasetName; var alignmentData = e.AlignmentData; if (alignmentData == null) { return; } var directory = Path.Combine(Config.AnalysisPath, PlotPath, name); var heatmap = HeatmapFactory.CreateAlignedHeatmap(alignmentData.HeatScores, alignmentData.BaselineIsAmtDB); var feature = ScatterPlotFactory.CreateFeatureMassScatterPlot(e.AligneeFeatures); var netHistogram = HistogramFactory.CreateHistogram(alignmentData.NetErrorHistogram, "NET Error", "NET Error"); var massHistogram = HistogramFactory.CreateHistogram(alignmentData.MassErrorHistogram, "Mass Error", "Mass Error (ppm)"); var residuals = alignmentData.ResidualData; var netResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Net, residuals.LinearCustomNet, residuals.LinearNet, "NET Residuals", "Scans", "NET"); var massMzResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Mz, residuals.MzMassError, residuals.MzMassErrorCorrected, "Mass Residuals", "m/z", "Mass Errors"); var massScanResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Net, residuals.MzMassError, residuals.MzMassErrorCorrected, "Mass Residuals", "Scan", "Mass Errors"); var report = Config.Report; report.PushLargeText(string.Format("Alignee Statistics - {0}", name)); report.PushStartTable(); // Features report.PushStartTableRow(); report.PushTextHeader("Features"); report.PushEndTableRow(); report.PushStartTableRow(); Config.Report.PushImageColumn(directory + "_features.png", WIDTH, HEIGHT); Config.Report.PushImageColumn(directory + "_heatmap.png", WIDTH, HEIGHT); PlotImageUtility.SaveImage(feature, directory + "_features.png"); PlotImageUtility.SaveImage(heatmap, directory + "_heatmap.png"); report.PushEndTableRow(); // Histograms report.PushStartTableRow(); report.PushTextHeader("Histograms"); report.PushEndTableRow(); report.PushStartTableRow(); Config.Report.PushImageColumn(directory + "_netHistogram.png"); Config.Report.PushImageColumn(directory + "_massHistogram.png"); PlotImageUtility.SaveImage(netHistogram, directory + "_netHistogram.png"); PlotImageUtility.SaveImage(massHistogram, directory + "_massHistogram.png"); report.PushEndTableRow(); // Residuals report.PushStartTableRow(); report.PushTextHeader("Histograms"); report.PushEndTableRow(); report.PushStartTableRow(); Config.Report.PushImageColumn(directory + "_netResidual.png"); Config.Report.PushImageColumn(directory + "_massMzResidual.png"); Config.Report.PushImageColumn(directory + "_massScanResidual.png"); PlotImageUtility.SaveImage(netResidual, directory + "_netResidual.png"); PlotImageUtility.SaveImage(massMzResidual, directory + "_massMzResidual.png"); PlotImageUtility.SaveImage(massScanResidual, directory + "_massScanResidual.png"); report.PushEndTableRow(); report.PushEndTable(); }
private static void TestNow(string relativeBaselinePath, string relativeAligneePath, string relativeOutput, string name) { string baselinePath = GetPath(relativeBaselinePath); var aligneePath = GetPath(relativeAligneePath); var aligner = new LcmsWarpFeatureAligner(); var rawBaselineData = File.ReadAllLines(baselinePath); var rawFeaturesData = File.ReadAllLines(aligneePath); var outputPath = GetOutputPath(relativeOutput); var delimiter = new[] { TextDelimiter }; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } var baseline = (from line in rawBaselineData where line != "" select line.Split(delimiter, StringSplitOptions.RemoveEmptyEntries) into parsed select new UMCLight { Net = Convert.ToDouble(parsed[0]), ChargeState = Convert.ToInt32(parsed[1]), Mz = Convert.ToDouble(parsed[2]), Scan = Convert.ToInt32(parsed[3]), MassMonoisotopic = Convert.ToDouble(parsed[4]), MassMonoisotopicAligned = Convert.ToDouble(parsed[5]), Id = Convert.ToInt32(parsed[6]), ScanStart = Convert.ToInt32(parsed[7]), ScanEnd = Convert.ToInt32(parsed[8]), ScanAligned = Convert.ToInt32(parsed[9]) }).ToList(); var features = (from line in rawFeaturesData where line != "" select line.Split(delimiter, StringSplitOptions.RemoveEmptyEntries) into parsed select new UMCLight { Net = Convert.ToDouble(parsed[0]), ChargeState = Convert.ToInt32(parsed[1]), Mz = Convert.ToDouble(parsed[2]), Scan = Convert.ToInt32(parsed[3]), MassMonoisotopic = Convert.ToDouble(parsed[4]), MassMonoisotopicAligned = Convert.ToDouble(parsed[5]), Id = Convert.ToInt32(parsed[6]), ScanStart = Convert.ToInt32(parsed[7]), ScanEnd = Convert.ToInt32(parsed[8]), ScanAligned = Convert.ToInt32(parsed[9]) }).ToList(); var maxd = features.Max(x => x.Net); var mind = features.Min(x => x.Net); if (maxd - mind < double.Epsilon) { throw new Exception("There is something wrong with the features NET values"); } aligner.Options.AlignType = AlignmentType.NET_MASS_WARP; var outputData = aligner.Align(baseline, features); var residuals = outputData.ResidualData; using (var writer = new StreamWriter(@"E:\MultiAlignTest\Results\heat-scores-old.txt")) { foreach (var oovarscore in outputData.heatScores) { writer.WriteLine(oovarscore); } } var heatmap = HeatmapFactory.CreateAlignedHeatmap(outputData.heatScores); var netHistogram = HistogramFactory.CreateHistogram(outputData.netErrorHistogram, "NET Error Histogram", "NET Error"); var massHistogram = HistogramFactory.CreateHistogram(outputData.massErrorHistogram, "Mass Error Histogram", "Mass Error (ppm)"); var netResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Scan, residuals.LinearCustomNet, residuals.LinearNet, "NET Residuals", "Scans", "NET"); var massMzResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Mz, residuals.MzMassError, residuals.MzMassErrorCorrected, "Mass Residuals", "m/z", "Mass Errors"); var massScanResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Scan, residuals.MzMassError, residuals.MzMassErrorCorrected, "Mass Residuals", "Scan", "Mass Errors"); var directory = Path.Combine(outputPath, name); var encoder = new SvgEncoder(); PlotImageUtility.SaveImage(heatmap, directory + "_heatmap.svg", encoder); PlotImageUtility.SaveImage(netResidual, directory + "_netResidual.svg", encoder); PlotImageUtility.SaveImage(massMzResidual, directory + "_massMzResidual.svg", encoder); PlotImageUtility.SaveImage(massScanResidual, directory + "_massScanResidual.svg", encoder); //PlotImageUtility.SaveImage(netHistogram, directory + "_netHistogram.svg", encoder); PlotImageUtility.SaveImage(massHistogram, directory + "_massHistogram.svg", encoder); }
public void TestLcmsWarpPort(string relativeBaselinePath, string relativeAligneePath, string relativeOutput, string name) { var baselinePath = GetPath(relativeBaselinePath); var aligneePath = GetPath(relativeAligneePath); var options = new LcmsWarpAlignmentOptions { AlignType = LcmsWarpAlignmentType.NET_MASS_WARP, CalibrationType = LcmsWarpCalibrationType.Both }; var aligner = new LcmsWarpFeatureAligner(options); var rawBaselineData = File.ReadAllLines(baselinePath); var rawFeaturesData = File.ReadAllLines(aligneePath); var outputPath = GetOutputPath(relativeOutput); var delimiter = new[] { TextDelimiter }; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } var baseline = (from line in rawBaselineData where line != "" select line.Split(delimiter, StringSplitOptions.RemoveEmptyEntries) into parsed select new UMCLight { Net = Convert.ToDouble(parsed[0]), ChargeState = Convert.ToInt32(parsed[1]), Mz = Convert.ToDouble(parsed[2]), Scan = Convert.ToInt32(parsed[3]), MassMonoisotopic = Convert.ToDouble(parsed[4]), MassMonoisotopicAligned = Convert.ToDouble(parsed[5]), Id = Convert.ToInt32(parsed[6]), ScanStart = Convert.ToInt32(parsed[7]), ScanEnd = Convert.ToInt32(parsed[8]), ScanAligned = Convert.ToInt32(parsed[9]) }).ToList(); var features = (from line in rawFeaturesData where line != "" select line.Split(delimiter, StringSplitOptions.RemoveEmptyEntries) into parsed select new UMCLight { Net = Convert.ToDouble(parsed[0]), ChargeState = Convert.ToInt32(parsed[1]), Mz = Convert.ToDouble(parsed[2]), Scan = Convert.ToInt32(parsed[3]), MassMonoisotopic = Convert.ToDouble(parsed[4]), MassMonoisotopicAligned = Convert.ToDouble(parsed[5]), Id = Convert.ToInt32(parsed[6]), ScanStart = Convert.ToInt32(parsed[7]), ScanEnd = Convert.ToInt32(parsed[8]), ScanAligned = Convert.ToInt32(parsed[9]) }).ToList(); var outputData = aligner.Align(baseline, features); var residuals = outputData.ResidualData; var heatmap = HeatmapFactory.CreateAlignedHeatmap(outputData.HeatScores, false); var netHistogram = HistogramFactory.CreateHistogram(outputData.NetErrorHistogram, "NET Error", "NET Error"); var massHistogram = HistogramFactory.CreateHistogram(outputData.MassErrorHistogram, "Mass Error", "Mass Error (ppm)"); var netResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Net, residuals.LinearCustomNet, residuals.LinearNet, "NET Residuals", "Scans", "NET"); var massMzResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Mz, residuals.MzMassError, residuals.MzMassErrorCorrected, "Mass Residuals", "m/z", "Mass Errors"); var massScanResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Net, residuals.MzMassError, residuals.MzMassErrorCorrected, "Mass Residuals", "Scan", "Mass Errors"); var directory = Path.Combine(outputPath, name); var encoder = new SvgEncoder(); PlotImageUtility.SaveImage(heatmap, directory + "_heatmap.svg", encoder); PlotImageUtility.SaveImage(netResidual, directory + "_netResidual.svg", encoder); PlotImageUtility.SaveImage(massMzResidual, directory + "_massMzResidual.svg", encoder); PlotImageUtility.SaveImage(massScanResidual, directory + "_massScanResidual.svg", encoder); PlotImageUtility.SaveImage(netHistogram, directory + "_netHistogram.svg", encoder); PlotImageUtility.SaveImage(massHistogram, directory + "_massHistogram.svg", encoder); }