Source code for MSQuant: AnalystRawDataFileHandling.vb, MSQuant/msquant/src/main/massbase/AnalystRawDataFileHandling.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: Holds Class AnalystRawDataFileHandling, see below               *
'*          for documentation.                                              * 
'*                                                                          *
'****************************************************************************

'****************************************************************************
'*                               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:   AnalystRawDataFileHandling.vb                             *
'*    MAIN_CLASS:   AnalystRawDataFileHandling                              *
'*    STRUCTS_AND_CLASSES:   <none>                                         *
'*    TYPE:       VISUAL_BASIC                                              *
'*                                                                          *
'* CREATED: PM 2003-06-06   Vrs 1.0.                                        *
'* UPDATED: PM 2003-xx-xx                                                   *
'*                                                                          *
'****************************************************************************

'Future: 
' 1. Unit testing: bad input, e.g. file does not exist.
' 2.
' 3.
' 4.


Option Strict On
Option Explicit On 

Imports System.IO 'For "File".

'Changed PM_DOTNET_HELL 2007-06-22
''Changed PM_REFERENCES 2004-07-20
'Imports ExploreDataObjects '\Analyst\bin\ExploreDataObjects.dll

'Requires adding references to project, 3 files:
'  QS20.Interop.ExploreDataObjects.dll 
'
'Those 3 are generated by the BAT script "Vendor COM versioning.bat", 
'using Tlbimp and Aximp. 



'Requires adding reference to project:
'  menu Project/Add Reference/Browse, 
'  select D:\Program Files\Analyst\bin\ExploreDataObjects.dll.

'Typical objects:
'  ExploreDataObjects.WhichClosestPointType.CLOSEST_POINT
'  ExploreDataObjects.FMANSpecData
'  ExploreDataObjects.FMANWiffFile
'  ExploreDataObjects.FMANWiffFileControl
'  ExploreDataObjects.XYData



