예제 #1
0
        /// <summary>
        /// This function generates a LadderInstance based upon the given theoryList and the given peptide.
        /// </summary>
        /// <param name="theoryList">A list of elements that have been processed through the ComparedListBuilder.</param>
        /// <param name="peptide">The Peptide sequence that the List of Elements are generated from.</param>
        /// <returns></returns>
        public LadderInstance GenerateInstance(List <SpectrumLook.Builders.Element> theoryList, string peptide, Dictionary <char, double> modificationValues)
        {
            int             i = 0;
            List <string[]> tempListHolder         = new List <string[]>();
            List <string>   tempListColumnOptions  = new List <string>();
            LadderInstance  returnedLadderInstance = new LadderInstance();

            foreach (SpectrumLook.Builders.Element currentElement in theoryList)
            {
                i = 0;
                if (!(tempListColumnOptions.Contains(spliceNumberFromAnnotation(currentElement.Annotation))))
                {
                    //Need to filter out Modification values when calculating the length of the string.
                    tempListHolder.Add(new string[peptideLength(peptide, modificationValues)]);
                    tempListColumnOptions.Add(spliceNumberFromAnnotation(currentElement.Annotation));
                }
                //Find the index to add.
                while (tempListColumnOptions[i] != spliceNumberFromAnnotation(currentElement.Annotation))
                {
                    ++i;
                }
                string tempDoubleString = string.Format("{0:#.00}", currentElement.Mz);
                try
                {
                    tempListHolder[i][unformatAnnotation(currentElement.Annotation) - 1] = tempDoubleString + "|" + currentElement.Matched.ToString();
                }
                catch { }
            }

            for (i = 0; i < tempListColumnOptions.Count; ++i)
            {
                for (int j = 0; j < tempListHolder[i].Length; ++j)
                {
                    if (tempListHolder[i][j] == null)
                    {
                        tempListHolder[i][j] = "";
                    }
                }
            }

            returnedLadderInstance.mzValue        = tempListHolder;
            returnedLadderInstance.mzValueHeaders = tempListColumnOptions;
            return(returnedLadderInstance);
        }
예제 #2
0
        /// <summary>
        /// Adds annotations from the matchedPoints to the Graph Pane
        /// Plot Options specify how much of the top % of annotations to display, along with size and color.
        /// </summary>
        /// <param name="pointsList"></param>
        /// <param name="myPane"></param>
        private void AddAnnotations(IPointList pointsList, GraphPane myPane)
        {
            //add the annotations for the matched items
            double         offset = 5;
            double         minIntensityToDisplay = FindMinIntensityToDisplay(pointsList);
            LadderInstance currentInstance       = m_manager.GetCurrentInstance();

            for (int i = 0; i < pointsList.Count; i++)
            {
                bool    usingCustomAnnotation = false;
                TextObj text = new TextObj();

                //look for if the user has defined a custom annotation if they have we deal with that instead of making a new one
                for (int j = 0; j < currentInstance.annotations.Count; j++)
                {
                    if ((currentInstance.annotations[j].m_point.X == pointsList[i].X) &&
                        (currentInstance.annotations[j].m_point.Y == pointsList[i].Y))
                    {
                        usingCustomAnnotation = true;
                        Annotation customAnnotation = currentInstance.annotations[j];
                        PointPair  pt = pointsList[i];

                        // Create a text label from the Y data value
                        text = new TextObj(customAnnotation.m_text, pt.X, pt.Y + offset,
                                           CoordType.AxisXYScale, AlignH.Left, AlignV.Center);

                        // Store the point into the text object's tag
                        text.Tag = (object)pt;

                        if (customAnnotation.m_showHideAuto > 0)
                        {
                            // Always show this annotation
                            text.IsVisible = true;
                        }
                        else if (customAnnotation.m_showHideAuto < 0)
                        {
                            // Always hide this annotation
                            text.IsVisible = false;
                        }
                        else if (pt.Y <= minIntensityToDisplay)
                        {
                            // Auto Determine if we are going to show the annotation for this point
                            text.IsVisible = false;
                        }

                        break;
                    }
                }

                if (!usingCustomAnnotation)
                {
                    // Get the pointpair
                    PointPair pt = pointsList[i];

                    // Create a text label from the Y data value
                    string tagText;
                    if (pt.Tag != null)
                    {
                        tagText = pt.Tag as string;
                    }
                    else
                    {
                        tagText = string.Empty;
                    }

                    text = new TextObj(tagText, pt.X, pt.Y + offset,
                                       CoordType.AxisXYScale, AlignH.Left, AlignV.Center);

                    // Store the point into the text object's tag
                    text.Tag = (object)pt;

                    // Determine if we are going to show the annotation for this point
                    if (pt.Y <= minIntensityToDisplay)
                    {
                        text.IsVisible = false;
                    }
                }

                text.IsClippedToChartRect = true; //set true because we want the annotations to hide when they go off the borders of the graph
                text.FontSpec.Size        = m_options.annotationTextSize;
                text.FontSpec.FontColor   = m_options.annotationColor;
                text.ZOrder = ZOrder.C_BehindChartBorder;

                // Hide the border and the fill
                text.FontSpec.Border.IsVisible = false;
                text.FontSpec.Fill.IsVisible   = false;

                // Rotate the text to 90 degrees
                text.FontSpec.Angle = 90;

                myPane.GraphObjList.Add(text);
            }
        }
