Source code for MSQuant: retentionTimePlotting.vb, MSQuant/msquant/src/GUI/retentionTimePlotting.vb.

Table of contents page.

Home page for MSQuant.

'****************************************************************************
'* Copyright (C) 2008 Peter Mortensen and Matthias Mann                     *
'* This file is part of MSQuant.                                            *
'*                                                                          *
'* MSQuant is distributed under the terms of                                *
'* the GNU General Public License. See src/COPYING.TXT or                   *
'* <http://www.gnu.org/licenses/gpl.txt> for details.                       *
'*                                                                          *
'* MSQuant is free software; you can redistribute it                        *
'* and/or modify it under the terms of the GNU                              *
'* General Public License as published by the Free                          *
'* Software Foundation; either version 2 of the                             *
'* License, or (at your option) any later version.                          *
'*                                                                          *
'* MSQuant is distributed in the hope that it will be                       *
'* useful, but WITHOUT ANY WARRANTY; without even the                       *
'* implied warranty of MERCHANTABILITY or FITNESS FOR                       *
'* A PARTICULAR PURPOSE.  See the GNU General Public                        *
'* License for more details.                                                *
'*                                                                          *
'* You should have received a copy of the GNU General                       *
'* Public License along with MSQuant; if not, write to                      *
'* the Free Software Foundation, Inc., 59 Temple                            *
'* Place, Suite 330, Boston, MA  02111-1307  USA                            *
'*                                                                          *
'* Purpose: Encapsulates/handles plotting of LC profiles and other          *
'*          things related to retention time using a passed                 *
'*          instance of the ZedGraph .NET component. While used             *
'*          from the application quantitation window it is independent      *
'*          and could be used by other clients.                             *
'*                                                                          *
'****************************************************************************

'****************************************************************************
'*                               CEBI                                       *
'*                    Software Development Group                            *
'*                         Peter Mortensen                                  *
'*                E-mail: NUKESPAMMERSdrmortensen@get2netZZZZZZ.dk          *
'*                 WWW: http://www.cebi.sdu.dk/                             *
'*                                                                          *
'*  Program for post-processing of result from search in mass               *
'*    spectrometric data.                                                   *
'*                                                                          *
'*    FILENAME:   retentionTimePlotting.vb                                  *
'*    TYPE:  VISUAL_BASIC                                                   *
'*                                                                          *
'* CREATED: PM 2008-01-22   Vrs 1.0. Estimated date.                        *
'* UPDATED: PM 2008-xx-xx                                                   *
'*                                                                          *
'****************************************************************************

Option Strict On
Option Explicit On

Imports System.Text  'For StringBuilder

Imports MolecularSharedStructures 'For PeptideHitStructure.
Imports ZedGraph


