'****************************************************************************
'* Copyright (C) 2006 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: Holds Class automator, see below for *
'* documentation. It allows for external scripts to *
'* start a series of steps in MSQuant, e.g. load bin file, do *
'* quantitation on specified proteins, save to bin file and *
'* exit of the program. *
'* *
'****************************************************************************
'****************************************************************************
'* CEBI *
'* Software Development Group *
'* Peter Mortensen *
'* WWW: http://www.cebi.sdu.dk/ *
'* *
'* Program for post-processing of result from search in mass *
'* spectrometric data. *
'* *
'* FILENAME: automator.vb *
'* TYPE: VISUAL_BASIC *
'* *
'* CREATED: PM 2006-11-15 Vrs 1.0. Estimated date... *
'* UPDATED: PM 2006-xx-xx *
'* *
'****************************************************************************
Option Strict On
Option Explicit On
Imports MSQuant 'For quantApplication and automationInfoStructure.
'Should it be another namespace??
Namespace MSQuantAutomation
'Changed PM_COMMANDLINE 2006-11-15
Public Class automator
Private Enum task1StatesEnum
enumInitial1 = 337
enumLoadingBinFile
enumQuantitating
'Changed PM_CMD_MS3_AND_PTM 2006-11-27
enumScoringPTM
enumScoringMS3
enumSaving
enumExit
enumError_BadInputParameters
enumError_Loading
End Enum 'task1StatesEnum
Private mMainWindow As frmMainForm
Private mTaskNumber As Integer
Private mState As Integer
Private mBusyWithAtomicOperation As Boolean 'Avoid problem
' with re-entrance.
' Can be considered a sub-state for each main state.
Private mTask1params As automationInfoStructure
'What if we have several??
Private mMascotResultForm As frmProteinList
Private mApplication As quantApplication
Private mErrMsg_Parameters As String 'Sort of a sub state; there can
' be many types of ***parameter*** errors.
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub New( _
ByRef anInForm As frmMainForm, _
ByRef anInApplication As quantApplication)
MyBase.New()
Trace.Assert(Not anInForm Is Nothing, "PIL ASSERT. anInForm Is Nothing.")
Trace.Assert(Not anInApplication Is Nothing, _
"PIL ASSERT. anInApplication Is Nothing.")
Me.init(anInForm, anInApplication)
End Sub 'New
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub init( _
ByRef anInForm As frmMainForm, _
ByRef anInApplication As quantApplication)
mMainWindow = anInForm
mApplication = anInApplication
mTaskNumber = -1
mState = -1
mMascotResultForm = Nothing
End Sub 'init
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub initTask1(ByVal aParams As automationInfoStructure)
mTask1params = aParams
mTaskNumber = 1
mState = task1StatesEnum.enumInitial1
mBusyWithAtomicOperation = False
End Sub 'initTask1
'Changed PM_REFACTOR 2006-11-27
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Private Sub paramCheck( _
ByVal aProteinsHitNumberStart As Integer, _
ByVal aProteinsHitNumberEnd As Integer, _
ByRef anOutProceeed As Boolean _
)
'Note: anOutProceeed will left ***unchanged*** if the condition (to proceed) is
If aProteinsHitNumberEnd < aProteinsHitNumberStart Then
mState = _
task1StatesEnum.enumError_BadInputParameters
mErrMsg_Parameters = _
"Protein number range not accepted. " & _
"The end protein number (" & _
mTask1params.quantProteinsEnd & ") must equal to " & _
"or greater than the start protein number (" & _
mTask1params.quantProteinsStart & ")."
anOutProceeed = False
End If
End Sub 'paramCheck
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Private Sub vectorisedCommand( _
ByVal aCommand As task1StatesEnum, _
ByVal aProteinsHitNumberStart As Integer, _
ByVal aProteinsHitNumberEnd As Integer _
)
Dim firstTime As Boolean = True
'Bad: data-index is not the same as the protein
' number - there may be missing protein in
' the list; especially at the end.
Dim proteinIndex As Integer = 1
Dim lastProteinIndex As Integer = 99999
Dim emptyRange As Boolean
mMascotResultForm.getDataIndicesFromProteinNumbers( _
aProteinsHitNumberStart, _
aProteinsHitNumberEnd, _
proteinIndex, _
lastProteinIndex, _
emptyRange)
Dim done As Boolean = emptyRange
While Not done
'Is called inside the loop because we need to update
'the protein validation window with a new protein.
Dim OKtoUse As Boolean = _
mMascotResultForm.auto_openPrValFrm2( _
proteinIndex, firstTime, 0)
'Changed PM_CMD_EMPTY_PROTEINS 2006-11-22
If OKtoUse Then
Dim prValFrm As frmProtValidation = _
mMascotResultForm.getCurPrValFrm()
'We could get the protein number by
'asking someProteinVal...
Select Case aCommand
Case task1StatesEnum.enumQuantitating
prValFrm.doUnattentedQuantitation(False)
Case task1StatesEnum.enumScoringPTM
prValFrm.doUnattendedPTMscoring()
Case task1StatesEnum.enumScoringMS3
prValFrm.doUnattentedMS3scoring()
Case Else
Trace.Assert(False, "PIL ASSERT. Select Case never fall-through")
End Select
Else
Dim peter2 As Integer = 2 'Empty protein, no peptides...
End If
If True Then
Dim qPepts As Integer = _
mApplication.getQuantifiedPeptideCount()
Dim tooManyPeptides As Boolean = _
qPepts > mTask1params.maxPeptides
Dim quantifiedlastProtein As Boolean = _
proteinIndex >= lastProteinIndex
done = _
tooManyPeptides Or _
quantifiedlastProtein
'For breakpoints...
If tooManyPeptides Then
Dim peter2 As Integer = 2
End If
End If
proteinIndex += 1
End While
End Sub 'vectorisedCommand
'****************************************************************************
'* doIdle() *
'****************************************************************************
Public Function doIdle() _
As Boolean
'Return value: TRUE for busy.
' FALSE for idle - end of job, error state or similar.
Dim busy As Boolean = True
Select Case mTaskNumber
Case 1
If mBusyWithAtomicOperation Then
Dim peter7 As Integer = 7 'We can be here if we get back
' here as a result of a call to Application.DoEvents().
' It works with this flag because we are single-threaded.
Else
mBusyWithAtomicOperation = True
Select Case mState
Case task1StatesEnum.enumInitial1
'This state exists to delay the loading, so
'the application can come to rest.
'
'It would probably be better to explicitly
'have mechanisms for this as a heavily computer
'can delay the start-up.
mState = task1StatesEnum.enumLoadingBinFile
Case task1StatesEnum.enumLoadingBinFile
'Changed PM_CMD_PARAMETER_CHECKS 2006-11-22. If
' the end protein number was specified
' less than the start protein numbers then
' it would quantify all proteins!
'
Dim proceeed As Boolean = True
If True Then 'First some parameter checks...
'Changed PM_REFACTOR 2006-11-27
Me.paramCheck( _
mTask1params.quantProteinsStart, _
mTask1params.quantProteinsEnd, _
proceeed)
Me.paramCheck( _
mTask1params.PTMscoreProteinsStart, _
mTask1params.PTMscoreProteinsEnd, _
proceeed)
Me.paramCheck( _
mTask1params.ms3scoreProteinsStart, _
mTask1params.ms3scoreProteinsEnd, _
proceeed)
'Should we report immediately instead of
'in the state??
End If
'Later:
' Check that the file exists before trying
' to load it. A new error state should be
' added.
If proceeed Then
If mMainWindow.externalControl_loadBinFile2( _
mTask1params.binPath, _
mMascotResultForm) Then
mState = task1StatesEnum.enumQuantitating
Else
mState = task1StatesEnum.enumError_Loading
End If
End If
'Note: We chain; execute one command after another.
' This implies a defined order (user can not
' specify it) and commands is upper level, all
' proteins will be quantified, then all proteins
' are PTM scored, etc.
Case task1StatesEnum.enumQuantitating
'Changed PM_REFACTOR 2006-11-27
Me.vectorisedCommand( _
task1StatesEnum.enumQuantitating, _
mTask1params.quantProteinsStart, _
mTask1params.quantProteinsEnd)
mState = task1StatesEnum.enumScoringPTM
Case task1StatesEnum.enumScoringPTM
'Changed PM_REFACTOR 2006-11-27
Me.vectorisedCommand( _
task1StatesEnum.enumScoringPTM, _
mTask1params.PTMscoreProteinsStart, _
mTask1params.PTMscoreProteinsEnd)
mState = task1StatesEnum.enumScoringMS3
Case task1StatesEnum.enumScoringMS3
'Changed PM_REFACTOR 2006-11-27
Me.vectorisedCommand( _
task1StatesEnum.enumScoringMS3, _
mTask1params.ms3scoreProteinsStart, _
mTask1params.ms3scoreProteinsEnd)
mState = task1StatesEnum.enumSaving
Case task1StatesEnum.enumSaving
Dim saveName As String = _
mTask1params.binPath
mMascotResultForm.saveParseToBinFile(saveName)
mState = task1StatesEnum.enumExit
Case task1StatesEnum.enumExit
Dim dummy As Boolean
mMainWindow.doClose2(True, dummy)
mTaskNumber = -1 'End state...
'Error states (unfortunately forced indention):
Case task1StatesEnum.enumError_BadInputParameters
'Changed PM_CMD_PARAMETER_CHECKS 2006-11-22
mTaskNumber = -1 'End state...
MsgBox( _
"MSQuant could not proceed. " & _
"Command line parameters were not accepted. " & _
mErrMsg_Parameters)
Case task1StatesEnum.enumError_Loading
mTaskNumber = -1 'End state...
Dim mgs2 As String = _
"Error loading saved parse " & _
mTask1params.binPath & _
". (Command line start of MSQuant)."
MsgBox(mgs2)
'Note: end state, we don't exit the program
' as we normally would.
Case Else
Trace.Assert(False, _
"PIL ASSERT. Select Case never fall-through. " & _
"Unknown or unhandled state in doIdle()")
End Select
mBusyWithAtomicOperation = False
End If 'Not busy with atomic operation...
Case Else
busy = False 'No current task. Let the client know so
'busy calling can be avoided.
End Select
Return busy
End Function 'doIdle
End Class 'automator
End Namespace 'MSQuantAutomation
Generated by script codePublish.pl at 2008-09-23T11:59:18.