コード例 #1
0
        private void DrawChromatogram(ChromatographicPeak peak, Canvas canvas)
        {
            if (chargeToColor == null)
            {
                var converter = new BrushConverter();
                chargeToColor = new Dictionary <int, SolidColorBrush>();
                chargeToColor.Add(0, Brushes.Maroon);

                chargeToColor.Add(1, Brushes.DeepPink);
                chargeToColor.Add(2, Brushes.Purple);
                chargeToColor.Add(3, Brushes.Blue);
                chargeToColor.Add(4, Brushes.Green);
                chargeToColor.Add(5, Brushes.Gold);
                chargeToColor.Add(6, Brushes.Orange);
                //chargeToColor.Add(7, Brushes.DarkCyan);
                //chargeToColor.Add(8, Brushes.DimGray);
                //chargeToColor.Add(9, Brushes.Firebrick);
                //chargeToColor.Add(10, Brushes.LimeGreen);

                chargeToColor.Add(int.MinValue, Brushes.Black);
            }

            List <Tuple <double, double> >[] dataPointsForEachCharge = new List <Tuple <double, double> > [peak.isotopicEnvelopes.Max(p => p.charge)];

            double xAxisLowerbound = double.MaxValue;
            double xAxisUpperbound = 0;
            double yAxisLowerbound = 0;
            double yAxisUpperbound = 0;

            for (int zIndex = 0; zIndex < dataPointsForEachCharge.Length; zIndex++)
            {
                int z = zIndex + 1;

                dataPointsForEachCharge[zIndex] = new List <Tuple <double, double> >();
                var g = peak.isotopicEnvelopes.Where(p => p.charge == z).OrderBy(p => p.retentionTime).ToList();

                if (g.Any())
                {
                    double rt = g.Min(p => p.retentionTime);
                    if (rt < xAxisLowerbound)
                    {
                        xAxisLowerbound = rt;
                    }
                    rt = g.Max(p => p.retentionTime);
                    if (rt > xAxisUpperbound)
                    {
                        xAxisUpperbound = rt;
                    }

                    double inten = g.Max(p => p.intensity);
                    if (inten > yAxisUpperbound)
                    {
                        yAxisUpperbound = inten;
                    }
                }

                foreach (var env in g)
                {
                    dataPointsForEachCharge[zIndex].Add(new Tuple <double, double>(env.retentionTime, env.intensity));
                }
            }

            canvas.Children.Clear();

            if (xAxisUpperbound - xAxisLowerbound == 0)
            {
                return;
            }

            double xAxisStep = (xAxisUpperbound - xAxisLowerbound) / 5;
            double yAxisStep = (yAxisUpperbound - yAxisLowerbound) / 5;

            DrawGraphAxes(canvas, xAxisLowerbound, xAxisUpperbound, xAxisStep, yAxisLowerbound, yAxisUpperbound, yAxisStep, 20, "{0:0.00}", "0.0E0");

            int offset = 0;
            // Make some data sets.
            bool observedSomethingYet = false;

            for (int j = 0; j < dataPointsForEachCharge.Length; j++)
            {
                PointCollection points = new PointCollection();

                var dataPoints = dataPointsForEachCharge[j];
                if (dataPoints.Any())
                {
                    observedSomethingYet = true;
                }

                if (observedSomethingYet)
                {
                    for (int i = 0; i < dataPoints.Count; i++)
                    {
                        Point p = new Point(dataPoints[i].Item1, dataPoints[i].Item2);
                        var   transformedPoint = WtoD(p);
                        points.Add(transformedPoint);
                    }

                    Polyline polyline = new Polyline();
                    polyline.StrokeThickness = lineStroke;
                    SolidColorBrush brushColor;
                    if (chargeToColor.TryGetValue(j + 1, out brushColor))
                    {
                    }
                    else
                    {
                        brushColor = chargeToColor[int.MinValue];
                    }

                    polyline.Stroke = brushColor;
                    polyline.Points = points;

                    canvas.Children.Add(polyline);

                    var rectangle = new Rectangle();
                    rectangle.Stroke = brushColor;
                    rectangle.Fill   = brushColor;
                    rectangle.Height = 4;
                    rectangle.Width  = 4;
                    Canvas.SetTop(rectangle, offset + 5);
                    Canvas.SetLeft(rectangle, canvas.ActualWidth - 45);

                    TextBlock textBlock = new TextBlock();
                    textBlock.FontSize = fontSize;
                    textBlock.Text     = "z=" + (j + 1) + "; " + dataPoints.Count;
                    Canvas.SetTop(textBlock, offset + 1);
                    Canvas.SetLeft(textBlock, canvas.ActualWidth - 39);

                    offset += 12;

                    canvas.Children.Add(rectangle);
                    canvas.Children.Add(textBlock);
                }
            }

            TextBlock sbr = new TextBlock();

            sbr.Text = peak.GetSignalToBaseline().ToString("F1");
            Canvas.SetTop(sbr, 0);
            Canvas.SetLeft(sbr, 0);
            canvas.Children.Add(sbr);

            TextBlock peakcount = new TextBlock();

            peakcount.Text = DeconvolutedFeatures.Count.ToString();
            Canvas.SetTop(peakcount, 20);
            Canvas.SetLeft(peakcount, 0);
            canvas.Children.Add(peakcount);
        }
