Exemple #1
0
        // Using a DependencyProperty as the backing store for MassMzImage.  This enables animation, styling, binding, etc...


        private void CreatePlots()
        {
            if (AlignmentData == null || AlignmentData.AlignmentData == null)
            {
                return;
            }

            var alignmentData = AlignmentData.AlignmentData;

            var heatmap       = HeatmapFactory.CreateAlignedHeatmap(alignmentData.HeatScores, alignmentData.BaselineIsAmtDB);
            var feature       = ScatterPlotFactory.CreateFeatureMassScatterPlot(AlignmentData.AligneeFeatures);
            var netHistogram  = HistogramFactory.CreateHistogram(alignmentData.NetErrorHistogram, "NET Error", "NET Error");
            var massHistogram = HistogramFactory.CreateHistogram(alignmentData.NetErrorHistogram, "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");

            NetScanImage     = ImageConverter.ConvertImage(PlotImageUtility.CreateImage(netResidual));
            MassHistogram    = ImageConverter.ConvertImage(PlotImageUtility.CreateImage(massHistogram));
            NetHistogram     = ImageConverter.ConvertImage(PlotImageUtility.CreateImage(netHistogram));
            HeatmapImage     = ImageConverter.ConvertImage(PlotImageUtility.CreateImage(heatmap));
            MassMzImage      = ImageConverter.ConvertImage(PlotImageUtility.CreateImage(massMzResidual));
            MassScanImage    = ImageConverter.ConvertImage(PlotImageUtility.CreateImage(massScanResidual));
            FeaturePlotImage = ImageConverter.ConvertImage(PlotImageUtility.CreateImage(feature));
        }
Exemple #2
0
        public AlignmentPlotCreator(AlignmentData alignment)
        {
            var residuals = alignment.ResidualData;

            Heatmap     = HeatmapFactory.CreateAlignedHeatmap(alignment.HeatScores, alignment.BaselineIsAmtDB);
            NetResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Net, residuals.LinearCustomNet,
                                                                residuals.LinearNet, "NET Residuals", "Scans", "NET");

            MassHistogram = HistogramFactory.CreateHistogram(alignment.MassErrorHistogram, "Mass Error", "Mass Error (ppm)");
            NetHistogram  = HistogramFactory.CreateHistogram(alignment.NetErrorHistogram, "NET Error", "NET Error");

            MassMzResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Mz, residuals.MzMassError,
                                                                   residuals.MzMassErrorCorrected, "Mass Residuals", "m/z", "Mass Errors");

            MassScanResidual = ScatterPlotFactory.CreateResidualPlot(residuals.Net, residuals.MzMassError,
                                                                     residuals.MzMassErrorCorrected, "Mass Residuals", "Scan", "Mass Errors");
        }
Exemple #3
0
        /// <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();
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }