Exemple #1
0
        public void TestAlignment(string datasetNameX, string datasetNameY)
        {
            var featureFileX = GetTestPath(datasetNameX + "_isos.csv");
            var rawFileX     = GetTestPath(datasetNameX + ".raw");

            var featureFileY = GetTestPath(datasetNameY + "_isos.csv");
            var rawFileY     = GetTestPath(datasetNameY + ".raw");

            Print("Detecting Features");
            var featuresX = FindFeatures(rawFileX, featureFileX);
            var featuresY = FindFeatures(rawFileY, featureFileY);

            PrintFeatureMsMsData(featuresX);
            PrintFeatureMsMsData(featuresY);

            Print("Aligning Features");
            // Align the features
            var alignmentOptions = new AlignmentOptions();
            var aligner          = new LcmsWarpFeatureAligner(alignmentOptions.LCMSWarpOptions);

            aligner.Align(featuresX, featuresY);

            Print("");
            Print("NET, NETAligned");
            foreach (var feature in featuresY)
            {
                if (feature.HasMsMs())
                {
                    Print(string.Format("{0}", feature.Net - feature.NetAligned));
                }
            }
        }
Exemple #2
0
        public void TestPerformNetAlignment(string baselinePath, string aligneePath)
        {
            Console.WriteLine(@"I'm Testing!");

            var rawBaselineData = File.ReadAllLines(baselinePath);
            var rawFeaturesData = File.ReadAllLines(aligneePath);

            var baseline = (from line in rawBaselineData
                            where line != ""
                            select line.Split(',')
                            into parsed
                            select new UMCLight
            {
                Net = Convert.ToDouble(parsed[0]),
                ChargeState = Convert.ToInt32(parsed[1]),
                Mz = Convert.ToDouble(parsed[2]),
                ScanStart = Convert.ToInt32(parsed[3]),
                Scan = Convert.ToInt32(parsed[3]),
                MassMonoisotopic = Convert.ToDouble(parsed[4]),
                MassMonoisotopicAligned = Convert.ToDouble(parsed[5]),
                Id = Convert.ToInt32(parsed[6])
            }).ToList();

            var features = (from line in rawFeaturesData
                            where line != ""
                            select line.Split(',')
                            into parsed
                            select new UMCLight
            {
                Net = Convert.ToDouble(parsed[0]),
                ChargeState = Convert.ToInt32(parsed[1]),
                Mz = Convert.ToDouble(parsed[2]),
                ScanStart = Convert.ToInt32(parsed[3]),
                Scan = Convert.ToInt32(parsed[3]),
                MassMonoisotopic = Convert.ToDouble(parsed[4]),
                MassMonoisotopicAligned = Convert.ToDouble(parsed[5]),
                Id = Convert.ToInt32(parsed[6])
            }).ToList();

            var oldStyle = new LcmsWarpFeatureAligner(new LcmsWarpAlignmentOptions());

            var oldOutputData = oldStyle.Align(baseline, features);

            Console.WriteLine(@"Done testing");
        }
