コード例 #1
0
        public ChargeHistogramPlot(Dictionary <int, int> histogram, string name) :
            base(name)
        {
            var axis = new CategoryAxis
            {
                Position        = AxisPosition.Bottom,
                MinorStep       = 1,
                LabelField      = "Charge States",
                AbsoluteMinimum = 0,
                GapWidth        = 0
            };

            // Count axis
            var linearAxis = new LinearAxis
            {
                Position        = AxisPosition.Left,
                MaximumPadding  = .15,
                AbsoluteMinimum = 1,
                Minimum         = 0,
                MinimumPadding  = 1
            };

            Model.IsLegendVisible = true;
            Model.Axes.Add(axis);
            Model.Axes.Add(linearAxis);
            //Model.Title = name;

            // Add the data to the view model
            var data = new ColumnSeries
            {
                ValueField        = "Value",
                StrokeThickness   = 1,
                LabelFormatString = "{0}",
            };

            var colors = new ColorTypeIterator();

            foreach (var key in histogram.Keys)
            {
                axis.Labels.Add(key.ToString());
                int number = histogram[key];

                var column = new ColumnItem(number)
                {
                    Color = colors.GetColor(key)
                };
                data.Items.Add(column);
            }

            m_xAxis = axis;
            Model.Series.Add(data);

            Model.Axes[0].MajorGridlineStyle = LineStyle.Solid;
            Model.Axes[1].MajorGridlineStyle = LineStyle.Solid;
        }
コード例 #2
0
        public ChargeHistogramPlot(Dictionary<int, int> histogram, string name)
            : base(name)
        {
            var axis = new CategoryAxis
            {
                Position = AxisPosition.Bottom,
                MinorStep = 1,
                LabelField = "Charge States",
                AbsoluteMinimum = 0,
                GapWidth = 0
            };

            // Count axis
            var linearAxis = new LinearAxis
            {
                Position = AxisPosition.Left,
                MaximumPadding = .15,
                AbsoluteMinimum = 1,
                Minimum = 0,
                MinimumPadding = 1
            };

            Model.IsLegendVisible = true;
            Model.Axes.Add(axis);
            Model.Axes.Add(linearAxis);

            // Add the data to the view model
            var data = new ColumnSeries
            {
                ValueField = "Value",
                StrokeThickness = 1,
                LabelFormatString = "{0}",
            };

            var colors = new ColorTypeIterator();
            foreach (var key in histogram.Keys)
            {
                axis.Labels.Add(key.ToString());
                int number = histogram[key];

                var column = new ColumnItem(number)
                {
                    Color = colors.GetColor(key)
                };
                data.Items.Add(column);
            }

            m_xAxis = axis;
            Model.Series.Add(data);

            Model.Axes[0].MajorGridlineStyle = LineStyle.Solid;
            Model.Axes[1].MajorGridlineStyle = LineStyle.Solid;
        }
コード例 #3
0
        public static PlotBase CreateResidualPlot(IEnumerable <double> x,
                                                  IEnumerable <double> yPre,
                                                  IEnumerable <double> yPost,
                                                  string title,
                                                  string xLabel,
                                                  string yLabel)
        {
            var colorIterator = new ColorTypeIterator();
            var plot          = new ScatterPlot(title, xLabel, yLabel);

            var preColor  = colorIterator.GetColor(1);
            var postColor = colorIterator.GetColor(2);

            plot.AddSeries(x, yPre, "Pre-Alignment ", preColor);
            plot.AddSeries(x, yPost, "Post-Alignment ", postColor);

            return(plot);
        }
