'****************************************************************************
'* 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 the application, 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 System.Collections.Generic 'For List.
Imports App 'For quantApplication and automationInfoStructure.
'Note: sample command lines in frmMainForm_Load(), file frmMainForm.vb.
'Should it be another namespace??
Namespace AppAutomation
'Changed PM_COMMANDLINE 2006-11-15
Public Class automator
Private Enum task1StatesEnum
enumInitial1 = 337
enumLoadingBinFile
enumQuantitating2
'Changed PM_CMD_MS3_AND_PTM 2006-11-27
enumScoringPTM
enumScoringMS3
'Changed PM_COMMANDLINE_EXPORT 2008-08-22
enumExport
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 paramCheck2( _
ByVal aProteinsHitNumberStart As Integer, _
ByVal aProteinsHitNumberEnd As Integer, _
ByRef anOutProceeed As Boolean _
)
'Note: anOutProceeed will left ***unchanged*** if the
' condition (to proceed) is true.
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.quantProteinsStart2 & ")."
anOutProceeed = False
End If
End Sub 'paramCheck2
'Changed PM_COMMANDLINE_EXPORT 2008-08-22
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Private Sub doExport( _
ByVal aProteinsHitNumberStart2 As Integer, _
ByVal aProteinsHitNumberEnd2 As Integer _
)
Dim protein_dataIndex As Integer = 1 'Default value. Is overwritten below.
Dim lastProtein_dataIndex As Integer = 99999 'Default value. Is overwritten below.
Dim emptyRange As Boolean
mMascotResultForm.getDataIndicesFromProteinNumbers( _
aProteinsHitNumberStart2, _
aProteinsHitNumberEnd2, _
protein_dataIndex, _
lastProtein_dataIndex, _
emptyRange)
'Changed PM_AUTOEXPORT_BUG_EXPORTED_ALL_PROTEINS 2008-09-15
'We need this guard. Otherwise all proteins are exported when none
'are specified for export...
If Not emptyRange Then
Dim protein_dataIndexes As List(Of Integer) = Nothing 'Set below.
'Build list of indexes to comply to existing interface.
If True Then
Dim maxProteins As Integer = _
aProteinsHitNumberEnd2 - aProteinsHitNumberStart2 + 1 'Can be
' larger than the actual number as some proteins may missing (filtered
' out during parsing if the peptide filter is such that there are
' no peptides for protein.).
' +1: hit numbers are inclusive...
'
' Why don't we use protein_dataIndex and lastProtein_dataIndex to
' to find the exact number??
protein_dataIndexes = New List(Of Integer)(maxProteins)
Dim j As Integer
'Changed PM_AUTOEXPORT_BUG 2008-09-15. Protein hit numbers
' were used, not data index numbers!!!!!!!
'For j = aProteinsHitNumberStart2 To aProteinsHitNumberEnd2
For j = protein_dataIndex To lastProtein_dataIndex
protein_dataIndexes.Add(j)
Next j
End If
mMascotResultForm.exportProteinsAndPeptides2(protein_dataIndexes)
Else
Dim peter2 As Integer = 2 'For breakpoints. Export not specified
' on command line. Or some other reason?
End If
End Sub 'doExport()
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Private Sub vectorisedCommand2( _
ByVal aCommand As task1StatesEnum, _
ByVal aProteinsHitNumberStart2 As Integer, _
ByVal aProteinsHitNumberEnd2 As Integer _
)
Dim firstTime As Boolean = True
Dim protein_dataIndex As Integer = 1 'Default value. Is overwritten below.
Dim lastProtein_dataIndex As Integer = 99999 'Default value. Is overwritten below.
Dim emptyRange As Boolean
mMascotResultForm.getDataIndicesFromProteinNumbers( _
aProteinsHitNumberStart2, _
aProteinsHitNumberEnd2, _
protein_dataIndex, _
lastProtein_dataIndex, _
emptyRange)
Dim done As Boolean = emptyRange
While Not done 'We are not using a for loop as we may exit
' prematurely if the number of peptides is above the
' maximum (after a whole number of proteins). Or if there are
' no proteins in the specified range.
'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( _
protein_dataIndex, 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.enumQuantitating2
prValFrm.doUnattentedQuantitation(False)
Case task1StatesEnum.enumScoringPTM
prValFrm.doUnattendedPTMscoring()
Case task1StatesEnum.enumScoringMS3
prValFrm.doUnattentedMS3scoring()
'Changed PM_COMMANDLINE_EXPORT 2008-08-22
Case task1StatesEnum.enumExport
'We don't expect to be here as we don't need
'to open a protein validation window for each protein
'for export.
Trace.Assert(False, _
"PIL ASSERT. This should never happen...")
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 = _
protein_dataIndex >= lastProtein_dataIndex
done = _
tooManyPeptides Or _
quantifiedlastProtein
'For breakpoints...
If tooManyPeptides Then
Dim peter2 As Integer = 2
End If
End If
protein_dataIndex += 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.paramCheck2( _
mTask1params.quantProteinsStart2, _
mTask1params.quantProteinsEnd, _
proceeed)
Me.paramCheck2( _
mTask1params.PTMscoreProteinsStart, _
mTask1params.PTMscoreProteinsEnd, _
proceeed)
Me.paramCheck2( _
mTask1params.ms3scoreProteinsStart, _
mTask1params.ms3scoreProteinsEnd, _
proceeed)
'Changed PM_COMMANDLINE_EXPORT 2008-08-22
Me.paramCheck2( _
mTask1params.exportProteinsStart, _
mTask1params.exportProteinsEnd, _
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, _
AppConstants.CURRENT_SAVEDFILEVERSION) Then
mState = task1StatesEnum.enumQuantitating2
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.enumQuantitating2
'Changed PM_REFACTOR 2006-11-27
Me.vectorisedCommand2( _
task1StatesEnum.enumQuantitating2, _
mTask1params.quantProteinsStart2, _
mTask1params.quantProteinsEnd)
mState = task1StatesEnum.enumScoringPTM
Case task1StatesEnum.enumScoringPTM
'Changed PM_REFACTOR 2006-11-27
Me.vectorisedCommand2( _
task1StatesEnum.enumScoringPTM, _
mTask1params.PTMscoreProteinsStart, _
mTask1params.PTMscoreProteinsEnd)
mState = task1StatesEnum.enumScoringMS3
Case task1StatesEnum.enumScoringMS3
'Changed PM_REFACTOR 2006-11-27
Me.vectorisedCommand2( _
task1StatesEnum.enumScoringMS3, _
mTask1params.ms3scoreProteinsStart, _
mTask1params.ms3scoreProteinsEnd)
mState = task1StatesEnum.enumExport
'Changed PM_COMMANDLINE_EXPORT 2008-08-22
Case task1StatesEnum.enumExport
doExport( _
mTask1params.exportProteinsStart, _
mTask1params.exportProteinsEnd)
mState = task1StatesEnum.enumSaving
Case task1StatesEnum.enumSaving
Dim saveName As String = _
mTask1params.binPath
'Note: will save in latest format (e.g. MB4 ) even if
' the input file is in an older format (e.g. MB3).
mMascotResultForm.saveParseToBinFile( _
saveName, AppConstants.CURRENT_SAVEDFILEVERSION)
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( _
AppConstants.LONG_APP & _
" 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 " & _
AppConstants.LONG_APP & ")."
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 'AppAutomation
Generated by script codePublish.pl at 2009-01-05T15:20:59.