예제 #1
0
        /// <summary>
        ///     Loads MS Features from a CSV file or existing database.
        /// </summary>
        /// <returns></returns>
        public static List <MSFeatureLight> LoadMsFeatureData(string path, DeconToolsIsosFilterOptions isosFilterOptions)
        {
            var msFeatures = new List <MSFeatureLight>();
            var extension  = Path.GetExtension(path);

            if (extension == null)
            {
                return(msFeatures);
            }

            extension = extension.ToUpper();
            switch (extension)
            {
            case ".PEK":
                throw new NotImplementedException("Support for .PEK files is not available at this time");
                // var pekReader = new PEKFileReader();
                // var pekMsFeatures = pekReader.ReadFile(path);
                // msFeatures.AddRange(pekMsFeatures);
                // UpdateStatus("Loaded features from the PEK file.");
                break;

            default:
                var reader = new MsFeatureLightFileReader {
                    Delimiter = ','
                };
                reader.IsosFilteroptions = isosFilterOptions;
                var newMsFeatures = reader.ReadFile(path);
                msFeatures.AddRange(newMsFeatures);
                UpdateStatus("Loaded features from the CSV files.");
                break;
            }

            return(msFeatures);
        }
예제 #2
0
        public DeconToolsIsosFilterOptions GetIsosFilterOptions()
        {
            var isosFilterOptions = new DeconToolsIsosFilterOptions();

            if (UseIsotopicFitFilter)
            {
                isosFilterOptions.MaximumIsotopicFit = MaximumIsotopicFit;
            }

            if (UseAbundanceFilter)
            {
                isosFilterOptions.AbundanceMinimum = MinimumAbundance;
                isosFilterOptions.AbundanceMaximum = MaximumAbundance;
            }

            if (UseLCScanFilter)
            {
                isosFilterOptions.LCScanStart = MinimumLCScan;
                isosFilterOptions.LCScanEnd   = MaximumLCScan;
            }

            if (UseMaximumDataCountFilter)
            {
                isosFilterOptions.MaximumDataPoints = MaximumPointsToLoad;
            }

            return(isosFilterOptions);
        }
예제 #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);
        }
예제 #4
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);
            }
        }