예제 #3
0
        /// <summary>
        /// Handles selecting the nearest peptide to edit the annotation for, and showing the editAnnotation form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void msPlot_DoubleClick(object sender, EventArgs e)
        {
            bool           usingCustomAnnotation = false;
            MouseEventArgs mouseArgs             = (MouseEventArgs)e;
            Graphics       g = msPlot.CreateGraphics();
            GraphPane      closestPane;
            PointPair      closestPoint;
            PointF         mousePt         = new PointF(mouseArgs.X, mouseArgs.Y);
            TextObj        selectedTextObj = null;

            //retrieve the text object that the user may have selected
            if (msPlot.FindClosestPoint(mousePt, out closestPoint, out closestPane))
            {
                foreach (GraphObj textObject in closestPane.GraphObjList)
                {
                    if (textObject.Tag == closestPoint)
                    {
                        //zed graph found the annotation object, use that text object
                        selectedTextObj = textObject as TextObj;
                        break;
                    }
                }
            }
            else
            {
                //couldn't find the annotation from where the user clicked
                return;
            }

            if (selectedTextObj == null)
            {
                return; //no obj, so don't do anything
            }
            //see if we have a custom annotation for this annotation we selected
            LadderInstance currentInstance    = m_manager.GetCurrentInstance();
            Annotation     selectedAnnotation = new Annotation();

            foreach (Annotation annotation in currentInstance.annotations)
            {
                if (annotation.m_point == (PointPair)selectedTextObj.Tag)
                {
                    usingCustomAnnotation = true;
                    selectedAnnotation    = annotation;
                    currentInstance.annotations.Remove(annotation);
                    break;
                }
            }
            if (selectedAnnotation.m_point == null && selectedAnnotation.m_text == null)
            {
                selectedAnnotation.m_showHideAuto = 0;
                selectedAnnotation.m_text         = selectedTextObj.Text;
                selectedAnnotation.m_point        = (PointPair)selectedTextObj.Tag;
            }

            // Open the AnnotationEdit form
            PlotView.AnnotationEdit editForm = new PlotView.AnnotationEdit(selectedAnnotation);
            if (editForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (editForm.m_annotation.m_showHideAuto < 0)
                {
                    selectedTextObj.IsVisible = false;
                }
                else if (editForm.m_annotation.m_showHideAuto > 0)
                {
                    selectedTextObj.IsVisible = true;
                }
                selectedTextObj.Text = editForm.m_annotation.m_text;

                currentInstance.annotations.Add(editForm.m_annotation);
            }
            else if (usingCustomAnnotation)
            {
                //recreate the annotation we thought we were replacing
                currentInstance.annotations.Add(selectedAnnotation);
            }

            msPlot.ReevaluateAnnotations();
            msPlot.Invalidate();
            return;
        }