Exemple #3
0
        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);
        }
        public void TestSpectralAlignment(string basePath, string baselineName, string aligneeName,
            double comparisonCutoff)
        {
            RootDataPath = basePath;

            var featureFileX = GetTestPath(baselineName + "_isos.csv");
            var rawFileX = GetTestPath(baselineName + ".raw");

            var featureFileY = GetTestPath(aligneeName + "_isos.csv");
            var rawFileY = GetTestPath(aligneeName + ".raw");

            Print("Detecting Features");
            var baselineFeatures = FindFeatures(rawFileX, featureFileX);
            var aligneeFeatures = FindFeatures(rawFileY, featureFileY);

            Print("Aligning Features");
            // Align the features
            var aligner = new LcmsWarpFeatureAligner();
            var alignmentOptions = new AlignmentOptions();
            aligner.Options = alignmentOptions.LCMSWarpOptions;
            aligner.Align(baselineFeatures, aligneeFeatures);

            PrintFeatureMsMsData(baselineFeatures);
            PrintFeatureMsMsData(aligneeFeatures);

            var matches = GetSpectralMatches(
                baselineFeatures, aligneeFeatures, comparisonCutoff);
            Print(string.Format("Found {0} spectral matches", matches.Count));
            Print("Similarity, Pre-Alignment, Post-Alignment");

            var counts = new Dictionary<double, int>();
            counts.Add(.9, 0);
            counts.Add(.8, 0);
            counts.Add(.7, 0);
            counts.Add(.6, 0);
            counts.Add(.5, 0);

            var preDist = new List<double>();
            var postDist = new List<double>();

            foreach (var match in matches)
            {
                var baselineFeature = match.Baseline.ParentFeature.ParentFeature;
                var aligneeFeature = match.Alignee.ParentFeature.ParentFeature;

                var preAlignment = baselineFeature.Net - aligneeFeature.Net;
                var postAlignment = baselineFeature.Net - aligneeFeature.NetAligned;

                postDist.Add(postAlignment);
                preDist.Add(preAlignment);

                Print(string.Format("{0},{1},{2}", match.Similarity, preAlignment, postAlignment));

                if (match.Similarity > .9)
                {
                    counts[.9]++;
                }
                else if (match.Similarity > .8)
                {
                    counts[.8]++;
                }
                else if (match.Similarity > .7)
                {
                    counts[.7]++;
                }
                else if (match.Similarity > .6)
                {
                    counts[.6]++;
                }
            }
            Print("");
            Print("Counts");
            Print("");
            foreach (var key in counts.Keys)
            {
                Print(string.Format("{0},{1}", key, counts[key]));
            }

            var test = new MannWhitneyTest();
            var data = test.Test(preDist, postDist);
            Print(string.Format("Two Tail - {0} ", data.TwoTail));
            Print(string.Format("Left Tail - {0} ", data.LeftTail));
            Print(string.Format("Right Tail - {0} ", data.RightTail));
        }
        public void TestAlignment(string datasetNameX, string datasetNameY)
        {
            var featureFileX = GetTestPath(datasetNameX + "_isos.csv");
            var rawFileX = GetTestPath(datasetNameX + ".raw");

            var featureFileY = GetTestPath(datasetNameY + "_isos.csv");
            var rawFileY = GetTestPath(datasetNameY + ".raw");

            Print("Detecting Features");
            var featuresX = FindFeatures(rawFileX, featureFileX);
            var featuresY = FindFeatures(rawFileY, featureFileY);

            PrintFeatureMsMsData(featuresX);
            PrintFeatureMsMsData(featuresY);

            Print("Aligning Features");
            // Align the features
            var aligner = new LcmsWarpFeatureAligner();
            var alignmentOptions = new AlignmentOptions();
            aligner.Options = alignmentOptions.LCMSWarpOptions;
            aligner.Align(featuresX, featuresY);

            Print("");
            Print("NET, NETAligned");
            foreach (var feature in featuresY)
            {
                if (feature.HasMsMs())
                {
                    Print(string.Format("{0}", feature.Net - feature.NetAligned));
                }
            }
        }
Exemple #6
0
        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();

            var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1);
            var aligneeMs = UmcLoaderFactory.LoadMsFeatureData(path2);
            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);
            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);
        }
Exemple #7
0
        public void TestSpectralAlignment(string basePath, string baselineName, string aligneeName,
                                          double comparisonCutoff)
        {
            RootDataPath = basePath;


            var featureFileX = GetTestPath(baselineName + "_isos.csv");
            var rawFileX     = GetTestPath(baselineName + ".raw");

            var featureFileY = GetTestPath(aligneeName + "_isos.csv");
            var rawFileY     = GetTestPath(aligneeName + ".raw");

            Print("Detecting Features");
            var baselineFeatures = FindFeatures(rawFileX, featureFileX);
            var aligneeFeatures  = FindFeatures(rawFileY, featureFileY);

            Print("Aligning Features");
            // Align the features
            var alignmentOptions = new AlignmentOptions();
            var aligner          = new LcmsWarpFeatureAligner(alignmentOptions.LCMSWarpOptions);

            aligner.Align(baselineFeatures, aligneeFeatures);

            PrintFeatureMsMsData(baselineFeatures);
            PrintFeatureMsMsData(aligneeFeatures);

            var matches = GetSpectralMatches(
                baselineFeatures, aligneeFeatures, comparisonCutoff);

            Print(string.Format("Found {0} spectral matches", matches.Count));
            Print("Similarity, Pre-Alignment, Post-Alignment");

            var counts = new Dictionary <double, int>();

            counts.Add(.9, 0);
            counts.Add(.8, 0);
            counts.Add(.7, 0);
            counts.Add(.6, 0);
            counts.Add(.5, 0);

            var preDist  = new List <double>();
            var postDist = new List <double>();

            foreach (var match in matches)
            {
                var baselineFeature = match.Baseline.ParentFeature.GetParentFeature();
                var aligneeFeature  = match.Alignee.ParentFeature.GetParentFeature();

                var preAlignment  = baselineFeature.Net - aligneeFeature.Net;
                var postAlignment = baselineFeature.Net - aligneeFeature.NetAligned;

                postDist.Add(postAlignment);
                preDist.Add(preAlignment);

                Print(string.Format("{0},{1},{2}", match.Similarity, preAlignment, postAlignment));

                if (match.Similarity > .9)
                {
                    counts[.9]++;
                }
                else if (match.Similarity > .8)
                {
                    counts[.8]++;
                }
                else if (match.Similarity > .7)
                {
                    counts[.7]++;
                }
                else if (match.Similarity > .6)
                {
                    counts[.6]++;
                }
            }
            Print("");
            Print("Counts");
            Print("");
            foreach (var key in counts.Keys)
            {
                Print(string.Format("{0},{1}", key, counts[key]));
            }

            var test = new MannWhitneyTest();
            var data = test.Test(preDist, postDist);

            Print(string.Format("Two Tail - {0} ", data.TwoTail));
            Print(string.Format("Left Tail - {0} ", data.LeftTail));
            Print(string.Format("Right Tail - {0} ", data.RightTail));
        }
