예제 #1
0
 public AnnotationSettings()
 {
     labelToAliasAndColorMap        = new Map <string, Pair <string, Color> >();
     pointAnnotations               = new PointDataMap <SeemsPointAnnotation>();
     pointFontSpec                  = new ZedGraph.FontSpec("Arial", 10, Color.Gray, false, false, false);
     pointFontSpec.Border.IsVisible = false;
 }
예제 #2
0
        public AnnotationEditForm(GraphForm graphForm)
        {
            InitializeComponent();

            ownerGraphForm = graphForm;

            PointDataMap <SeemsPointAnnotation> annotationMap = (ownerGraphForm.CurrentScan.IsMassSpectrum ? ownerGraphForm.AnnotationSettings.ScanPointAnnotations : ownerGraphForm.AnnotationSettings.ChromatogramPointAnnotations);

            foreach (SeemsPointAnnotation annotation in annotationMap.Values)
            {
                annotationListBox.Items.Add(new AnnotationListItem(annotation));
            }
        }
예제 #3
0
        public SeemsAnnotationSettings()
        {
            // ms-product-label -> (label alias, known color)
            labelToAliasAndColorMap          = new Map <string, Pair <string, Color> >();
            labelToAliasAndColorMap["y"]     = new Pair <string, Color>("y", Color.Blue);
            labelToAliasAndColorMap["b"]     = new Pair <string, Color>("b", Color.Red);
            labelToAliasAndColorMap["y-NH3"] = new Pair <string, Color>("y^", Color.Green);
            labelToAliasAndColorMap["y-H2O"] = new Pair <string, Color>("y*", Color.Cyan);
            labelToAliasAndColorMap["b-NH3"] = new Pair <string, Color>("b^", Color.Orange);
            labelToAliasAndColorMap["b-H2O"] = new Pair <string, Color>("b*", Color.Violet);

            scanPointAnnotations         = new PointDataMap <SeemsPointAnnotation>();
            chromatogramPointAnnotations = new PointDataMap <SeemsPointAnnotation>();
        }
예제 #4
0
        private void okButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;

            PointDataMap <SeemsPointAnnotation> annotationMap = (ownerGraphForm.CurrentScan.IsMassSpectrum ? ownerGraphForm.AnnotationSettings.ScanPointAnnotations : ownerGraphForm.AnnotationSettings.ChromatogramPointAnnotations);

            annotationMap.Clear();
            foreach (object itr in annotationListBox.Items)
            {
                AnnotationListItem item = (AnnotationListItem)itr;
                annotationMap[item.annotation.Point] = item.annotation;
            }

            this.Close();
        }
예제 #5
0
        public override Spectrum spectrum(int index, bool getBinaryData)
        {
            Spectrum s = base.spectrum(index, true);

            if (s.cvParam(CVID.MS_MSn_spectrum).empty() ||
                (int)s.cvParam(CVID.MS_ms_level).value == 1)
            {
                if (!getBinaryData)
                {
                    s.binaryDataArrays.Clear();
                }
                return(s);
            }

            PrecursorList pl = s.precursors;

            BinaryData            mzArray        = s.getMZArray().data;
            BinaryData            intensityArray = s.getIntensityArray().data;
            PointDataMap <double> mziMap         = new PointDataMap <double>();

            for (int i = 0; i < (int)s.defaultArrayLength; ++i)
            {
                mziMap.Insert(mzArray[i], intensityArray[i]);
            }

            Set <double> pointsToRemove = new Set <double>();

            foreach (Precursor p in pl)
            {
                foreach (SelectedIon si in p.selectedIons)
                {
                    double mz = (double)si.cvParam(CVID.MS_selected_ion_m_z).value;
                    PointDataMap <double> .Enumerator itr = mziMap.LowerBound(mz - 4.0);
                    if (itr != null && itr.IsValid)
                    {
                        while (itr.IsValid && itr.Current.Key - mz < 4.0)
                        {
                            pointsToRemove.Add(itr.Current.Key);
                            itr.MoveNext();
                        }
                    }

                    CVParam chargeParam = si.cvParam(CVID.MS_charge_state);
                    if (!chargeParam.empty())
                    {
                        int z = (int)chargeParam.value;
                        for (int i = 1; i < z; ++i)
                        {
                            double strippedMz = (mz * z) / (z - i);
                            itr = mziMap.LowerBound(strippedMz - 4.0);
                            if (itr != null && itr.IsValid)
                            {
                                while (itr.IsValid && itr.Current.Key - strippedMz < 4.0)
                                {
                                    pointsToRemove.Add(itr.Current.Key);
                                    itr.MoveNext();
                                }
                            }
                        }
                    }
                }
            }

            if (getBinaryData)
            {
                mzArray.Clear();
                intensityArray.Clear();
                foreach (PointDataMap <double> .MapPair pair in mziMap)
                {
                    if (pointsToRemove.Contains(pair.Key))
                    {
                        continue;
                    }

                    mzArray.Add(pair.Key);
                    intensityArray.Add(pair.Value);
                }
                s.defaultArrayLength = (ulong)mzArray.Count;
            }
            else
            {
                s.binaryDataArrays.Clear();
                s.defaultArrayLength -= (ulong)pointsToRemove.Count;
            }

            return(s);
        }