コード例 #4
0
        /// <summary>
        ///     Creates a residual alignment plot from the features provided.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="abscissaFunc"></param>
        /// <param name="ordinateFuncPre"></param>
        /// <param name="ordinateFuncPost"></param>
        /// <param name="xLabel"></param>
        /// <param name="yLabel"></param>
        /// <returns></returns>
        public static PlotBase CreateResidualAlignmentPlot <T>(IEnumerable <T> x,
                                                               IEnumerable <T> y,
                                                               Func <T, double> abscissaFunc,
                                                               Func <T, T, double> ordinateFuncPre,
                                                               Func <T, T, double> ordinateFuncPost,
                                                               string xLabel,
                                                               string yLabel)
            where T : FeatureLight
        {
            var xPoints = x as T[] ?? x.ToArray();
            var yPoints = y as T[] ?? y.ToArray();

            var colorIterator = new ColorTypeIterator();
            var plot          = new ScatterPlot("", xLabel, yLabel);

            if (xPoints.Length != yPoints.Length)
            {
                throw new Exception("The two data arrays must be of equal length.");
            }

            var preColor  = colorIterator.GetColor(1);
            var postColor = colorIterator.GetColor(2);

            var preX  = new List <double>();
            var preY  = new List <double>();
            var postY = new List <double>();

            for (var i = 0; i < xPoints.Length; i++)
            {
                var featureX = xPoints[i];
                var featureY = yPoints[i];

                preX.Add(abscissaFunc(featureX));
                preY.Add(ordinateFuncPre(featureX, featureY));
                postY.Add(ordinateFuncPost(featureX, featureY));
            }

            plot.AddSeries(preX, preY, "Pre-Alignment ", preColor);
            plot.AddSeries(preX, postY, "Post-Alignment ", postColor);

            return(plot);
        }
コード例 #5
0
        /// <summary>
        ///     Creates a feature plot enumerating each charge state with a different color.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="features"></param>
        /// <param name="timeSelector"></param>
        /// <param name="massSelector"></param>
        /// <param name="timeLabel"></param>
        /// <param name="massLabel"></param>
        /// <returns></returns>
        public static PlotBase CreateFeatureScatterPlot <T>(IEnumerable <T> features,
                                                            Func <T, double> timeSelector,
                                                            Func <T, double> massSelector,
                                                            string timeLabel,
                                                            string massLabel
                                                            )
            where T : FeatureLight
        {
            // Map charge states.
            var chargeMap = new Dictionary <int, IList <T> >();

            foreach (var feature in features)
            {
                var charge = feature.ChargeState;
                if (!chargeMap.ContainsKey(charge))
                {
                    chargeMap.Add(charge, new List <T>());
                }
                chargeMap[charge].Add(feature);
            }

            var colorIterator = new ColorTypeIterator();
            var plot          = new ScatterPlot("Features", timeLabel, massLabel);

            foreach (var charge in chargeMap.Keys)
            {
                var x = new List <double>();
                var y = new List <double>();
                foreach (var feature in chargeMap[charge])
                {
                    x.Add(timeSelector(feature));
                    y.Add(massSelector(feature));
                }
                var color = colorIterator.GetColor(charge);
                plot.AddSeries(x, y, "Charge " + charge, color);
            }
            plot.Model.Axes[0].MajorGridlineStyle = LineStyle.Solid;
            plot.Model.Axes[1].MajorGridlineStyle = LineStyle.Solid;

            return(plot);
        }
コード例 #6
0
        public ChargeStateViewModel(int charge,
            double mz,
            int scanStart,
            int scanEnd)
        {
            var iterator = new ColorTypeIterator();
            var oldColor = iterator.GetColor(charge);
            var newColor = new Color
            {
                A = oldColor.A,
                R = oldColor.R,
                G = oldColor.G,
                B = oldColor.B
            };
            ChargeColor = new SolidColorBrush(newColor);

            ChargeState = charge;
            ScanStart = scanStart;
            ScanEnd = scanEnd;
            Mz = mz;
        }