Exemple #8
0
        public void TestLcmsWarpAlignment(string path1, string path2, string svgPath)
        {
            // Convert relative paths to absolute paths
            path1   = GetPath(path1);
            path2   = GetPath(path2);
            svgPath = GetPath(HEATMAP_RESULTS_FOLDER_BASE + svgPath);

            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)
            {
                MaximumNetRange = .002
            };

            var baseline = finder.FindFeatures(baselineMs, options, null);
            var alignee  = finder.FindFeatures(aligneeMs, options, null);
            var data     = 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 = data.HeatScores;
            var width  = scores.GetLength(0);
            var height = scores.GetLength(1);

            heatMapSeries1.Data = new double[width, height];


            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    heatMapSeries1.Data[i, j] = Convert.ToDouble(scores[i, j]);
                }
            }

            plotModel1.Series.Add(heatMapSeries1);


            var svg       = new SvgExporter();
            var svgString = svg.ExportToString(plotModel1);

            using (var writer = File.CreateText(svgPath + ".svg"))
            {
                writer.Write(svgString);
            }
        }
Exemple #9
0
        public void TestLcmsWarpAlignment(string path1, string path2, string svgPath)
        {
            // Convert relative paths to absolute paths
            path1 = GetPath(path1);
            path2 = GetPath(path2);
            svgPath = GetPath(HEATMAP_RESULTS_FOLDER_BASE + svgPath);

            var aligner = new LcmsWarpFeatureAligner();

            var baselineMs = UmcLoaderFactory.LoadMsFeatureData(path1);
            var aligneeMs = UmcLoaderFactory.LoadMsFeatureData(path2);
            var finder = FeatureFinderFactory.CreateFeatureFinder(FeatureFinderType.TreeBased);

            var tolerances = new FeatureTolerances
            {
                FragmentationWindowSize = .5,
                Mass = 13,
                DriftTime = .3,
                Net = .01
            };
            var options = new LcmsFeatureFindingOptions(tolerances)
            {
                MaximumNetRange = .002
            };

            var baseline = finder.FindFeatures(baselineMs, options, null);
            var alignee = finder.FindFeatures(aligneeMs, options, null);
            var data = 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 = data.heatScores;
            var width = scores.GetLength(0);
            var height = scores.GetLength(1);

            heatMapSeries1.Data = new double[width, height];

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    heatMapSeries1.Data[i, j] = Convert.ToDouble(scores[i, j]);
                }
            }

            plotModel1.Series.Add(heatMapSeries1);

            var svg = new SvgExporter();
            var svgString = svg.ExportToString(plotModel1);
            using (var writer = File.CreateText(svgPath + ".svg"))
            {
                writer.Write(svgString);
            }
        }
Exemple #10
0
        public void TestPerformNetAlignment(string baselinePath, string aligneePath)
        {
            Console.WriteLine(@"I'm Testing!");

            var rawBaselineData = File.ReadAllLines(baselinePath);
            var rawFeaturesData = File.ReadAllLines(aligneePath);

            var baseline = (from line in rawBaselineData
                where line != ""
                select line.Split(',')
                into parsed
                select new UMCLight
                {

                    Net = Convert.ToDouble(parsed[0]),
                    ChargeState = Convert.ToInt32(parsed[1]),
                    Mz = Convert.ToDouble(parsed[2]),
                    ScanStart = Convert.ToInt32(parsed[3]),
                    Scan = Convert.ToInt32(parsed[3]),
                    MassMonoisotopic = Convert.ToDouble(parsed[4]),
                    MassMonoisotopicAligned = Convert.ToDouble(parsed[5]),
                    Id = Convert.ToInt32(parsed[6])
                }).ToList();

            var features = (from line in rawFeaturesData
                where line != ""
                select line.Split(',')
                into parsed
                select new UMCLight
                {
                    Net = Convert.ToDouble(parsed[0]),
                    ChargeState = Convert.ToInt32(parsed[1]),
                    Mz = Convert.ToDouble(parsed[2]),
                    ScanStart = Convert.ToInt32(parsed[3]),
                    Scan = Convert.ToInt32(parsed[3]),
                    MassMonoisotopic = Convert.ToDouble(parsed[4]),
                    MassMonoisotopicAligned = Convert.ToDouble(parsed[5]),
                    Id = Convert.ToInt32(parsed[6])
                }).ToList();

            var oldStyle = new LcmsWarpFeatureAligner();

            var oldOutputData = oldStyle.Align(baseline, features);

            Console.WriteLine(@"Done testing");
        }
Exemple #11
0
        public void TestLcmsWarpPortCpp(string relativeBaselinePath, string relativeAligneePath, string relativeOutput, string name)
        {
            var 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;

            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 #12
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 #13
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);
        }