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

Table of contents page.

Home page for MSQuant.

'****************************************************************************
'* Copyright (C) 2007 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: plotting of recalibration related values.                       *
'*                                                                          *
'****************************************************************************

'****************************************************************************
'*                               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:   frmPeptideFilters.vb                                      *
'*    TYPE:  VISUAL_BASIC                                                   *
'*                                                                          *
'* CREATED: PM 2007-09-02   Vrs 1.0.                                        *
'* UPDATED: PM 2007-xx-xx                                                   *
'*                                                                          *
'****************************************************************************

Option Strict On
Option Explicit On

Imports System.Text  'For StringBuilder

Imports System
Imports System.Reflection 'For MemberInfo.

Imports System.Collections.Generic 'For Dictionary


Imports ZedGraph


Imports SDUPutility 'For SDUPstatistics

Imports massSpectrometryBase 'For peptideFilterSpecificationStructure.
Imports MolecularSharedStructures 'For ProteinHitStructure.

Imports App 'For class quantApplication


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


    Private Structure MCRpoint
        Dim MCR As Double 'Depends 
        Dim calibratedMCR As Double
        Dim MCRdiff As Double 'Derived, difference of the two above.

        Dim MCRrelDiff As Double 'Relative version of MCRdiff. In ppm.

        Dim effectiveDiffValue As Double 'Depends on unit, Th, mTH, Da, ppm, etc.
    End Structure 'MCRpoint


    'Not needed. Delete at any time.
    ''Changed PM_RECALIB_VISUAL_TRENDLINE 2007-12-05
    'Private mLowestMCR As MCRpoint
    'Private mMiddleMCR As MCRpoint 'To make non-linear line in MCR clear for
    ''  e.g. frequency domain recalibration.
    'Private mHighestMCR As MCRpoint

    Private mUncalibMassErrors As PointPairList
    Private mCaliMassErrors As PointPairList

    'Changed PM_RECALIB_VISUAL_TRENDLINE 2007-12-07
    Private mTrendLine As PointPairList 'E.g 3 poins: for lowest, highest
    '  and in-between MCR. Or 5 points.

    'Changed PM_PLOTSPACE 2007-11-17
    Private mUncalibValues As statsStructure 'For manual control
    '  of Xaxis zoom state. The default choices of ZedGraph seems
    '  to inappropriate.

    Private mUncalibBinArray As Double()
    Private mUncalibBinXlabels As String()

    Private mCalibBinArray As Double()
    Private mCalibBinXlabels As String()
    Private mBinSize As Double

    Private mUncalibMedianErrors As PointPairList
    Private mCalibMedianErrors As PointPairList

    'Changed PM_RECALIB_VISUAL_BYRETENTIONTIME 2008-02-28
    Private mUncalibRetTvsMassErrors As PointPairList
    Private mCalibRetTvsMassErrors As PointPairList

    Private mProteinsSubset As Generic.List(Of Integer)
    Private mProteinList As Generic.List(Of ProteinHitStructure)
    Private mPeptideFilter As peptideFilterStructure

    Private mApplication As quantApplication

    'Changed PM_RAWFILE_PEPFILTER 2007-11-17
    Private mRawFiles() As fileSpecStructure

    'Changed PM_SILAC_AWARE_PEPTIDEFILTERDIALOG 2008-10-05
    Private mSILACmods As Dictionary(Of Integer, Integer)


    Private mStartingUp As Boolean

    Private mCurMassAccUnit As massErrorUnitEnum
    Private mDisplayType As massErrorDisplayTypeEnum

    'Changed PM_RECALIB_VISUAL_ID_IN_TITLE 2007-11-06
    Private mMascotResultFile As String 'For display in this
    '  window's title line.

    Private mScrapSB As StringBuilder

    'Changed PM_RECALIB_VISUAL_TRENDLINE 2007-12-05
    Private mRecalibrator As SDUPrecalibrator

    Private WithEvents mFilterForm As frmPeptideFilters

    'Changed PM_RECALIB_VISUAL_SAVE 2007-09-04
    'Needed because this dialog can be started from two different places
    'and clients needs to know when this dialog is dismissed (or rather, 
    'right now, when the peptide filter dialog for it is) and with 
    'some data that needs to be persisted.
    Public Event calibVisualDismissed( _
      ByVal aSender As Object, ByVal anEvent As pepFilterEventArgs)

    'Changed PM_RECALIB_VISUAL_CLICK_TO_PEPTIDEINFO 2008-03-12
    Private mParent As frmProteinList

    'Changed PM_TWOLEVEL_WINDOWNUMBERING_PREFIX 2008-12-03
    Private mParseIDnumber As Integer



    Private Enum massErrorUnitEnum
        enumUnitDa = 367
        enumUnitPPM
        enumUnitMilliDa

        'Changed PM_VISUALISATION_ABSOLUTE_MCR 2007-11-02
        enumUnitTh
        enumUnitMilliTh

        enumUnitPPB
    End Enum 'massErrorUnitEnum


    Private Enum massErrorDisplayTypeEnum
        enumByMCR = 367
        enumBinned
        enumMedianErrorByMCR

        'Changed PM_RECALIB_VISUAL_BYRETENTIONTIME 2008-02-28
        enumByRetT
    End Enum 'massErrorDisplayTypeEnum


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Sub New( _
      ByRef aParent As frmProteinList, _
      ByRef aProteinsSubset_dataStructureIndices2 As Generic.List(Of Integer), _
      ByRef aProteinList2 As Generic.List(Of ProteinHitStructure), _
      ByVal aPeptideFilter As peptideFilterStructure, _
      ByRef anApp As quantApplication, _
      ByRef anInMascotResultFile As String, _
      ByRef anInRawFiles() As fileSpecStructure, _
      ByRef anInRecalibrator As SDUPrecalibrator, _
      ByRef aSILACmods As Dictionary(Of Integer, Integer), _
      ByVal aParseIDnumber As Integer _
      )
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        mStartingUp = True

        'Changed PM_RECALIB_VISUAL_CLICK_TO_PEPTIDEINFO 2008-03-12
        mParent = aParent

        'Save for use when the peptide filter changes.
        mProteinsSubset = aProteinsSubset_dataStructureIndices2
        mProteinList = aProteinList2
        mApplication = anApp

        'Changed PM_RAWFILE_PEPFILTER 2007-11-17
        mRawFiles = anInRawFiles

        'Changed PM_RECALIB_VISUAL_TRENDLINE 2007-12-05
        mRecalibrator = anInRecalibrator

        'Changed PM_SILAC_AWARE_PEPTIDEFILTERDIALOG 2008-10-05
        mSILACmods = aSILACmods

        'Changed PM_TWOLEVEL_WINDOWNUMBERING_PREFIX 2008-12-03
        mParseIDnumber = aParseIDnumber 'Need to save for use in displayData().


        'Changed PM_CANCEL_ALSO_SAVES_PEPTFILT_BUG 2007-09-06. Not
        '  strictly necessary as we don't have a cancel in this
        '  dialog (in fact the settings are directly saved each
        '  time the sub dialog, the peptide filter dialog, is OK'ed),
        'mPeptideFilter = aPeptideFilter
        mPeptideFilter = aPeptideFilter.deepCopy2()

        mBinSize = -1.0 'Undefined. Expected to be set later in initialisation.

        'Changed PM_RECALIB_VISUAL_DEFAULT_THOMSON 2007-11-06
        'mCurMassAccUnit = massErrorUnitEnum.enumUnitDa
        mCurMassAccUnit = massErrorUnitEnum.enumUnitTh

        'Changed PM_RECALIB_VISUAL_DEFAULT_MEDIANERRORS 2007-11-06
        'mDisplayType = massErrorDisplayTypeEnum.enumByMCR
        mDisplayType = _
          massErrorDisplayTypeEnum.enumMedianErrorByMCR

        'Assume all set to false at design time.
        Select Case mCurMassAccUnit
            Case massErrorUnitEnum.enumUnitDa
                rbUnitDa.Checked = True
            Case massErrorUnitEnum.enumUnitPPM
                rbUnitPPM.Checked = True
            Case massErrorUnitEnum.enumUnitMilliDa
                rbUnitMilliDa.Checked = True

                'Changed PM_VISUALISATION_ABSOLUTE_MCR 2007-11-02
            Case massErrorUnitEnum.enumUnitTh
                rbUnitTh.Checked = True
            Case massErrorUnitEnum.enumUnitMilliTh
                rbUnitMilliTh.Checked = True

            Case massErrorUnitEnum.enumUnitPPB
                rbUnitPPB.Checked = True

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

        'Assume all set to false at design time.
        Select Case mDisplayType
            Case massErrorDisplayTypeEnum.enumByMCR
                rbByMCR.Checked = True
            Case massErrorDisplayTypeEnum.enumBinned
                rbBinnedMassErrors.Checked = True
            Case massErrorDisplayTypeEnum.enumMedianErrorByMCR
                rbMedianErrorByMassWindow.Checked = True
            Case Else
                Trace.Assert(False, _
                  "PIL ASSERT. Select Case never fall-through")
        End Select

        'Changed PM_RECALIB_VISUAL_ID_IN_TITLE 2007-11-06
        mMascotResultFile = anInMascotResultFile
    End Sub 'Constructor.


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub frmRecalibrationVisualisation_Load( _
      ByVal aSender As Object, ByVal anEvent As System.EventArgs) _
      Handles Me.Load

        mStartingUp = True 'Just in case.
        Me.updateDisplay()
        mStartingUp = False
    End Sub 'frmRecalibrationVisualisation_Load


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub displayData( _
      ByRef aProteinsSubset_dataStructureIndices2 As Generic.List(Of Integer), _
      ByRef aProteinList2 As Generic.List(Of ProteinHitStructure), _
      ByVal aPeptideFilter As peptideFilterStructure, _
      ByVal aMassAccUnit As massErrorUnitEnum)

        setupDatastructures( _
          aProteinsSubset_dataStructureIndices2, _
          aProteinList2, _
          aPeptideFilter, _
          aMassAccUnit)

        createTheGraphs(aMassAccUnit, mDisplayType)

        updatePeptideFilterSummary(aPeptideFilter)

        Dim peptides As Integer = mUncalibMassErrors.Count()

        'Changed PM_RECALIB_VISUAL_SELECTED_PROTEINS_IN_TITLE 2007-11-26
        Dim useAllProteins As Boolean = _
          aProteinsSubset_dataStructureIndices2 Is Nothing
        Dim titleStr As String = Nothing 'Keep compiler happy.
        If useAllProteins Then
            titleStr = "All proteins"
        Else
            Dim proteins As Integer = aProteinsSubset_dataStructureIndices2.Count()
            titleStr = proteins & " selected proteins"
        End If

        'Changed PM_RECALIB_VISUAL_ID_IN_TITLE 2007-11-06
        ''lblPeptides.Text = peptides & " peptides."
        'Me.Text = "Recalibration Visualisation, " & peptides & " peptides."
        If mScrapSB Is Nothing Then 'Lazy instantitation
            mScrapSB = New StringBuilder(100)
        End If
        mScrapSB.Length = 0

        'Changed PM_TWOLEVEL_WINDOWNUMBERING_PREFIX 2008-12-03
        mScrapSB.Append("#")
        mScrapSB.Append(mParseIDnumber)
        mScrapSB.Append(". ")


        mScrapSB.Append("Recalibration Visualisation. ")

        mScrapSB.Append(titleStr)
        mScrapSB.Append(". ")

        'Changed PM_RECALIB_VISUAL_SELECTED_PROTEINS_IN_TITLE 2007-11-26
        mScrapSB.Append(peptides)
        mScrapSB.Append(" peptides. ")

        mScrapSB.Append(mMascotResultFile)
        Dim windowTitle As String = mScrapSB.ToString()
        Me.Text = windowTitle
    End Sub 'displayData


    'Changed PM_REFACTOR 2007-10-01
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Sub effectiveErrorValues( _
      ByVal anInPept As PeptideHitStructure, _
      ByVal aMassAccUnit As massErrorUnitEnum, _
      ByRef anOutUncalibMCR As Double, _
      ByRef anOutUncalibValue As Double, _
      ByRef anOutCalibValue As Double, _
      ByRef anOutTheoMCR As Double)

        'Changed PM_RECALIB_VISUAL_PLOTX_THEO_MCR 2008-02-28
        '  New parameter: anOutTheoMCR

        Dim uncalibMCR2 As Double = anInPept.measuredMCR
        Dim charge As Integer = anInPept.charge

        Dim theoMCR As Double = _
          PILmassCalc.chargeTransform(anInPept.MascotCalculatedMass, 0, charge)


        Dim merr2 As massErrorStructure = helper.massErrors(anInPept)

        Dim uncalibError As Double = -9.9
        Dim calibError As Double = -19.9

        Select Case aMassAccUnit
            Case massErrorUnitEnum.enumUnitDa

                'Add new option: enumUnitTh
                'Perhaps phase out enumUnitDa and enumUnitMilliDa??

                uncalibError = merr2.uncalibMassError
                calibError = merr2.calibMassError

            Case massErrorUnitEnum.enumUnitPPM
                uncalibError = merr2.uncalibMassRelativeError 'MCR instead?
                calibError = merr2.calibMassRelativeError 'MCR instead?

            Case massErrorUnitEnum.enumUnitMilliDa
                uncalibError = 1000.0 * merr2.uncalibMassError
                calibError = 1000.0 * merr2.calibMassError

                'Changed PM_VISUALISATION_ABSOLUTE_MCR 2007-11-02
            Case massErrorUnitEnum.enumUnitTh
                uncalibError = merr2.uncalibMCRError
                calibError = merr2.calibMCRError

            Case massErrorUnitEnum.enumUnitMilliTh
                uncalibError = 1000.0 * merr2.uncalibMCRError
                calibError = 1000.0 * merr2.calibMCRError

            Case massErrorUnitEnum.enumUnitPPB
                uncalibError = _
                  1000.0 * merr2.uncalibMassRelativeError 'MCR instead?
                calibError = _
                  1000.0 * merr2.calibMassRelativeError 'MCR instead?

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

        anOutUncalibValue = uncalibError
        anOutCalibValue = calibError
        anOutUncalibMCR = uncalibMCR2
        anOutTheoMCR = theoMCR
    End Sub 'effectiveErrorValues


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Sub buildBin( _
      ByRef anInBinningArray As Integer(), _
      ByVal aStartMassError As Double, _
      ByVal aBinSize As Double, _
      ByRef anOutBinningArray As Double(), _
      ByRef anOutXlabels As String() _
      )

        Dim lastIndex As Integer = anInBinningArray.Length() - 1

        ReDim anOutBinningArray(lastIndex)
        ReDim anOutXlabels(lastIndex)

        'First pass. Find bin with max count. To use as
        'center to compute accumulative numbers for each bin.
        Dim indexForMax As Integer = -1
        Dim maxCount As Integer = -1
        Dim countSumInt As Integer = 0 'Deli
        Dim j As Integer
        For j = 0 To lastIndex
            Dim count As Integer = anInBinningArray(j)
            countSumInt += count
            If maxCount < count Then
                maxCount = count
                indexForMax = j
            End If

            anOutBinningArray(j) = count
        Next
        Dim countSum As Double = countSumInt 'Deliberately double. 

        Dim accum(lastIndex) As Double 'Given center bin, symmetrical
        '  extension to the left and to the right, accumulative
        '  percentage: relative number peptides compared to total
        '  that are within a certain mass deviation (from the center bin).
        Dim accumCount As Integer = maxCount
        accum(indexForMax) = 100.0 * accumCount / countSum
        Dim leftIndex As Integer = indexForMax - 1
        Dim rightIndex As Integer = indexForMax + 1

        Dim end2 As Boolean = False
        While Not end2
            Dim leftOn As Boolean = leftIndex >= 0
            Dim rightOn As Boolean = rightIndex <= lastIndex

            If leftOn Then
                accumCount += anInBinningArray(leftIndex)
            End If
            If rightOn Then
                accumCount += anInBinningArray(rightIndex)
            End If

            Dim accumRel As Double = 100.0 * accumCount / countSum

            If leftOn Then
                accum(leftIndex) = accumRel
            End If
            If rightOn Then
                accum(rightIndex) = accumRel
            End If

            leftIndex -= 1
            rightIndex += 1

            If Not leftOn AndAlso Not rightOn Then
                end2 = True
            End If
        End While 'Extending left and right from bin center.

        Dim startMassError As Double = aStartMassError
        Dim endMassError As Double = startMassError + aBinSize

        Dim labelSB As StringBuilder = New StringBuilder(25)

        'Later: save on strings by having strings for start and
        '       end and setting the start str to the end str,
        '       like for the numbers.
        For j = 0 To lastIndex
            Dim count As Integer = anInBinningArray(j)

            labelSB.Length = 0
            If count > 0 Then
                Dim relAccum As Double = accum(j)
                labelSB.Append(relAccum.ToString("0.0"))
                labelSB.Append("%.")
                labelSB.Append(ControlChars.NewLine)
                labelSB.Append("[")

                'Later: significant digits instead of fixed number of digits.
                labelSB.Append(startMassError.ToString("G2"))
                labelSB.Append(";")
                labelSB.Append(endMassError.ToString("G2"))
                labelSB.Append("]")
            End If
            anOutXlabels(j) = labelSB.ToString()

            startMassError = endMassError
            endMassError += aBinSize
        Next
    End Sub 'buildBin


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Function initStatArray( _
      ByVal aSize As Integer) _
      As statsStructure()

        Dim lastIndex As Integer = aSize - 1

        Dim toReturn(lastIndex) As statsStructure

        Dim j As Integer
        For j = 0 To lastIndex Step 1
            toReturn(j) = New statsStructure(j, True, False)
        Next j

        Return toReturn
    End Function 'initStatArray


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Function setupMCRpoint( _
      ByVal anUncalibMCRvalue As Double, _
      ByRef anInRecalibrator As SDUPrecalibrator, _
      ByVal aCalibID As Integer, _
      ByVal aMassAccUnit As massErrorUnitEnum, _
      ByRef anInOutTrendLine As PointPairList) _
      As MCRpoint

        'Trendline: effectively zero error points in the calibrated domain are
        '  transformed into a non-zero error in the uncalibrated domain.

        Dim toReturn As MCRpoint
        toReturn.MCR = anUncalibMCRvalue
        toReturn.calibratedMCR = _
          anInRecalibrator.uncalib2calib(toReturn.MCR, aCalibID)

        toReturn.MCRdiff = toReturn.MCR - toReturn.calibratedMCR
        toReturn.MCRrelDiff = 1000000.0 * toReturn.MCRdiff / toReturn.MCR

        Dim effectiveDiffValue As Double

        Dim charge As Integer = 1 ' Does it make much sense to use the
        '  plot MCR vs. Da error??
        Dim DaDiff As Double = charge * toReturn.MCRdiff 'Approximate value ??
        Select Case aMassAccUnit
            Case massErrorUnitEnum.enumUnitDa
                effectiveDiffValue = DaDiff

            Case massErrorUnitEnum.enumUnitPPM
                effectiveDiffValue = toReturn.MCRrelDiff

            Case massErrorUnitEnum.enumUnitMilliDa
                effectiveDiffValue = 1000 * DaDiff

            Case massErrorUnitEnum.enumUnitTh
                effectiveDiffValue = toReturn.MCRdiff

            Case massErrorUnitEnum.enumUnitMilliTh
                effectiveDiffValue = 1000 * toReturn.MCRdiff

            Case massErrorUnitEnum.enumUnitPPB
                effectiveDiffValue = 1000 * toReturn.MCRrelDiff

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

        toReturn.effectiveDiffValue = effectiveDiffValue

        anInOutTrendLine.Add( _
          toReturn.MCR, toReturn.effectiveDiffValue, "")

        Return toReturn
    End Function 'setupMCRpoint


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub setupDatastructures( _
      ByRef aProteinsSubset_dataStructureIndices2 As Generic.List(Of Integer), _
      ByRef aProteinList2 As Generic.List(Of ProteinHitStructure), _
      ByVal aPeptideFilter As peptideFilterStructure, _
      ByVal aMassAccUnit2 As massErrorUnitEnum)

        mUncalibMassErrors = New PointPairList()
        mCaliMassErrors = New PointPairList()

        'Changed PM_RECALIB_VISUAL_TRENDLINE 2007-12-07
        mTrendLine = New PointPairList() 'For trend line in uncalibrated
        '  scatter plot.

        mUncalibMedianErrors = New PointPairList()
        mCalibMedianErrors = New PointPairList()

        'Changed PM_RECALIB_VISUAL_BYRETENTIONTIME 2008-02-28
        mUncalibRetTvsMassErrors = New PointPairList()
        mCalibRetTvsMassErrors = New PointPairList()


        Dim useAllProteins As Boolean = _
          aProteinsSubset_dataStructureIndices2 Is Nothing

        If True Then
            'Changed PM_REFACTOR 2007-10-04
            ' Dim absMCRerrorSum_uncalib As Double = 0.0
            ' Dim absMCRerrorSum_calib As Double = 0.0
            ' 
            ' Dim minMCRerror_uncalib As Double = 1.0E+19
            ' Dim maxMCRerror_uncalib As Double = -1.0E+19
            ' 
            ' Dim minMCRerror_calib As Double = 1.0E+19
            ' Dim maxMCRerror_calib As Double = -1.0E+19
            Dim uncalibValues As statsStructure = _
              New statsStructure(1, False, False)
            Dim calibValues As statsStructure = _
              New statsStructure(2, False, False)

            Dim peptides2 As Integer = 0

            Dim uncalibMCR2 As Double = -19.9
            Dim theoMCR As Double = -19.9

            Dim uncalibError As Double = -9.9
            Dim calibError As Double = -19.9

            Dim len As Integer
            If useAllProteins Then
                len = aProteinList2.Count()
            Else
                len = aProteinsSubset_dataStructureIndices2.Count()
            End If

            Dim tagSB As StringBuilder = New StringBuilder(50)

            Dim proteinIndex As Integer
            Dim lastIndex As Integer = len - 1
            Dim i As Integer

            'First pass. For scatter plot and collecting information
            '            for second pass.
            For i = 0 To lastIndex 'Protein loop.

                If useAllProteins Then
                    proteinIndex = i
                Else
                    proteinIndex = aProteinsSubset_dataStructureIndices2(i)
                End If

                Dim someProt As ProteinHitStructure = _
                  aProteinList2(proteinIndex)

                'Changed PM_INTERNALPROTINDEX_BUG 2007-09-07
                Dim proteinNumber As Integer = someProt.hitNumber

                Dim pept As PeptideHitStructure = _
                  PeptideHitStructure.blankPeptide() 'Keep compiler happy.

                Dim pepIter As peptideListIterator = _
                  New peptideListIterator(someProt.peptides, aPeptideFilter)

                While Not pepIter.nextPeptide(pept)

                    'E.g. calibError is a different value depending
                    '     on whether in Th, mTH, Da or ppm...
                    effectiveErrorValues( _
                      pept, aMassAccUnit2, _
                      uncalibMCR2, uncalibError, calibError, theoMCR)

                    'Changed PM_RECALIB_VISUAL_PLOTX_THEO_MCR 2008-02-28
                    'Dim xMCR As Double = uncalibMCR2
                    Dim xMCR As Double = theoMCR

                    If True Then 'Finding properties about the set of peptides.

                        uncalibValues.update(xMCR, uncalibError)

                        'Note: same x value.
                        calibValues.update(xMCR, calibError)
                    End If

                    Dim tag2 As String = Nothing
                    If True Then
                        tagSB.Length = 0
                        tagSB.Append("q")
                        tagSB.Append(pept.queryNumber)
                        tagSB.Append(",")
                        tagSB.Append(pept.AASequence)
                        tagSB.Append(",sc")
                        tagSB.Append(pept.MascotScore2.ToString("0.0"))
                        tagSB.Append(",ch=")
                        tagSB.Append(pept.charge)
                        tagSB.Append(",prot ")

                        'Changed PM_INTERNALPROTINDEX_BUG 2007-09-07
                        'tagSB.Append(proteinIndex + 1)
                        tagSB.Append(proteinNumber)

                        tagSB.Append(".")

                        tag2 = tagSB.ToString()

                        mUncalibMassErrors.Add( _
                          xMCR, uncalibError, tag2)

                        'Uncalib on x to have exactly the same x-values.
                        mCaliMassErrors.Add( _
                          xMCR, calibError, tag2)
                    End If

                    'Changed PM_RECALIB_VISUAL_BYRETENTIONTIME 2008-02-28
                    If True Then
                        Dim xRetT As Double = pept.MSMSretentionTimeMinutes

                        Dim tag3 As String = Nothing
                        mUncalibRetTvsMassErrors.Add( _
                          xRetT, uncalibError, tag2)

                        'Uncalib on x to have exactly the same x-values.
                        mCalibRetTvsMassErrors.Add( _
                          xRetT, calibError, tag2)
                    End If 'Block. retT vs. mass error.

                End While 'Through peptides. For: first pass for scatter
                '          plot and collecting information for second pass.

            Next i 'Through proteins. For: first pass for scatter
            '       plot and collecting information for second pass.

            'Changed PM_RECALIB_VISUAL_TRENDLINE 2007-12-05
            If True Then
                Dim rawFileID As Integer = mPeptideFilter.rawFileID
                Dim tag As Integer
                If rawFileID < 0 Then
                    tag = SDUPrecalibrator.ALL_TAGCODE
                Else
                    tag = rawFileID
                End If

                Dim minMCR As Double = uncalibValues.minX
                Dim maxMCR As Double = uncalibValues.maxX
                Dim middleMCR As Double = (maxMCR + minMCR) / 2

                Dim firstQuarterMCR As Double = (minMCR + middleMCR) / 2
                Dim lastQuarterMCR As Double = (middleMCR + maxMCR) / 2

                Dim lowestMCRp As MCRpoint = _
                  setupMCRpoint( _
                    minMCR, mRecalibrator, tag, aMassAccUnit2, mTrendLine)

                Dim quarter1p As MCRpoint = _
                  setupMCRpoint( _
                    firstQuarterMCR, mRecalibrator, tag, aMassAccUnit2, _
                    mTrendLine)

                Dim middleMCRp As MCRpoint = _
                  setupMCRpoint( _
                    middleMCR, mRecalibrator, tag, aMassAccUnit2, mTrendLine)

                Dim quarter2p As MCRpoint = _
                  setupMCRpoint( _
                    lastQuarterMCR, mRecalibrator, tag, aMassAccUnit2, _
                    mTrendLine)

                Dim highestMCRp As MCRpoint = _
                  setupMCRpoint( _
                    maxMCR, mRecalibrator, tag, aMassAccUnit2, mTrendLine)
            End If

            'Changed PM_PLOTSPACE 2007-11-17
            mUncalibValues = uncalibValues 'Record for later use in plotting.

            Dim binningArray_calib As Integer() = Nothing
            'Dim binSize_calib As Double
            Dim calibBins As Integer
            Dim binSize_common As Double

            'Note: calib before uncalib as we use the binsize
            '      from calibrated MCR errors in the uncalibrated.

            'y-values in this case as it is the mass errors (that we
            'want to bin).
            SDUPstatistics.binningSetup_computeBinSize( _
              calibValues.sumOfabsY, calibValues.N, _
              calibValues.minY, calibValues.maxY, _
              binningArray_calib, binSize_common, _
              calibBins)
            Dim xLabels_calib(calibBins - 1) As String

            Dim binningArray_uncalib As Integer() = Nothing
            'Dim binSize_uncalib As Double
            Dim uncalibBins As Integer

            'Note: use the same bin size as for calibrated. The
            '      start mass error is not the same however.


            'y-values in this case as it is the mass errors (that we
            'want to bin).
            '
            'Note: we use another function as we want to use the bin size 
            '      that was computed above
            SDUPstatistics.binningSetup_inputBinSize( _
              uncalibValues.minY, uncalibValues.maxY, _
              binSize_common, _
              binningArray_uncalib, _
              uncalibBins)
            Dim xLabels_uncalib(uncalibBins - 1) As String

            Trace.Assert(calibValues.N = uncalibValues.N, _
              "PIL ASSERT. " & _
              "Count for calibValues and uncalibValues are not the same...")

            Dim massWindowCommon As Double = 100.0
            Dim windowed_calib() As statsStructure = Nothing
            'x values (MCR) because we don't actual want to bin, but rather
            'setup functions for preparing to compute statistics for
            'each mass window and in particular the median MCR error
            'for each window.
            If True Then
                Dim binArr_averageMCRerr_calib As Integer() = Nothing
                Dim averageMCRerr_calibBins As Integer
                SDUPstatistics.binningSetup_inputBinSize( _
                  calibValues.minX, calibValues.maxX, _
                  massWindowCommon, _
                  binArr_averageMCRerr_calib, _
                  averageMCRerr_calibBins)

                windowed_calib = Me.initStatArray(averageMCRerr_calibBins)
            End If

            Dim windowed_uncalib() As statsStructure = Nothing
            'x values (MCR) because we don't actual want to bin, but rather
            'setup functions for preparing to compute statistics for
            'each mass window and in particular the median MCR error
            'for each window.
            If True Then
                Dim binArr_averageMCRerr_uncalib As Integer() = Nothing
                Dim averageMCRerr_uncalibBins As Integer
                SDUPstatistics.binningSetup_inputBinSize( _
                  uncalibValues.minX, uncalibValues.maxX, _
                  massWindowCommon, _
                  binArr_averageMCRerr_uncalib, _
                  averageMCRerr_uncalibBins)

                windowed_uncalib = Me.initStatArray(averageMCRerr_uncalibBins)
            End If

            'Second pass, for binning and windowed median error (that needs
            '  some information from a first pass).
            For i = 0 To lastIndex 'Protein loop.
                If useAllProteins Then
                    proteinIndex = i
                Else
                    proteinIndex = aProteinsSubset_dataStructureIndices2(i)
                End If

                Dim someProt As ProteinHitStructure = _
                  aProteinList2(proteinIndex)

                Dim pept As PeptideHitStructure = _
                  PeptideHitStructure.blankPeptide() 'Keep compiler happy.

                Dim pepIter As peptideListIterator = _
                  New peptideListIterator(someProt.peptides, aPeptideFilter)

                While Not pepIter.nextPeptide(pept)

                    'E.g. calibError is a different value depending
                    '     on whether in Th, mTH, Da or ppm...
                    effectiveErrorValues( _
                      pept, aMassAccUnit2, _
                      uncalibMCR2, uncalibError, calibError, theoMCR)

                    'Changed PM_RECALIB_VISUAL_PLOTX_THEO_MCR 2008-02-28
                    'Dim xValue As Double = uncalibMCR2
                    Dim xValue As Double = theoMCR

                    Dim index_uncalib As Integer = _
                      CInt( _
                          (uncalibError - uncalibValues.minY) / _
                          binSize_common _
                          - 0.5 _
                        ) '0.5 because .NET int() rounds (not trunc)

                    Dim lastIndexUn As Integer = _
                      binningArray_uncalib.GetLength(0) - 1
                    Trace.Assert(index_uncalib <= lastIndexUn, _
                      "PIL ASSERT. " & _
                      "Index out of range for binningArray_uncalib: " & _
                      index_uncalib)

                    binningArray_uncalib(index_uncalib) += 1

                    Dim index_calib As Integer = _
                      CInt( _
                          (calibError - calibValues.minY) / _
                          binSize_common _
                          - 0.5 _
                        ) '0.5 because .NET int() rounds (not trunc)
                    binningArray_calib(index_calib) += 1

                    'Changed PM_AVERAGEERROR_BYMCR 2007-10-04
                    'For uncalib: x-values (MCR) have been chosen to be the 
                    'same so we can use the value from calib.
                    '
                    Dim index_massWindow_common As Integer = _
                      CInt( _
                          (xValue - calibValues.minX) / _
                          massWindowCommon _
                          - 0.5 _
                        ) '0.5 because .NET int() rounds (not trunc)


                    'For debugging only.
                    If index_massWindow_common = 9 Then
                        Dim peter9 As Integer = 9
                    End If

                    Dim lastIndex7 As Integer = windowed_calib.Length - 1
                    Trace.Assert(index_massWindow_common <= lastIndex7, _
                      "PIL ASSERT. index_massWindow_common, " & _
                      index_massWindow_common & _
                      ", is out of range, [0; " & lastIndex7 & "].")

                    'Note: no y value as we are only interested in one quantity,
                    '      mass error and in particular the median value.
                    windowed_calib(index_massWindow_common).update( _
                      calibError, 0.0)
                    windowed_uncalib(index_massWindow_common).update( _
                      uncalibError, 0.0)

                End While 'Through peptides. For: second pass for binning
                '          and windowed median error.

            Next i 'Through proteins. For: second pass for binning and
            '       windowed median error.

            If True Then
                buildBin( _
                  binningArray_uncalib, uncalibValues.minY, binSize_common, _
                  mUncalibBinArray, mUncalibBinXlabels)

                buildBin( _
                  binningArray_calib, calibValues.minY, binSize_common, _
                  mCalibBinArray, mCalibBinXlabels)
            End If

            If True Then
                Dim centerMass As Double = _
                  calibValues.minX + 0.5 * massWindowCommon

                Dim lastIndex2 As Integer = windowed_calib.Length() - 1
                Dim j As Integer
                For j = 0 To lastIndex2 Step 1

                    'Changed PM_REFACTOR 2007-10-08
                    'Dim count As Double = countErr_calib(j)
                    Dim count As Integer = windowed_calib(j).N

                    If count > 0 Then 'Jump over if there are no counts
                        '  within a mass window.

                        'Changed PM_REFACTOR 2007-10-08
                        'Dim sumErrCalib As Double = sumErr_calib(j)
                        'Dim sumErrUncalib As Double = sumErr_uncalib(j)
                        Dim sumErrCalib As Double = windowed_calib(j).sumOfX
                        Dim sumErrUncalib As Double = windowed_uncalib(j).sumOfX

                        Dim averageError_calib As Double = sumErrCalib / count
                        Dim averageError_uncalib As Double = _
                          sumErrUncalib / count

                        'Note: side-effects in medianValue()!
                        Dim medianError_calib As Double = _
                          SDUPstatistics.medianValue(windowed_calib(j).xValues)
                        Dim medianError_uncalib As Double = _
                          SDUPstatistics.medianValue(windowed_uncalib(j).xValues)

                        'Changed PM_RECALIB_VISUAL_MEDIAN 2007-10-08
                        'mCalibAverageErrors.Add( _
                        '  centerMass, averageError_calib, "")
                        'mUncalibAverageErrors.Add( _
                        '  centerMass, averageError_uncalib, "")
                        mCalibMedianErrors.Add( _
                          centerMass, medianError_calib, "")
                        mUncalibMedianErrors.Add( _
                          centerMass, medianError_uncalib, "")
                    Else
                        'Empty mass window - no peptides in mass
                        '  window, centered at "centerMass".
                        Dim peter2 As Integer = 2
                    End If

                    centerMass += massWindowCommon
                Next j
            End If 'Block.

            mBinSize = binSize_common
        End If 'Block.

    End Sub 'setupDatastructures


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub createTheGraphs( _
      ByVal aMassAccUnit As massErrorUnitEnum, _
      ByVal aDisplayType As massErrorDisplayTypeEnum)

        Select Case aDisplayType
            Case massErrorDisplayTypeEnum.enumByMCR
                CreateGraph_MCR2MassError( _
                  massErrors_ZedGraph, mUncalibMassErrors, _
                  "Before recalibration. ", aMassAccUnit, _
                  mUncalibValues, mTrendLine)

                CreateGraph_MCR2MassError( _
                  massErrors2_ZedGraph, mCaliMassErrors, _
                  "After recalibration. ", aMassAccUnit, _
                  mUncalibValues, Nothing) 'Uncalib/mUncalibValues because
                '   the x values we use are the same.

            Case massErrorDisplayTypeEnum.enumBinned
                CreateGraph_BinnedMassError( _
                  massErrors_ZedGraph, _
                  mUncalibBinArray, _
                  mUncalibBinXlabels, _
                  "Before recalibration. Binned errors. ", _
                  aMassAccUnit)

                CreateGraph_BinnedMassError( _
                  massErrors2_ZedGraph, _
                  mCalibBinArray, _
                  mCalibBinXlabels, _
                  "After recalibration. Binned errors. ", _
                  aMassAccUnit)

                Dim unitStr As String = massErrorUnitString(aMassAccUnit)
                lblBinSize.Text = "Bin size " & unitStr & ":"
                txtBinSize.Text = mBinSize.ToString("0.000")

            Case massErrorDisplayTypeEnum.enumMedianErrorByMCR
                CreateGraph_massWindow2medianError( _
                  massErrors_ZedGraph, mUncalibMedianErrors, _
                  "Before recalibration. Median errors. Window size: 100 Th. ", _
                  aMassAccUnit, _
                  mUncalibValues)

                CreateGraph_massWindow2medianError( _
                  massErrors2_ZedGraph, mCalibMedianErrors, _
                  "After recalibration. Median errors. Window size: 100 Th. ", _
                  aMassAccUnit, _
                  mUncalibValues) 'Uncalib/mUncalibValues because
                '   the x values we use are the same.


                'Changed PM_RECALIB_VISUAL_BYRETENTIONTIME 2008-02-28
            Case massErrorDisplayTypeEnum.enumByRetT
                CreateGraph_retT2MassError( _
                  massErrors_ZedGraph, mUncalibRetTvsMassErrors, _
                  "Before recalibration. ", aMassAccUnit, _
                  mUncalibValues)

                CreateGraph_retT2MassError( _
                  massErrors2_ZedGraph, mCalibRetTvsMassErrors, _
                  "After recalibration. ", aMassAccUnit, _
                  mUncalibValues)

        End Select

        Me.SetSize()
    End Sub 'createTheGraphs


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Function massErrorUnitString( _
      ByVal aMassAccUnit As massErrorUnitEnum) _
      As String

        'Replace this function with a hash?

        Dim toReturn As String = Nothing
        Select Case aMassAccUnit
            Case massErrorUnitEnum.enumUnitDa
                toReturn = "[Da]"
            Case massErrorUnitEnum.enumUnitPPM
                toReturn = "[ppm]"
            Case massErrorUnitEnum.enumUnitMilliDa
                toReturn = "[mDa]"

                'Changed PM_VISUALISATION_ABSOLUTE_MCR 2007-11-02
            Case massErrorUnitEnum.enumUnitTh
                toReturn = "[Th]"
            Case massErrorUnitEnum.enumUnitMilliTh
                toReturn = "[mTh]"

            Case massErrorUnitEnum.enumUnitPPB
                toReturn = "[ppb]"
            Case Else
                Trace.Assert(False, _
                  "PIL ASSERT. Select Case never fall-through")
        End Select
        Return toReturn
    End Function 'massErrorUnitString


    'Changed PM_VISUALISATION_ABSOLUTE_MCR 2007-11-02
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Sub massTypeString( _
      ByVal aMassAccUnit As massErrorUnitEnum, _
      ByRef anOutCapitalised As String, _
      ByRef anOutNonCapitalised As String)

        anOutCapitalised = "Mass"
        anOutNonCapitalised = "mass"

        Select Case aMassAccUnit
            'Case massErrorUnitEnum.enumUnitDa
            '    toReturn = "Mass"
            'Case massErrorUnitEnum.enumUnitPPM
            '    toReturn = "Mass" 'Could also MCR.
            'Case massErrorUnitEnum.enumUnitMilliDa
            '    toReturn = "Mass"

            'Changed PM_VISUALISATION_ABSOLUTE_MCR 2007-11-02
            Case massErrorUnitEnum.enumUnitTh
                anOutCapitalised = "MCR"
                anOutNonCapitalised = "MCR"
            Case massErrorUnitEnum.enumUnitMilliTh
                anOutCapitalised = "MCR"
                anOutNonCapitalised = "MCR"

        End Select
    End Sub 'massTypeString


    'Perhaps refactor with similar function in retentionTimePlotting.vb
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Sub commonGraph( _
      ByRef anInOutZgc As ZedGraphControl, _
      ByRef anInTitle As String, _
      ByVal aMassAccUnit As massErrorUnitEnum, _
      ByRef anOutPane As GraphPane, _
      ByRef anOutMassErrorUnit As String)

        ' 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_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

            'Changed PM_BACKCOLOUR_FOR_ZOOMRECTANGLE 2008-02-26
            ''Changed PM_BACKCOLOUR_FOR_ZOOMRECTANGLE 2008-02-15
            ''Note: this is the plot area - does not includes axes, etc.
            ''anOutPane.Chart.Fill = New Fill()
            'anOutPane.Chart.Fill = New Fill(Color.FromArgb(0, 0, 0)) 'Colour
            ''  is black.

            'Changed PM_BACKCOLOUR_FOR_ZOOMRECTANGLE 2008-02-14
            'anOutPane.Fill = New Fill()
            '
            'Note: this is everything: x-axis, y-axis, plot area, header.
            '
            'anOutPane.Fill = New Fill(Color.FromArgb(223, 223, 255)) 'Colour
            ''  is whitened blue-violet.
            'anOutPane.Fill = New Fill(Color.FromArgb(128, 128, 128)) 'Colour
            ''  is dark-grey.
            'anOutPane.Fill = New Fill(Color.FromArgb(0, 0, 0)) 'Colour
            ''  is black.
            anOutPane.Fill = New Fill(Color.FromArgb(255, 255, 255)) 'Colour
            '  is white.
        End If

        anOutPane.Title.Text = anInTitle
        anInOutZgc.IsShowPointValues = True

        anOutMassErrorUnit = massErrorUnitString(aMassAccUnit)
    End Sub 'commonGraph


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Sub massErrorYcommon( _
      ByRef anInOutZedGraphPane As GraphPane, _
      ByVal aMassAccUnit As massErrorUnitEnum, _
      ByVal anInYaxisUnitStr As String)

        'Changed PM_VISUALISATION_ABSOLUTE_MCR 2007-11-02
        Dim massTypeStr1 As String = Nothing
        Dim massTypeStr2 As String = Nothing
        massTypeString(aMassAccUnit, massTypeStr1, massTypeStr2)
        'Dim yAxisLabel As String = "Mass error " & yAxisUnitStr
        Dim yAxisLabel As String = massTypeStr1 & " error " & anInYaxisUnitStr

        anInOutZedGraphPane.YAxis.Title.Text = yAxisLabel

        'Changed PM_RECALIBVISUAL_GRID 2007-09-24
        anInOutZedGraphPane.YAxis.MajorGrid.IsVisible = True
        anInOutZedGraphPane.YAxis.MajorGrid.DashOn = 5
        anInOutZedGraphPane.YAxis.MajorGrid.Color = Color.BlueViolet

        'Changed PM_RECALIB_VISUAL_AVOID_Y1000SCALING 2008-03-06
        anInOutZedGraphPane.YAxis.Scale.Mag = 0

    End Sub 'massErrorYcommon


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Sub CreateGraph_MCR2MassError( _
      ByRef anInOutZgc As ZedGraphControl, _
      ByRef anInSomeData As PointPairList, _
      ByRef anInTitle As String, _
      ByVal aMassAccUnit As massErrorUnitEnum, _
      ByVal aDataRanges As statsStructure, _
      ByRef anInTrendline As PointPairList)

        'statsStructure happens to have the values we need: minimum
        'and maximum values for x values, MCR.

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

        myPane.XAxis.Title.Text = "MCR [Th]"

        'Changed PM_REFACTOR 2008-02-28
        frmRecalibrationVisualisation.massErrorYcommon( _
          myPane, aMassAccUnit, yAxisUnitStr)

        If Not anInTrendline Is Nothing Then
            Dim myCurve2 As LineItem = myPane.AddCurve( _
              "", _
              anInTrendline, Color.Blue, SymbolType.Triangle)

            myCurve2.Line.IsVisible = True 'Line.
            'myCurve2.Symbol.Size = 2
            myCurve2.Symbol.Fill = New Fill(Color.Cyan)

            myCurve2.Line.Width = 2
        End If

        'Changed PM_RECALIBVISUAL_MORESPACE 2007-10-03
        'Dim curveLavel As String = "Mass errors"
        Dim curveLabel As String = ""

        Dim myCurve As LineItem = myPane.AddCurve( _
          curveLabel, _
          anInSomeData, Color.Red, SymbolType.Diamond)

        myCurve.Line.Fill = New Fill()

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

        'Changed PM_PLOTSPACE 2007-11-17
        'Make the XAxis start with the lowest mass (e.g. 352 Th) and
        'not 0.0.
        'myPane.XAxis.Scale.BaseTic = aStartX  Then starts at 200.0
        '  and not to a set value of 350.21 Th. -Why ???
        'myPane.XAxis.Scale.BaseTic = aStartX - 30.0
        '
        myPane.XAxis.Scale.Min = aDataRanges.minX - 30.0
        myPane.XAxis.Scale.Max = aDataRanges.maxX + 30.0

        ' 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()
    End Sub 'CreateGraph_MCR2MassError


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Sub CreateGraph_BinnedMassError( _
      ByRef anInOutZgc As ZedGraphControl, _
      ByRef anInBinArray As Double(), _
      ByRef anInXlabels As String(), _
      ByRef anInTitle As String, _
      ByVal aMassAccUnit As massErrorUnitEnum)

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

        'myPane.XAxis.Title.Text = _
        '  "Bins. Mass error interval unit: " & xAxisUnitStr & "."
        myPane.XAxis.Title.Text = ""

        myPane.YAxis.Title.Text = "Count"

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

        Dim myCurve As BarItem = myPane.AddBar( _
          "", Nothing, anInBinArray, Color.Red)

        ' Fill the bar with a red-white-red color gradient for a 3d look
        myCurve.Bar.Fill = New Fill(Color.Red, Color.White, Color.Red, 90.0F)

        ' Set the XAxis to Text type
        myPane.XAxis.Type = AxisType.Text
        ' Set the XAxis labels
        myPane.XAxis.Scale.TextLabels = anInXlabels
        ' Set the labels at an angle so they don't overlap
        myPane.XAxis.Scale.FontSpec.Angle = 90

        '' Draw the Y tics between the labels instead of at the labels
        'myPane.YAxis.MajorTic.IsBetweenLabels = True

        ' Draw the X tics between the labels instead of 
        ' at the labels.
        myPane.XAxis.MajorTic.IsBetweenLabels = True

        'myCurve.Symbol.Size = 8.0F
        'myCurve.Symbol.Fill = New Fill(Color.White)
        'myCurve.Line.Width = 2.0F


        'Changed PM_BACKCOLOUR_FOR_ZOOMRECTANGLE 2008-02-14. Stay with
        '  common default for all three (set in commonGraph()).
        '' Fill the Axis and Pane backgrounds.
        'myPane.Chart.Fill = New Fill(Color.White, _
        '      Color.FromArgb(255, 255, 166), 90.0F)
        'myPane.Fill = New Fill(Color.FromArgb(250, 250, 255)) 'Colour
        ''  is nearly white.


        ' 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()
    End Sub 'CreateGraph_BinnedMassError


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Shared Sub CreateGraph_massWindow2medianError( _
      ByRef anInOutZgc As ZedGraphControl, _
      ByRef anInSomeData As PointPairList, _
      ByRef anInTitle As String, _
      ByVal aMassAccUnit As massErrorUnitEnum, _
      ByVal aDataRanges As statsStructure)

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

        myPane.XAxis.Title.Text = "MCR [Th]"

        'Changed PM_VISUALISATION_ABSOLUTE_MCR 2007-11-02
        'Dim yAxisLabel As String = _
        '  "Median mass error " & yAxisUnitStr
        Dim massTypeStr1 As String = Nothing
        Dim massTypeStr2 As String = Nothing
        massTypeString(aMassAccUnit, massTypeStr1, massTypeStr2)
        Dim yAxisLabel As String = _
          "Median " & massTypeStr2 & " error " & yAxisUnitStr

        myPane.YAxis.Title.Text = yAxisLabel

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

        Dim curveLavel As String = ""
        Dim myCurve As LineItem = myPane.AddCurve( _
          curveLavel, _
          anInSomeData, Color.Red, SymbolType.Diamond)

        myCurve.Line.Fill = New Fill()

        'Line between points.
        myCurve.Line.IsVisible = True

        'Fill the area under the curve.
        myCurve.Line.Fill = _
          New Fill(Color.White, Color.FromArgb(60, 190, 50), 90.0F) 'Second
        '   parameter is approx. dark green.

        'Fill the symbols with white to make them opaque
        myCurve.Symbol.Fill = New Fill(Color.White)
        myCurve.Symbol.Size = 5

        'Changed PM_PLOTSPACE 2007-11-17
        myPane.XAxis.Scale.Min = aDataRanges.minX - 30.0
        myPane.XAxis.Scale.Max = aDataRanges.maxX + 30.0

        ' 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()
    End Sub 'CreateGraph_massWindow2medianError


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub CreateGraph_retT2MassError( _
      ByRef anInOutZgc As ZedGraphControl, _
      ByRef anInSomeData As PointPairList, _
      ByRef anInTitle As String, _
      ByVal aMassAccUnit As massErrorUnitEnum, _
      ByVal aDataRanges As statsStructure)

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

        myPane.XAxis.Title.Text = "Retention time [minutes]"

        frmRecalibrationVisualisation.massErrorYcommon( _
          myPane, aMassAccUnit, yAxisUnitStr)

        Dim curveLabel As String = ""
        Dim myCurve As LineItem = myPane.AddCurve( _
          curveLabel, _
          anInSomeData, Color.Red, SymbolType.Diamond)
        myCurve.Line.Fill = New Fill()
        'Turn off the line so it's a scatter plot.
        myCurve.Line.IsVisible = False

        ' 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()
    End Sub 'CreateGraph_retT2MassError


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub frmRecalibrationVisualisation_Resize( _
      ByVal aSender As Object, ByVal anEvent As System.EventArgs) _
      Handles Me.Resize

        Me.SetSize()
    End Sub 'frmRecalibrationVisualisation_Resize


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    ' SetSize() is separate from Resize() so we can 
    ' call it independently from the Form1_Load() method.
    '
    ' This leaves a 10 px margin around the outside of the control.
    ' Customize this to fit your needs.
    Private Sub SetSize()

        Dim yOffset As Integer = 52
        Dim xOffset As Integer = 13

        Dim rightBottomMargin As Integer = 20

        Dim plotSeparation As Integer = 30

        Dim xSize As Integer = _
          ClientRectangle.Width - rightBottomMargin - xOffset

        Dim ySizeAll As Integer = _
          ClientRectangle.Height - yOffset - rightBottomMargin

        Dim ySize As Integer = (ySizeAll - plotSeparation) \ 2

        Dim y1 As Integer = yOffset
        Dim y2 As Integer = yOffset + ySize + plotSeparation

        massErrors_ZedGraph.Location = New Point(xOffset, y1)
        massErrors_ZedGraph.Size = New Size(xSize, ySize)

        massErrors2_ZedGraph.Location = New Point(xOffset, y2)
        massErrors2_ZedGraph.Size = New Size(xSize, ySize)
    End Sub 'SetSize


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub btnPeptideFilter_Click( _
      ByVal aSender As System.Object, _
      ByVal anEvent As System.EventArgs) _
      Handles btnPeptideFilter.Click

        Dim key As peptideFilterEnum = peptideFilterEnum.enumRecalibVisual

        Dim programDefaults As peptideFilterStructure = _
          quantApplication.defaultPeptideFilters2()(key)

        'Changed PM_PEPTIDEFILTER_GENERALISED 2007-08-29
        'Dim filterForm As New frmPeptideFilters( _
        '  peptideFilter, Me, mApplication)
        mFilterForm = New frmPeptideFilters( _
          mPeptideFilter, mApplication, True, True, _
          programDefaults, _
          "visualisation of recalibration", _
          mRawFiles, _
          mSILACmods)
        mFilterForm.Show()

        'Note: the call-back is the function that handles
        '      event "mFilterForm.dialogDismissed2".
    End Sub 'btnPeptideFilter_Click


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Sub updatePeptideFilterSummary( _
      ByVal anInPeptideFilterSpecification As _
        peptideFilterStructure)

        Dim summaryStr As String = _
          someStatic.pepFilterShortSummary( _
            anInPeptideFilterSpecification, mApplication)

        lblPeptideFilterSummary.Text = summaryStr
    End Sub 'updatePeptideFilterSummary


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '*    Call-back from peptide filter form.                                   *
    '****************************************************************************
    Private Sub mFilterForm_pepFilterDismissed( _
      ByVal aSender As Object, _
      ByVal anEvent As pepFilterEventArgs) _
      Handles mFilterForm.pepFilterDismissed

        Dim filter As peptideFilterStructure = anEvent.getFilter()

        mPeptideFilter = filter 'New filter.

        Me.updateDisplay()

        'Changed PM_RECALIB_VISUAL_SAVE 2007-09-04
        'Immediately persist new setting. We need to use an event
        'as this dialog can be started from two different places,
        'during parsing and from the Protein List window.
        RaiseEvent calibVisualDismissed( _
          aSender, New pepFilterEventArgs(filter))
    End Sub 'mFilterForm_pepFilterDismissed


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub newMassErrorUnits(ByVal aMassAccUnit As massErrorUnitEnum)

        mCurMassAccUnit = aMassAccUnit
        Me.updateDisplay()
    End Sub 'newMassErrorUnits


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rbUnitDa_CheckedChanged( _
      ByVal aSender As System.Object, _
      ByVal anEvent As System.EventArgs) _
      Handles rbUnitDa.CheckedChanged

        If Not mStartingUp Then
            'How do we get it from the event?
            Dim newVal As Boolean = rbUnitDa.Checked
            If newVal = True Then
                newMassErrorUnits(massErrorUnitEnum.enumUnitDa)
            End If
        Else
            Dim peter2 As Integer = 2
        End If
    End Sub 'rbUnitDa_CheckedChanged


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rbUnitPPM_CheckedChanged( _
      ByVal aSender As System.Object, _
      ByVal anEvent As System.EventArgs) _
      Handles rbUnitPPM.CheckedChanged

        If Not mStartingUp Then
            'How do we get it from the event?
            Dim newVal As Boolean = rbUnitPPM.Checked
            If newVal = True Then
                newMassErrorUnits(massErrorUnitEnum.enumUnitPPM)
            End If
        Else
            Dim peter2 As Integer = 2
        End If
    End Sub 'rbUnitPPM_CheckedChanged


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rbUnitMilliDa_CheckedChanged( _
      ByVal aSender As System.Object, _
      ByVal anEvent As System.EventArgs) _
      Handles rbUnitMilliDa.CheckedChanged

        If Not mStartingUp Then
            'How do we get it from the event?
            Dim newVal As Boolean = rbUnitMilliDa.Checked
            If newVal = True Then
                newMassErrorUnits(massErrorUnitEnum.enumUnitMilliDa)
            End If
        Else
            Dim peter2 As Integer = 2
        End If
    End Sub 'rbUnitMilliDa_CheckedChanged



    'Changed PM_VISUALISATION_ABSOLUTE_MCR 2007-11-02
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rbUnitTh_CheckedChanged( _
      ByVal aSender As System.Object, _
      ByVal anEvent As System.EventArgs) _
      Handles rbUnitTh.CheckedChanged

        If Not mStartingUp Then
            'How do we get it from the event?
            Dim newVal As Boolean = rbUnitTh.Checked
            If newVal = True Then
                newMassErrorUnits(massErrorUnitEnum.enumUnitTh)
            End If
        Else
            Dim peter2 As Integer = 2
        End If
    End Sub 'rbUnitTh_CheckedChanged


    'Changed PM_VISUALISATION_ABSOLUTE_MCR 2007-11-02
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rbUnitMilliTh_CheckedChanged( _
      ByVal aSender As System.Object, _
      ByVal anEvent As System.EventArgs) _
      Handles rbUnitMilliTh.CheckedChanged

        If Not mStartingUp Then
            'How do we get it from the event?
            Dim newVal As Boolean = rbUnitMilliTh.Checked
            If newVal = True Then
                newMassErrorUnits(massErrorUnitEnum.enumUnitMilliTh)
            End If
        Else
            Dim peter2 As Integer = 2
        End If
    End Sub 'rbUnitMilliTh_CheckedChanged


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rbUnitPPB_CheckedChanged( _
      ByVal aSender As System.Object, _
      ByVal anEvent As System.EventArgs) _
      Handles rbUnitPPB.CheckedChanged

        If Not mStartingUp Then
            'How do we get it from the event?
            Dim newVal As Boolean = rbUnitPPB.Checked
            If newVal = True Then
                newMassErrorUnits(massErrorUnitEnum.enumUnitPPB)
            End If
        Else
            Dim peter2 As Integer = 2
        End If
    End Sub 'rbUnitPPB_CheckedChanged


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub newDisplayType(ByVal aDisplayType As massErrorDisplayTypeEnum)

        mDisplayType = aDisplayType
        Me.updateDisplay()
    End Sub 'newDisplayType


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rbBinnedMassErrors_CheckedChanged( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles rbBinnedMassErrors.CheckedChanged

        If Not mStartingUp Then
            'How do we get it from the event?
            Dim newVal As Boolean = rbBinnedMassErrors.Checked
            If newVal = True Then
                newDisplayType(massErrorDisplayTypeEnum.enumBinned)
            End If
        Else
            Dim peter2 As Integer = 2
        End If
    End Sub 'rbBinnedMassErrors_CheckedChanged


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rbByMCR_CheckedChanged( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles rbByMCR.CheckedChanged

        If Not mStartingUp Then
            'How do we get it from the event?
            Dim newVal As Boolean = rbByMCR.Checked
            If newVal = True Then
                newDisplayType(massErrorDisplayTypeEnum.enumByMCR)
            End If
        Else
            Dim peter2 As Integer = 2
        End If
    End Sub 'rbByMCR_CheckedChanged


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub updateDisplay()

        displayData( _
          mProteinsSubset, _
          mProteinList, _
          mPeptideFilter, _
          mCurMassAccUnit)
    End Sub 'updateDisplay


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rbMedianErrorByMassWindow_CheckedChanged( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles rbMedianErrorByMassWindow.CheckedChanged

        If Not mStartingUp Then
            'How do we get it from the event?
            Dim newVal As Boolean = rbMedianErrorByMassWindow.Checked
            If newVal = True Then
                newDisplayType(massErrorDisplayTypeEnum.enumMedianErrorByMCR)
            End If
        Else
            Dim peter2 As Integer = 2
        End If
    End Sub 'rbMedianErrorByMassWindow_CheckedChanged


    'Changed PM_RECALIB_VISUAL_BYRETENTIONTIME 2008-02-28
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub rbByRetT_CheckedChanged( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles rbByRetT.CheckedChanged

        If Not mStartingUp Then
            'How do we get it from the event?
            Dim newVal As Boolean = rbByRetT.Checked
            If newVal = True Then
                newDisplayType(massErrorDisplayTypeEnum.enumByRetT)
            End If
        Else
            Dim peter2 As Integer = 2
        End If
    End Sub 'rbByRetT_CheckedChanged


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Function massErrors_ZedGraph_MouseMoveEvent( _
      ByVal aSender As ZedGraph.ZedGraphControl, _
      ByVal anEvent As System.Windows.Forms.MouseEventArgs) _
      As Boolean _
      Handles massErrors_ZedGraph.MouseMoveEvent

        Return False
    End Function 'massErrors_ZedGraph_MouseMoveEvent


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Function massErrors_ZedGraph_MouseUpEvent( _
      ByVal aSender As ZedGraph.ZedGraphControl, _
      ByVal anEvent As System.Windows.Forms.MouseEventArgs) _
      As Boolean _
      Handles massErrors_ZedGraph.MouseUpEvent

        Return False
    End Function 'massErrors_ZedGraph_MouseMoveEvent


    'Changed PM_REFACTOR 2008-10-14. This function is completely 
    'general and should be moved to a more general place.
    'Is an equivalent function already in ZedGraph??
    '****************************************************************************
    '*    Return empty string if nothing was hit                                              *
    '****************************************************************************
    Public Shared Function getTagFromHitZedGraphCurve( _
      ByRef anInPane As GraphPane, _
      ByVal aX As Integer, ByVal anY As Integer) _
      As String

        Dim toReturn As String = "" 'Default value if nothing is hit (or similar)

        'To adapt to previous. Do the substitution at any time.
        'Dim pane As GraphPane = aSender.GraphPane
        'Dim xm As Integer = anEvent.X
        'Dim ym As Integer = anEvent.Y
        Dim pane As GraphPane = anInPane
        Dim xm As Integer = aX
        Dim ym As Integer = anY


        Dim pt As PointF
        pt.X = xm
        pt.Y = ym

        '  "This is normally e.Graphics from the PaintEventArgs argument
        '  to the Paint() method. "

        Dim bm As Bitmap = New Bitmap(1, 1)
        Dim g As Graphics = Graphics.FromImage(bm)
        ' pane.AxisChange(g)

        ' Dim g As Graphics = Me.zedGraphControl.CreateGraphics()
        ' myMaster.AutoPaneLayout(g, PaneLayout.SingleRow)
        ' myMaster.AxisChange(g)
        ' g.Dispose() 

        Dim obj2 As Object = Nothing 'Keep compiler happy.
        Dim index2 As Integer
        Dim found As Boolean = _
          pane.FindNearestObject(pt, g, obj2, index2)

        If Not obj2 Is Nothing Then
            Dim TypeToReflect As Type = obj2.GetType()
            Dim typeName As String = TypeToReflect.ToString

            If typeName = "ZedGraph.LineItem" Then

                Dim theCurve As ZedGraph.LineItem = _
                  DirectCast(obj2, ZedGraph.LineItem)

                Dim pairHit As ZedGraph.PointPair = theCurve(index2)

                'Sample:
                '  q17801,DNLTLWTSDTQGDEAEAGEGGEN,sc44,ch=2,prot 2.
                Dim withInfo As String = DirectCast(pairHit.Tag, String)


                toReturn = withInfo 'To adapt to previous. Do the 
                '  substitution at any time.

                Dim peter3 As Integer = 3
            Else
                Dim peter4 As Integer = 4 'Hit something else (or empty
                '  space) - not a point/line.
            End If

            'No, this is for all function of the class, etc.
            ' Dim members As System.Reflection.MemberInfo() = _
            '   TypeToReflect.GetMembers()
            ' 
            ' 'Later: assert length of "members" to 1.
            ' 
            ' Dim someMember As MemberInfo
            ' For Each someMember In members
            '     Dim typeName As String = someMember.ToString
            '     If typeName = "ZedGraph.LineItem" Then
            ' 
            '         Dim theCurve As ZedGraph.LineItem = _
            '           DirectCast(obj2, ZedGraph.LineItem)
            ' 
            '         Dim pairHit As ZedGraph.PointPair = theCurve(index2)
            ' 
            '         Dim withQnum As String = DirectCast(pairHit.Tag, String)
            ' 
            '         Dim peter3 As Integer = 3
            '     Else
            '         Dim peter4 As Integer = 4 'Hit something else.
            '     End If
            ' Next

            g.Dispose()
        Else
            Dim peter2 As Integer = 2 'User did not hit near a graphical 
            '  element.
        End If

        Return toReturn
    End Function 'getTagFromHitZedGraphCurve


    'Changed PM_REFACTOR 2008-10-14.
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub openProtValWindowForClicked( _
      ByRef anInPane As GraphPane, _
      ByVal aX As Integer, ByVal anY As Integer)

        'Changed PM_REFACTOR 2008-10-14
        Dim tagForHit As String = _
          frmRecalibrationVisualisation.getTagFromHitZedGraphCurve( _
            anInPane, aX, anY)

        If tagForHit <> "" Then

            'Extract information from the tag (that is also displayed
            'to the user if the mouse hovers above a plotted point.)

            Dim queryNum As Integer
            If True Then
                Dim idx As Integer = tagForHit.IndexOf(",", 0)
                Trace.Assert(idx >= 0, _
                  "PIL ASSERT. "","" not found in: " & tagForHit)

                Dim len As Integer = idx

                'Extra memory garbage!! Eliminate?
                Dim qStr As String = tagForHit.Substring(0, len)

                Dim idx2 As Integer = qStr.IndexOf("q", 0)
                idx2 += 1 'Step past "q".

                Dim len2 As Integer = qStr.Length - idx2
                Dim qNumStr As String = qStr.Substring(idx2, len2)

                queryNum = CInt(qNumStr)
            End If

            'Note: we could find the protein from the query number, but
            '      we will extract it directly.
            Dim protNum As Integer
            If True Then
                Dim idx5 As Integer = tagForHit.IndexOf(",prot ", 0)
                Trace.Assert(idx5 >= 0, _
                  "PIL ASSERT. "",prot "" not found in: " & tagForHit)
                idx5 += 6

                'Changed PM_BROKENOPEN_FROM_RECALIBVIS 2008-12-12
                '  There is now an extra dot:
                '    "q22061,IAGPGLGSGVR,sc63.0,ch=2,prot 51." 
                '
                'Dim idx6 As Integer = tagForHit.IndexOf(".", 0)
                Dim idx6 As Integer = tagForHit.IndexOf(".", idx5)

                If idx6 < 0 Then
                    idx6 = tagForHit.Length()
                End If
                'idx6 += 1

                Dim len5 As Integer = idx6 - idx5
                Dim protNumStr As String = tagForHit.Substring(idx5, len5)
                protNum = CInt(protNumStr)
            End If

            mParent.openParticularPeptide(protNum, queryNum)
        Else
            Dim peter2 As Integer = 2 'Did not hit any plotted point...
        End If

    End Sub 'openProtValWindowForClicked


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Function massErrors_ZedGraph_MouseDownEvent( _
      ByVal aSender As ZedGraph.ZedGraphControl, _
      ByVal anEvent As System.Windows.Forms.MouseEventArgs) _
      As Boolean _
      Handles massErrors_ZedGraph.MouseDownEvent

        'Dim pane As GraphPane = aSender.GraphPane

        'Changed PM_REFACTOR 2008-10-14.
        openProtValWindowForClicked( _
          aSender.GraphPane, anEvent.X, anEvent.Y)

        Return False
    End Function 'massErrors_ZedGraph_MouseDownEvent


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub massErrors2_ZedGraph_MouseMove( _
      ByVal aSender As System.Object, _
      ByVal anEvent As System.Windows.Forms.MouseEventArgs) _
      Handles massErrors2_ZedGraph.MouseMove

        'What is the difference between MouseMove and MouseMoveEvent??

        Dim peter2 As Integer = 2
    End Sub 'massErrors2_ZedGraph_MouseMove


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Function massErrors2_ZedGraph_MouseMoveEvent( _
      ByVal aSender As ZedGraph.ZedGraphControl, _
      ByVal anEvent As System.Windows.Forms.MouseEventArgs) _
      As System.Boolean _
      Handles massErrors2_ZedGraph.MouseMoveEvent

        Return False
    End Function 'massErrors2_ZedGraph_MouseMoveEvent


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Function massErrors2_ZedGraph_MouseUpEvent( _
      ByVal aSender As ZedGraph.ZedGraphControl, _
      ByVal anEvent As System.Windows.Forms.MouseEventArgs) _
      As System.Boolean _
      Handles massErrors2_ZedGraph.MouseUpEvent

        Return False
    End Function 'massErrors2_ZedGraph_MouseUpEvent


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Function massErrors2_ZedGraph_MouseDownEvent( _
      ByVal aSender As ZedGraph.ZedGraphControl, _
      ByVal anEvent As System.Windows.Forms.MouseEventArgs) _
      As System.Boolean _
      Handles massErrors2_ZedGraph.MouseDownEvent

        'Changed PM_OPENHIT_CALIBRATED_MASSERRORS 2008-10-14
        openProtValWindowForClicked( _
          aSender.GraphPane, anEvent.X, anEvent.Y)
    End Function 'massErrors2_ZedGraph_MouseDownEvent


    'Try to use ZedMouseEventHandler.
    'And perhaps nearest hit object, etc.


End Class 'frmRecalibrationVisualisation


    

    

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