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

Table of contents page.

Home page for MSQuant.

'****************************************************************************
'* Copyright (C) 2004 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: Windows dialog for getting peptide modification filter          *
'*          user choices.                                                   *
'*                                                                          *
'****************************************************************************

'****************************************************************************
'*                               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:   frmModificationFilter.vb                                  *
'*    TYPE:  VISUAL_BASIC                                                   *
'*                                                                          *
'* CREATED: PM 2004-12-07   Vrs 1.0.                                        *
'* UPDATED: PM 2004-xx-xx                                                   *
'*                                                                          *
'****************************************************************************

Option Strict On
Option Explicit On 

Imports System.Text  'For StringBuilder
Imports System.Collections.Generic 'For Dictionary


Imports App 'For class quantApplication
Imports massSpectrometryBase 'For QuantitationModes
Imports massSpectrometryBase.quantitation


Public Class frmModificationFilter
    Inherits System.Windows.Forms.Form

    Private mPrefix As String = "_ModCB_"

    'Changed PM_PEPTIDEFILTER_GENERALISED 2007-08-24
    'Private mOptionsForm As frmOptions
    Private mFilterForm As frmPeptideFilters


    Private mApplication As quantApplication

    'Changed PM_EXCLUDE_MODFILTER 2008-06-30
    Private mToken As Integer
    Friend WithEvents btnSetQuantMods As System.Windows.Forms.Button
    Friend WithEvents btnInvertChecked As System.Windows.Forms.Button

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


    'Changed PM_SILAC_AWARE_PEPTIDEFILTERDIALOG 2008-10-06
    Private mSILACmodsCheckBoxes As List(Of System.Windows.Forms.CheckBox)