'****************************************************************************
'*    <placeholder for header>                                              *
'****************************************************************************
Public Class retentionTimePlotting

    Private mLCcolours() As Color = _
      {Color.DarkBlue, _
       Color.DarkRed, _
       Color.DarkGreen, _
       Color.DarkOrange, _
       Color.Yellow, _
 _
       Color.Violet, _
       Color.Brown, _
       Color.DarkSlateBlue, _
       Color.DarkSalmon _
      }

    Private mSymbolTypes() As SymbolType = _
      {SymbolType.Diamond, _
       SymbolType.XCross, _
       SymbolType.Triangle, _
       SymbolType.Circle, _
       SymbolType.Plus, _
 _
       SymbolType.Square, _
       SymbolType.Star, _
       SymbolType.TriangleDown, _
       SymbolType.Diamond _
      }


    Public Enum retTplotTypeEnum
        enumLCprofilePlot = 401
        enumQuantRatiosPlot
    End Enum 'retTplotTypeEnum


    Private mZedGraphControl As ZedGraph.ZedGraphControl

    Private mLCprofiles() As ZedGraph.PointPairList

    Private mRatios() As ZedGraph.PointPairList

    Private mQueryNumber As Integer

    'This does not work as ZoomStateStack is read-only....
    'Private mRestoreZoom_LC As Boolean
    'Private mRestoreZoom_ratio As Boolean
    'Private mZoomState_LC As ZedGraph.ZoomStateStack
    'Private mZoomState_ratio As ZedGraph.ZoomStateStack


    Private mScratchSB As StringBuilder


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Sub New( _
      ByRef anInZedGraphControl As ZedGraph.ZedGraphControl)

        MyBase.New()

        mZedGraphControl = anInZedGraphControl

        'mRestoreZoom_LC = False
        'mRestoreZoom_ratio = False
    End Sub 'New


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Sub setData( _
      ByRef anInPept As PeptideHitStructure)
        '  ByVal aPlotType As retTplotTypeEnum

        'Later: less broad parameter, e.g. perhaps only anInPept.spectra.

        'Later: avoid recomputing the same.

        'Later: just record the information from the peptide and
        '       postpone building up datastructures until there
        '       are actually needed (lazy instantiation).


        Dim dishes As Integer = anInPept.LCprofilesProperties.Count
        If dishes > 0 Then

            If mScratchSB Is Nothing Then
                mScratchSB = New StringBuilder(30)
            End If

            Dim lastDishIndex As Integer = dishes - 1
            ReDim mLCprofiles(lastDishIndex)
            ReDim mRatios(lastDishIndex)

            Dim dish As Integer
            For dish = 0 To lastDishIndex
                Dim dishOneBased As Integer = dish + 1

                'Perhaps later: preallocation through building up
                '               temporary redimmed x and y arrays.
                mLCprofiles(dish) = New PointPairList()
                mRatios(dish) = New PointPairList()

                Dim lastIndex As Integer = anInPept.spectra.Count - 1
                Dim i As Integer
                For i = 0 To lastIndex
                    Dim specQuant As SpecQuantStructure = anInPept.spectra(i)

                    Dim retTsecs As Double = specQuant.retT
                    Dim retTmins As Double = retTsecs / 60.0

                    Dim quantItem As shortFormSILACinfoStructure = _
                      specQuant.dishInfo(dish)

                    If True Then 'LC profile
                        Dim MSpeakArea As Double = quantItem.MSpeakArea2

                        'Changed PM_MARKER_USEOF_APPENDFORMAT 2008-02-14
                        '  .AppendFormat("{0, 10:f3}", myFloat);
                        'Sample at:
                        '  http://www.java2s.com/Code/CSharp/Language-Basics/StringBuilderAppendFormatmethodtoaddaformattedstringcontainingafloatingpointnumbertomyStringBuilder.htm
                        '
                        'mScratchSB.AppendFormat( _
                        '  "{0, 6:f3} min, {1, 10:f1}. Ratio ?.", _
                        '  retTmins, MSpeakArea)) 'Will be
                        ''  e.g. XXXX.

                        'Changed PM_PM_LCPROFILE_MODERNPLOT_FEWER_DECIMALS 2008-02-14
                        'Dim tag2 As String = Nothing '"Nothing" is needed for
                        ''  ZedGraph's default behavior.
                        mScratchSB.Length = 0

                        mScratchSB.Append("Dish ")
                        mScratchSB.Append(dishOneBased.ToString())
                        mScratchSB.Append(". ")

                        mScratchSB.Append(retTmins.ToString("0.000"))
                        mScratchSB.Append(" mins, ")
                        mScratchSB.Append(MSpeakArea.ToString("0.0"))
                        mScratchSB.Append(" Th*counts. ")

                        'Temporary - for debugging. Can be eliminated.
                        Dim tag2 As String = mScratchSB.ToString()

                        mLCprofiles(dish).Add(retTmins, MSpeakArea, tag2)
                    End If 'Block, 

                    If True Then 'Ratios
                        Dim ratio As Double = quantItem.MSpeakAreaRatioToBase

                        'Avoid the infinities.
                        'If ratio < 0.02 Or ratio > 50.0 Then '
                        If ratio < 0.01 Or ratio > 100.0 Then
                            'ratio = -0.5
                            ratio = 100.0
                        End If

                        Dim effectiveRatioValue As Double

                        'Changed PM_LCPROFILE_MODERNPLOT_LOGSCALE 2008-01-31. Use
                        'ZedGraph's log scale instead.
                        'effectiveRatioValue = Math.Log10(ratio) 'Only log for now.
                        effectiveRatioValue = ratio

                        'Changed PM_PM_LCPROFILE_MODERNPLOT_FEWER_DECIMALS 2008-02-14
                        'Dim tag3 As String = Nothing '"Nothing" is needed for
                        '  ZedGraph's default behavior.
                        mScratchSB.Length = 0
                        mScratchSB.Append(retTmins.ToString("0.000"))
                        mScratchSB.Append(" mins, ")
                        mScratchSB.Append(effectiveRatioValue.ToString("0.00"))
                        mScratchSB.Append(" ")
                        mScratchSB.Append(dishOneBased.ToString())
                        mScratchSB.Append("/1")
                        Dim tag3 As String = mScratchSB.ToString()

                        mRatios(dish).Add(retTmins, effectiveRatioValue, tag3)
                    End If 'Block, ratios.

                    If specQuant.useForQuant_WT Then
                        Dim peter2 As Integer = 2
                    End If
                Next i
            Next dish

            If True Then
                'drawVerticalMarker(anInPept.MSMSretentionTimeMinutes * 60, _
                '  Color.Black, xOffset, xScaleFactor, yOffset, mLCG)
                'drawVerticalMarker(anInPept.retentionTimeCentroid_secs, _
                '  Color.Violet, xOffset, xScaleFactor, yOffset, mLCG)
                'drawVerticalMarker(anInPept.LCpeakDetectionTimeCentroidSeconds, _
                '  Color.LightGreen, xOffset, xScaleFactor, yOffset, mLCG)
            End If

            mQueryNumber = anInPept.queryNumber
        End If 'Quantitation result exists.

        ''Immediately update the visual display. Is this bad separation
        ''between data structures and user interface?
        'setDisplayType(aPlotType)
    End Sub 'setData


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Sub setDisplayType(ByVal aPlotType As retTplotTypeEnum)

        Dim qStr As String = "Query " & mQueryNumber & "."

        Select Case aPlotType
            Case retTplotTypeEnum.enumLCprofilePlot

                If Not mLCprofiles Is Nothing Then 'Can happen when the protein 
                    '  is initially opened and this option is chosen (or
                    '  selected by default).

                    Dim graphTitle As String = _
                      "LC profiles. " & qStr
                    CreateGraph_LCprofile( _
                      mZedGraphControl, graphTitle, mLCprofiles)
                End If

            Case retTplotTypeEnum.enumQuantRatiosPlot

                If Not mRatios Is Nothing Then 'Can happen when the protein 
                    '  is initially opened and this option is chosen (or
                    '  selected by default).

                    Dim graphTitle As String = _
                      "Quant ratios. " & qStr
                    CreateGraph_ratios(mZedGraphControl, graphTitle, mRatios)
                End If

            Case Else
                Trace.Assert(False, _
                  "PIL ASSERT. Select Case never fall-through")
        End Select
    End Sub 'setDisplayType


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Sub commonGraph( _
      ByRef anInOutZgc As ZedGraphControl, _
      ByRef anInTitle As String, _
     ByRef anOutPane As GraphPane)

        ' Get a reference to the GraphPane. Note: this does not create a new
        ' one with some defaults. If a plot is already active then we get
        ' the current settings...
        anOutPane = anInOutZgc.GraphPane

        anOutPane.CurveList.Clear()

        'Defaults. Important if changing back to a pane
        'that relies on some defaults.
        anOutPane.XAxis.Type = AxisType.Linear

        'Changed PM_LCPROFILE_MODERNPLOT_LOGSCALE 2008-01-31
        anOutPane.YAxis.Type = AxisType.Linear

        'Changed PM_RECALIB_VISUAL_BINNING_BROKEN 2007-11-26
        'Important as for 2 out of 3 types of plots we now set 
        'the x-axis manually.
        anOutPane.XAxis.Scale.MinAuto = True
        anOutPane.XAxis.Scale.MaxAuto = True

        If True Then
            anOutPane.XAxis.Scale.TextLabels = Nothing
            anOutPane.XAxis.MajorTic.IsBetweenLabels = False

            anOutPane.Chart.Fill = New Fill()
            anOutPane.Fill = New Fill()
        End If

        anOutPane.Title.Text = anInTitle

        anInOutZgc.IsShowPointValues = True
    End Sub 'commonGraph


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Sub updateForNewData( _
      ByRef anInOutZgc As ZedGraphControl)

        'If user zoomed: maintain x-axis scaling. But auto-scale y as the 
        '  units may be vastly different, e.g. around 1.0 for quant 
        '  ratios and 6000 for absolute quant values.

        'Pane: property ZoomStack, list of ZoomState.

        'Each axis:

        'anInOutZgc.ZoomOutAll()
        'anInOutZgc.
        'ZedGraph.

        '  ZoomStateStack 
        Dim pane2 As GraphPane = anInOutZgc.GraphPane
        Dim zoomState2 As ZedGraph.ZoomStateStack = pane2.ZoomStack

        ' Tell ZedGraph to refigure the
        ' axes since the data have changed.
        '
        ' The AxisChange() method call must be made
        ' any time you add or change the data.
        anInOutZgc.AxisChange()

        'anInOutZgc.Refresh()
        anInOutZgc.Invalidate()
    End Sub 'updateForNewData


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub CreateGraph_LCprofile( _
      ByRef anInOutZgc As ZedGraphControl, _
      ByRef anInTitle As String, _
      ByRef anInSomeData() As PointPairList)

        Dim myPane As GraphPane = Nothing 'Keep compiler happy.
        commonGraph(anInOutZgc, anInTitle, myPane)

        myPane.XAxis.Title.Text = "Retention time [min]"
        myPane.YAxis.Title.Text = "MS peak area [Th*counts]"

        myPane.YAxis.MajorGrid.IsVisible = True
        myPane.YAxis.MajorGrid.DashOn = 5
        myPane.YAxis.MajorGrid.Color = Color.BlueViolet

        Dim dishes As Integer = anInSomeData.GetLength(0)
        Dim lastIndex As Integer = dishes - 1
        Dim j As Integer
        For j = 0 To lastIndex

            'Perhaps cache the labels in a member variable.
            Dim oneBased As Integer = j + 1
            Dim curveLabel As String = "Dish " & oneBased

            Dim LCcolour As Color = mLCcolours(j)
            Dim plotSymbol As SymbolType = mSymbolTypes(j)
            Dim myCurve As LineItem = myPane.AddCurve( _
              curveLabel, _
              anInSomeData(j), LCcolour, plotSymbol)

            'myCurve.Line.Fill = New Fill(LCcolour)
            myCurve.Line.Fill = New Fill()

            ''Turn off the line so it's a scatter plot.
            'myCurve.Line.IsVisible = False

            'Perhaps later:
            'myPane.XAxis.Scale.Min = aDataRanges.minX - 30.0
            'myPane.XAxis.Scale.Max = aDataRanges.maxX + 30.0
        Next j

        updateForNewData(anInOutZgc)
    End Sub 'CreateGraph_LCprofile


    'Note: refactoring opportunities with CreateGraph_LCprofile().
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub CreateGraph_ratios( _
      ByRef anInOutZgc As ZedGraphControl, _
      ByRef anInTitle As String, _
      ByRef anInSomeData() As PointPairList)

        Dim myPane As GraphPane = Nothing 'Keep compiler happy.
        commonGraph(anInOutZgc, anInTitle, myPane)

        myPane.XAxis.Title.Text = "Retention time [min]"
        myPane.YAxis.Title.Text = "MS peak area ratio []"

        myPane.YAxis.MajorGrid.IsVisible = True
        myPane.YAxis.MajorGrid.DashOn = 5
        myPane.YAxis.MajorGrid.Color = Color.Red

        'Changed PM_LCPROFILE_MODERNPLOT_LOGSCALE 2008-01-31
        myPane.YAxis.Type = AxisType.Log


        Dim dishes As Integer = anInSomeData.GetLength(0)
        Dim lastIndex As Integer = dishes - 1
        Dim j As Integer
        For j = 0 To lastIndex

            'Perhaps cache the labels in a member variable.
            Dim oneBased As Integer = j + 1
            Dim curveLabel As String = "Dish " & oneBased

            Dim LCcolour As Color = mLCcolours(j)
            Dim plotSymbol As SymbolType = mSymbolTypes(j)
            Dim myCurve As LineItem = myPane.AddCurve( _
              curveLabel, _
              anInSomeData(j), LCcolour, plotSymbol)

            'myCurve.Line.Fill = New Fill(LCcolour)
            myCurve.Line.Fill = New Fill()

            ''Turn off the line so it's a scatter plot.
            'myCurve.Line.IsVisible = False

            'Perhaps later:
            'myPane.XAxis.Scale.Min = aDataRanges.minX - 30.0
            'myPane.XAxis.Scale.Max = aDataRanges.maxX + 30.0
        Next j

        updateForNewData(anInOutZgc)
    End Sub 'CreateGraph_ratios


End Class 'retentionTimePlotting




    

    

Generated by script codePublish.pl at 2009-01-05T15:20:59.