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

'****************************************************************************
'*                               CEBI                                       *
'*                    Software Development Group                            *
'*                         Peter Mortensen                                  *
'*                E-mail: NUKESPAMMERSdrmortensen@get2netZZZZZZ.dk          *
'*                 WWW: http://www.cebi.sdu.dk/                             *
'*                                                                          *
'*  Program for ........                                                    *
'*                                                                          *
'*    FILENAME:   MS3scoring.vb                                             *
'*    TYPE:       VISUAL_BASIC                                              *
'*                                                                          *
'* CREATED: PM 2005-02-22   Vrs 1.0.                                        *
'* UPDATED: PM 2005-xx-xx                                                   *
'*                                                                          *
'****************************************************************************

Option Strict On
Option Explicit On 

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


Imports SDUPutility 'For SDUPstatistics
Imports MolecularSharedStructures 'For modificationCountStructure.
Imports massSpectrometryBase.quantitation 'For QuantitationModes_moreGeneral.


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


    Public Structure MS3matchStructure
        Dim MS3scored As Boolean
        Dim extraScoreByMS3 As Double

        Dim foundMS3spectrum As Boolean 'With ms precursor 
        '  close enough to a theoretical fragment ions mass.
        Dim foundCloseEnoughFragmentPrecursor As Boolean 'With ms
        '  precursor close enough.

        'Changed PM_ORBI_EMPTYSPECTRA 2005-09-29
        Dim emptyMS3spectrum As Boolean

        Dim ms3spectrumNumber As Integer
        Dim missDistance As Double
        Dim explainString As String
        Dim matchedFragmentForBestMSscore As fragmentExStructure

        Dim definedCode As Integer 'For error checking, of client code.
    End Structure 'MS3matchStructure


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Class MS3scoring

        Private mRawDataFileHandling As rawDataFileHandling

        'Changed PM_REFACTOR 2006-10-12
        'Private mMS3signalForBestScore As ArrayList
        Private mMS3signalForBestScore As _
          Generic.List(Of massSpectrometryBase.signalStructure)

        Private mMS3Fragments As peptideFragments

        'Changed PM_ALWAYSSHOW_BEST_MS3_MATCH 2006-03-03
        'Is a member in order to use it over and over again.
        Private mTempFragments As peptideFragments

        'Changed PM_REFACTOR 2007-10-30
        'Private mRecalibSlope As Double
        'Private mRecalibOffset As Double
        Private mRecalibrator As SDUPrecalibrator

        'Changed PM_ALSO_PRECURSOR_FOR_MS3 2006-10-31
        Dim mQuantitationModesObject As QuantitationModes_moreGeneral
        Dim mQuantModeCode As Integer

        'Private mMatchedFragmentForBestMSscore As fragmentExStructure

        Dim mMS3dumpSB As StringBuilder

        ''Changed PM_MS3_EXPORT 2005-01-20
        'Dim mMS2signal As ArrayList

        'Changed PM_FRAGMENTEXPORT_ASSERT 2006-03-09
        Private mValidFragments As Boolean

        'Changed PM_GENERALISED_IONSERIES 2008-05-09
        Dim mPILgeneralisedIonSeries As PILgeneralisedIonSeries



        '****************************************************************************
        '*  SUBROUTINE NAME:   New                                                  *
        'd$ <summary>Constructor</summary>
        Public Sub New( _
          ByRef anInRawDataFileHandling As rawDataFileHandling, _
          ByRef anInCalibration As SDUPrecalibrator, _
          ByRef anInQuantitationModesObject As QuantitationModes_moreGeneral, _
          ByVal aQuantModeCode As Integer, _
          ByRef anInPILgeneralisedIonSeries As PILgeneralisedIonSeries)

            'Changed PM_REFACTOR 2007-10-30
            'Old:
            '  ByVal aRecalibSlope As Double, _
            '  ByVal aRecalibOffset As Double, _

            MyBase.New() 'Is this necessary??

            'Changed PM_REFACTOR 2007-10-30
            'mRecalibSlope = aRecalibSlope
            'mRecalibOffset = aRecalibOffset
            mRecalibrator = anInCalibration


            'Changed PM_ALSO_PRECURSOR_FOR_MS3 2006-10-31
            mQuantitationModesObject = anInQuantitationModesObject
            mQuantModeCode = aQuantModeCode

            'Changed PM_GENERALISED_IONSERIES 2008-05-09
            mPILgeneralisedIonSeries = anInPILgeneralisedIonSeries

            'Changed PM_REFACTOR 2007-10-30. Is in the new class.
            'Trace.Assert(aRecalibSlope > 0.9 AndAlso aRecalibSlope < 1.1, _
            '  "PIL ASSERT. aRecalibSlope is outside a reasonable range. Value: " & _
            '  aRecalibSlope)

            mRawDataFileHandling = anInRawDataFileHandling
            Trace.Assert(Not mRawDataFileHandling Is Nothing, _
              "PIL ASSERT. <message>.")

            'Note: dump information for MS3 scoring
            '      for several proteins, started from Protein List window.
            mMS3dumpSB = Nothing 'To be explicit

            'mMS3Fragments = New peptideFragments(aRecalibSlope, aRecalibOffset)
            mMS3Fragments = Nothing 'We use this as a flag to determine whether 
            '  we need to create a new instance of mTempFragments.

            'Changed PM_ALWAYSSHOW_BEST_MS3_MATCH 2006-03-03
            mTempFragments = _
              New peptideFragments( _
                anInCalibration, _
                anInQuantitationModesObject, _
                aQuantModeCode, anInPILgeneralisedIonSeries)

            init()
        End Sub 'New


        '****************************************************************************
        '*    <placeholder for header>                                              *
        '****************************************************************************
        Private Sub init()
            If Not mMS3Fragments Is Nothing Then
                mMS3Fragments.reset()
            End If
            mTempFragments.reset()

            'Changed PM_FRAGMENTEXPORT_ASSERT 2006-03-09
            mValidFragments = False
        End Sub 'init


        '****************************************************************************
        '*    <placeholder for header>                                              *
        '****************************************************************************
        Public Sub reset2()
            Me.init()
        End Sub 'reset


        '****************************************************************************
        '*    <placeholder for header>                                              *
        '****************************************************************************
        Public Function getMS3Fragments( _
          ByVal anyFragments As Boolean) _
          As peptideFragments

            'Changed PM_FRAGMENTEXPORT_ASSERT 2006-03-09. Client now
            'has responsibility of not using the return value if it is Nothing....
            'Trace.Assert(Not mMS3Fragments Is Nothing, _
            '  "PIL ASSERT. mMS3Fragments is Nothing " & _
            '  "- in getMS3Fragments().")

            'We can't use Nothingness of mMS3Fragments, as 
            'the object exists if score() is called repeatedly - most often the case.

            anyFragments = mValidFragments

            Return mMS3Fragments
        End Function 'getMS3Fragments


        '****************************************************************************
        '*    <placeholder for header>                                              *
        '****************************************************************************
        Public Function getMS3dump() As String
            Dim toReturn As String = ""
            If Not mMS3dumpSB Is Nothing Then
                toReturn = mMS3dumpSB.ToString
            End If
            Return toReturn
        End Function 'getMS3dump


        'Changed PM_MS3INTEGRATION 2004-06-02
        '****************************************************************************
        '*    <placeholder for header>                                              *
        '****************************************************************************
        Private Shared Function DetermineNumFragInMassRange( _
          ByVal aLowerMass As Double, ByVal aHigherMass As Double, _
          ByRef anInFragmentsObject As peptideFragments) As Integer

            'Changed PM_REFACTOR 2005-02-25
            'Old. Delete at any time.
            'Dim count As Integer = 0
            'Dim i As Integer
            'Dim lastIndex As Integer = mDisplItmArr1.Length - 1
            'For i = 0 To lastIndex
            '    Dim curMass As Double = mDisplItmArr1(i).MCRcalcLoc
            '    If curMass >= aLowerMass AndAlso curMass <= aHigherMass AndAlso _
            '       curMass > 30.0 Then
            '
            '        count += 1
            '    End If
            'Next

            'This should be taken care of internally in the class...
            'If aLowerMass < 30.0 Then
            '    aLowerMass = 30.0
            'End If

            Dim tokens As List(Of Integer) = _
              anInFragmentsObject.getFragmentTokens(aLowerMass, aHigherMass)
            Dim count As Integer = tokens.Count

            Return count
        End Function 'DetermineNumFragInMassRange


        'Changed PM_MS3INTEGRATION 2004-06-02
        '****************************************************************************
        '*    <placeholder for header>                                              *
        '****************************************************************************
        'Changed PM_REFACTOR 2005-09-01. Fragment object now passed as a parameter
        '  so other parts of the application can use it as a utility function.
        '  Was mMS3Fragments.
        '  Future: for reason of avoiding cyclic dependency this function should
        '          be moved to a common place.
        '
        'Private Function DetermineScore() As Double
        Public Shared Function DetermineScore( _
          ByRef anInFragmentsObject As peptideFragments, _
          ByVal aXmin As Double, _
          ByVal aXmax As Double, _
          ByRef anOutN As Integer, _
          ByRef anOutK As Integer _
          ) _
          As Double

            'Note: through its caller, getDataMatchAndScore3(), this
            '      function is used by MS3 as well as PTM scoring...

            'Changed PM_HIGHERSCORES_MS3_AND_PTM 2007-11-13
            'New parameters:
            '  aXmin and aXmax.

            'Changed PM_PTMSCORE_TROUBLE 2008-05-22
            'Dim toReturn As Double = -9999.9
            Dim toReturn As Double = -8888.8

            'Determine p. This is the number of ion signals allowed per 
            'hundred Da so p = 0.04.
            '
            'Determine number of calculated fragments. This is the number 
            'of b and y ions in the mass range. Mass range is lowest to 
            'highest ion mass.
            '
            'Determine number of matches k. This is number
            'of check marks.

            Dim p As Double = 0.04

            'Changed PM_HIGHERSCORES_MS3_AND_PTM 2007-11-13
            ''Changed PM_REFACTOR 2005-02-25. Possible change: start at lowest
            ''fragment mass instead of 0.0 Th.
            ''Dim Xmin As Double = mDisplItmArr1(0).MCRcalcLoc
            'Dim Xmin As Double = anInFragmentsObject.lightestFragmentMCR()
            Dim Xmin As Double = aXmin 'Use observed/spectrum mass range 
            '  instead of theoretical mass range !!!

            'Changed PM_HIGHERSCORES_MS3_AND_PTM 2007-11-13
            ''Changed PM_REFACTOR 2005-02-25.
            ''Dim lastIndex As Integer = mDisplItmArr1.Length - 1
            ''Dim Xmax As Double = mDisplItmArr1(lastIndex).MCRcalcLoc
            'Dim Xmax As Double = anInFragmentsObject.heaviestFragmentMCR()
            Dim Xmax As Double = aXmax 'Use observed/spectrum mass range 
            '  instead of theoretical mass range !!!

            'Determine n, the number of tries. This is the number of b
            'and y ions in the mass range.
            Dim n As Integer = _
              DetermineNumFragInMassRange(Xmin, Xmax, anInFragmentsObject)

            'Changed PM_REFACTOR 2005-02-25
            'Dim k As Integer = fragmentsMatchedCount() 'Number of matches.
            Dim k As Integer = _
              anInFragmentsObject.fragmentsMatchedCount() 'Number of matches.

            'Changed PM_DISPLAY_SCORE 2008-06-25
            anOutN = n
            anOutK = k


            Dim noverk As Double = SDUPstatistics.NoverK(n, k)
            Dim pToPowerK As Double = Math.Pow(p, k)
            Dim lastTerm As Double = Math.Pow((1 - p), (n - k)) 'Better name?

            'Determine n over k.
            Dim probability As Double = noverk * pToPowerK * lastTerm

            'Changed PM_MS3_ZEROSCORE_NOMATCHES 2005-09-29
            If k = 0 Then

                'Changed PM_EXPORT_TROUBLE 2008-05-22
                'probability = 0.0
                probability = 1.0
            End If

            'Changed PM_EXPORT_TROUBLE 2008-05-22
            'If probability = 0 Then
            '  toReturn = 0
            If probability = 0.0 Then
                toReturn = 999.0 'Like infinite score.

                'Changed PM_EXPORT_TROUBLE 2008-05-22
                'Temp only. Also uses memory.
                Dim nkStr As String = "n: " & n & ". k: " & k & ". "

                Trace.Assert(False, _
                  "Stop!", _
                  "PIL ASSERT. Internal/development assert for stopping execution......" & _
                  "Infinite probability of false positive match. " & nkStr)
            Else
                toReturn = -10 * Math.Log10(probability) 'Same probability scaling 
                '  as Mascot.
            End If

            Trace.Assert( _
              toReturn > -0.00001 AndAlso toReturn < 1000.0, _
              "PIL ASSERT. PTM score, " & toReturn & _
              ", is outside range ]-0.00001; 1000.0[.")

            Return toReturn
        End Function 'DetermineScore


        'Disabled for now. Not currently used.
        ''****************************************************************************
        ''*    <placeholder for header>                                              *
        ''****************************************************************************
        'Private Sub dumpMS3information(ByRef anInMS2Signal As ArrayList)
        '
        '    If Not mMS3signalForBestScore Is Nothing Then
        '
        '        'Note: this reduction is also done during MS3 scoring, but
        '        '      we want to do it independently for dumping.
        '        Dim ms3Peaks As ArrayList
        '        If True Then 'MS3
        '
        '            Dim catchDistance As Double = 0.3 'Bigger peaks will not svallow smaller
        '            '  ones, even if the data is already centroided.
        '            'Dim catchDistanceForExtension As Double = 1.1
        '            Dim catchDistanceForExtension As Double = 0.4
        '
        '            'false negatives!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        '
        '            'Dim findPeaksMaxSearchLevel As Integer = 99
        '            Dim findPeaksMaxSearchLevel As Integer = 7
        '
        '            Dim actualDeepestSearchLevel As Integer
        '
        '            Dim ms3PeaksLC As ArrayList
        '            BSignal.findThePeaksNonEx( _
        '              mMS3signalForBestScore, _
        '              ms3PeaksLC, _
        '              catchDistance, catchDistanceForExtension, _
        '              findPeaksMaxSearchLevel, actualDeepestSearchLevel)
        '            Dim inputPeaks As Integer = mMS3signalForBestScore.Count
        '            Dim outputPeaks As Integer = ms3PeaksLC.Count
        '            Dim reductionRatio As Double = inputPeaks / outputPeaks
        '            ms3Peaks = _
        '              BSignal.convertListTo_signalStructureList(ms3PeaksLC)
        '        End If
        '
        '        Dim ms2Peaks As ArrayList
        '        If True Then
        '            Dim catchDistance As Double = 0.3 'Bigger peaks will 
        '            '   not svallow smaller ones, even if the data is already centroided.
        '            'Dim catchDistanceForExtension As Double = 1.1
        '            Dim catchDistanceForExtension As Double = 0.4
        '
        '            'Dim findPeaksMaxSearchLevel As Integer = 99
        '            Dim findPeaksMaxSearchLevel As Integer = 7
        '
        '            Dim actualDeepestSearchLevel As Integer
        '
        '            Dim ms2PeaksLC As ArrayList
        '            BSignal.findThePeaksNonEx( _
        '              mLastMS2signal, _
        '              ms2PeaksLC, _
        '              catchDistance, catchDistanceForExtension, _
        '              findPeaksMaxSearchLevel, actualDeepestSearchLevel)
        '            Dim inputPeaks As Integer = mLastMS2signal.Count
        '            Dim outputPeaks As Integer = ms2PeaksLC.Count
        '            Dim reductionRatio As Double = inputPeaks / outputPeaks
        '            ms2Peaks = _
        '              BSignal.convertListTo_signalStructureList(ms2PeaksLC)
        '        End If
        '
        '        'Matched in MS3 scoring
        '        'Changed PM_REFACTOR 2005-02-24
        '        'If False Then
        '        '    Dim fragDumpSB As StringBuilder = New StringBuilder(3000)
        '        '    Dim lastIndex As Integer = mDisplItmArr1.Length - 1
        '        '    Dim j As Integer
        '        '    For j = 0 To lastIndex
        '        '        Dim curItem As pDisplItmStructure = mDisplItmArr1(j)
        '        '        'fragDumpSB.Append(curItem.seq)
        '        '        ''strSB.Append(ControlChars.Tab)
        '        '        ''strSB.Append("Y")
        '        '        ''strSB.Append(ControlChars.NewLine)
        '        '        'If curItem.ms3ionChecked Then
        '        '        '    mFinneganMSMS.highLightMarker(Me, j)
        '        '        'End If
        '        '    Next
        '        'End If
        '
        '        If mMS3dumpSB Is Nothing Then
        '            mMS3dumpSB = New StringBuilder(50000)
        '        End If
        '        mMS3dumpSB.Append("[BEGIN_PEPTIDE]")
        '        mMS3dumpSB.Append(ControlChars.NewLine)
        '
        '        'Dim ms2Xpoints As String = _
        '        '  PILInputOutput.dumpXpointsInOneLine(ms2Peaks)
        '        'Dim ms3Xpoints As String = _
        '        '  PILInputOutput.dumpXpointsInOneLine(ms3Peaks)
        '        Dim ms2Xpoints As String = _
        '          PILInputOutput.dumpXYSpectrumPoints(ms2Peaks, "", "", "", "", False)
        '        Dim ms3Xpoints As String = _
        '          PILInputOutput.dumpXYSpectrumPoints(ms3Peaks, "", "", "", "", False)
        '
        '        mMS3dumpSB.Append(mLastPeptHit.AASequence)
        '        mMS3dumpSB.Append(ControlChars.NewLine)
        '
        '        mMS3dumpSB.Append("Calculated neutral mass [Da]")
        '        mMS3dumpSB.Append(ControlChars.Tab)
        '        mMS3dumpSB.Append(mLastPeptHit.MascotCalculatedMW)
        '        mMS3dumpSB.Append(ControlChars.NewLine)
        '
        '        mMS3dumpSB.Append("Mascot score:")
        '        mMS3dumpSB.Append(ControlChars.Tab)
        '        mMS3dumpSB.Append(mLastPeptHit.MascotScore)
        '        mMS3dumpSB.Append(ControlChars.NewLine)
        '
        '        mMS3dumpSB.Append("Protein:")
        '        mMS3dumpSB.Append(ControlChars.Tab)
        '        mMS3dumpSB.Append(mProt.accNum)
        '        mMS3dumpSB.Append(ControlChars.NewLine)
        '
        '        mMS3dumpSB.Append("ms2 peaklist [MS2]:")
        '        mMS3dumpSB.Append(ControlChars.NewLine)
        '        mMS3dumpSB.Append(ms2Xpoints)
        '        mMS3dumpSB.Append(ControlChars.NewLine) 'Will be empty line
        '
        '        mMS3dumpSB.Append("ms3 peaklist [MS3]:")
        '        mMS3dumpSB.Append(ControlChars.NewLine)
        '        mMS3dumpSB.Append(ms3Xpoints)
        '        mMS3dumpSB.Append(ControlChars.NewLine) 'Will be empty line
        '
        '        mMS3dumpSB.Append("ms3 theoretical fragments and matching info [MS3match]:")
        '        mMS3dumpSB.Append(ControlChars.NewLine)
        '
        '        'mMS3dumpSB.Append(ControlChars.Tab)
        '        mMS3dumpSB.Append("ms3 precursor:")
        '        mMS3dumpSB.Append(ControlChars.Tab)
        '        mMS3dumpSB.Append(mLastPeptHit.MS3precursorStr)
        '        mMS3dumpSB.Append(ControlChars.NewLine)
        '
        '        'mMS3dumpSB.Append(ControlChars.Tab)
        '        mMS3dumpSB.Append("Total score:")
        '        mMS3dumpSB.Append(ControlChars.Tab)
        '        mMS3dumpSB.Append(mLastPeptHit.MascotScorePlusMS3Score)
        '        mMS3dumpSB.Append(ControlChars.NewLine)
        '
        '        mMS3Fragments.fragmentsSaveString(mMS3dumpSB)
        '        mMS3dumpSB.Append(ControlChars.NewLine) 'Will be empty line
        '    Else
        '        Dim peter2 As Integer = 2
        '    End If
        'End Sub 'dumpMS3information


        '****************************************************************************
        '*    <placeholder for header>                                              *
        '****************************************************************************
        Public Shared Sub getDataMatchAndScore3( _
          ByRef anOutMS3Fragments As peptideFragments, _
          ByRef anInOutWorkingMS3Fragments As peptideFragments, _
          ByRef aInFragSeq As String, _
          ByVal aInFragCharge As Integer, _
          ByRef anInPeptideSequence As String, _
          ByVal aInPeptideCharge As Integer, _
          ByRef anInMassesList As _
             Generic.List(Of Generic.List(Of quantitation.AAsetStruct)), _
          ByRef aCurrPeptMod As String, _
          ByRef anInMassAdjustments As ionSetStruct, _
          ByVal aMS3flag As Boolean, _
          ByVal aMatchedFragment As fragmentExStructure, _
          ByVal aSpectrumNumber As Integer, _
          ByRef aRawDataFileHandling As rawDataFileHandling, _
          ByVal aRawFileID As Integer, _
          ByVal aSmartPickingLevel As Integer, _
          ByVal aMassWindow As Double, _
          ByVal aMannLevel As Integer, _
          ByVal aMassTol As Double, _
          ByRef anInOutMS3match As MS3matchStructure, _
          ByRef aOutSignalForBestScore2 As _
            Generic.List(Of signalStructure), _
          ByRef anOutScore As Double, _
          ByRef aInPeakList As _
            Generic.List(Of LCPeakInfoStructure), _
          ByRef aInOverrideMaxIntPeakLst() As Integer, _
          ByRef aModifications As Generic.List(Of modificationCountStruct), _
          ByVal anExperimentNumber As Integer _
          )
            'Note: aInPeakList is:
            '        Nothing    : this function retrieves some datapoints and
            '                     make the peak list from them.
            '
            '        otherwise  : client passes the peak list.
            '

            'Changed PM_BAD_QSTARSPECTRUM_FOR_PTMSCORING 2007-09-14
            'Note: anExperimentNumber is for QSTAR/Sciex/Analyst

            'Old:
            '  ByRef aInOverRideSignal As ArrayList
            '  ByRef aOutSignalForBestScore As ArrayList, _
            '
            '  ByRef anInDatapointsInfoForOverrideSignal As dataPointsInfoStructure2 _
            '
            '  Changed PM_QUANTGENERAL_PREPARATION 2006-07-14
            '  ByRef anInModificationsList As ArrayList, _

            'Changed PM_PTMSCORE_TROUBLE 2008-05-22
            'anOutScore = -9999.9
            anOutScore = -6666.6

            aOutSignalForBestScore2 = Nothing 'If we don't retrieve data points
            '  in this function.

            'Client should initially set field extraScoreByMS3 to a low
            'value. 
            Trace.Assert(anInOutMS3match.definedCode = 997, _
              "PIL ASSERT. Variable of type MS3matchStructure is not defined properly!.")

            'Changed PM_BAD_QSTARSPECTRUM_FOR_PTMSCORING 2007-09-14
            'Dim experimentNumber As Integer = 0 '0: ????????
            Dim experimentNumber As Integer = anExperimentNumber

            Dim rtSecs As Double = _
              aRawDataFileHandling.SpectrumNumber2RetentionTime( _
                aSpectrumNumber, experimentNumber)


            'Changed PM_REFACTOR 2005-08-15
            '************
            'By the client: should use
            '  displaySpectrumInformation()
            '
            'To do: update for new fragment spectrum.
            ' Me.setSpectrumAndDisplay(ms3spectrumNumber) 'Will
            ' '  this display the right MS3 spectrum if there is
            ' '  more than one???
            'Dim rtSecs As Double = _
            '  mRawDataFileHandling.SpectrumNumber2RetentionTime( _
            '    ms3spectrumNumber)
            'Me.setFragmentSpectrumAndDisplay(rtSecs, 1)

            'Changed PM_BAD_QSTARSPECTRUM_FOR_PTMSCORING 2007-09-14
            'Dim experimentNumber2 As Integer = 1
            Dim experimentNumber2 As Integer = anExperimentNumber

            Dim dummy As Integer
            aRawDataFileHandling.setSpectrumCONV( _
              rtSecs, experimentNumber2, dummy)

            'Trace.Assert(ms3spectrumNumber = spectrumNumberMS3comp, _
            '  "PIL ASSERT. MS3 spectrum number are not the same.")

            'Changed PM_REFACTOR 2005-08-15
            'By the client....
            'Dim quantitationModesObject As QuantitationModes_moreGeneral = _
            '  mApplication.getQuantModes()
            'Dim modificationsList As ArrayList = _
            '  quantitationModesObject.constructSimpleModificationList( _
            '    mCurrSelPept.modHits)

            '************
            'By the client: should use
            '  displaySpectrumWithFragments().


            'Changed PM_GENERALISED_IONSERIES_SPECTRUMCLASSIFICATION 2008-06-24
            Dim curSpectrumClassification As SpectrumClassificationStructure = _
              aRawDataFileHandling.getCurSpectrumClassification()


            anInOutWorkingMS3Fragments.CalcFragIons2( _
              aInFragSeq, False, _
              anInPeptideSequence, aInPeptideCharge, _
              anInMassesList, _
              aCurrPeptMod, anInMassAdjustments, _
              aModifications, _
              aMS3flag, _
              curSpectrumClassification.spectrumSubType2)

            'Changed PM_TYPESAFE_TYPEMISMATCH 2006-11-03
            ''Changed PM_REFACTOR 2006-10-12
            ''Dim effectiveFullSignal As ArrayList = Nothing
            'Dim effectiveFullSignal As _
            '  Generic.List(Of signalStructure) = Nothing

            'Changed PM_TYPESAFE 2006-11-01
            'Dim effectiveReducedDatapoints As ArrayList = _
            '  Nothing 'Keep compiler happy.
            Dim effectivePeakList As Generic.List(Of LCPeakInfoStructure) = _
              Nothing 'Keep compiler happy.

            Dim effectiveReducedMaxIntPeakLst2() As Integer = _
              Nothing 'Keep compiler happy.

            'Changed PM_USERSET_MS3_MATCHING_TOLERANCE 2007-07-13
            Dim smartPickingLevel As Integer = 99
            Dim massWindow As Double = 100.0
            Dim mannLevel As Integer = 4
            Dim massTol As Double = 0.3

            smartPickingLevel = aSmartPickingLevel
            massWindow = aMassWindow
            mannLevel = aMannLevel
            massTol = aMassTol

            Dim XminForScore As Double = -2.2E+22
            Dim XmaxForScore As Double = -2.2E+22

            If True Then
                If aInPeakList Is Nothing Then
                    'No peak list from the client. Get datapoints and
                    'make a peak list...

                    'Dim MS3Signal As ArrayList
                    'Dim MS3dataPointsInfo As dataPointsInfoStructure2
                    Dim MS3LowestX As Double
                    Dim MS3HighestX As Double
                    Dim effectiveFullDataPointsInfo2 As dataPointsInfoStructure2
                    aRawDataFileHandling.datapointsCONV( _
                      aRawFileID, _
                      aOutSignalForBestScore2, effectiveFullDataPointsInfo2, _
                      MS3LowestX, MS3HighestX)

                    BSignal.reducePeakList2( _
                      aOutSignalForBestScore2, effectiveReducedMaxIntPeakLst2, _
                      effectivePeakList, _
                      smartPickingLevel, massWindow, mannLevel, massTol)

                    'Changed PM_HIGHERSCORES_MS3_AND_PTM 2007-11-13
                    'Use raw datapoints mass range. Other possibilities
                    'are the mass range for:
                    '
                    '  1. the reduced peaklist.
                    '
                    '  2. from the spectrum header.
                    '
                    XminForScore = MS3LowestX
                    XmaxForScore = MS3HighestX

                Else
                    effectiveReducedMaxIntPeakLst2 = aInOverrideMaxIntPeakLst
                    effectivePeakList = aInPeakList

                    'Changed PM_HIGHERSCORES_MS3_AND_PTM 2007-11-13
                    'Assume it is sorted...
                    Dim lastIndex As Integer = aInPeakList.Count() - 1
                    XminForScore = aInPeakList(0).LCpeakTimeCentroid
                    XmaxForScore = aInPeakList(lastIndex).LCpeakTimeCentroid
                End If
            End If

            '99: smartPicking search level. To have
            '    exactly same behavior as before.

            anInOutWorkingMS3Fragments.resetMarkMatches()

            peptideFragments.matchFragmentIons( _
              effectivePeakList, effectiveReducedMaxIntPeakLst2, _
              aInFragCharge, _
              massTol, _
              anInOutWorkingMS3Fragments)

            'Changed PM_REFACTOR 2005-08-16. Now in client.
            'highlightMatchedFragments()

            'Changed PM_HIGHER_PTM_SCORE 2008-01-08
            Dim useNewPTMscore As Boolean = True


            'Changed PM_HIGHERSCORES_MS3_AND_PTM 2007-11-13
            'Old behavior:
            If Not useNewPTMscore Then

                'Mass range is theoretical fragment mass range, 
                'even if this mass range is not observed or 
                'no data is observed there. The score will be lower
                'than it should be.
                '
                'Note: old behavior!!!!
                XminForScore = _
                  anInOutWorkingMS3Fragments.lightestFragmentMCR()
                XmaxForScore = _
                  anInOutWorkingMS3Fragments.heaviestFragmentMCR()
            End If

            Dim N As Integer
            Dim K As Integer
            Dim MS3Score As Double = _
              DetermineScore( _
                anInOutWorkingMS3Fragments, _
                XminForScore, XmaxForScore, _
                N, K)

            'How can the score be non-zero when there are no datapoints???????
            'Update: is now 0.0 if no fragments are matched.

            If effectivePeakList.Count > 0 Then
                'MS3scored = True
                anInOutMS3match.MS3scored = True
            Else
                anInOutMS3match.emptyMS3spectrum = True
            End If

            anOutScore = MS3Score

            'Changed PM_MS3INTEGRATION 2004-06-15
            If MS3Score > anInOutMS3match.extraScoreByMS3 Then

                anOutMS3Fragments = anInOutWorkingMS3Fragments

                anInOutMS3match.extraScoreByMS3 = MS3Score

                'Changed PM_TYPESAFE_TYPEMISMATCH 2006-11-03
                ''Changed PM_REFACTOR 2005-09-02
                ' ''Changed PM_REFACTOR 2005-08-16
                ''d$ Changed PM_MS3_EXPORT 2005-01-20
                ' ''mMS3signalForBestScore = mLastMSMSSignal
                ''mMS3signalForBestScore = MS3Signal
                ''aOutSignalForBestScore = MS3Signal
                'aOutSignalForBestScore = effectiveFullSignal

                anInOutMS3match.matchedFragmentForBestMSscore = _
                  aMatchedFragment
            Else
                Dim peter7 As Integer = 7
            End If
        End Sub 'getDataMatchAndScore


        '****************************************************************************
        '*    <placeholder for header>                                              *
        '****************************************************************************
        Private Shared Sub breakPointBlock( _
          ByVal aMajorSelector As Integer, ByVal aValue As Integer)

            Select Case aMajorSelector
                Case 0
                    Select Case aValue
                        Case 0

                        Case 1

                        Case 2

                        Case 3

                        Case Else
                    End Select

                Case 1
                    Select Case aValue
                        Case 0

                        Case 1

                        Case 2

                        Case 3

                        Case Else
                    End Select

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


        '****************************************************************************
        '*    <placeholder for header>                                              *
        '****************************************************************************
        Public Sub MS3score( _
          ByRef anInMSMSFragments As peptideFragments, _
          ByRef anInPeptideSequence As String, _
          ByVal aInPeptideCharge As Integer, _
          ByVal aRawFileID As Integer, _
          ByRef anInMassesList As _
             Generic.List(Of Generic.List(Of quantitation.AAsetStruct)), _
          ByRef aCurrPeptMod As String, _
          ByRef anInMassAdjustments As ionSetStruct, _
          ByRef anInMS2Signal As ArrayList, _
          ByVal aReductionParameters As reductionParametersStructure, _
 _
          ByRef anOutMS3fragments As peptideFragments, _
          ByRef anOutMS3match As MS3matchStructure, _
          ByRef aModifications As Generic.List(Of modificationCountStruct), _
          ByVal aQueryNumber_forErrDetectionOnly As Integer _
          )
            'ByRef aOutMatchedFragmentForBestMSscore As fragmentExStructure, _

            'Old:
            '  ByRef anInModificationsList As ArrayList, _

            anOutMS3fragments = mTempFragments 'Default: set it to some 
            '  fragments, even if it is some old fragments. E.g. from the  
            '  previous peptide. Is this the right way to do it??

            'mMS2signal = anInMS2Signal

            'Dim MS3match As MS3matchStructure
            anOutMS3match.MS3scored = False
            anOutMS3match.missDistance = -10.0
            anOutMS3match.explainString = "<>"
            anOutMS3match.ms3spectrumNumber = -1

            'Changed PM_MS3_ASSERT 2006-03-03
            'anOutMS3match.extraScoreByMS3 = 0.0
            anOutMS3match.extraScoreByMS3 = -99999.9 'Marker as undefined.
            '  We will set it to zero at the end of this function if it remains
            '  at the marker value.

            anOutMS3match.foundCloseEnoughFragmentPrecursor = False

            anOutMS3match.emptyMS3spectrum = False

            'aPrecursorCharge: MS charge, not used yet...
            '
            'aCurrPeptMod: to be phased out, read from visual interface.

            Dim spectrumNum2 As Integer = _
              mRawDataFileHandling.getCurrentSpectrumNumber()

            'Changed PM_MS3_EXPORT 2005-01-20
            mMS3signalForBestScore = Nothing 'If not changed later in MS3 scoring
            '        then this is a signal that no proper ms3 spectrum was found.

            If spectrumNum2 > 0 Then 'Will be zero if "Show MS3" is pressed before
                '  any peptide has been opened - and thus a fragment spectrum set.

                anOutMS3match.definedCode = 997

                Dim MS3spectraFromSameMS2Precursor As Integer = 0
                Dim done As Boolean = False

                'Dim MS3scored As Boolean = False

                'Dim foundMS3spectrum As Boolean = False 'With ms precursor 
                '  close enough to a theoretical fragment ions mass.
                anOutMS3match.foundMS3spectrum = False

                'Dim foundCloseEnoughFragmentPrecursor As Boolean = False 'With ms
                '  precursor close enough.
                anOutMS3match.foundCloseEnoughFragmentPrecursor = False

                Dim MS2precursorSeqLongEnough As Boolean = False

                'Dim ms3spectrumNumber As Integer
                Dim supposedPrecursorMass_MS3 As Double
                Dim closestTheoFragmentMass As Double = -10.0
                Dim precursorLength As Integer = -1
                Dim fragSeq As String = Nothing 'Keep compiler happy.
                Const MINPRECURSORLENGTH As Integer = 3

                'Changed PM_REFACTOR 2007-07-11
                Dim MS3spectra As Generic.List(Of spectrumSpecStructure) = _
                  rawDataFileHandling.MS3spectraList( _
                    spectrumNum2, mRawDataFileHandling)

                Dim someMSspectrum As spectrumSpecStructure

                'Note: there may be more than one MS3 spectrum after
                '      the MS2 spectrum.
                For Each someMSspectrum In MS3spectra

                    'Refactor adaption for now.
                    Dim supposedPrecursorMass As Double = _
                      someMSspectrum.supposedPrecursorMass
                    anOutMS3match.ms3spectrumNumber = someMSspectrum.specNum

                    anOutMS3match.foundMS3spectrum = True
                    supposedPrecursorMass_MS3 = supposedPrecursorMass

                    'Changed PM_TYPESAFE 2007-07-12
                    'Dim matchedTokens As ArrayList = Nothing 'Keep compiler happy.
                    Dim matchedTokens2 As Generic.List(Of Integer) = Nothing 'Keep 
                    '  compiler happy.

                    'Match precursor mass from MS3 spectrum to a 
                    'fragment in theoretical MS2 fragment masses.
                    Dim matchingMSPrecursor As Boolean = _
                      anInMSMSFragments.MatchesCalcFragIon( _
                        supposedPrecursorMass, aInPeptideCharge, _
                        matchedTokens2)

                    If matchingMSPrecursor Then
                        Dim len As Integer = matchedTokens2.Count()
                        Dim matchedFragment2 As fragmentExStructure
                        Dim token As Integer

                        'Changed PM_ALWAYSSHOW_BEST_MS3_MATCH 2006-03-03
                        mMS3Fragments = Nothing 'Flag to test whether more than
                        '  one MS2 precursor was considered.

                        'Changed PM_MARKER 2006-03-02
                        If matchedTokens2.Count > 1 Then
                            Dim peter1 As Integer = 1 'More than one
                            '  theoretical MS2 fragment mass matches
                            '  the acquisition MS2 precursor mass,
                            '  e.g. a b and a y ion.
                            If matchedTokens2.Count > 2 Then
                                Dim peter2 As Integer = 2
                            End If
                        End If

                        For Each token In matchedTokens2
                            matchedFragment2 = _
                              anInMSMSFragments.getFragment(token)

                            ' 'Changed PM_ALSO_PRECURSOR_FOR_MS3 2006-10-31
                            ' 'Only for debugging.
                            ' If matchedFragment2.ionType = _
                            '    ionTypeEnum.enumPrecursorIon Then
                            ' 
                            '     Dim peter2 As Integer = 2
                            ' End If

                            Dim fragmentPrecursorCharge As Integer = _
                              matchedFragment2.charge

                            anOutMS3match.foundCloseEnoughFragmentPrecursor = _
                              True

                            'Changed PM_MS3_ALLOW_Y3 2005-02-25
                            'If matchedFragment.seq.Length < 4 Then
                            fragSeq = matchedFragment2.seq
                            precursorLength = fragSeq.Length
                            If precursorLength < MINPRECURSORLENGTH Then
                                'MsgBox("can't do this for y3 ions yet") 'MM to 
                                'change  toReturn = True 'Could still have
                                'more MS3 spectra. (??)
                            Else
                                MS2precursorSeqLongEnough = True

                                Dim precursorIsForwardIon As Boolean = True

                                'Changed PM_REFACTOR 2005-01-26
                                Select Case matchedFragment2.ionType
                                    Case ionTypeEnum.enumYion2
                                        precursorIsForwardIon = False
                                    Case ionTypeEnum.enumBion2
                                        precursorIsForwardIon = True
                                    Case ionTypeEnum.enumAion2
                                        'Should we do MS3 scoring at all???
                                        Dim peter9 As Integer = 9

                                    Case ionTypeEnum.enumPrecursorIon2
                                        'Changed PM_ALSO_PRECURSOR_FOR_MS3 2006-10-31
                                        precursorIsForwardIon = False 'Precursor
                                        '  is equivalent to yN.

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

                                Dim ms3flag As Boolean = precursorIsForwardIon

                                'Changed PM_ALWAYSSHOW_BEST_MS3_MATCH 2006-03-03
                                If Not mMS3Fragments Is Nothing Then
                                    'We need to create a new instance of 
                                    'mTempFragments in order not to change 
                                    'the content of mMS3Fragments, set in 
                                    'previous loop iteration.

                                    mTempFragments = _
                                      New peptideFragments( _
                                        mRecalibrator, _
                                        mQuantitationModesObject, _
                                        mQuantModeCode, mPILgeneralisedIonSeries)
                                End If

                                'Transform anInMassAdjustments (that is for
                                'the entire peptide) into a form
                                'corresponding to the current MS3
                                'precursor (a MS2 fragment ion).
                                'E.g. a b ion precursor is missing
                                'the C - terminal part and all backward
                                'ions mass adjustments must be lowered
                                'a fixed amount. The length will also be 
                                'shorter.

                                'Changed PM_BROKEN_MS3 2006-08-18
                                Dim massAdjustmentsForMS3 As ionSetStruct
                                massAdjustmentsForMS3.backwardIonDiffs = Nothing
                                massAdjustmentsForMS3.forwardIonDiffs = Nothing

                                Dim definedMassDiffs As Boolean = _
                                  Not anInMassAdjustments.backwardIonDiffs Is Nothing

                                If definedMassDiffs Then
                                    'Dim diffRegionStart As Integer = -1
                                    'Dim diffRegionEnd As Integer = -1

                                    Dim ionNumber As Integer = _
                                      matchedFragment2.seq.Length()

                                    Dim peptideLen As Integer = _
                                      anInPeptideSequence.Length()

                                    'Zero based.
                                    Dim startCopyIndex As Integer = -1

                                    'Zero based. Inclusive.
                                    Dim endCopyIndex As Integer = -1

                                    'Zero based.
                                    Dim indexForBackwardDiff As Integer = -1
                                    Dim indexForForwardDiff As Integer = -1

                                    If precursorIsForwardIon Then
                                        startCopyIndex = 0
                                        endCopyIndex = ionNumber - 1

                                        indexForBackwardDiff = endCopyIndex + 1
                                        indexForForwardDiff = -1 'No correction

                                        'diffRegionStart = ionNumber
                                        'diffRegionEnd = peptideLen - 1
                                    Else
                                        'Backward precursor ion

                                        startCopyIndex = _
                                          peptideLen - ionNumber
                                        endCopyIndex = peptideLen - 1

                                        indexForBackwardDiff = -1 'No correction
                                        indexForForwardDiff = startCopyIndex - 1

                                        'diffRegionStart = 0
                                        'diffRegionEnd = ionNumber - 1
                                    End If

                                    Dim backwardMassDiff As Double = 0.0
                                    If indexForBackwardDiff >= 0 Then
                                        backwardMassDiff = _
                                          anInMassAdjustments.backwardIonDiffs( _
                                            indexForBackwardDiff)
                                    End If

                                    Dim forwardMassDiff As Double = 0.0
                                    If indexForForwardDiff >= 0 Then
                                        forwardMassDiff = _
                                          anInMassAdjustments.forwardIonDiffs( _
                                            indexForForwardDiff)
                                    End If

                                    If Math.Abs(backwardMassDiff) > 0.00001 Then
                                        Dim peter1 As Integer = 1
                                    End If
                                    If Math.Abs(forwardMassDiff) > 0.00001 Then
                                        Dim peter2 As Integer = 2
                                    End If

                                    ReDim massAdjustmentsForMS3.backwardIonDiffs( _
                                      ionNumber - 1)
                                    ReDim massAdjustmentsForMS3.forwardIonDiffs( _
                                      ionNumber - 1)

                                    'Changed PM_MS3_CRASH 2007-05-14. 
                                    Dim lastIndex1 As Integer = _
                                      anInMassAdjustments.backwardIonDiffs.Length() - 1

                                    Trace.Assert(endCopyIndex <= lastIndex1, _
                                      "PIL ASSERT. endCopyIndex, " & endCopyIndex & _
                                      ", is outside of backwardIonDiffs (last index at " & _
                                      lastIndex1 & ")." & _
                                      " Peptide: " & anInPeptideSequence & "." & _
                                      " Query: " & aQueryNumber_forErrDetectionOnly & "." & _
                                      "" _
                                      )
                                    Trace.Assert(startCopyIndex >= 0, _
                                      "PIL ASSERT. startCopyIndex, " & startCopyIndex & _
                                      ", is outside of backwardIonDiffs (last index at " & _
                                      lastIndex1 & ")." & _
                                      " Peptide: " & anInPeptideSequence & "." & _
                                      " Query: " & aQueryNumber_forErrDetectionOnly & "." & _
                                      "" _
                                      )
                                    Trace.Assert(startCopyIndex <= endCopyIndex, _
                                      "PIL ASSERT. Empty copying range. " & _
                                      "startCopyIndex: " & startCopyIndex & ". " & _
                                      "endCopyIndex: " & endCopyIndex & ". " & _
                                      " Peptide: " & anInPeptideSequence & "." & _
                                      " Query: " & aQueryNumber_forErrDetectionOnly & "." & _
                                      "" _
                                      )

                                    Dim outputIndex As Integer = 0
                                    Dim j As Integer
                                    For j = startCopyIndex To endCopyIndex Step 1

                                        Dim backwardMass As Double = _
                                          anInMassAdjustments.backwardIonDiffs(j)

                                        Dim forwardMass As Double = _
                                          anInMassAdjustments.forwardIonDiffs(j)

                                        backwardMass -= backwardMassDiff
                                        forwardMass -= forwardMassDiff

                                        massAdjustmentsForMS3.backwardIonDiffs( _
                                          outputIndex) = _
                                            backwardMass
                                        massAdjustmentsForMS3.forwardIonDiffs( _
                                          outputIndex) = _
                                            forwardMass

                                        outputIndex += 1
                                    Next j
                                Else
                                    Dim peter2 As Integer = 2 'Not defined....
                                End If 'definedMassDiffs

                                'Changed PM_MS3SCORE_ASSERT 2007-09-24
                                ''Changed PM_BAD_QSTARSPECTRUM_FOR_PTMSCORING 2007-09-14
                                ''Note: this will show the wrong spectrum
                                ''      for QSTAR, but we don't have 
                                ''      MS3 spectra for QSTAR...
                                'Dim experimentNumber As Integer = _
                                '  0 '0 means MS spectrum. This may or may
                                ''not be corrected/changed to the first MS/MS
                                ''spectrum.
                                Dim experimentNumber As Integer = 1 'Avoid ASSERT. It
                                '  is not really used for anything as experiment
                                '  numbers are not used by Finnegan and we only 
                                '  have MS3 spectra for Finnegan.

                                Dim dummyScore As Double
                                MS3scoring.getDataMatchAndScore3( _
                                  mMS3Fragments, _
                                  mTempFragments, _
                                  fragSeq, _
                                  matchedFragment2.charge, _
                                  anInPeptideSequence, _
                                  aInPeptideCharge, _
                                  anInMassesList, _
                                  aCurrPeptMod, _
                                  massAdjustmentsForMS3, _
                                  ms3flag, _
                                  matchedFragment2, _
                                  anOutMS3match.ms3spectrumNumber, _
                                  mRawDataFileHandling, _
                                  aRawFileID, _
                                  aReductionParameters.smartPickingLevel3, _
                                  aReductionParameters.smartPickingMassWindow, _
                                  aReductionParameters.MannReductionLevel2, _
                                  aReductionParameters.matchingMassTolerance, _
                                  anOutMS3match, _
                                  mMS3signalForBestScore, _
                                  dummyScore, _
                                  Nothing, _
                                  Nothing, _
                                  aModifications, _
                                  experimentNumber _
                                  )

                                Trace.Assert( _
                                  Not mMS3signalForBestScore Is Nothing, _
                                  "PIL ASSERT. mMS3signalForBestScore is Nothing!")

                                Trace.Assert(Not mMS3Fragments Is Nothing, _
                                  "PIL ASSERT. mMS3Fragments is Nothing - " & _
                                  "return value from getDataMatchAndScore().")

                                anOutMS3fragments = mMS3Fragments

                                'Changed PM_FRAGMENTEXPORT_ASSERT 2006-03-09
                                mValidFragments = True

                                '  Return True 'We are not necessarily at the
                                '    end of MS3 spectra.
                            End If 'Precursor length test
                        Next 'Tokens for matched precursor for MS3.
                    Else
                        'No MS2 precursor match.

                        'Assumption on what function returns
                        Trace.Assert(matchedTokens2.Count = 1, _
                          "PIL ASSERT. <message>.")

                        Dim tokenForClosest As Integer = matchedTokens2(0)
                        Dim closestFragment As fragmentExStructure = _
                          anInMSMSFragments.getFragment(tokenForClosest)

                        'There was no mass match for this ion.
                        closestTheoFragmentMass = closestFragment.MCRcalcLoc
                        Trace.Assert(closestTheoFragmentMass > 10.0 AndAlso _
                                     closestTheoFragmentMass < 5000.0, _
                          "PIL ASSERT. closestTheoFragmentMass was not set.")
                    End If

                    'Dim theMassAcc As Double = 0.4 'go with 0.4 for now
                    'Dim theIdx As Integer = _
                    '  MatchesCalcFragIon(supposedPrecursorMass, theMassAcc)

                    'Changed PM_MS3INTEGRATION 2004-06-15

                    'Changed PM_REFACTOR 2007-07-11. In outfactored function.
                    'spectrumNum2 += 1

                    MS3spectraFromSameMS2Precursor += 1

                    'Changed PM_CODEMARKER_MS3_MULTIPLE 2006-11-21
                    If MS3spectraFromSameMS2Precursor > 1 Then
                        Dim peter1 As Integer = 1
                    End If

                    'What does this do?? Answer: is only for debugging purposes.
                    MS3scoring.breakPointBlock( _
                      0, MS3spectraFromSameMS2Precursor)
                Next 'Through MS3spectra

                'What does this do?? Answer: is only for debugging purposes.
                MS3scoring.breakPointBlock(1, MS3spectraFromSameMS2Precursor)

                'Display MS3 spectrum even if it was not proper.
                If Not anOutMS3match.MS3scored Then
                    Dim prefixStr As String = "Peptide was not MS3 scored because"
                    Dim str2 As String = Nothing 'Keep compiler happy.

                    If Not anOutMS3match.foundMS3spectrum Then
                        str2 = _
                          " no MS3 spectrum was found."

                        'Changed PM_REFACTOR 2005-08-16. Now in client.
                        ''Clear spectrum so as not to confuse the user.
                        'Select Case mOptions.rawFileMode
                        '    Case rawFileModeEnum.enumAnalyst
                        '        'Not yet....
                        '    Case rawFileModeEnum.enumFinnegan, rawFileModeEnum.enumMicromass
                        '        mFinneganMSMS.clearDisplay("No MS3 spectra found")
                        'End Select
                    Else
                        If anOutMS3match.emptyMS3spectrum Then
                            str2 = _
                              " a MS3 spectrum was found, but appeared to be " & _
                              "empty (at least after reduction). Possible reasons: " & _
                              ControlChars.NewLine & _
                              "1. XCalibur version 2.0 (Orbi special version?) is " & _
                              " installed and an older LTQ-FT data file is used."
                        Else
                            'Changed PM_REFACTOR 2005-08-16. Now in client.
                            ''Does this really work???
                            ''Display last MS3 spectrum
                            'Me.setSpectrumAndDisplay(ms3spectrumNumber)

                            If Not anOutMS3match.foundCloseEnoughFragmentPrecursor Then
                                'Found ms3 spectrum, but precursor mass of the 
                                'experimentally selected fragment peak in the 
                                'MS2 spectrum did not match any theoretical 
                                'fragment ion.

                                'Changed PM_REFACTOR 2005-02-26
                                Trace.Assert(closestTheoFragmentMass > 0, _
                                  "PIL ASSERT. closestTheoFragmentMass was not set!.")

                                Dim missDistance As Double = _
                                  supposedPrecursorMass_MS3 - closestTheoFragmentMass
                                anOutMS3match.missDistance = missDistance

                                str2 = _
                                  " the ms2 precursor mass of " & _
                                  supposedPrecursorMass_MS3.ToString("0.00") & _
                                  " Th was too far from the " & _
                                  "nearest theoretical fragment mass of " & _
                                  closestTheoFragmentMass.ToString("0.00") & _
                                  " Th. Difference: " & _
                                  missDistance.ToString("0.00") & " Th."
                            Else
                                If Not MS2precursorSeqLongEnough Then
                                    str2 = _
                                      " the ms2 precursor, " & fragSeq & _
                                      ", is shorter than " & MINPRECURSORLENGTH & _
                                      " amino acids."

                                    'Dim precursorLength As Integer = -1
                                    'Const MINPRECURSORLENGTH As Integer = 3
                                Else
                                    Trace.Assert(False, _
                                      "PIL ASSERT. This should never happen...")
                                End If
                            End If
                        End If
                    End If

                    'Changed PM_REFACTOR 2005-08-16
                    'lblExtraInfo.BackColor = Color.Salmon
                    'lblExtraInfo.Text = prefixStr & str2
                    anOutMS3match.explainString = prefixStr & str2
                End If
            End If

            'Changed PM_MS3_ASSERT 2006-03-03
            If anOutMS3match.extraScoreByMS3 < 0.0 Then
                anOutMS3match.extraScoreByMS3 = 0.0
            End If

            'Changed PM_MS3_EXPORT 2005-01-20
            If False Then
                ' dumpMS3information(anInMS2Signal)
            End If
        End Sub 'score

    End Class 'MS3scoring


End Namespace 'massSpectrometryBase


    

    

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