Source code for MSQuant: newFinneganRawDataFileHandling.vb, MSQuant/msquant/src/main/massbase/newFinneganRawDataFileHandling.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 betterFinneganRawDataFileHandling, 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:     newFinneganRawDataFileHandling.vb                       *
'*    MAIN_CLASS:   betterFinneganRawDataFileHandling                       *
'*    STRUCTS_AND_CLASSES:   <none>                                         *
'*    TYPE:       VISUAL_BASIC                                              *
'*                                                                          *
'* CREATED: PM 2003-08-21   Vrs 1.0. Cloned from                            *
'*                          FinneganRawDataFileHandling.vb                  *
'* UPDATED: PM 2003-xx-xx                                                   *
'*                                                                          *
'****************************************************************************

'Future: 
' 1. 
' 2.

Option Strict On
Option Explicit On 

Imports System.IO 'For "File".

Imports System.Text.RegularExpressions 'For Regex.Match.


'Imports XRAWFILE2Lib  '\Xcalibur\system\programs\XRawfile2.dll
''Requires adding reference to project:
''  menu Project/Add Reference/Browse, 
''  select D:\Program Files\Xcalibur\system\programs\XRawfile2.dll.
''
''Typical objects:
''  XRAWFILE2Lib.XRawfile


'Changed PM_FINNIGAN_MEMORY_WORKAROUND 2004-08-30
Imports FinniganRawfile2WrapLib
'  Contains class SFinniganRawfile2WrapClass. 
'Requires adding reference to project:
'  menu Project/Add Reference/Browse, 
'  select \FinniganCOMworkaround\FinniganCOMworkaround\Debug\FinniganRawfile2Wrap.dll.


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

    'Changed PM_MULTIPLE_FINNEGAN_TROUBLE 2004-01-18
    Public Structure rawDiscStruct
        'Dim fileSpec As String
        'Dim xRawFileIndex As Integer

        'Changed PM_FINNIGAN_MEMORY_WORKAROUND 2004-08-30
        'Dim rawFile_FINNEGANCOM As XRawfile
        Dim rawFile_FINNEGANCOM As SFinniganRawfile2WrapClass

        Dim openCloseBalance As Integer
    End Structure


    '****************************************************************************
    'd$ <summary>
    'd$   Purpose: 
    'd$     Note: in contrast to FinneganRawDataFileHandling.vb this class
    'd$           uses XRawfile.ocx/XRawfile that does not have the severe
    'd$           memory requirements of XcaliburFiles.dll/XRaw.
    'd$ 
    'd$     Knows about handling of Finnegan/Xcalibur/RAW raw
    'd$     data files with mass spectra.
    'd$ 
    'd$     ?(or is it the base class): Hides the fact that the Xcalibur
    'd$     compoment (XYZ) can only handle one open RAW 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 betterFinneganRawDataFileHandling
        Inherits rawDataFileHandling

        'Changed PM_JA_FINNEGAN_ASSERT_RESOURCE_LEAK 2003-12-19
        Implements IDisposable

        'Dim mRawfile As XRaw
        'Dim mSpectra As XSpectra
        'Dim mSpectrum As XSpectrum

        'Changed PM_FINNIGAN_MEMORY_WORKAROUND 2004-08-30
        'Dim mRawfile As XRawfile 'Needed: access to XYZ.dll, 
        ''  Requires adding reference to project: menu Project/Add Reference/Browse, 
        ''  select S:\Program Files\Xcalibur\system\programs\XYZ.dll.
        ''  XRawfile: coclass XYZ, interface XYZ, interface XYZ.
        ''        Part of XYZ.dll.
        Dim mRawfile As SFinniganRawfile2WrapClass

        'Dim TODELETE_mRawfile As XRawfile

        'Dim mFirstScan As Integer
        'Dim mLastScan As Integer
        Dim mSpectrumRange As spectrumRangeStructure

        'Now in mSpectrumRange...
        'Dim mFirstRetentionTimeSeconds As Double
        'Dim mLastRetentionTimeSeconds As Double

        Dim mCurrentSpectrumNumber As Integer
        Dim mData(,) As Double 'Two dimensional...

        'Changed PM_DTA_PERL_INTERPRET 2003-08-22
        Dim mSpectrumNumberEncodedInRetentionTime As Boolean

        'Changed PM_JA_FINNEGAN_ASSERT_RESOURCE_LEAK 2003-12-17
        Dim mOpenCloseBalance As Integer

        'Changed PM_PM_MEMORY_ALLOCATION 2004-09-23
        Dim mOpenCount As Integer
        'Dim mLastOpenedRawfile As SFinniganRawfile2WrapClass
        'Dim mLastOpenedDescr As rawDiscStruct
        Dim mLastRawFilePath As String

        'Changed PM_MULTIPLE_FINNEGAN_TROUBLE 2004-01-18
        Dim mFilesOpen As Hashtable 'Type is rawDiscStruct


        '****************************************************************************
        '*  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_DTA_PERL_INTERPRET 2003-08-22
            mSpectrumNumberEncodedInRetentionTime = True 'For DTA files that were
            '  converted to Mascot format by a Perl that assumes the number in
            '  the file name were retention time seconds. Those numbers are in
            '  fact spectrum numbers.....

            'Changed PM_JA_FINNEGAN_ASSERT_RESOURCE_LEAK 2003-12-17
            mOpenCloseBalance = 0

            'Changed PM_PM_MEMORY_ALLOCATION 2004-09-23
            mOpenCount = 0

            'Changed PM_PM_MEMORY_ALLOCATION 2004-09-27
            'mLastOpenedRawfile = Nothing
            'mLastOpenedDescr.rawFile_FINNEGANCOM = Nothing
            mLastRawFilePath = ""

            'Changed PM_MULTIPLE_FINNEGAN_TROUBLE 2004-01-18
            mFilesOpen = New Hashtable

            mSpectrumRange.startSpectrum = -3000
            mSpectrumRange.endSpectrum = -3200
            mSpectrumRange.firstRetentionTimeSeconds = -10000.0
            mSpectrumRange.lastRetentionTimeSeconds = -10200.0

            mCurrentSpectrumNumber = -9999
        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()
            Me.Dispose()
        End Sub 'doCleanUp


        'Changed PM_JA_FINNEGAN_ASSERT_RESOURCE_LEAK 2003-12-19
        '****************************************************************************
        '*  SUBROUTINE NAME:   Dispose                                              *
        'd$ <summary> N/A </summary>
        Public Sub Dispose() Implements IDisposable.Dispose
            Me.cleanUp()
        End Sub 'Dispose


        'Changed PM_MEMORY_ALLOCATION 2004-08-03. Finalize() is evil (?)
        '
        'Changed PM_JA_FINNEGAN_ASSERT_RESOURCE_LEAK 2003-12-17
        '****************************************************************************
        ' '*  SUBROUTINE NAME:   finalise                                           *
        ' '''<summary> N/A </summary>
        ' Protected Overrides Sub finalize()
        ' 
        '     'Note: we can do better than this. Clients should properly
        '     '      call a Dispose method, etc.
        '     Me.cleanUp() 'finalise
        ' 
        '     MyBase.Finalize()
        ' End Sub 'finalise


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

            'Changed PM_REFACTOR 2008-10-27
            Dim fileToOpen As String = aFileSpec2.path 'In 9 places...

            Trace.Assert(File.Exists(fileToOpen), _
              "PIL ASSERT. File does not exist, " _
              & fileToOpen & ".")
            'For now we require file extension of .raw
            Dim ext As String = Path.GetExtension(fileToOpen)
            Trace.Assert(ext = ".raw" Or ext = ".RAW", _
              "PIL ASSERT. Extension .raw is required for Finnegan raw files! File: " _
              & fileToOpen & ".")
            Dim sample As Integer = 1 '1: sample, to be generalised.

            'Changed PM_MULTIPLE_FINNEGAN_TROUBLE 2004-01-18
            'Effectively keep a list of open files that this
            'function was called with. For ensuring that Open()
            'is only called once per file.
            Dim someDescr As rawDiscStruct
            Dim key As String = fileToOpen
            If mFilesOpen.ContainsKey(key) Then
                someDescr = DirectCast(mFilesOpen(key), rawDiscStruct)
            Else
                someDescr.openCloseBalance = 0

                'Changed PM_MARKER_MEMORY_ALLOCATION 2004-07-28
                '"New XRawfile" increases memory footprint by approx 4 MB....

                'Changed PM_ERROR_HANDLING_FINWRAP 2006-07-02
                Try
                    'This can fail if the file FinniganRawfile2Wrap.dll is
                    'not registered.
                    '
                    'Can we automatically attempt to register it?


                    'Changed PM_FINNIGAN_MEMORY_WORKAROUND 2004-08-30
                    'someDescr.rawFile_FINNEGANCOM = New XRawfile
                    someDescr.rawFile_FINNEGANCOM = _
                      New SFinniganRawfile2WrapClass

                    If True Then 'Block.
                        'Changed PM_FINNIGANWRAPCOM_VERSIONCHECK 2008-10-27
                        'This is a good place to check for the required version
                        'of FinniganRawfile2Wrap.dll.

                        Dim requiredVersion As Integer = 102
                        Dim requiredVersionStr As String = "1.02"

                        Dim version As Integer = -1 'In 0.01 increments. Max 10 for
                        '  each of the 3 levels. 102 for v. 1.0.2
                        Dim out1 As Double
                        someDescr.rawFile_FINNEGANCOM.times2b(0.03, out1)
                        If out1 < 1.0 Then
                            version = 100 'The oldest version (of the 
                            '  Finnigan COM wrapper).
                        Else
                            version = CInt(out1 * 100.0)
                        End If

                        If version < requiredVersion Then
                            Dim vrsStr As String = _
                              (version / 100.0).ToString("0.00")

                            Dim msgStr As String = _
                              "Could not continue in opening raw file " & _
                              fileToOpen & ". " & _
                              "The installed version of " & _
                              "FinniganRawfile2Wrap.dll, " & vrsStr & _
                              ", is too old (" & requiredVersionStr & _
                              " required). " & _
                              "Use the " & _
                              AppConstants.LONG_APP & _
                              " installer to install " & _
                              AppConstants.LONG_APP & "."
                            MsgBox(msgStr)

                            'Throw exception??
                        End If

                    End If 'Block.


                Catch exceptionObject As Exception
                    AppCommon2.displayStandardExceptionInfo( _
                      exceptionObject, _
                      "Could not access the raw file " & fileToOpen & _
                      ". The DLL ""FinniganRawfile2Wrap.dll"" is " & _
                      "probably not registered or installed properly. " & _
                      "Try to register the DLL: " & _
                      "1) find the location of " & _
                      """FinniganRawfile2Wrap.dll"" by e.g. using " & _
                      "the search function in Windows Explorer " & _
                      "(note: Windows Explorer, not Internet Exploiter), e.g. " & _
                      """D:\Program Files\" & AppConstants.LONG_APP & _
                      """. " & _
                      "2) open Start menu/run/cmd. " & _
                      "3) Change to drive and directory: d: <RETURN> " & _
                      " cd ""D:\Program Files\" & AppConstants.LONG_APP & _
                      """  <RETURN> " & _
                      "4) Register the DLL: " & _
                      "regsvr32 FinniganRawfile2Wrap.dll" & _
                      ControlChars.NewLine & _
                      "Notes: FinniganRawfile2Wrap.dll is dependent " & _
                      "on the file msvcr71d.dll (or similar) and " & _
                      "registration does not succeed unless it is in " & _
                      "the same directory. " & _
                      ControlChars.NewLine & _
                      ControlChars.NewLine & _
                      "" _
                      )

                    'How to rethrow??

                    Exit Sub
                End Try

                mFilesOpen.Add(key, someDescr)
            End If
            mRawfile = someDescr.rawFile_FINNEGANCOM

            'Changed PM_MULTIPLE_FINNEGAN_TROUBLE 2004-01-18
            ''Changed PM_MULTIPLE_FINNEGAN_TROUBLE 2004-01-06
            ''Moved up here because it needs to do close() on 
            ''the old mRawfile.....
            ''Changed PM_JA_FINNEGAN_ASSERT_RESOURCE_LEAK 2003-12-17
            ''We don't rely on closeRawFile() being called.
            'Me.cleanUp()

            'Changed PM_RESOURCE_LEAK 2004-01-15
            'Only create it once...
            If mRawfile Is Nothing Then

                'Changed PM_FINNIGAN_MEMORY_WORKAROUND 2004-08-30
                'mRawfile = New XRawfile   'What if it already exists?? Should
                ''  we allow calling openRawFile()??
                mRawfile = New SFinniganRawfile2WrapClass   'What if it already exists?? Should
                '  we allow calling openRawFile()??
            End If

            'Test only....
            If False Then
                'mRawfile.Close()
            End If

            Try
                'Here was Me.cleanUp()....

                'Changed PM_MULTIPLE_FINNEGAN_TROUBLE 2004-01-18
                If someDescr.openCloseBalance = 0 Then

                    'Changed PM_MARKER_MEMORY_ALLOCATION 2004-07-28
                    'Open() can increase memory used by application by 10 MB!

                    'Changed PM_PM_MEMORY_ALLOCATION 2004-09-23
                    If mLastRawFilePath <> "" Then
                        Dim oldKey As String = mLastRawFilePath
                        Dim oldDescr As rawDiscStruct = _
                          DirectCast(mFilesOpen(oldKey), rawDiscStruct)
                        oldDescr.rawFile_FINNEGANCOM.Close()
                        oldDescr.openCloseBalance -= 1
                        mFilesOpen(oldKey) = someDescr 'Write-back
                    End If

                    'Changed PM_FINNIGAN_MEMORY_WORKAROUND 2004-08-30
                    'What happens if file does not exist? Exception?
                    'mRawfile.Open(aFileSpec.path)
                    mRawfile.Open_FWA(fileToOpen)

                    mLastRawFilePath = fileToOpen

                    'Changed PM_JA_FINNEGAN_ASSERT_RESOURCE_LEAK 2003-12-17
                    mOpenCloseBalance += 1

                    'Changed PM_PM_MEMORY_ALLOCATION 2004-09-23
                    mOpenCount += 1

                    'Changed PM_MULTIPLE_FINNEGAN_TROUBLE 2004-01-18
                    someDescr.openCloseBalance += 1
                    mFilesOpen(key) = someDescr 'Write-back
                Else
                    Dim peter81 As Integer = 81
                End If

            Catch e2 As System.Exception
                Dim errMsg As String = e2.Message
                MsgBox(errMsg)
                Exit Sub
            End Try

            mRawfile.SetCurrentController(0, 1) 'Mass spec device, first MS device.

            'Changed PM_JA_FINNEGAN_ASSERT 2003-12-17
            mSpectrumRange.startSpectrum = -17
            mSpectrumRange.endSpectrum = -17

            mRawfile.GetFirstSpectrumNumber(mSpectrumRange.startSpectrum)
            mRawfile.GetLastSpectrumNumber(mSpectrumRange.endSpectrum)

            'mSpectrumRange.startSpectrum = 0 'NoTest only!!!!!!!!!!!!!!!!!!!

            'Changed PM_ERRHANDLING_OUT_OF_MEMORY 2006-07-26
            'Now assume this ***only*** happens when out of memory.
            ''Changed PM_JA_FINNEGAN_ASSERT 2003-12-17
            If mSpectrumRange.startSpectrum <= 0 Then

                'Perhaps in the future:
                '  pass in application specific strings to the constructor

                'Changed PM_ERRMESSAGE_OLD_XCALIBUR_VERSION 2008-02-05. Added
                '  the possibility that the XCalibur version is too old to 
                '  open the RAW file.


                Dim fileNaneNoFullPath As String = _
                  Path.GetFileName(mLastRawFilePath)
                Dim msgStr As String = _
                  "The application can not continue. " & _
                  "Possible reasons:" & _
                  ControlChars.NewLine & ControlChars.NewLine & _
                  "  1) the raw file has been acquired with a newer version " & _
                  "of XCalibur that can not be accessed with the version of " & _
                  "XCalibur installed on this computer (this can be " & _
                  "investigated by opening the raw file in QualBrowser). " & _
                  ControlChars.NewLine & ControlChars.NewLine & _
                  "  2) the raw file type does not match what is selected in " & _
                  "menu Tools/Options/'Raw file type'." & _
                  ControlChars.NewLine & ControlChars.NewLine & _
                  "  3) it has run out of memory." & _
                  ControlChars.NewLine & ControlChars.NewLine & _
                  ControlChars.NewLine & ControlChars.NewLine & _
                  "If it has run out of memory then it happend while accessing " & _
                  "the Finnigan raw file " & _
                  fileNaneNoFullPath & _
                  ", in newFinneganRawDataFileHandling.vb/openRawFile(). " & _
                  "Nothing can be done to recover now as garbage collection " & _
                  "in .NET is one big memory leak, " & _
                  "but this condition may or may not be prevented: " & _
                  ControlChars.NewLine & ControlChars.NewLine & _
                  "In " & AppConstants.LONG_APP & ":" & ControlChars.NewLine & _
                  "  1. In the main window (blue), issue menu command" & _
                  "  Utility/Garbage Collect a lot of times during a lengthy " & _
                  "operation." & _
                  ControlChars.NewLine & _
                  "  2. Reduce the number of proteins to process for lengthy " & _
                  "operations (quantitation, MS3 scoring, etc.). " & _
                  "Do the save-quit-open cycle inbetween the lengthy operations." & _
                  ControlChars.NewLine & _
                  "  3. Do a save, quit, load cycle. This is the most " & _
                  "efficient workaround, especially right after parsing the " & _
                  "Mascot result file. Save: Protein Window, menu File/Save. " & _
                  "Quit: quit the program. Open: main window (blue), then issue " & _
                  "menu command File/Open/<select the saved file>" & _
                  ControlChars.NewLine & ControlChars.NewLine & _
                  "In DTASuperCharge:" & ControlChars.NewLine & _
                  "  <to be completed>" & _
                  ControlChars.NewLine & _
                  ControlChars.NewLine & _
                  "(text for this dialog is to be completed)" & _
                  ""

                MsgBox(msgStr)

                'To get the stack trace. How do we get it in the above??
                Trace.Assert(mSpectrumRange.startSpectrum > 0, _
                  "PIL ASSERT. mSpectrumRange.startSpectrum not set!.")
            End If

            Trace.Assert(mSpectrumRange.endSpectrum > 0, _
              "PIL ASSERT. mSpectrumRange.endSpectrum not set!.")

            'Changed PM_FRAGMENTS_FOR_INSERTED 2004-11-25
            mSpectrumRange.firstRetentionTimeSeconds = _
              derived_SpectrumNumber2RetentionTime(mSpectrumRange.startSpectrum, 0)
            mSpectrumRange.lastRetentionTimeSeconds = _
              derived_SpectrumNumber2RetentionTime(mSpectrumRange.endSpectrum, 0)
        End Sub 'openRawFile


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

            'Changed PM_MULTIPLE_FINNEGAN_TROUBLE 2004-01-06
            If Not mRawfile Is Nothing Then 'Just in case
                'Changed PM_JA_FINNEGAN_ASSERT_RESOURCE_LEAK 2003-12-17
                mRawfile.Close() 'This is mandatory to avoid resource leaks....
                mOpenCloseBalance -= 1
            End If
        End Sub 'closeRawFile


        '****************************************************************************
        '*  SUBROUTINE NAME:   cleanUp                                              *
        'd$ <summary>private helper function
        'd$ </summary>
        Private Sub cleanUp()
            If mOpenCloseBalance > 0 Then
                Dim dummy As fileSpecStructure
                dummy.path = "xyz"
                dummy.tag2 = -9999
                closeRawFile(dummy)
            End If
        End Sub 'cleanUp


        '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


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

            Dim toReturn As Integer = -17

            If aRetentionTime_Secs > mSpectrumRange.firstRetentionTimeSeconds AndAlso _
               aRetentionTime_Secs < mSpectrumRange.lastRetentionTimeSeconds Then
                'Dim aRetentionTime_Hours As Double = aRetentionTime_Secs / 3600.0 'Define the inverse constant for multiplication to avoid the division?
                'Dim aRetentionTime_Minutes As Double = aRetentionTime_Secs / 60.0 'Define the inverse constant for multiplication to avoid the division?

                Dim retMinutes As Double = aRetentionTime_Secs / 60.0
                mRawfile.ScanNumFromRT(retMinutes, toReturn)
            Else
                If aRetentionTime_Secs <= mSpectrumRange.firstRetentionTimeSeconds Then
                    toReturn = mSpectrumRange.startSpectrum
                End If
                If aRetentionTime_Secs >= mSpectrumRange.lastRetentionTimeSeconds Then
                    toReturn = mSpectrumRange.endSpectrum
                End If
            End If

            'What is going on here????
            If mSpectrumNumberEncodedInRetentionTime Then
                'Override the previous. It is assumed the retention time came from 
            End If

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

            Return toReturn
        End Function 'retentionTime2SpectrumNumber()


        '****************************************************************************
        '*  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(aSpectrumNumber >= mSpectrumRange.startSpectrum AndAlso _
              aSpectrumNumber <= mSpectrumRange.endSpectrum, _
              "PIL ASSERT. Spectrum number, " & aSpectrumNumber & _
              ", is outside the range for the raw file, [" & _
              mSpectrumRange.startSpectrum & "; " & _
              mSpectrumRange.endSpectrum & "] .")

            Trace.Assert(aSpectrumNumber < 210000, _
              "PIL ASSERT. Spectrum number is more than 210000....")

            Dim toReturn As Double = -4444.4444

            Dim retMinutes As Double
            mRawfile.RTFromScanNum(aSpectrumNumber, retMinutes)
            toReturn = retMinutes * 60.0
            Return toReturn
        End Function 'derived_SpectrumNumber2RetentionTime


        'Changed PM_DTASC_SUPPORT 2006-11-07. Now public...
        '****************************************************************************
        '*  SUBROUTINE NAME:   classifySpectrum                                     *
        'd$ <summary>   XYZ.
        'd$ </summary>
        Public Overrides Function classifySpectrum( _
          ByVal aSpectrumNumber As Integer) _
          As SpectrumClassificationStructure

            Dim toReturn As SpectrumClassificationStructure
            toReturn.dataSourceName = Nothing 'Keep compiler happy.

            'Changed PM_FINNIGAN_OUTSIDE_SPECTRUMRANGE 2004-06-25
            'Return something reasonanble if outside spectrum range. Here
            'we assume that clients are looking for spectrum types
            'at a lower level so that a MS spectrum would terminate client's
            'searches.
            toReturn.mainClassification = spectrumTypeEnum.enumIsMSspectrum
            toReturn.spectrumSubType2 = spectrumSubTypeEnum.enumIsNormalMS

            If aSpectrumNumber >= mSpectrumRange.startSpectrum AndAlso _
               aSpectrumNumber <= mSpectrumRange.endSpectrum Then

                Trace.Assert(aSpectrumNumber >= mSpectrumRange.startSpectrum AndAlso _
                  aSpectrumNumber <= mSpectrumRange.endSpectrum, _
                  "PIL ASSERT. Spectrum number, " & aSpectrumNumber & _
                  ", is outside the range for the raw file, [" & _
                  mSpectrumRange.startSpectrum & "; " & _
                  mSpectrumRange.endSpectrum & "] .")

                'Note: output string ****MUST**** be set to nothing,
                '      otherwise the string will be left unchanged!!!!!!
                Dim outFilter2 As String = Nothing
                mRawfile.GetFilterForScanNum(aSpectrumNumber, outFilter2)

                'Changed PM_GENERALISED_SPECTRUMCLASSIFICATION 2005-03-13
                'Now data-driven...
                toReturn = mSpectrumClassifier.classify(outFilter2)
            Else
                Dim peter8 As Integer = 8
            End If 'Spectrum range

            'Post condition...
            Select Case toReturn.mainClassification
                Case spectrumTypeEnum.enumIsMSspectrum
                    'OK...
                Case spectrumTypeEnum.enumIsFragmentSpectrum
                    'OK...
                Case Else
                    Trace.Assert(False, _
                      "PIL ASSERT. Invalid value of spectrumTypeEnum: " & _
                      toReturn.mainClassification & _
                      ". Should have been either eIsMSspectrum or eIsFragmentSpectrum.")
            End Select

            Return toReturn
        End Function 'classifySpectrum


        '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

            Dim maxTries As Integer = 20
            Dim tries As Integer = 0
            'Search for MS spectrum number....

            'Will this work if there is more than one MS3 spectrum?????????????

            'Changed PM_MS3_DTASUPERCHARGE 2004-04-15
            Dim spectrumClassification As SpectrumClassificationStructure = _
              classifySpectrum(aSpectrumNumber)
            Dim considerMS3 As Boolean = False
            If spectrumClassification.mainClassification = _
               spectrumTypeEnum.enumIsFragmentSpectrum Then

                If spectrumClassification.spectrumSubType2 = _
                   spectrumSubTypeEnum.enumIsFragmentMS3 Then
                    considerMS3 = True
                Else
                    Dim peter5 As Integer = 5
                End If
            Else
                Dim peter4 As Integer = 4
            End If

            Dim endLoop As Boolean = False
            Dim curSpectrumNumber As Integer = aSpectrumNumber

            'Changed PM_BIG_BAD_BUG 2005-10-10
            'Only go up if client insists....
            If aForceOneLevelUp Then
                'Changed PM_SPECTRUM_BROWSE 2005-08-02
                'Step back if already on a MS-spectrum, unless we
                'are at the highest level.
                'This is to step over a current SIM spectrum to get a
                'full scan spectrum. But what if we are at the second SIM spectrum??.
                If spectrumClassification.mainClassification = _
                   spectrumTypeEnum.enumIsMSspectrum Then
                    If spectrumClassification.spectrumSubType2 = _
                       spectrumSubTypeEnum.enumIsZoomMS Then
                        curSpectrumNumber -= 1
                    End If
                End If
            End If

            While Not endLoop
                anOutSpectrumClassification = classifySpectrum(curSpectrumNumber)

                'Changed PM_INFINITELOOP_SPECCLASSIFY 2006-02-09
                ''Changed PM_REFACTOR 2004-04-15
                'If anOutSpectrumClassification.mainClassification = _
                '   spectrumTypeEnum.eIsMSspectrum Then
                If anOutSpectrumClassification.mainClassification <> _
                   spectrumTypeEnum.enumIsFragmentSpectrum Then
                    endLoop = True
                End If
                'Changed PM_MS3_DTASUPERCHARGE 2004-04-15
                If considerMS3 Then

                    'Changed PM_PHASEOUT_FRAGNORMAL 2006-04-04

                    Dim subtype As spectrumSubTypeEnum = _
                      anOutSpectrumClassification.spectrumSubType2
                    If anOutSpectrumClassification.mainClassification = _
                         spectrumTypeEnum.enumIsFragmentSpectrum AndAlso _
                        subtype = _
                         spectrumSubTypeEnum.enumIsFragmentCID _
                       Then
                        endLoop = True

                        'Patch main type, just in case.
                        anOutSpectrumClassification.mainClassification = _
                          spectrumTypeEnum.enumIsMSspectrum
                    End If
                End If

                If endLoop <> True Then
                    curSpectrumNumber -= 1
                    tries += 1
                    If tries > maxTries Then
                        endLoop = True
                        MsgBox( _
                          "Could not find MS spectrum!. MS-MS spectrum number: " & _
                          aSpectrumNumber & ". Raw file: " & _
                          mReadOnly_CurrentFile.path)
                    End If
                End If
            End While
            Return curSpectrumNumber
        End Function 'spectrumNumberForMSspectrum


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

            Dim maxTries As Integer = 20
            Dim tries As Integer = 0
            Dim endLoop As Boolean = False
            Dim curSpectrumNumber As Integer = aSpectrumNumber + 1
            While Not endLoop
                If curSpectrumNumber > mSpectrumRange.endSpectrum Then
                    endLoop = True
                    'curSpectrumNumber = mSpectrumRange.endSpectrum
                Else
                    anOutSpectrumClassification = _
                      classifySpectrum(curSpectrumNumber)
                    If anOutSpectrumClassification.mainClassification = _
                       spectrumTypeEnum.enumIsMSspectrum Then

                        endLoop = True
                    Else
                        curSpectrumNumber += 1
                        tries += 1
                        If tries > maxTries Then
                            endLoop = True
                            MsgBox("Could not find MS spectrum!. MS-MS spectrum number: " & _
                              aSpectrumNumber & ". Raw file: " & mReadOnly_CurrentFile.path)
                        End If
                    End If
                End If
            End While

            Return curSpectrumNumber
        End Function 'nextMSspectrum


        'Changed PM_SUPERCHARGE 2003-11-03
        'Note: currently used only by the non-Mascot-Parser project....
        '****************************************************************************
        '*  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

            'Note: the regular expression in this function is not for
            '      classification of spectrum type, but is only used to extract
            '      information from the header - like the precursor mass.

            anOutExperimentNumber = 0 'Set to safe value. Does not make
            '  sense for Finnigan.

            'Changed PM_MAX_TRIES 2006-05-04
            ''Changed PM_ACCEPT_LONG_STRETCH_OF_MS_SPECTRA 2004-06-15
            ''Dim maxTries As Integer = 20
            'Dim maxTries As Integer = 300 'In one sample spectrum the 
            '  first 256 spectra were "Full ms" spectra.
            Dim maxTries As Integer = 40000 'This effectively disables it, but
            '  at least we will not get an infinite loop if detection of the
            '  end of the spectrum file somehow fails.

            Dim tries As Integer = 0
            Dim endLoop As Boolean = False
            Dim curSpectrumNumber As Integer = aSpectrumNumber + 1
            While Not endLoop
                If curSpectrumNumber > mSpectrumRange.endSpectrum Then
                    endLoop = True

                    'Changed PM_CORR_TROUBLE 2008-03-06
                    curSpectrumNumber = -10 'Don't return something that is past
                    '  the end of the file. Instead return a negative value so
                    '  the client can take appropriate action.

                    'This can happen if a MGF generator has been chosen that does
                    'not match the Mascot result file. E.g. "Protein Explorer" with
                    'a match string of "scans:(\d+)" for the spectrum number and
                    'an empty string for the retention time. This may result
                    'in some default retention time that points outside the 
                    'raw spectrum file...

                Else
                    Dim curClassification As SpectrumClassificationStructure = _
                      classifySpectrum(curSpectrumNumber)

                    'Changed PM_MORE_MS3_DTASUPERCHARGE 2004-05-10
                    anOutCurClassification = curClassification

                    If curClassification.mainClassification = _
                      spectrumTypeEnum.enumIsFragmentSpectrum Then

                        Dim outFilter2 As String = Nothing
                        mRawfile.GetFilterForScanNum(curSpectrumNumber, outFilter2)
                        'Sample:
                        '  "ITMS + p ESI d Full ms2 915.47@27.00 [ 240.00-1845.00]"

                        Dim ms2regex As String = ".*ms2 ([.0-9]+)\@"
                        Dim result As Match = Regex.Match(outFilter2, ms2regex)

                        If result.Success Then
                            Dim resStr As String = result.Groups(1).Value
                            If IsNumeric(resStr) Then
                                anOutSupposedPrecursorMass = CDbl(resStr)
                            Else
                                'Later: msgbox...
                                Trace.Assert(False, "PIL ASSERT. Non-numeric.")
                            End If
                        Else
                            'Changed PM_MS3_HEADERPARSE_TROUBLE 2007-05-15
                            '  In XCalibur 2.0 SR2 the spectrum headers are
                            '  different (for the same data). "cid" is added.
                            '  Sample:
                            '
                            '    "ITMS + p NSI d w Full ms3 948.07@cid30.00 1539.77@cid30.00 [410.00-1550.00]"
                            '
                            '
                            'Dim ms3regex As String = _
                            '  "\.*ms3\s+[\.0-9]+\@[\.0-9]+\s+([\.0-9]+)\@"
                            Dim ms3regex As String = _
                              "\.*ms3\s+[\.0-9]+\@\D*[\.0-9]+\s+([\.0-9]+)\@"

                            'Changed PM_MS3_DTASUPERCHARGE 2004-04-13
                            Dim result2 As Match = Regex.Match(outFilter2, ms3regex)
                            If result2.Success Then
                                Dim resStr As String = result2.Groups(1).Value
                                If IsNumeric(resStr) Then
                                    anOutSupposedPrecursorMass = CDbl(resStr)
                                Else
                                    'Later: msgbox...
                                    Trace.Assert(False, "PIL ASSERT. Non-numeric.")
                                End If
                            Else
                                'Changed PM_MS3_HEADERPARSE_TROUBLE 2007-05-15. Was
                                '  misleading error message...
                                'Dim msg2 As String = _
                                '  "Unknown spectrum type, could not be derived from " & _
                                '  " spectrum title (looking for ms3 or ms2)'" & _
                                '  outFilter2 & " '. " & _
                                '  "The configuration file " & _
                                '  AppConstants.NEW_SPECCLASSIFICATION_FILENAME & " does " & _
                                '  "not contain information to recognise the spectrum type, " & _
                                '  "MS or MS/MS. Edit " & _
                                '  AppConstants.NEW_SPECCLASSIFICATION_FILENAME & "."
                                Dim msg2 As String = _
                                  "Precursor mass could not be derived from " & _
                                  " the spectrum title (looking for ms3 or ms2) '" & _
                                  outFilter2 & " '. " & _
                                  "Regular expressions used: '" & ms2regex & _
                                  "' and '" & ms3regex & "'."
                                MsgBox(msg2)
                            End If
                        End If

                        endLoop = True
                    Else
                        'MS spectrum. Extract some information and  store it??

                        curSpectrumNumber += 1
                        tries += 1
                        If tries > maxTries Then
                            endLoop = True
                            MsgBox("Could not find MS-MS spectrum!. MS-MS spectrum number: " & _
                              aSpectrumNumber & ". Raw file: " & mReadOnly_CurrentFile.path)
                        End If

                        If tries >= 300 Then
                            Dim PETER2 As Integer = 2
                        End If


                    End If
                End If
            End While
            'Changed PM_MS3INTEGRATION 2004-05-12
            Return curSpectrumNumber
        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

            Dim startT As Double = _
              Me.SpectrumNumber2RetentionTime(aSpectrumNumber, 0)

            'Note: we only regard aSpectrumNumber as an approximate spectrum
            '      number, it may point at an MS-MS spectrum in a cycle. Therefore
            '      if MS is specified we search for that....

            'Changed PM_MS3_DTASUPERCHARGE 2004-04-15
            'Look forward to see if the following spectrum is a ms3 spectrum.....
            Dim spectrumClassification As SpectrumClassificationStructure = _
              classifySpectrum(aSpectrumNumber + 1)

            'Changed PM_PHOSPHO_SCORING 2005-08-12
            anOutSpectrumClassification = classifySpectrum(aSpectrumNumber)


            Dim isMSforFragmentMS3 As Boolean = False
            If spectrumClassification.mainClassification = _
                spectrumTypeEnum.enumIsFragmentSpectrum AndAlso _
              spectrumClassification.spectrumSubType2 = _
                spectrumSubTypeEnum.enumIsFragmentMS3 Then

                isMSforFragmentMS3 = True
            End If

            Trace.Assert( _
              mExperimentInfo.spectrumType <> spectrumTypeEnum.enumIsUndefinedSpectrumType, _
              "PIL ASSERT. mExperimentInfo.spectrumType is undefined!")

            'Changed PM_PREV_MS_BUG 2005-10-06
            'Reverted back. What was that change good for anyway???
            '
            'Impact: for normal MS spectra the previous MS spectrum would erroniously
            '     be taken. Except for the first SIM the datapoints would be 
            '     completely wrong.
            If True Then 'True: Reverted back.

                mCurrentSpectrumNumber = aSpectrumNumber

            Else
                'Bad old code. Was active for 1 1/2 years....
                '
                'Before it is deleted it would be good to find out
                'what the change was good for. Related to PM_BIG_BAD_BUG ?


                'Changed PM_MS3_DTASUPERCHARGE 2004-04-15
                If mExperimentInfo.spectrumType = spectrumTypeEnum.enumIsMSspectrum And _
                   Not isMSforFragmentMS3 Then

                    Dim upSpecClassification As SpectrumClassificationStructure
                    upSpecClassification.dataSourceName = Nothing 'Keep compiler happy.

                    mCurrentSpectrumNumber = spectrumNumberForMSspectrum( _
                      aSpectrumNumber, upSpecClassification, False)

                    'For debugging only. Use of full scan MS spectra.
                    If upSpecClassification.spectrumSubType2 = _
                       spectrumSubTypeEnum.enumIsNormalMS Then
                        Dim peter9 As Integer = 9
                    End If
                Else
                    mCurrentSpectrumNumber = aSpectrumNumber 'Just store the spectrum
                End If
            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)

        '    'Not implemented!!
        '    Trace.Assert(False, "Stop!", "PIL ASSERT. Internal/development 
        '         assert for stopping execution......")
        'End Sub


        'Changed PM_REFACTOR 2008-10-27. Primarily to help in profiling.
        '****************************************************************************
        '*  SUBROUTINE NAME:   convertToList                                        *
        'd$ <summary>Convert from the 8xN XCalibur array structure to 
        'd$          list of non-zero (x,y) pairs.
        'd$ </summary>
        'd$ <param name="anOutDatapoints">
        'd$   Items are of type signalStructure, <see cref="T:xyz.abc" />
        'd$ </param>
        Private Sub convertToList( _
          ByRef anInRawData As Object, ByVal anArraySize As Integer, _
          ByVal aStartMass As Double, ByVal anEndMass As Double, _
          ByRef anOutDatapoints As _
            Generic.List(Of massSpectrometryBase.signalStructure), _
          ByRef anOutDataPointsInfo As dataPointsInfoStructure2)

            anOutDatapoints.Clear()

            'Changed PM_REFACTOR 2004-06-22
            'Dim minY As Double = 1000000.0
            'Dim maxY As Double = -1000000.0
            Dim minYsignal As signalStructure
            minYsignal.Ysig = 1000000.0
            Dim maxYsignal As signalStructure
            maxYsignal.Ysig = -1000000.0

            Dim rawDataPoints As Double(,) = DirectCast(anInRawData, Double(,))

            If rawDataPoints Is Nothing Then
                Dim pete1 As Integer = 1
            Else
                Dim pete2 As Integer = 2
            End If
            Dim len2 As Integer = rawDataPoints.GetLength(1) '2xN, GetLength(0) is 2....

            'From D:\Program Files\Xcalibur\Help\xdkhelp\xSpectrum.htm:
            '
            '    Description: Gets or sets a 2 dimensional variant array 
            '
            '    that contains the points that make up a spectrum. The 
            '    first dimension is always indexed from 0 to 9, each 
            '    corresponding to a Double value representing the 
            '    following values in each chromatogram point: position, 
            '    intensity, basepeak, scan, saturated, fragmented, 
            '    merged, exception, reference, modified. The second 
            '    dimension is indexed from 0 to (number of points - 1). 
            '    Parameters: Get: None 

            'Changed PM_FINNIGAN_SPEEDUP 2004-06-25.
            'In one example the array from GetMassListFromScanNum() 
            'contained 18700 points, but only the first 1967 were
            'actually filled in...
            'Dim lastIndex As Integer = len2 - 1
            Dim lastIndex As Integer = anArraySize - 1
            If anArraySize <> len2 Then
                Dim peter2 As Integer = 2
            End If

            'Changed PM_MEMORY_EFFICIENCY 2008-10-27
            'Note: two passes through the data in order to reduce memory garbage.
            '      This can be reverted when the COM wrapper will have it built-in.
            '
            'Will the program be significantly slower with two passes?
            '
            'Answer: no. With a profiler it has been measured that more 
            '        than 99% of the time is spent in retrieving the 
            '        data points, in XCaliburGetDataPoints().
            '
            Dim reduceMemoryGarbage As Boolean = True

            Dim surveyPass As Integer = 1
            Dim addPass As Integer = 1
            Dim endPass As Integer = 1
            If reduceMemoryGarbage Then
                surveyPass = 1
                addPass = 2
                endPass = 2
            End If

            Dim pass As Integer = 1
            Dim estimatedSize As Integer = 0
            While pass <= endPass
                Dim isAddPass As Boolean = pass = addPass

                If isAddPass Then
                    anOutDatapoints.Capacity = estimatedSize
                End If

                'Brute force: scanning through the entire data set.
                Dim j As Integer
                For j = 0 To lastIndex
                    Dim xVal As Double = rawDataPoints(0, j)

                    'This test is strictly not needed as the wrapper COM component
                    'already makes the test.
                    If xVal >= aStartMass AndAlso xVal <= anEndMass Then

                        Dim yVal As Double = rawDataPoints(1, j)

                        If yVal > 0.000001 Then 'Ignore datapoints with zero
                            '  count, like Analyst.
                            Dim pt As signalStructure
                            pt.Xsig = xVal
                            pt.Ysig = yVal

                            If pass = surveyPass Then
                                estimatedSize += 1
                                If yVal < minYsignal.Ysig Then
                                    minYsignal = pt
                                End If

                                If yVal > maxYsignal.Ysig Then
                                    maxYsignal = pt
                                End If
                            End If

                            If isAddPass Then
                                anOutDatapoints.Add(pt)
                            End If
                        Else
                            Dim peter3 As Integer = 3
                        End If
                    End If
                Next j 'Through incoming data points (some of which may be zero).

                pass += 1
            End While 'One or more passes through the incoming data points.

            'Changed PM_MEMORY_ALLOCATION 2004-08-02
            rawDataPoints = Nothing
            anInRawData = Nothing

            Dim reslen As Integer = anOutDatapoints.Count
            If reslen > 0 Then
                Dim minX As Double = anOutDatapoints.Item(0).Xsig
                Dim maxX As Double = anOutDatapoints.Item(reslen - 1).Xsig

                anOutDataPointsInfo.minX2 = minX
                anOutDataPointsInfo.maxX2 = maxX

                anOutDataPointsInfo.minimumSignal = minYsignal
                anOutDataPointsInfo.maximumSignal = maxYsignal
            Else
                Dim noSignal As signalStructure
                noSignal.Xsig = -10.0
                noSignal.Ysig = 0.0

                anOutDataPointsInfo.minX2 = 0
                anOutDataPointsInfo.maxX2 = 0

                anOutDataPointsInfo.minimumSignal = noSignal
                anOutDataPointsInfo.maximumSignal = noSignal
            End If
        End Sub 'convertToList()


        'Changed PM_REFACTOR 2008-10-27. Primarily to help in profiling.
        '****************************************************************************
        '*  SUBROUTINE NAME:   XCaliburGetDataPoints                                        *
        'd$ <summary>Get the raw array from XCalibur
        'd$ </summary>
        'd$ <param name="anOutDatapoints">
        'd$   Items are of type signalStructure, <see cref="T:xyz.abc" />
        'd$ </param>
        Private Sub XCaliburGetDataPoints( _
          ByVal aStartMass As Double, ByVal anEndMass As Double, _
          ByRef anOutRawData As Object, ByRef anOutArraySize As Integer)

            'Note: output string ****MUST**** be set to nothing,
            '      otherwise the string will be left unchanged!!!!!!
            Dim outFilter2 As String = Nothing
            mRawfile.GetFilterForScanNum(mCurrentSpectrumNumber, outFilter2)

            Dim noFilter As String = Nothing
            Dim noCutOff_Type As Integer = 0
            Dim absoluteCutOff_Type As Integer = 1
            Dim noCutOff As Integer = 0
            Dim minimumCutOff As Integer = 1
            Dim allPeaksReturned As Integer = 0
            Dim doNotCentroid As Integer = 0
            Dim outCentroidWidth As Double

            Dim outPeakFlags As Object = Nothing 'Keep compiler happy.

            'Cut-off configuration
            Dim effective_CutOff_Type As Integer
            Dim effective_CutOff As Integer

            'Changed PM_DATAPOINT_THRESHOLD_ZERO 2004-10-27. To True. Why was it
            'set to false? Note that we can not set it to 1 as MS3 spectra
            'are scaled such that the y values are low, often below 1.0.
            If True Then
                effective_CutOff_Type = noCutOff_Type
                effective_CutOff = noCutOff
            Else
                effective_CutOff_Type = absoluteCutOff_Type
                effective_CutOff = minimumCutOff
            End If

            'Changed PM_ORBITROUBLE 2005-09-08
            Trace.Assert(Not mRawfile Is Nothing, "PIL ASSERT. mRawfile is nothing...")

            Try
                'Attempt a few retries if call of GetMassListFromScanNumEx()
                'throws exception. This happens from time to time with
                'the buggy XCalibur 2.0 software.
                Dim tries As Integer = 4
                Dim tryCounter As Integer = 0
                Dim OK As Boolean = False

                While tryCounter < tries AndAlso Not OK
                    Try
                        'Changed PM_FINNIGAN_MEMORY_WORKAROUND 2004-08-31. Mass 
                        'range added, uses the new nifty wrapper DLL.
                        'Note: the effective length of rawDataPoints is 
                        '      shorter than its actual length (when a 
                        '      cutoff is specified). The last part of the 
                        '      array contains zeros.
                        Trace.Assert(mCurrentSpectrumNumber > 0, _
                          "PIL ASSERT. mCurrentSpectrumNumber is not valid: " & _
                          mCurrentSpectrumNumber)
                        mRawfile.GetMassListFromScanNumEx( _
                          mCurrentSpectrumNumber, noFilter, _
                          effective_CutOff_Type, effective_CutOff, _
                          allPeaksReturned, doNotCentroid, _
                          outCentroidWidth, anOutRawData, outPeakFlags, anOutArraySize, _
                          aStartMass, anEndMass)
                        OK = True
                    Catch exceptionObjectInner As Exception
                        'Ignore until we are out of tries.

                        'Remove this later. To make we discover/debug this
                        'problem
                        Trace.Assert(False, "Stop!", _
                          "PIL ASSERT. Internal/development assert for stopping execution......")
                    End Try
                    tryCounter += 1
                End While

            Catch exceptionObject As Exception
                Dim errMsg1 As String = "Error: " & exceptionObject.ToString & ControlChars.NewLine
                Dim errMsg2 As String = _
                  "Message: " & exceptionObject.Message & ControlChars.NewLine
                Dim errMsg3 As String = ""
                If Not exceptionObject.InnerException Is Nothing Then
                    errMsg3 = _
                        "Extra info: " & exceptionObject.InnerException.Message & ControlChars.NewLine
                End If
                Dim errMsg As String = errMsg1 & errMsg2 & errMsg3
                MsgBox(errMsg)
                Exit Sub
            End Try
        End Sub 'XCaliburGetDataPoints()


        '****************************************************************************
        '*  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 anOutDataPointsInfo As dataPointsInfoStructure2)

            'Old:
            '  ByRef anOutDatapoints As ArrayList


            'Move this to derived_NewSpectrum() if it turns out that
            'this function is called repeatedly.

            Trace.Assert(mCurrentSpectrumNumber >= mSpectrumRange.startSpectrum AndAlso _
              mCurrentSpectrumNumber <= mSpectrumRange.endSpectrum, _
              "PIL ASSERT. Spectrum number, " & mCurrentSpectrumNumber & _
              ", is outside the range for the raw file, [" & _
              mSpectrumRange.startSpectrum & "; " & _
              mSpectrumRange.endSpectrum & "] .")

            Trace.Assert(mCurrentSpectrumNumber > 0, _
              "PIL ASSERT. mCurrentSpectrumNumber is not valid: " & _
              mCurrentSpectrumNumber)


            'Down-calls to make it easier to profile.


            Dim outMassList As Object = Nothing 'Keep compiler happy.
            'Becomes two-dimensional. All mass values
            '     first (1,n) and then all intensity values (2,n).
            'Changed PM_ORBITROUBLE 2005-09-08
            Dim outArraySize As Integer = -1
            Me.XCaliburGetDataPoints(aStartMass, anEndMass, outMassList, outArraySize)

            Me.convertToList( _
              outMassList, outArraySize, _
              aStartMass, anEndMass, anOutDatapoints, anOutDataPointsInfo)
        End Sub 'returnDataPoints()


        '****************************************************************************
        '*  SUBROUTINE NAME:   DataTitle                                            *
        'd$ <summary>
        'd$ </summary>
        Public Overrides Function DataTitle() As String

            Trace.Assert(mCurrentSpectrumNumber > 0, _
              "PIL ASSERT. mCurrentSpectrumNumber is not valid: " & _
              mCurrentSpectrumNumber)

            Dim str As String = Nothing
            mRawfile.GetFilterForScanNum(mCurrentSpectrumNumber, str)
            Return str
        End Function


        ''Changed PM_FINNEGAN_DISPLAY 2003-10-23
        ''****************************************************************************
        ''*  SUBROUTINE NAME:   getFinneganSpectrum                                  *
        'd$ '<summary>   Specfific to this class.
        'd$ '</summary>
        'Public Function getFinneganSpectrum() As XSpectrum

        '    Return mSpectrum
        'End Function 'getFinneganSpectrum


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


            'TODELETE_mRawfile.GetMassListFromScanNum(

            'Ignore aExtraNumber, only used by Micromass.
            Return derived_SpectrumNumber2RetentionTime(aMSMSspecification, 0) 'Error?, 0 is not exactly MS/MS...
        End Function
    End Class 'betterFinneganRawDataFileHandling


    'Public Class microRawDataFileHandling
    '    Inherits rawDataFileHandling

    'End Class


End Namespace

    

    

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