コード例 #2
0
        private void LoadData(string path, FileType fileType)
        {
            if (fileType == FileType.DeconvolutionTSV)
            {
                System.IO.StreamReader reader = new System.IO.StreamReader(path);
                string line;
                int    lineNum = 1;

                while (reader.Peek() > 0)
                {
                    line = reader.ReadLine();
                    List <IsotopicEnvelope> envs = new List <IsotopicEnvelope>();

                    if (lineNum != 1)
                    {
                        var parsedLine = line.Split('\t');
                        var mass       = double.Parse(parsedLine[0]);
                        var apexRt     = double.Parse(parsedLine[10]);

                        var envelopes = parsedLine[17].Split(new string[] { "[", "]" }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var envelope in envelopes)
                        {
                            var    split  = envelope.Split(new string[] { "|", "(", ")" }, StringSplitOptions.RemoveEmptyEntries);
                            int    charge = int.Parse(split[0]);
                            double rt     = double.Parse(split[1]);
                            int    scan   = int.Parse(split[2]);
                            List <MassSpectralPeak> peaks = new List <MassSpectralPeak>();

                            for (int i = 3; i < split.Length; i++)
                            {
                                string[]         sp   = split[i].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                                MassSpectralPeak peak = new MassSpectralPeak(double.Parse(sp[0]), double.Parse(sp[1]));
                                peaks.Add(peak);
                            }

                            IsotopicEnvelope env = new IsotopicEnvelope(rt, charge, peaks);
                            envs.Add(env);
                        }

                        var gsdf = envs.GroupBy(p => p.charge).Where(v => v.Count() > 1);

                        if (gsdf.Any())
                        {
                            var deconvolutedFeature = new ChromatographicPeak(envs, mass, apexRt);
                            if (deconvolutedFeature.GetSignalToBaseline() > 2.0)
                            {
                                DeconvolutedFeatures.Add(deconvolutedFeature);
                            }
                        }
                    }

                    lineNum++;
                }

                reader.Close();
            }
            else if (fileType == FileType.MetaMorpheusPsmTsv)
            {
                System.IO.StreamReader reader = new System.IO.StreamReader(path);
                string line;
                int    lineNum = 1;

                while (reader.Peek() > 0)
                {
                    line = reader.ReadLine();
                    List <IsotopicEnvelope> envs = new List <IsotopicEnvelope>();

                    if (lineNum != 1)
                    {
                        var parsedLine = line.Split('\t');
                    }
                }
            }
            else if (fileType == FileType.RawFile)
            {
                string ext = System.IO.Path.GetExtension(path).ToUpperInvariant();

                if (ext.Equals(".RAW"))
                {
                    rawFile = ThermoStaticData.LoadAllStaticData(path);
                }
                if (ext.Equals(".MZML"))
                {
                    rawFile = Mzml.LoadAllStaticData(path);
                }
                else
                {
                    throw new Exception("Cannot read file format: " + ext);
                }
            }
            else
            {
                throw new Exception("Cannot read file " + path);
            }
        }