'****************************************************************************
'd$ <summary>
'd$   Purpose: Namespace for lower layers of mass spectrometric
'd$            applications: raw data file handling, descriptive statistics,
'd$            fragment masses, digestion, file associations, etc.
'd$   <see cref="T:VBXMLDoc.CVBXMLDoc" />.
'd$   <isUnitTest></isUnitTest>
'd$   <applicationname>test_rawDataFileHandling</applicationname>
'd$   <author>Peter Mortensen</author>
'd$   <seealso>http://www.cebi.sdu.dk/</seealso>
'd$   <codetype>PLATFORM independent</codetype>
'd$ </summary>
Namespace massSpectrometryBase


    '****************************************************************************
    'd$ <summary>
    'd$   Purpose: 
    'd$     Knows about handling of Analyst/WIFF raw data files with mass spectra.
    'd$ 
    'd$     ?(or is it the base class): Hides the fact that the Analyst
    'd$     compoment (XYZ) can only handle one open WIFF file at a time.
    'd$ 
    'd$   <see cref="T:VBXMLDoc.CVBXMLDoc" />.
    'd$   <applicationname>test_rawDataFileHandling</applicationname>
    'd$   <author>Peter Mortensen</author>
    'd$   <seealso>http://www.cebi.sdu.dk/</seealso>
    'd$   <codetype>PLATFORM independent</codetype>
    'd$ </summary>
    Public Class AnalystRawDataFileHandling
        Inherits rawDataFileHandling


        'Changed PM_REFACTOR 2005-03-05
        Private Structure setSpectrumParametersStructure
            Dim sampleNumber As Integer
            Dim periodNumber As Integer
            Dim experimentNumber As Integer
            Dim timeSeconds As Single
        End Structure


        'Changed PM_REFACTOR 2007-07-18
        ' 'Changed PM_DOTNET_HELL 2007-06-22
        ' 'Dim mANALYSTCOM_Data As FMANSpecData 'Current XYZ, we can only open one at a time.
        ' ''  Requires adding reference to project: menu Project/Add Reference/Browse, 
        ' ''  select D:\Program Files\Analyst\bin\ExploreDataObjects.dll
        Private mANALYSTCOM_Data5 As QS20.ExploreDataObjects.FMANSpecData
        '
        'Why do we have a reference here in the base/controller class to
        'a specific version, QS 2.0?


        ' 'Changed PM_DOTNET_HELL 2007-06-22
        ' 'Dim mANALYSTCOM_WiffFile As FMANWiffFile
        ' Private mANALYSTCOM_WiffFile3 As QS20.ExploreDataObjects.FMANWiffFile
        ' 
        ' 'Changed PM_DOTNET_HELL 2007-06-22
        ' ''Changed PM_QSTAR_DOUBLE_INSTANCE 2007-06-11. Only in the
        ' ''  constructor; was instantiated twice before.
        ' ''Dim mANALYSTCOM_WFC As New FMANWiffFileControl
        ' 'Dim mANALYSTCOM_WFC As FMANWiffFileControl
        ' Private mANALYSTCOM_WFC3 As QS20.ExploreDataObjects.FMANWiffFileControl
        Private mANALYST3 As AnalystCOM 'Actual type at runtime is one of the derived.


        'Dim mExperimentNumber As Integer
        'Dim mExperimentInfo As spectrumSpecificationStructure

        Private mSpectrumRange As spectrumRangeStructure
        Private mSpectrumParameters As setSpectrumParametersStructure


        '****************************************************************************
        '*  SUBROUTINE NAME:   New                                                  *
        'd$ <summary> N/A </summary>
        Public Sub New(ByRef anInSpectrumClassifier As spectrumClassifier, _
          ByVal aCOMversion As COMversionEnum)
            MyBase.New(anInSpectrumClassifier, aCOMversion) 'Is this necessary? Yes!

            'InitializeComponent()    Is this necessary??

            'Add any initialization after the InitializeComponent() call


            'Changed PM_COMVERSIONS 2007-07-24
            ''Changed PM_REFACTOR 2007-07-18
            ''mANALYSTCOM_Data2 = New QS20.ExploreDataObjects.FMANSpecData
            ''mANALYSTCOM_WFC2 = New QS20.ExploreDataObjects.FMANWiffFileControl
            'mANALYST3 = New QS20analystCOM() 'QS 2.0 for now.
            mANALYST3 = DirectCast(newCOMobject(aCOMversion), AnalystCOM)



            'mExperimentNumber = 0 'Stays this way unless changed by the client.
        End Sub 'New()


        'Changed PM_JA_FINNEGAN_ASSERT_RESOURCE_LEAK 2003-12-19
        '****************************************************************************
        '*  SUBROUTINE NAME:   doCleanUp                                            *
        'd$ <summary> N/A </summary>
        Public Overrides Sub doCleanUp()

            'Nothing for now....
            Dim peter53 As Integer = 53
        End Sub 'Dispose


        '****************************************************************************
        '*  SUBROUTINE NAME:   COMversionString                                     *
        'd$ <summary>
        'd$          
        'd$ </summary>
        Private Shared Function COMversionString( _
          ByVal anCOMversion As COMversionEnum) _
          As String

            Dim toReturn As String = Nothing

            Select Case anCOMversion
                Case COMversionEnum.enumAnalystQS10
                    toReturn = "Analyst QS 1.0"
                Case COMversionEnum.enumAnalystQS11
                    toReturn = "Analyst QS 1.1"
                Case COMversionEnum.enumAnalystQS20
                    toReturn = "Analyst QS 2.0"

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

            Return toReturn
        End Function 'COMversionString


        '****************************************************************************
        '*  SUBROUTINE NAME:   autoDetectCOMversion                                 *
        'd$ <summary>
        'd$          
        'd$ </summary>
        Private Function autoDetectCOMversion( _
          ByRef anInFileFullPath As String, ByVal aSampleNumber As Integer, _
          ByVal anOrigCOMversion As COMversionEnum, _
          ByRef anOutExplainStr As String) _
          As Boolean

            'Perhaps return a list of checked analyst versions (e.g. for the
            'case where no version could be detected).

            'Perhaps check trivial things like file existence.

            Dim toReturn As Boolean = False

            Dim versionList As Generic.List(Of COMversionEnum) = _
              New Generic.List(Of COMversionEnum)
            'versionList.Add(COMversionEnum.enumAnalystQS10)  Not yet. Avoid ASSERT.
            versionList.Add(COMversionEnum.enumAnalystQS11)
            versionList.Add(COMversionEnum.enumAnalystQS20)

            Dim IDList As Generic.List(Of String) = _
              New Generic.List(Of String)
            IDList.Add("")
            IDList.Add("")
            IDList.Add("")

            Dim someVersion As COMversionEnum
            For Each someVersion In versionList

                Try
                    Dim someNewAnalystObj As AnalystCOM = _
                      DirectCast(newCOMobject(someVersion), _
                        AnalystCOM)
                    someNewAnalystObj.data_setWiffFileName( _
                      anInFileFullPath, aSampleNumber)

                    'We are here if it succeeded...
                    toReturn = True

                    Dim origStr As String = COMversionString(anOrigCOMversion)
                    Dim detectedStr As String = COMversionString(someVersion)

                    anOutExplainStr = _
                      AppConstants.LONG_APP & _
                      " currently assumes that " & origStr & _
                      " is installed. However it seems that " & detectedStr & _
                      " is installed on computer. " & _
                      "To change " & _
                      AppConstants.LONG_APP & "'s assumption edit the " & _
                      "field 'COMversion' in the file " & _
                      AppConstants.NEW_PARSER_SETTINGS_FILENAME & _
                      ", <vendors> / <vendor> / ""QSTAR/Sciex/Analyst"". " & _
                      "Valid values are: enumAnalystQS11 and enumAnalystQS20."
                    Exit For

                Catch ex As Exception
                    'Ignore. Try the next COM version...
                End Try
            Next 'Through versionList

            If Not toReturn Then
                anOutExplainStr = ""
            End If

            Return toReturn
        End Function 'autoDetectCOMversion


        '****************************************************************************
        '*  SUBROUTINE NAME:   openRawFile                                          *
        'd$ <summary>Analyst specific open action - use the component XYZ to prepare
        'd$          for reading
        'd$ </summary>
        Protected Overrides Sub openRawFile(ByVal aFileSpec As fileSpecStructure)

            mOpenRawCalls += 1

            Trace.Assert(File.Exists(aFileSpec.path), _
              "PIL ASSERT. File does not exist, " _
              & aFileSpec.path & ".")

            'Changed PM_IRINA_SAMPLE_NUMBER_TROUBLE 2003-12-02
            'Dim sample As Integer = 1 '1: sample, to be generalised.

            Try 'Failed in Greifswald....

                'Note: will fail here (because of the way this class  
                '      is used by the application) if the installed  
                '      version of Analyst QS on the client computer 
                '      does not match the setting in the  
                '      application. We will try to 
                '      auto-detect the installed 
                '      version and advise the 
                '      user based on the 
                '      result.
                '
                'Note on the exception:
                '  with the application setting equal to QS20 
                '  and Analyst QS 1.1 installed the exception 
                '  is something like: 
                '
                '        "'Attempted to read or write protected memory.
                '        This is often an indication that other memory is
                '        corrupt.',	System.AccessViolationException"

                mANALYST3.data_setWiffFileName( _
                  aFileSpec.path, mSampleNumberInRawFile)

            Catch exceptionObject As Exception

                ' Dim cr As String = ControlChars.NewLine 'Shortcut..
                ' Dim extraInfo As String = _
                '   "Setting of property WiffFileName on mANALYSTCOM_Data failed. " & _
                '   "Wiff file that was to be set: " & aFileSpec.path & cr & _
                '   cr
                ' 
                ' AppCommon2.displayStandardExceptionInfo( _
                '   exceptionObject, _
                '   extraInfo)

                Dim msgPrefix As String = _
                  AppConstants.LONG_APP & " could not open the wiff file " & _
                  aFileSpec.path & ". "

                Dim str2 As String = Nothing
                If Me.autoDetectCOMversion( _
                  aFileSpec.path, mSampleNumberInRawFile, _
                  mCOMversion, str2) Then

                    Dim msgStr As String = _
                      msgPrefix & _
                      "It seems the version of Analyst QS set in " & _
                      AppConstants.LONG_APP & _
                      " does not match the version that is installed on " & _
                      "the computer. " & _
                      str2
                    MsgBox(msgStr)
                Else
                    Dim msgStr2 As String = _
                      msgPrefix & _
                      "Based on this wiff file " & AppConstants.LONG_APP & _
                      " could not detect which " & _
                      "version of Analyst QS is installed. Either the wiff " & _
                      "file is bad, there is something wrong with the " & _
                      "installation of Analyst QS or the installed version " & _
                      "of Analyst QS is either too new or too old... Try to " & _
                      "use a wiff file that is known to work, e.g. the " & _
                      "standard QSTAR dataset from the " & _
                      AppConstants.LONG_APP & " home page. " & _
                      str2

                    MsgBox(msgStr2)
                End If

                Exit Sub
            End Try

            'Changed PM_REFACTOR 2007-07-18. Now implicit
            '  in data_setWiffFileName().
            ''Note: If file does not exist then this exception can happen:
            ''        System.Runtime.InteropServices.COMException()
            ''
            '' Failed with QS 2.0 (with hotfixes till 2007-02).
            'mANALYSTCOM_WiffFile2 = _
            '  mANALYSTCOM_WFC2.GetWiffFileObject( _
            '    aFileSpec.path, mSampleNumberInRawFile)

            Dim cycle As Integer = 1

            'For Mascot/Analyst: Cycle is derived from the retention time
            '  that is encoded in the Mascot result HTML file.

            Dim tickCount1 As Integer = Environment.TickCount 'Unit is 1e-3 secs

            'Changed PM_REFACTOR 2007-07-18
            ''  It seems this can take a very long time (seconds).
            ''  Example: 2.7 for seconds for
            ''  "\TripleEncoding\Q1LCMS190203_01DoubleArg.wiff",
            ''  cycle=1.
            'Dim startT As Single = _
            '  mANALYSTCOM_WiffFile2.GetActualTimeFromPeriodAndCycle( _
            '    1, 0, 0, cycle)
            Dim startT As Single = _
              mANALYST3.wiffFile_GetActualTimeFromPeriodAndCycle( _
                1, 0, 0, cycle)

            'Changed PM_REFACTOR 2007-07-18
            ''Changed PM_ANALYST_BACKINBUSINESS 2003-08-22
            'Dim period As Integer = 0
            'Dim cycles As Integer = _
            '  mANALYSTCOM_WiffFile3.GetActualNumberOfCycles( _
            '     mSampleNumberInRawFile, period)
            Dim period As Integer = 0
            Dim cycles As Integer = _
              mANALYST3.wiffFile_GetActualNumberOfCycles( _
                mSampleNumberInRawFile, period)

            mSpectrumRange.startSpectrum = 1 '0 ?
            mSpectrumRange.endSpectrum = cycles


            mSpectrumRange.firstRetentionTimeSeconds = _
              derived_SpectrumNumber2RetentionTime(mSpectrumRange.startSpectrum, 0) '0: MS spectrum
            mSpectrumRange.lastRetentionTimeSeconds = _
              derived_SpectrumNumber2RetentionTime(mSpectrumRange.endSpectrum, 0) '0: MS spectrum. So
            '  end time is not the actual end time for the raw file.

            Dim tickCount2 As Integer = Environment.TickCount 'Unit is 1e-3 secs
            Dim intervalTick As Integer = tickCount2 - tickCount1

            'Changed PM_UNDEFINED_EXPERIMENTNUMBER 2004-11-29. Disabled setting a spectrum.
            If False Then
                ' Trace.Assert(mExperimentInfo.experimentNumber >= 0, _
                '   "PIL ASSERT. mExperimentInfo.experimentNumber is undefined!")
                ' Dim analystExperimentNumber As Integer = _
                '   mExperimentInfo.experimentNumber
                ' 
                ' 'Is this really necessary? Or should we wait until a call to XYZ()??
                ' 'Changed PM_MARKET_ANALYSTSP7 2003-08-20
                ' 'Observed 2003-08-20: an exception could be thrown
                ' 'executing SetSpectrum() if SP5 and not SP7 was
                ' 'installed. File: "Carmen, 2003-08-20\CdHCrk-7.wiff".
                ' 
                ' 'Changed PM_REFACTOR 2005-03-05
                ' 'Call mANALYSTCOM_Data.SetSpectrum( _
                ' '  mSampleNumberInRawFile, period, _
                ' '  analystExperimentNumber, startT, startT)
                ' Me.analystSetSpectrum(mANALYSTCOM_Data, mSampleNumberInRawFile, period, _
                '   analystExperimentNumber, startT)
            End If
        End Sub 'openRawFile


        '****************************************************************************
        '*  SUBROUTINE NAME:   closeRawFile                                         *
        'd$ <summary>XYZ
        'd$ </summary>
        Protected Overrides Sub closeRawFile(ByVal aFileSpec As fileSpecStructure)

            mOpenRawCalls -= 1 '??

            'For the time being: do nothing.
        End Sub 'closeRawFile


        '****************************************************************************
        '*  SUBROUTINE NAME:   retentionTime2SpectrumNumber                         *
        'd$ <summary>   See base class. Specifics: XYZ.
        'd$ </summary>
        Protected Overrides Function retentionTime2SpectrumNumber( _
          ByVal aRetentionTime_Secs As Double) As Integer

            'As (unfortunate) automatic conversion can happen from integer
            'to double in the call to this function: temporary checks to detect
            'it at runtime.
            Dim intSecs As Integer = CInt(aRetentionTime_Secs)
            Dim diff As Double = aRetentionTime_Secs - intSecs
            Dim absDiff As Double = Math.Abs(diff)
            'Trace.Assert(absDiff > 0.0000001, "PIL ASSERT. Argument is an integer. In retentionTime2SpectrumNumber().")

            'No!!!. We don't need to have set a spectrum to find a spectrum number
            'given the retentiontime. For this only a current ***file*** needs to
            'have been selected.
            'Trace.Assert(mOpenRawCalls > 0, "PIL ASSERT. mOpenRawCalls>0. Client protocol error: openRawFile not called... .")

            Dim toReturn As Integer = -17
            Dim period As Integer

            Trace.Assert(Not mANALYST3 Is Nothing, _
              "PIL ASSERT. In retentionTime2SpectrumNumber(): " & _
              " mANALYST3 does not exist... .")

            'Dim sample As Integer = 1
            Dim experiment As Integer = 0

            'Changed PM_QSTAR_ROUNDING 2007-06-14
            'Dim toPass As Single = CSng(aRetentionTime_Secs)
            'Dim toPass As Single = CSng(aRetentionTime_Secs + 0.0)
            ''Dim toPass As Single = CSng(aRetentionTime_Secs + 0.306)
            ''  0.306 = 0.0102 / 2 * 60: worst case rounding for the
            ''  old QS 1.0 Mascot.dll with assumed proper rounding 
            ''  for 2 digits after the decimal comma and plus
            ''  a 2 percent margin.
            Dim toPass As Single = CSng(aRetentionTime_Secs)

            'Changed PM_REFACTOR 2007-07-19
            ''Changed PM_QSTAR_ROUNDING 2007-06-14
            ''mANALYSTCOM_WiffFile.GetActualPeriodAndCycleFromTime( _
            ''    mSampleNumberInRawFile, experiment, _
            ''    toPass, period, toReturn)
            'Me.GetActualPeriodAndCycleFromTime_ex( _
            '    mSampleNumberInRawFile, experiment, _
            '    toPass, period, toReturn)
            mANALYST3.wiffFile_GetActualPeriodAndCycleFromTime_ex( _
                mSampleNumberInRawFile, experiment, _
                toPass, period, toReturn)

            Trace.Assert(toReturn > 0, _
              "PIL ASSERT. Bad value to return from retentionTime2SpectrumNumber(), " _
                & retentionTime2SpectrumNumber & ".")

            'Debugging only. 2007-06-14. Demonstrates QS 1.1 vs. QS 2.0
            'return values for cycle number.
            'If True Then
            '    Dim time1 As Single = _
            '      mANALYSTCOM_WiffFile.GetActualTimeFromPeriodAndCycle( _
            '        mSampleNumberInRawFile, period, experiment, 2644)
            '    Dim time2 As Single = _
            '      mANALYSTCOM_WiffFile.GetActualTimeFromPeriodAndCycle( _
            '        mSampleNumberInRawFile, period, experiment, 2643)
            '    Dim peter9 As Integer = 9
            'End If

            Return toReturn
        End Function 'retentionTime2SpectrumNumber()


        'Changed PM_REFACTOR_FINNEGAN 2003-08-21
        '****************************************************************************
        '*  SUBROUTINE NAME:   derived_SpectrumNumber2RetentionTime                 *
        'd$ <summary>   For current(??) raw file: convert from spectrum number to
        'd$             retention time (sec).
        'd$ </summary>
        Protected Overrides Function derived_SpectrumNumber2RetentionTime( _
          ByVal aSpectrumNumber As Integer, _
          ByVal anInExperimentNumber As Integer) As Double

            Trace.Assert(Not (mANALYST3 Is Nothing), _
              "PIL ASSERT. In retentionTime2SpectrumNumber(): " & _
              "mANALYSTCOM_WiffFile does not exist... .")

            If anInExperimentNumber > 0 Then
                Dim peter12 As Integer = 12
            End If

            'Dim sample As Integer = 1
            Dim period As Integer = 0

            'Changed PM_FRAGMENTS_FOR_INSERTED 2004-11-29
            'Dim experiment As Integer = 0 'MS spectrum!
            Dim experiment As Integer = anInExperimentNumber

            'Changed PM_REFACTOR 2007-07-19
            'Dim toReturn As Double = _
            '  mANALYSTCOM_WiffFile2.GetActualTimeFromPeriodAndCycle( _
            '    mSampleNumberInRawFile, period, experiment, aSpectrumNumber)
            Dim toReturn As Double = _
              mANALYST3.wiffFile_GetActualTimeFromPeriodAndCycle( _
                mSampleNumberInRawFile, period, experiment, aSpectrumNumber)

            Return toReturn
        End Function 'derived_SpectrumNumber2RetentionTime


        'Changed PM_REFACTOR_FINNEGAN 2003-08-21
        '****************************************************************************
        '*  SUBROUTINE NAME:   getSpectrumRange                                     *
        'd$ <summary>   Does NOT change state.....
        'd$ </summary>
        Public Overrides Function getSpectrumRange() _
          As spectrumRangeStructure

            Dim toReturn As spectrumRangeStructure = mSpectrumRange

            'Changed PM_MICROMASS_BROKEN 2008-07-04
            Trace.Assert(toReturn.firstRetentionTimeSeconds >= 0.0, _
              "PIL ASSERT. Finnigan, getSpectrumRange(). " & _
              "toReturn.firstRetentionTimeSeconds" & _
              " is undefined: " & _
              toReturn.firstRetentionTimeSeconds.ToString("0.0000"))

            Return toReturn
        End Function 'getSpectrumRange


        'Changed PM_REFACTOR_FINNEGAN 2003-08-21
        '****************************************************************************
        '*  SUBROUTINE NAME:   spectrumNumberForMSspectrum                          *
        'd$ <summary>   Does NOT change state.....
        'd$ </summary>
        Public Overrides Function spectrumNumberForMSspectrum( _
          ByVal aSpectrumNumber As Integer, _
          ByRef anOutSpectrumClassification As SpectrumClassificationStructure, _
          ByVal aForceOneLevelUp As Boolean) As Integer

            'Trivial for Analyst because the spectrum number equals the cycle
            'number. We have an experiment number of 0 to specify MS-spectra....

            anOutSpectrumClassification.mainClassification = _
              spectrumTypeEnum.enumIsMSspectrum
            anOutSpectrumClassification.spectrumSubType2 = _
              spectrumSubTypeEnum.enumIsNormalMS

            Return aSpectrumNumber
        End Function


        '****************************************************************************
        '*  SUBROUTINE NAME:   nextMSspectrum                                       *
        'd$ <summary>   .
        'd$ </summary>
        Public Overrides Function nextMSspectrum( _
          ByVal aSpectrumNumber As Integer, _
          ByRef anOutSpectrumClassification As SpectrumClassificationStructure) _
          As Integer

            'Trivial for Analyst because the spectrum number equals the cycle
            'number. We have an experiment number of 0 to specify MS-spectra....

            Dim toReturn As Integer = aSpectrumNumber + 1

            anOutSpectrumClassification.mainClassification = _
              spectrumTypeEnum.enumIsMSspectrum
            anOutSpectrumClassification.spectrumSubType2 = _
              spectrumSubTypeEnum.enumIsNormalMS

            Return toReturn
        End Function 'nextMSspectrum


        'Changed PM_SUPERCHARGE 2003-11-03
        '****************************************************************************
        '*  SUBROUTINE NAME:   nextFragmentspectrum                                 *
        'd$ <summary>   .
        'd$ </summary>
        Public Overrides Function nextFragmentspectrum2( _
          ByVal aSpectrumNumber As Integer, _
          ByRef anOutSupposedPrecursorMass As Double, _
          ByRef anOutCurClassification As SpectrumClassificationStructure, _
          ByRef anOutExperimentNumber As Integer) As Integer

            mExperimentInfo.experimentNumber += 1 'This can run past the
            '  last MS/MS spectrum. Find retention time for NEXT MS spectrum when
            '  an MS spectrum is set by derived_NewSpectrum in order to
            '  provide a ceiling?

            anOutSupposedPrecursorMass = 0.0 'For now.

            anOutCurClassification.mainClassification = _
              spectrumTypeEnum.enumIsFragmentSpectrum

            'Changed PM_PHASEOUT_FRAGNORMAL 2006-04-04
            anOutCurClassification.spectrumSubType2 = _
              spectrumSubTypeEnum.enumIsFragmentCID

            anOutExperimentNumber = mExperimentInfo.experimentNumber

            Return aSpectrumNumber 'Same as input for Analyst.
        End Function 'nextFragmentspectrum


        '****************************************************************************
        '*  SUBROUTINE NAME:   derived_NewSpectrum                                  *
        'd$ <summary>   Ignore aInfoRetentionTime_Seconds, only used by Micromass.
        'd$ </summary>
        Protected Overrides Function derived_NewSpectrum( _
          ByVal aSpectrumNumber As Integer, _
          ByVal aInfoRetentionTime_Seconds As Double, _
          ByRef anOutSpectrumClassification As SpectrumClassificationStructure) _
          As Double

            'Changed PM_PHOSPHO_SCORING 2005-08-12
            'Later: fill in anOutSpectrumClassification ....

            'Dim sample As Integer = 1

            Dim period As Integer = 0
            Dim experiment As Integer = 0 'Note: this means the ***MS*** spectrum!!!

            'Changed PM_QS11_TROUBLE 2005-09-26
            'Why????? It worked in the past....
            'Note: 0 was only for the time convert, in the call
            '      to analystSetSpectrum() the experiment number
            '      was actually used...
            experiment = mExperimentInfo.experimentNumber

            If experiment > 3 Then
                Dim peter4 As Integer = 4
            End If

            'Changed PM_MARKER 2005-11-25
            'aSpectrumNumber(, 4626)

            'Changed PM_MARKER 2005-11-28
            '  asdasd() 'Check somewhere that the precursor mass in the spectrum
            '  header correspond to the precursor mass from Mascot. This will be
            '  an early detection of the QS 1.1 offset on experiment number.

            'Changed PM_REFACTOR 2007-07-19
            'Dim startT As Single = _
            '  mANALYSTCOM_WiffFile2.GetActualTimeFromPeriodAndCycle( _
            '    mSampleNumberInRawFile, period, experiment, aSpectrumNumber)
            Dim startT As Single = _
              mANALYST3.wiffFile_GetActualTimeFromPeriodAndCycle( _
                mSampleNumberInRawFile, period, experiment, aSpectrumNumber)

            Trace.Assert(mExperimentInfo.experimentNumber >= 0, _
              "PIL ASSERT. mExperimentInfo.experimentNumber is undefined!")

            'Changed PM_REFACTOR 2005-03-05
            'Call mANALYSTCOM_Data.SetSpectrum( _
            '  mSampleNumberInRawFile, period, mExperimentInfo.experimentNumber, _
            '  startT, startT)
            Me.analystSetSpectrum( _
              mANALYST3, _
              mSampleNumberInRawFile, _
              period, _
              mExperimentInfo.experimentNumber, _
              startT)

            If mExperimentInfo.experimentNumber > 0 Then
                Dim peter8 As Integer = 8 'MS-MS spectrum is used....
            End If

            mExperimentInfo.experimentNumber = experiment 'Normally set to zero, 
            '  reset in the case e.g. nextFragmentspectrum2() have been called. 

            'Changed PM_PTM_FOR_ALL 2007-06-21
            If experiment > 0 Then
                'Fragment, MS-MS.
                anOutSpectrumClassification.mainClassification = _
                  spectrumTypeEnum.enumIsFragmentSpectrum
                anOutSpectrumClassification.spectrumSubType2 = _
                  spectrumSubTypeEnum.enumIsFragmentCID
            Else
                'MS
                anOutSpectrumClassification.mainClassification = _
                  spectrumTypeEnum.enumIsMSspectrum
                anOutSpectrumClassification.spectrumSubType2 = _
                  spectrumSubTypeEnum.enumIsNormalMS
            End If

            Return startT
        End Function 'derived_NewSpectrum


        'Changed PM_REFACTOR_FINNEGAN_MSMS 2003-08-18. Disabled.
        ''****************************************************************************
        ''*  SUBROUTINE NAME:   spectrumSpecification                                *
        'd$ '<summary>   .
        'd$ '</summary>
        'Protected Overrides Sub spectrumSpecification( _
        '  ByVal aSpectrumSpecification As spectrumSpecificationStructure)

        '    'mExperimentNumber = aSpectrumSpecification
        '    mExperimentInfo = aSpectrumSpecification
        'End Sub


        'd$ ****************************************************************************
        'd$ *  SUBROUTINE NAME:   spectraRange                                         *
        'd$ ''<summary>   
        'd$ ''</summary>
        'Protected MustOverride Sub spectraRange( _
        '  ByVal aRentionTimeRange As retentionTimeRangeStructure, _
        '  ByRef anOutStartSpectrum As spectrumSpecStructure, _
        '  ByRef anOutEndSpectrum As spectrumSpecStructure)


        '****************************************************************************
        '*  SUBROUTINE NAME:   returnDataPoints                                     *
        'd$ <summary>Retrieve datapoints from the current spectrum.
        'd$ </summary>
        'd$ <param name="anOutDatapoints">
        'd$   Items are of type signalStructure, <see cref="T:xyz.abc" />
        'd$ </param>
        Protected Overrides Sub returnDataPoints( _
          ByVal aStartMass As Double, ByVal anEndMass As Double, _
          ByRef anOutDatapoints As _
            Generic.List(Of massSpectrometryBase.signalStructure), _
          ByRef aDataPointsInfo As signalModule.dataPointsInfoStructure2)

            'Old:
            '  ByRef anOutDatapoints As ArrayList

            'Future:
            '  1. Ensure that aDataPointsInfo.maxY has a reasonable value when there are no data points.

            anOutDatapoints.Clear()

            Dim inputRangeOutSideSpectrumRAnge As Boolean = False

            If True Then 'Try-out
                '  .GetXValueRange()
                '  .GetStartMass
                '  .GetStopMass
                '  .GetStartTime
                '  .GetEndTime

                'Dim StartMass As Double = mANALYSTCOM_Data2.GetStartMass()
                'Dim EndMass As Double = mANALYSTCOM_Data2.GetStopMass()
                'Dim StartTime As Double = _
                '  mANALYSTCOM_Data2.GetStartTime()
                'Dim EndTime As Double = _
                '  mANALYSTCOM_Data2.GetEndTime()
                Dim StartMass As Double = mANALYST3.data_GetStartMass() 'E.g. 350.0
                Dim EndMass As Double = mANALYST3.data_GetStopMass() 'E.g. 1200.0
                Dim StartTime As Double = _
                  mANALYST3.data_GetStartTime() 'E.g. 2.0110001564025879
                Dim EndTime As Double = _
                  mANALYST3.data_GetEndTime() 'E.g. 2.0110001564025879
            End If

            'Moved out of try-out block...
            If True Then
                Dim Xmin As Double 'E.g. 350.16398029493382
                Dim Xmax As Double 'E.g. 1065.5432302635534

                'Changed PM_REFACTOR 2007-07-19
                'mANALYSTCOM_Data.GetXValueRange(Xmin, Xmax)
                mANALYST3.data_GetXValueRange(Xmin, Xmax)

                'Changed PM_BACK_TO_NORMAL 2003-07-29
                'Avoid returning datapoint sets with one datapoint, the last
                '(or first). And for Analyst spectra an example was observed
                'where the y value was zero....
                If aStartMass > Xmax Or anEndMass < Xmin Then
                    inputRangeOutSideSpectrumRAnge = True
                End If
            End If

            Dim minY As signalStructure
            minY.Ysig = 1000000.0
            Dim maxY As signalStructure
            maxY.Ysig = -1000000.0

            If Not inputRangeOutSideSpectrumRAnge Then
                Dim startPT As Integer

                'Changed PM_REFACTOR 2007-07-19
                'mANALYSTCOM_Data2.GetClosestPointNumberForXValue( _
                '  aStartMass, _
                '  QS20.ExploreDataObjects.WhichClosestPointType.CLOSEST_POINT, _
                '  startPT)
                mANALYST3.data_GetClosestPointNumberForXValue( _
                  aStartMass, _
                  whichClosestPointTypeEnum.enumCLOSEST_POINT, _
                  startPT)

                Dim stopPT As Integer

                'Changed PM_REFACTOR 2007-07-19
                'mANALYSTCOM_Data2.GetClosestPointNumberForXValue( _
                '  anEndMass, _
                '  QS20.ExploreDataObjects.WhichClosestPointType.CLOSEST_POINT, _
                '  stopPT)
                mANALYST3.data_GetClosestPointNumberForXValue( _
                  anEndMass, _
                  whichClosestPointTypeEnum.enumCLOSEST_POINT, _
                  stopPT)

                Dim datapoints As Integer = stopPT - startPT + 1
                Dim xVal, yVal As Double
                Dim j As Integer

                'Changed PM_MEMORY_EFFICIENCY 2008-10-27
                'Note: capacity is different than before. Should we set it
                '      to some typical expected value for most MS spectra?

                'Better to change minX/maxX just reading off the array?
                For j = startPT To stopPT

                    'Changed PM_REFACTOR 2007-07-19
                    'mANALYSTCOM_Data2.GetDataPoint(j, xVal, yVal)
                    mANALYST3.data_GetDataPoint(j, xVal, yVal)

                    'Changed PM_MS_QA_ARITOVERFLOW 2003-10-02. Note: actual 
                    'cause of this problem was use of Analyst's
                    'GetClosestPointNumberForXValue, above.

                    'We must exclude points outside the specified range.
                    If xVal >= aStartMass AndAlso xVal <= anEndMass Then
                        Dim pt As signalStructure
                        pt.Xsig = xVal
                        pt.Ysig = yVal
                        anOutDatapoints.Add(pt)

                        If yVal < minY.Ysig Then
                            minY = pt
                        End If

                        If yVal > maxY.Ysig Then
                            maxY = pt
                        End If
                    Else
                        Dim peter6 As Integer = 6
                    End If
                Next j
            End If

            Dim len As Integer = anOutDatapoints.Count

            If len > 0 Then
                Dim minX As Double = anOutDatapoints.Item(0).Xsig
                Dim maxX As Double = anOutDatapoints.Item(len - 1).Xsig
                aDataPointsInfo.minX2 = minX
                aDataPointsInfo.maxX2 = maxX

                aDataPointsInfo.minimumSignal = minY
                aDataPointsInfo.maximumSignal = maxY
            Else
                Dim noSignal As signalStructure
                noSignal.Xsig = -10.0
                noSignal.Ysig = 0.0

                aDataPointsInfo.minX2 = 0.0
                aDataPointsInfo.maxX2 = 0.0

                aDataPointsInfo.minimumSignal = noSignal
                aDataPointsInfo.maximumSignal = noSignal
            End If
        End Sub 'returnDataPoints


        'Changed PM_REFACTOR_FINNEGAN 2003-07-06
        '****************************************************************************
        '*  SUBROUTINE NAME:   DataTitle                                            *
        'd$ <summary>
        'd$ </summary>
        Public Overrides Function DataTitle() As String

            'We call through to the Analyst COM component, but we might want to
            'have it already stored in the base class at this point.
            'Sample:
            ' +TOF MS: Experiment 1, 0.034 min from Q1LCMS190203_01DoubleArg.wiff'

            'Changed PM_REFACTOR 2007-07-19
            'Return mANALYSTCOM_Data2.DataTitle
            Return mANALYST3.data_getDataTitle()
        End Function 'DataTitle


        ''Changed PM_REFACTOR 2007-07-19. This was used for connecting an Analyst
        ''  data COM instance to a spectrum on the client side. Now we do it
        ''  by sending a signal to the new COM version control layer, AnalystCOM.vb.
        ''
        ' '****************************************************************************
        ' '*  SUBROUTINE NAME:   getANALYSTCOM_Data                                   *
        ' 'd$ <summary>
        ' 'd$ </summary>
        ' Public Function getANALYSTCOM_Data() As _
        '   QS20.ExploreDataObjects.FMANSpecData
        ' 
        '     Return mANALYSTCOM_Data2
        ' End Function 'getANALYSTCOM_Data
        Public Function getAnalystDataSource() As _
          AnalystCOM

            Return mANALYST3
        End Function 'getANALYSTCOM_Data


        'Used???
        ' '****************************************************************************
        ' '*  SUBROUTINE NAME:   getClonedANALYSTCOM_Data                             *
        ' 'd$ <summary>
        ' 'd$ </summary>
        ' Public Function getClonedANALYSTCOM_Data3() As _
        '   QS20.ExploreDataObjects.FMANSpecData
        ' 
        '     '!!!!!!!!!!!!!!!
        '     'Cloning does not work....
        ' 
        '     Dim toReturn As QS20.ExploreDataObjects.FMANSpecData = _
        '       New QS20.ExploreDataObjects.FMANSpecData
        '     toReturn.WiffFileName = mANALYSTCOM_Data2.WiffFileName
        '     Me.analystSetSpectrum( _
        '       toReturn, mSpectrumParameters.sampleNumber, _
        '       mSpectrumParameters.periodNumber, _
        '       mSpectrumParameters.experimentNumber, _
        '       mSpectrumParameters.timeSeconds)
        ' 
        '     Dim toReturn2 As QS20.ExploreDataObjects.FMANSpecData = _
        '       DirectCast(mANALYSTCOM_Data2.Copy(), _
        '         QS20.ExploreDataObjects.FMANSpecData)
        ' 
        '     'toReturn.Copy()
        '     'toReturn.GetWiffFileObject()
        '     'toReturn.SaveToTextFile("filename.txt")
        '     ''toReturn.SetSpectrum( )
        '     'toReturn.UpdateInternalStateAfterCopy()
        ' 
        '     Return toReturn2
        ' End Function 'getClonedANALYSTCOM_Data


        'Changed PM_MEMORY_ALLOCATION 2004-08-03. Finalize() is evil (?)
        '
        ''****************************************************************************
        ''*  SUBROUTINE NAME:   Finalize                                             *
        'd$ '<summary>
        'd$ '</summary>
        'Protected Overrides Sub Finalize()
        '    MyBase.Finalize()
        'End Sub


        '****************************************************************************
        '*  SUBROUTINE NAME:   MaybeToBeChanged_MSMSretentionTime                   *
        'd$ <summary>xyz
        'd$   </summary>
        Public Overrides Function MaybeToBeChanged_MSMSretentionTime( _
          ByVal aMSMSspecification As Integer, _
          ByVal aExtraNumber As Integer) As Double

            Trace.Assert(False, "Stop!", "PIL ASSERT. Internal/development assert for stopping execution......")
            Return -27.457
        End Function 'MaybeToBeChanged_MSMSretentionTime


        'Changed PM_REFACTOR 2005-03-05
        '****************************************************************************
        '*  SUBROUTINE NAME:   analystSetSpectrum                                   *
        'd$ <summary>xyz
        'd$   </summary>
        Private Sub analystSetSpectrum( _
          ByRef anAnalystCOM_Data As AnalystCOM, _
          ByVal aSampleNumber As Integer, _
          ByVal aPeriodNumber As Integer, _
          ByVal anExperimentNumber As Integer, _
          ByVal aTimeSeconds As Single)

            Try
                'Changed PM_REFACTOR 2007-07-19
                ''Signature:
                ''  SetSpectrum(sample as Integer, period as Integer, 
                ''              experiment as Integer, startTime as Single,
                ''              endTime as Single)
                'anAnalystCOM_Data.data_SetSpectrum( _
                '  aSampleNumber, aPeriodNumber, _
                '  anExperimentNumber, aTimeSeconds, aTimeSeconds)
                anAnalystCOM_Data.data_SetSpectrum( _
                  aSampleNumber, aPeriodNumber, _
                  anExperimentNumber, aTimeSeconds, aTimeSeconds)

            Catch exceptionObject As Exception
                Dim cr As String = ControlChars.NewLine 'Shortcut..
                Dim retMin As Double = aTimeSeconds / 60.0
                Dim extraInfo As String = _
                  "Call to aANALYSTCOM_Data.SetSpectrum() failed. " & cr & _
                  "Sample number: " & aSampleNumber & cr & _
                  "Period number: " & aPeriodNumber & cr & _
                  "Experiment number: " & anExperimentNumber & cr & _
                  "Retention time [secs]: " & aTimeSeconds & cr & _
                  "Retention time [min]: " & retMin & cr

                AppCommon2.displayStandardExceptionInfo( _
                  exceptionObject, _
                  extraInfo)
                Exit Sub
            End Try

            mSpectrumParameters.sampleNumber = aSampleNumber
            mSpectrumParameters.periodNumber = aPeriodNumber
            mSpectrumParameters.experimentNumber = anExperimentNumber
            mSpectrumParameters.timeSeconds = aTimeSeconds
        End Sub 'analystSetSpectrum

    End Class 'AnalystRawDataFileHandling

End Namespace 'massSpectrometryBase


    

    

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