예제 #6
0
        public void SetDataLabelsVisible(bool visible)
        {
            //zedGraphControl1.GraphPane.GraphObjList.Clear();
            foreach (ZedGraph.GraphObj dataLabel in dataLabels)
            {
                zedGraphControl1.GraphPane.GraphObjList.Remove(dataLabel);
            }

            if (visible)
            {
                if (!(AnnotationSettings.ShowChromatogramPointTimes || AnnotationSettings.ShowScanPointMZs ||
                      AnnotationSettings.ShowChromatogramPointIntensities || AnnotationSettings.ShowScanPointIntensities ||
                      AnnotationSettings.ShowUnmatchedAnnotations || AnnotationSettings.ShowMatchedAnnotations))
                {
                    return;
                }

                // set direct references
                ZedGraph.GraphPane pane  = zedGraphControl1.GraphPane;
                ZedGraph.Axis      xAxis = pane.XAxis;
                ZedGraph.Axis      yAxis = pane.YAxis;
                yAxis.Scale.MinAuto = false;
                yAxis.Scale.Min     = 0;

                // setup axes scales to enable the Transform method
                xAxis.Scale.SetupScaleData(pane, xAxis);
                yAxis.Scale.SetupScaleData(pane, yAxis);

                Graphics g = zedGraphControl1.CreateGraphics();
                //pane.Draw( g );
                pane.CurveList.Draw(g, pane, 1.0f);
                System.Drawing.Bitmap gmap = new Bitmap(Convert.ToInt32(pane.Rect.Width), Convert.ToInt32(pane.Rect.Height));
                zedGraphControl1.DrawToBitmap(gmap, Rectangle.Round(pane.Rect));
                Region chartRegion = new Region(pane.Chart.Rect);
                Region clipRegion  = new Region();
                clipRegion.MakeEmpty();
                g.SetClip(zedGraphControl1.MasterPane.Rect, CombineMode.Replace);
                g.SetClip(chartRegion, CombineMode.Exclude);

                /*Bitmap clipBmp = new Bitmap( Convert.ToInt32( pane.Rect.Width ), Convert.ToInt32( pane.Rect.Height ) );
                 * Graphics clipG = Graphics.FromImage( clipBmp );
                 * clipG.Clear( Color.White );
                 * clipG.FillRegion( new SolidBrush( Color.Black ), g.Clip );
                 * clipBmp.Save( "C:\\clip.bmp" );*/

                PointDataMap <SeemsPointAnnotation> matchedAnnotations = new PointDataMap <SeemsPointAnnotation>();

                // add automatic labels
                foreach (ZedGraph.CurveItem curve in pane.CurveList)
                {
                    SeemsPointList pointList = (SeemsPointList)curve.Points;
                    for (int i = 0; i < pointList.MaxCount; i++)
                    {
                        ZedGraph.PointPair pt = pointList.GetPointAtIndex(pointList.ScaledMaxIndexList[i]);
                        if (pt.X < xAxis.Scale.Min || pt.Y > yAxis.Scale.Max || pt.Y < yAxis.Scale.Min)
                        {
                            continue;
                        }
                        if (pt.X > xAxis.Scale.Max)
                        {
                            break;
                        }

                        StringBuilder pointLabel = new StringBuilder();
                        Color         pointColor = curve.Color;

                        // Add annotation
                        double annotationX = 0.0;
                        SeemsPointAnnotation annotation = null;
                        if (CurrentScan.IsMassSpectrum)
                        {
                            PointDataMap <SeemsPointAnnotation> .MapPair annotationPair = AnnotationSettings.ScanPointAnnotations.FindNear(pt.X, AnnotationSettings.ScanMatchTolerance);
                            if (annotationPair != null)
                            {
                                annotationX = annotationPair.Key;
                                annotation  = annotationPair.Value;
                                matchedAnnotations.Add(annotationPair);
                            }
                        }
                        else
                        {
                            PointDataMap <SeemsPointAnnotation> .MapPair annotationPair = AnnotationSettings.ChromatogramPointAnnotations.FindNear(pt.X, AnnotationSettings.ChromatogramMatchTolerance);
                            if (annotationPair != null)
                            {
                                annotationX = annotationPair.Key;
                                annotation  = annotationPair.Value;
                                matchedAnnotations.Add(annotationPair);
                            }
                        }

                        if (AnnotationSettings.ShowMatchedAnnotations && annotation != null)
                        {
                            pointLabel.AppendLine(annotation.Label);
                            pointColor = annotation.Color;
                            //if( curve is ZedGraph.StickItem )
                            {
                                ZedGraph.LineObj stickOverlay = new ZedGraph.LineObj(annotationX, 0, annotationX, pt.Y);
                                //stickOverlay.IsClippedToChartRect = true;
                                stickOverlay.Location.CoordinateFrame = ZedGraph.CoordType.AxisXYScale;
                                stickOverlay.Line.Width = annotation.Width;
                                stickOverlay.Line.Color = pointColor;
                                zedGraphControl1.GraphPane.GraphObjList.Add(stickOverlay);
                                dataLabels.Add(stickOverlay);
                                //( (ZedGraph.StickItem) curve ).Color = pointColor;
                                //( (ZedGraph.StickItem) curve ).Line.Width = annotation.Width;
                            }
                        }

                        if (CurrentScan.IsMassSpectrum)
                        {
                            if (AnnotationSettings.ShowScanPointMZs)
                            {
                                pointLabel.AppendLine(pt.X.ToString("f2"));
                            }
                            if (AnnotationSettings.ShowScanPointIntensities)
                            {
                                pointLabel.AppendLine(pt.Y.ToString("f2"));
                            }
                        }
                        else
                        {
                            if (AnnotationSettings.ShowChromatogramPointTimes)
                            {
                                pointLabel.AppendLine(pt.X.ToString("f2"));
                            }
                            if (AnnotationSettings.ShowChromatogramPointIntensities)
                            {
                                pointLabel.AppendLine(pt.Y.ToString("f2"));
                            }
                        }

                        string pointLabelString = pointLabel.ToString();
                        if (pointLabelString.Length == 0)
                        {
                            continue;
                        }

                        // Create a text label from the X data value
                        ZedGraph.TextObj text = new ZedGraph.TextObj(pointLabelString, pt.X, yAxis.Scale.ReverseTransform(yAxis.Scale.Transform(pt.Y) - 5),
                                                                     ZedGraph.CoordType.AxisXYScale, ZedGraph.AlignH.Center, ZedGraph.AlignV.Bottom);
                        text.ZOrder = ZedGraph.ZOrder.A_InFront;
                        //text.IsClippedToChartRect = true;
                        text.FontSpec.FontColor = pointColor;
                        // Hide the border and the fill
                        text.FontSpec.Border.IsVisible = false;
                        text.FontSpec.Fill.IsVisible   = false;
                        //text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) );
                        // Rotate the text to 90 degrees
                        text.FontSpec.Angle = 0;

                        string shape, coords;
                        text.GetCoords(pane, g, 1.0f, out shape, out coords);
                        if (shape != "poly")
                        {
                            throw new InvalidOperationException("shape must be 'poly'");
                        }
                        string[] textBoundsPointStrings = coords.Split(",".ToCharArray());
                        if (textBoundsPointStrings.Length != 9)
                        {
                            throw new InvalidOperationException("coords length must be 8");
                        }
                        Point[] textBoundsPoints = new Point[]
                        {
                            new Point(Convert.ToInt32(textBoundsPointStrings[0]), Convert.ToInt32(textBoundsPointStrings[1])),
                            new Point(Convert.ToInt32(textBoundsPointStrings[2]), Convert.ToInt32(textBoundsPointStrings[3])),
                            new Point(Convert.ToInt32(textBoundsPointStrings[4]), Convert.ToInt32(textBoundsPointStrings[5])),
                            new Point(Convert.ToInt32(textBoundsPointStrings[6]), Convert.ToInt32(textBoundsPointStrings[7]))
                        };
                        byte[] textBoundsPointTypes = new byte[]
                        {
                            (byte)PathPointType.Start,
                            (byte)PathPointType.Line,
                            (byte)PathPointType.Line,
                            (byte)PathPointType.Line
                        };
                        GraphicsPath textBoundsPath = new GraphicsPath(textBoundsPoints, textBoundsPointTypes);
                        textBoundsPath.CloseFigure();
                        Region textBoundsRegion = new Region(textBoundsPath);
                        textBoundsRegion.Intersect(pane.Chart.Rect);
                        RectangleF[] textBoundsRectangles = textBoundsRegion.GetRegionScans(g.Transform);

                        bool overlapDetected = false;
                        for (int j = 0; j < textBoundsRectangles.Length && !overlapDetected; ++j)
                        {
                            if (g.Clip.IsVisible(textBoundsRectangles[j]))
                            {
                                overlapDetected = true;
                            }

                            for (float y = textBoundsRectangles[j].Top; y <= textBoundsRectangles[j].Bottom && !overlapDetected; ++y)
                            {
                                for (float x = textBoundsRectangles[j].Left; x <= textBoundsRectangles[j].Right && !overlapDetected; ++x)
                                {
                                    if (gmap.GetPixel(Convert.ToInt32(x), Convert.ToInt32(y)).ToArgb() != pane.Chart.Fill.Color.ToArgb())
                                    {
                                        overlapDetected = true;
                                    }
                                }
                            }
                        }
                        if (!overlapDetected)
                        {
                            pane.GraphObjList.Add(text);
                            clipRegion.Union(textBoundsRegion);
                            //g.SetClip( chartRegion, CombineMode.Replace );
                            g.SetClip(clipRegion, CombineMode.Replace);
                            //clipG.Clear( Color.White );
                            //clipG.FillRegion( new SolidBrush( Color.Black ), g.Clip );
                            //clipBmp.Save( "C:\\clip.bmp" );
                            dataLabels.Add(text);
                            //text.Draw( g, pane, 1.0f );
                            //zedGraphControl1.DrawToBitmap( gmap, Rectangle.Round( pane.Rect ) );
                        }
                    }
                }

                if (AnnotationSettings.ShowUnmatchedAnnotations)
                {
                    PointDataMap <SeemsPointAnnotation> annotations;
                    if (CurrentScan.IsMassSpectrum)
                    {
                        annotations = AnnotationSettings.ScanPointAnnotations;
                    }
                    else
                    {
                        annotations = AnnotationSettings.ChromatogramPointAnnotations;
                    }

                    foreach (PointDataMap <SeemsPointAnnotation> .MapPair annotationPair in annotations)
                    {
                        if (matchedAnnotations.Contains(annotationPair))
                        {
                            continue;
                        }

                        float            stickLength  = (yAxis.MajorTic.Size * 2) / pane.Chart.Rect.Height;
                        ZedGraph.LineObj stickOverlay = new ZedGraph.LineObj(annotationPair.Key, 1, annotationPair.Key, -stickLength);
                        //stickOverlay.IsClippedToChartRect = true;
                        stickOverlay.Location.CoordinateFrame = ZedGraph.CoordType.XScaleYChartFraction;
                        stickOverlay.Line.Width = annotationPair.Value.Width;
                        stickOverlay.Line.Color = annotationPair.Value.Color;
                        zedGraphControl1.GraphPane.GraphObjList.Add(stickOverlay);
                        dataLabels.Add(stickOverlay);
                    }
                }
                g.Dispose();
            }
            else
            {
                // remove labels
            }
        }