コード例 #7
0
        public void PlotSpectra(MSFeatureLight feature, IEnumerable<XYData> spectrum)
        {
            var series = new StemSeries
            {
                Color = OxyColors.Black
            };

            var minimumMz = double.MaxValue;
            var maximumMz = double.MinValue;
            var maxAbundance = double.MinValue;

            if (spectrum.Count() < 1)
                return;

            foreach (var peak in spectrum)
            {
                minimumMz = Math.Min(peak.X, minimumMz);
                maximumMz = Math.Max(peak.X, maximumMz);
                maxAbundance = Math.Max(maxAbundance, peak.Y);

                series.Points.Add(new DataPoint(peak.X, peak.Y));
            }

            var maxAbundanceTop = maxAbundance*.5;

            Model.Axes[0].AbsoluteMinimum = minimumMz;
            Model.Axes[0].AbsoluteMaximum = maximumMz;

            Model.Series.Add(series);

            // Add in the monoisotopic peak
            var colors = new ColorTypeIterator();
            var chargeColor = colors.GetColor(feature.ChargeState);
            var msFeature = new StemSeries
            {
                Color = chargeColor
            };
            msFeature.Points.Add(new DataPoint(feature.Mz, feature.Abundance));
            Model.Series.Add(msFeature);

            // Add in the rest of the isotopes
            var alphaColor = OxyColor.FromAColor(100, OxyColors.Red);
            var charge = feature.ChargeState;
            var mz = feature.Mz;
            var abundance = Convert.ToDouble(feature.Abundance);
            var monoPeakAnnotation = new LineAnnotation
            {
                Type = LineAnnotationType.Vertical,
                X = mz,
                Color = alphaColor,
                TextColor = alphaColor,
                Text = string.Format("mono peak: {0} m/z",
                    mz.ToString("F3"))
            };
            Model.Annotations.Add(monoPeakAnnotation);

            var lastMz = mz;
            var spacing = 1.0/charge;
            while (mz < maximumMz && abundance > 1)
            {
                mz = mz + (1.0/charge);
                abundance *= .75;
                var peakAnnotation = new LineAnnotation
                {
                    Type = LineAnnotationType.Vertical,
                    X = mz,
                    Color = alphaColor,
                    TextColor = alphaColor,
                    Text = string.Format("{0} m/z",
                        mz.ToString("F3"))
                };

                var spaceAnnotation = new LineAnnotation
                {
                    Type = LineAnnotationType.Horizontal,
                    Color = alphaColor,
                    TextColor = alphaColor,
                    TextHorizontalAlignment = HorizontalAlignment.Center,
                    TextVerticalAlignment = VerticalAlignment.Top,
                    TextPosition = new DataPoint(.5, 0),
                    MinimumX = lastMz,
                    MaximumX = mz,
                    Text = string.Format("d={0}", spacing.ToString("F2")),
                    Y = maxAbundance*.75
                };
                maxAbundance *= .75;
                lastMz = mz;
                Model.Annotations.Add(spaceAnnotation);
                Model.Annotations.Add(peakAnnotation);
            }

            if (feature.ParentFeature != null)
            {
                var features = feature.ParentFeature.Features;
                foreach (var subFeature in features)
                {
                    var msms =
                        subFeature.MSnSpectra.Where(x => x.PrecursorMz > minimumMz && x.PrecursorMz < maximumMz);
                    foreach (var fragmentation  in msms)
                    {
                        var spaceAnnotation = new LineAnnotation
                        {
                            Type = LineAnnotationType.Vertical,
                            Color = OxyColors.Gray,
                            TextColor = OxyColors.Gray,
                            FontWeight = 3,
                            TextVerticalAlignment = VerticalAlignment.Top,
                            TextPosition = new DataPoint(1, 0),
                            StrokeThickness = 2,
                            Text =
                                string.Format("msms {0} - scan {1}", fragmentation.PrecursorMz.ToString("F2"),
                                    fragmentation.Scan),
                            X = fragmentation.PrecursorMz
                        };
                        Model.Annotations.Add(spaceAnnotation);

                        var lowerMz = new LineAnnotation
                        {
                            Type = LineAnnotationType.Horizontal,
                            Color = OxyColors.LightGray,
                            TextColor = OxyColors.LightGray,
                            FontWeight = 3,
                            TextVerticalAlignment = VerticalAlignment.Top,
                            TextPosition = new DataPoint(1, 0),
                            StrokeThickness = 2,
                            Y = maxAbundanceTop,
                            Text = string.Format("{0} m/z", MsmsDistanceLower.ToString("F2")),
                            MinimumX = fragmentation.PrecursorMz - MsmsDistanceLower,
                            MaximumX = fragmentation.PrecursorMz
                        };

                        var upperMz = new LineAnnotation
                        {
                            Type = LineAnnotationType.Horizontal,
                            Color = OxyColors.LightGray,
                            TextColor = OxyColors.LightGray,
                            FontWeight = 3,
                            TextVerticalAlignment = VerticalAlignment.Top,
                            TextPosition = new DataPoint(1, 0),
                            StrokeThickness = 2,
                            Text = string.Format("{0} m/z", MsmsDistanceUpper.ToString("F2")),
                            Y = maxAbundanceTop,
                            MinimumX = fragmentation.PrecursorMz,
                            MaximumX = fragmentation.PrecursorMz + MsmsDistanceUpper
                        };

                        Model.Annotations.Add(upperMz);
                        Model.Annotations.Add(lowerMz);
                    }
                }
            }
        }