#Region " Windows Form Designer generated code "

    Public Sub New( _
      ByRef aInModificationFilter2 As Generic.List(Of Integer), _
      ByRef aParentForm As frmPeptideFilters, _
      ByRef anApp As quantApplication, _
      ByVal aToken As Integer, _
      ByRef anInDialogHeader As String, _
      ByRef aSILACmods As Dictionary(Of Integer, Integer) _
      )

        'Parameter aToken: for some client defined 
        '                  meaning (e.g. include or
        '                  exclude modification list)

        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

        Me.Init( _
          aInModificationFilter2, aParentForm, anApp, _
          aToken, anInDialogHeader, _
          aSILACmods)
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents cbxNoFilter As System.Windows.Forms.CheckBox
    Friend WithEvents lblDialogHeader As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnOK = New System.Windows.Forms.Button
        Me.btnCancel = New System.Windows.Forms.Button
        Me.cbxNoFilter = New System.Windows.Forms.CheckBox
        Me.lblDialogHeader = New System.Windows.Forms.Label
        Me.btnSetQuantMods = New System.Windows.Forms.Button
        Me.btnInvertChecked = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(232, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(152, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Peptide Modification Filter:"
        Me.Label1.Visible = False
        '
        'btnOK
        '
        Me.btnOK.Location = New System.Drawing.Point(335, 237)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 24)
        Me.btnOK.TabIndex = 1
        Me.btnOK.Text = "&OK"
        '
        'btnCancel
        '
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Location = New System.Drawing.Point(418, 237)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(72, 24)
        Me.btnCancel.TabIndex = 2
        Me.btnCancel.Text = "&Cancel"
        '
        'cbxNoFilter
        '
        Me.cbxNoFilter.Location = New System.Drawing.Point(224, 48)
        Me.cbxNoFilter.Name = "cbxNoFilter"
        Me.cbxNoFilter.Size = New System.Drawing.Size(128, 16)
        Me.cbxNoFilter.TabIndex = 3
        Me.cbxNoFilter.Text = "No filter"
        Me.cbxNoFilter.Visible = False
        '
        'lblDialogHeader
        '
        Me.lblDialogHeader.Location = New System.Drawing.Point(8, 8)
        Me.lblDialogHeader.Name = "lblDialogHeader"
        Me.lblDialogHeader.Size = New System.Drawing.Size(280, 16)
        Me.lblDialogHeader.TabIndex = 4
        Me.lblDialogHeader.Text = "<>"
        '
        'btnSetQuantMods
        '
        Me.btnSetQuantMods.Location = New System.Drawing.Point(11, 237)
        Me.btnSetQuantMods.Name = "btnSetQuantMods"
        Me.btnSetQuantMods.Size = New System.Drawing.Size(169, 24)
        Me.btnSetQuantMods.TabIndex = 5
        Me.btnSetQuantMods.Text = "Set &quantitation modifications"
        '
        'btnInvertChecked
        '
        Me.btnInvertChecked.Location = New System.Drawing.Point(196, 237)
        Me.btnInvertChecked.Name = "btnInvertChecked"
        Me.btnInvertChecked.Size = New System.Drawing.Size(102, 24)
        Me.btnInvertChecked.TabIndex = 6
        Me.btnInvertChecked.Text = "&Invert checked"
        '
        'frmModificationFilter
        '
        Me.AcceptButton = Me.btnOK
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.CancelButton = Me.btnCancel
        Me.ClientSize = New System.Drawing.Size(502, 273)
        Me.Controls.Add(Me.btnInvertChecked)
        Me.Controls.Add(Me.btnSetQuantMods)
        Me.Controls.Add(Me.lblDialogHeader)
        Me.Controls.Add(Me.cbxNoFilter)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmModificationFilter"
        Me.Text = "Peptide Modification Filter Options"
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Structure checkBoxItemStructure
        Dim text As String
        Dim ySize As Integer
        Dim checked As Boolean
        Dim modID2 As Integer

        Dim isSILACmod As Boolean
        Dim SILACdishOneBased As Integer 'Undefined if isSILACmod is false.
    End Structure 'checkBoxItemStructure


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub Init( _
      ByRef aInModificationFilter2 As Generic.List(Of Integer), _
      ByRef aParentForm As frmPeptideFilters, _
      ByRef anApp As quantApplication, _
      ByVal aToken As Integer, _
      ByRef anInDialogHeader As String, _
      ByRef aSILACmods As Dictionary(Of Integer, Integer) _
      )

        'Parameter aToken: for some client defined 
        '                  meaning (e.g. include or
        '                  exclude modification list).


        'Changed PM_PEPTIDEFILTER_GENERALISED 2007-08-24
        'mOptionsForm = aParentForm
        mFilterForm = aParentForm

        mApplication = anApp

        mToken = aToken

        'Changed PM_SILAC_AWARE_PEPTIDEFILTERDIALOG 2008-10-05
        mSILACmods = aSILACmods

        Dim MAX_TEXT_LEN As Integer = 43

        'Changed PM_MODFILTER_PAGING 2007-06-06
        Dim Y_MAX As Integer = 500 'It would be better to use the actual
        '  screen size. How do we get it?
        Dim xSize As Integer = 300 'Initial size. May be increased if
        '  there is a lot of modificatios.

        Dim checkBoxInfoList As Generic.List(Of checkBoxItemStructure) = _
          New Generic.List(Of checkBoxItemStructure)
        Dim ySize As Integer = -1

        If True Then 'Block. Go through defined modifications and build
            '  data structure for use in adding checkboxes below.

            'Make hash table to ease setting the checked modifications.

            'Changed PM_REFACTOR 2007-08-29
            ' 'Dim modHash As Hashtable = New Hashtable
            ' Dim modHash2 As Dictionary(Of Integer, Integer) = _
            '   New Dictionary(Of Integer, Integer)
            ' 
            ' Dim modID As Integer
            ' For Each modID In aInModificationFilter2
            '     modHash2.Add(modID, 1)
            ' Next
            Dim modHash2 As Dictionary(Of Integer, Integer) = _
              peptideFilterStructure.hashForModFilter(aInModificationFilter2)

            Dim quantitationModesObject As QuantitationModes_moreGeneral = _
              mApplication.getQuantModes()

            'Dim definedMods As ArrayList = _
            '  quantitationModesObject.getModifications()
            Dim definedMods2 As Generic.List( _
              Of quantModificationStructure) = _
                quantitationModesObject.getModifications()

            Dim chkYdiff As Integer = 24
            'Dim ySize As Integer = len * chkYdiff + 100 + 30

            Dim START_YSIZE As Integer = 100 + 30
            ySize = START_YSIZE 'Starting value. Margins for before and after
            '  the checkboxes to be added.

            Dim curY As Integer = START_YSIZE

            'Changed PM_SILAC_AWARE_PEPTIDEFILTERDIALOG 2008-10-06
            mSILACmodsCheckBoxes = New List(Of System.Windows.Forms.CheckBox)

            'First loop: find strings (for length) and total y size of the dialog.
            Dim modItem As quantModificationStructure
            For Each modItem In definedMods2

                Dim checkStatus As Boolean = False
                Dim modID As Integer = modItem.quantModificationID
                If modHash2.ContainsKey(modID) Then
                    checkStatus = True
                End If

                'Changed PM_SILAC_AWARE_PEPTIDEFILTERDIALOG 2008-10-06
                Dim isSILACmodification As Boolean = False 'In current quantitation 
                '  mode - not any SILAC modification.
                Dim dishNumberZeroBased2 As Integer
                If mSILACmods.TryGetValue(modID, dishNumberZeroBased2) Then
                    isSILACmodification = True
                Else
                    dishNumberZeroBased2 = -77
                End If
                Dim dishNumberOneBased As Integer = dishNumberZeroBased2 + 1

                Dim msgSB As StringBuilder = New StringBuilder
                msgSB.Append(modItem.modificationName)
                msgSB.Append(". ")
                Dim someAAset As AAsetStruct
                For Each someAAset In modItem.affectedAAs
                    msgSB.Append("+")
                    msgSB.Append(someAAset.diffFromBase3)
                    msgSB.Append(" Da for ")
                    msgSB.Append(someAAset.AAs)
                    msgSB.Append(". ")
                Next

                'Changed PM_TERMMOD 2007-09-10
                If Not (modItem.startPosition = 1 AndAlso _
                        modItem.endPosition2 = -1) Then

                    msgSB.Append("Pos ")
                    msgSB.Append(modItem.startPosition)
                    msgSB.Append(" to ")
                    msgSB.Append(modItem.endPosition2)
                    msgSB.Append(". ")
                End If

                'Changed PM_SILAC_AWARE_PEPTIDEFILTERDIALOG 2008-10-06
                If isSILACmodification Then
                    msgSB.Append("SILAC dish ")
                    msgSB.Append(dishNumberOneBased)
                    msgSB.Append(". ")
                End If

                Dim chkText As String = msgSB.ToString

                Dim yDiff As Integer = chkYdiff
                If chkText.Length >= MAX_TEXT_LEN Then
                    yDiff = _
                      CInt(chkText.Length / MAX_TEXT_LEN - 0.5 + 1.0) * chkYdiff
                End If

                Dim someNewItem As checkBoxItemStructure
                someNewItem.text = chkText
                someNewItem.checked = checkStatus
                someNewItem.ySize = yDiff
                someNewItem.modID2 = modID

                'Changed PM_SILAC_AWARE_PEPTIDEFILTERDIALOG 2008-10-06
                someNewItem.isSILACmod = isSILACmodification
                someNewItem.SILACdishOneBased = dishNumberOneBased

                checkBoxInfoList.Add(someNewItem)

                'Changed PM_MODFILTER_PAGING 2007-06-06

                curY += yDiff
                If curY > ySize Then
                    ySize = curY
                End If

                If curY > Y_MAX Then
                    curY = START_YSIZE
                    xSize += 300
                End If
            Next

            'Set window title.
            If True Then 'Block. 
                'Override whatever was defined in the designer.
                '
                'For now report total number of mods. In future we
                'could provide other statistics.
                Dim len2 As Integer = definedMods2.Count
                Dim windowTitle As String = _
                  "Peptide Modification Filter Options. " & _
                  len2 & " defined modifications."
                Me.Text = windowTitle
            End If 'Block.

        End If 'Block. Go through defined modifications.

        ySize += 100 'Make space for the OK and Cancel button.

        Dim newSize As System.Drawing.Size = Me.Size
        newSize.Height = ySize

        'Changed PM_MODFILTER_PAGING 2007-06-06
        newSize.Width = xSize
        Me.Size = newSize

        Dim index As Integer = 0

        Dim X_LOC_START As Integer = 40


        Dim Y_LOC_START As Integer = 48


        Dim yLoc As Integer = Y_LOC_START
        Dim xLoc As Integer = X_LOC_START

        Dim loc As System.Drawing.Point

        'Create one checkbox for each modification defined in the quantitation
        'modes file. Use the Tag property to store the modification ID.
        Dim someItem As checkBoxItemStructure
        For Each someItem In checkBoxInfoList
            Dim cbName As String = mPrefix & index

            loc.X = xLoc
            loc.Y = yLoc

            Dim yDiff As Integer = someItem.ySize

            Dim newCB As System.Windows.Forms.CheckBox = _
              Nothing 'Keep compiler happy.
            quantApplication.addCheckBox( _
              Me, cbName, someItem.text, loc, _
              someItem.checked, someItem.modID2.ToString, newCB)


            'Changed PM_SILAC_AWARE_PEPTIDEFILTERDIALOG 2008-10-06
            'Keep references to the SILAC ones. Then we don't have to
            'search for a mark or tag later.
            If someItem.isSILACmod Then
                mSILACmodsCheckBoxes.Add(newCB)
                newCB.ForeColor = Color.DarkRed
            End If


            'Needed?
            ''Changed PM_MODIFICATION_FILTER_UNTIDYNESS 2006-08-01
            'newCB.AutoSize = True

            newCB.Height = yDiff

            index += 1
            yLoc += yDiff

            'Changed PM_MODFILTER_PAGING 2007-06-06
            If yLoc > Y_MAX Then
                yLoc = Y_LOC_START
                xLoc += 300
            End If
        Next 'Through checkBoxInfoList

        'Adjust X and y-position of OK, Cancel and other buttons to account for
        'the variable number of modifications.
        If True Then 'Block.

            Dim xDiff As Integer = _
              xLoc - X_LOC_START - _
              (-50 + btnSetQuantMods.Width + btnInvertChecked.Width)

            Dim buttonsY As Integer = ySize - 70

            'Changed PM_REFACTOR 2008-10-06
            ' If True Then
            '     Dim locOK As System.Drawing.Point = btnOK.Location
            '     locOK.Y = buttonsY
            '
            '     'Changed PM_STANDARDISE 2007-06-20
            '     locOK.X += xDiff
            '
            '     btnOK.Location = locOK
            ' End If
            '
            ' If True Then
            '     Dim locCancel As System.Drawing.Point = btnCancel.Location
            '     locCancel.Y = buttonsY
            '
            '     'Changed PM_STANDARDISE 2007-06-20
            '     locCancel.X += xDiff
            '
            '     btnCancel.Location = locCancel
            ' End If
            adjustButtonLoc(btnOK, buttonsY, xDiff)
            adjustButtonLoc(btnCancel, buttonsY, xDiff)

            'Changed PM_SILAC_AWARE_PEPTIDEFILTERDIALOG 2008-10-06
            adjustButtonLoc(btnSetQuantMods, buttonsY, xDiff)
            adjustButtonLoc(btnInvertChecked, buttonsY, xDiff)
        End If 'Block. Adjust X and y-position of buttons.

        'Changed PM_EXCLUDE_MODFILTER 2008-06-30
        lblDialogHeader.Text = anInDialogHeader
    End Sub 'Init


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub adjustButtonLoc( _
      ByRef anInOutButton As Button, _
      ByVal anAbsoluteY As Integer, _
      ByVal aDiffX As Integer)

        Dim locButton As System.Drawing.Point = anInOutButton.Location
        locButton.X += aDiffX
        locButton.Y = anAbsoluteY
        anInOutButton.Location = locButton
    End Sub 'adjustButtonLoc()


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

        'Read-off ... and create new.

        'Changed PM_PEPTIDECOUNT_BUG 2007-09-04
        ''Changed PM_TYPESAFE 2007-08-23
        ''Dim filterIDs As ArrayList = New ArrayList
        'Dim filterIDs2 As Generic.List(Of Integer) = _
        '  New Generic.List(Of Integer)
        Dim filterIDs2 As Generic.List(Of Integer) = Nothing

        Dim control As Control
        For Each control In Me.Controls
            If control.Name.StartsWith(mPrefix) Then
                Dim chk As System.Windows.Forms.CheckBox = _
                  DirectCast(control, System.Windows.Forms.CheckBox)
                Dim checkStatus As Boolean = chk.Checked

                If checkStatus Then
                    'Changed PM_PEPTIDECOUNT_BUG 2007-09-04
                    'Is must be Nothing if there are no modifications in the
                    'filter. (In this case we never get here).
                    If filterIDs2 Is Nothing Then
                        filterIDs2 = New Generic.List(Of Integer)
                    End If

                    Dim modID As Integer = CInt(chk.Tag)
                    filterIDs2.Add(modID)
                End If
            Else
                Dim peter2 As Integer = 2 'Not a modification checkbox...
            End If
        Next 'Through controls, most of them check bottons.

        mFilterForm.newModFilterList3(filterIDs2, mToken)

        Me.Close()
    End Sub 'btnOK_Click


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub btnCancel_Click( _
      ByVal sender As System.Object, ByVal e As System.EventArgs) _
      Handles btnCancel.Click

        Me.Close()
    End Sub 'btnCancel_Click


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub frmModificationFilter_Load( _
      ByVal sender As System.Object, ByVal e As System.EventArgs) _
      Handles MyBase.Load

        'Why does this function exist?

    End Sub 'frmModificationFilter_Load


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

        Dim someCheckBox As System.Windows.Forms.CheckBox
        For Each someCheckBox In mSILACmodsCheckBoxes
            someCheckBox.Checked = True
        Next 'Through list of SILAC modification checkboxes 
    End Sub 'btnSetQuantMods_Click


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

        Dim control As Control
        For Each control In Me.Controls
            If control.Name.StartsWith(mPrefix) Then
                Dim chk As System.Windows.Forms.CheckBox = _
                  DirectCast(control, System.Windows.Forms.CheckBox)
                Dim checkStatus As Boolean = chk.Checked

                chk.Checked = Not checkStatus
            Else
                Dim peter2 As Integer = 2 'Not a modification checkbox...
            End If
        Next 'Through controls, most of them check bottons.

    End Sub 'btnInvertChecked_Click


End Class 'frmModificationFilter


    

    

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