コード例 #8
0
ファイル: XicViewModel.cs プロジェクト: msdna/MultiAlign
        /// <summary>
        ///     Plots the UMC's
        /// </summary>
        /// <param name="features"></param>
        private void PlotFeatures(IEnumerable<UMCLight> features)
        {
            var markerIterator = new MarkerTypeIterator();
            m_colorIterator = new ColorTypeIterator();

            var i = 0;

            m_scanAnnotation = new LineAnnotation
            {
                X = 0,
                TextColor = OxyColors.Gray,
                Text = "0",
                TextOrientation = AnnotationTextOrientation.Vertical,
                LineStyle = LineStyle.Dash,
                Type = LineAnnotationType.Vertical,
            };

            Model.Annotations.Add(m_scanAnnotation);

            foreach (var feature in features)
            {
                var chargeMap = feature.CreateChargeMap();

                foreach (var charge in chargeMap.Keys)
                {
                    var msFeatures = chargeMap[charge];
                    msFeatures = msFeatures.OrderBy(x => x.Scan).ToList();
                    var mz = msFeatures[0].Mz;

                    var newSeries = new LineSeries
                    {
                        Color = m_colorIterator.GetColor(charge),
                        MarkerFill = m_colorIterator.GetColor(charge),
                        MarkerSize = 3,
                        MarkerStroke = OxyColors.White,
                        MarkerStrokeThickness = 1.5,
                        MarkerType = markerIterator.GetMarker(i++),
                        Title = string.Format("{0} m/z  - Charge {1}",
                            mz.ToString("F3"),
                            charge)
                    };

                    double abundance = 0;
                    MSFeatureLight bestFeature = null;

                    foreach (var msFeature in msFeatures)
                    {
                        if (abundance < msFeature.Abundance)
                        {
                            bestFeature = msFeature;
                            abundance = msFeature.Abundance;
                        }

                        foreach (var msms in msFeature.MSnSpectra)
                        {
                            var peptideSequence = "";
                            if (msms.Peptides.Count > 0)
                                peptideSequence = msms.Peptides[0].Sequence;

                            var msmsAnnotation = new LineAnnotation
                            {
                                Type = LineAnnotationType.Vertical,
                                X = msms.Scan,
                                Y = msFeature.Abundance,
                                StrokeThickness = 2,
                                Color = m_colorIterator.GetColor(msFeature.ChargeState),
                                TextColor = m_colorIterator.GetColor(msFeature.ChargeState),
                                Text = string.Format("{2} - {0} m/z {1}",
                                    msms.PrecursorMz.ToString("F3"),
                                    peptideSequence,
                                    msms.CollisionType)
                            };
                            Model.Annotations.Add(msmsAnnotation);
                        }
                        newSeries.Points.Add(new DataPoint(msFeature.Scan, msFeature.Abundance));
                    }

                    newSeries.Tag = charge;

                    if (bestFeature != null)
                    {
                        ScanAnnotationX = bestFeature.Scan;
                        SelectedCharge = charge;
                    }
                    Model.Series.Add(newSeries);
                }
            }
        }