Source code for MSQuant: MSQdocDefs.vb, MSQuant/msquant/src/main/MSQdocDefs.vb.

Table of contents page.

Home page for MSQuant.

'* Copyright (C) 2008 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                   *
'* <> 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: data/structure definitions. In particular the upper part        *
'*          for the pseudo-document MB: MSQuantDocumentStructure            *
'*                                                                          *

'*                               CEBI                                       *
'*                    Software Development Group                            *
'*                         Peter Mortensen                                  *
'*                E-mail:          *
'*                 WWW:                             *
'*                                                                          *
'*  Program for post-processing of result from search in mass               *
'*    spectrometric data.                                                   *
'*                                                                          *
'*    FILENAME:   MSQdocDefs.vb                                             *
'*    TYPE:  VISUAL_BASIC                                                   *
'*                                                                          *
'* CREATED: PM 2008-04-16   Content moved from frmProteinList.vb...         *
'* UPDATED: PM 2008-xx-xx                                                   *
'*                                                                          *

Option Strict On
Option Explicit On

Imports System.Xml 'For XmlTextWriter
Imports System.Runtime.Serialization 'For ISerializable.

Imports SimmoTech.Utils.Serialization 'For SerializationReader
'  and SerializationWriter.

Imports MolecularSharedStructures 'For ProteinHitStructure
Imports massSpectrometryBase 'For fileSpecStructure

Imports SDUPutility 'For CEBIdimension
Imports System.Collections.Generic 'For Dictionary and List.

'Changed PM_REFACTOR 2008-04-16. Content moved from frmProteinList.vb...

'Changed PM_AUTODOCUMENTATION 2007-04-18
'Make private and move into class?
'Purpose: collect report items.
Public Structure reportStructure

    Dim XMLwriter As XmlTextWriter
    Dim XMLfileName As String

    Dim massFormatStr As String 'Really a constant. E.g. "0.00000"
End Structure 'reportStructure

'Changed PM_SAVE_RECALIBRATION 2005-01-27
'*    <placeholder for header>                                              *
<Serializable()> _
Public Structure MSQuantDocumentStructure

    'Note: if fields are added the constructor below and
    '      GetObjectData() should be updated!!!

    'Changed PM_FAST_SERIALISATION 2006-12-15
    Implements ISerializable

    'Changed PM_TYPESAFE 2006-10-25
    'Dim parsedProts As ArrayList
    Dim parsedProts3 As Generic.List(Of ProteinHitStructure) '2 vs. 3

    Dim rawFiles2() As fileSpecStructure

    'Note 1: these are for a global recalibration, not recalibration 
    '        per raw file. Phase them out?
    'Note 2: this is for MB3 only, but we keep them as placeholder
    '        for now for loading from MB3.
    Dim recalibSlope2 As Double
    Dim recalibOffset2 As Double

    'Changed PM_REFACTOR 2006-11-15
    Dim mascotFileStr As String 'Path to Mascot result file.
    Dim rawFileStr As String 'Path to raw file.

    'Changed PM_MB4_VERSIONING 2008-11-12
    Dim fileVersion As Integer

    'Changed PM_SAVE_RAWFILE_MAPPING_MB4 2008-11-17
    Dim experimentSettings2 As SDUPutility.experimentSettingsStruct

    'Changed PM_SAVE_ALLRECALIB_MB4 2008-11-21
    Dim recalibrator As SDUPrecalibrator

    'Changed PM_FAST_SERIALISATION 2006-12-30
    '*    For MSQuantDocumentStructure. Deserialisation constructor.            *
    Private Sub New( _
      ByVal anInfo As SerializationInfo, ByVal aContext As StreamingContext)

        'This constructor is called as a result of BFormatter.Deserialize() in

        'Dim reader As SerializationReader = _
        '  New SerializationReader( _
        '    DirectCast(anInfo.GetValue("data"),Byte()),  Byte()))

        'Changed PM_MB4_VERSIONING 2008-11-12
        Dim MBversion As Integer = -1 'Set below.

        'How can this be done in one line??
        Dim someType2 As Type = GetType(Byte())
        Dim reader As SerializationReader = _
          New SerializationReader( _
            DirectCast(anInfo.GetValue("data", someType2), Byte()) _

        If True Then 'Block. Reading protein list, including file
            '  version detection. For this reason it must be first...

            'Note: we will get the file format version number from the
            '      file itself, no matter what the user specifies. This
            '      user choice is only used for providing dialog
            '      filters (e.g. *.mb3)
            Dim proteins As Integer = -1
            Dim firstInteger As Integer = reader.ReadOptimizedInt32()

            'Changed PM_MB4_VERSIONING 2008-11-13
            If firstInteger > 0 Then

                'Older file format. mb3 or older. We can not distinguish 
                'those, but the mb3 format is 2 years old so it is 
                'unlikely we will run into trouble. There is the file 
                'extension filter in the dialog anyway. The only way 
                'would be if the user changed the file extension.
                MBversion = AppConstants.SAVEDFILEVERSION_MB3

                proteins = firstInteger
                'The optimised version is expected never to return a negative
                'value so the only value left is zero...
                Trace.Assert(firstInteger = 0, _
                  "PIL ASSERT. firstInteger, " & firstInteger & _
                  ", was expected to be zero.")

                'Newer version. We now have some guard information in 
                'the (logical) beginning of the file.
                Dim guardStr As String = reader.ReadString()
                If guardStr <> "__MSQ_SAVEDPARSE__" Then

                    'We could use some external information here: the name 
                    'of the file.
                    Dim msgStr As String = _
                      "Could not read the specified saved parse file. " & _
                      "It appears not to be such a file or it is corrupted. " & _
                      "Specify a proper file. " & _
                      "(The beginning of the specified file contains: """ & _
                      guardStr & """)"

                    'How do we stop????
                    Dim len As Integer = guardStr.Length
                    Dim explode As Integer = len \ (len - len)
                    'Newer file versions, MB4 and later.
                    MBversion = reader.ReadOptimizedInt32()
                    proteins = reader.ReadOptimizedInt32()
                End If
            End If

            'Changed PM_MB4_VERSIONING 2008-11-13. Now set above, depending
            '  on file version.
            'Dim proteins As Integer = reader.ReadOptimizedInt32()

            parsedProts3 = New Generic.List(Of ProteinHitStructure)(proteins)

            Dim lastIndex As Integer = proteins - 1
            Dim j As Integer
            For j = 0 To lastIndex
                parsedProts3.Add( _
                  ProteinHitStructure.readFromStream2(reader, MBversion))
            Next j
        End If

        'Changed PM_SAVE_RAWFILE_MAPPING_MB4 2008-11-17
        'Persist dimension and raw file mapping.
        If True Then

            'Use Nothing as a flag for later patch up after deserialisation 
            'has ended. Reason: we currently don't have a good way to 
            'pass parameters to this process.
            Dim defaultValue As experimentSettingsStruct
            defaultValue.JAspace = Nothing
            defaultValue.rawFileMapping3 = Nothing
            defaultValue.INTERNAL_rawFileID2NpointHash = Nothing

            'As in read from XML file, persistExperimentSettings().
            experimentSettings2 = experimentSettingsStruct.readFromStream2( _
              reader, MBversion, defaultValue)
        End If 'Block. Dimension and raw file mapping.

        'Changed PM_SAVE_ALLRECALIB_MB4 2008-11-21
        If True Then
            'Read a recalibrator.
            recalibrator = SDUPrecalibrator.readFromStream2( _
              reader, MBversion)
        End If

        If True Then 'List. Not Generic, is VB array. Code is not typical.
            rawFiles2 = Nothing
            Dim items As Integer = reader.ReadOptimizedInt32()
            If items > 0 Then

                'ASSERT on, items, the number of files? Say [1; 1000].

                Dim lastIndex As Integer = items - 1

                'rawFiles = New Generic.List(Of fileSpecStruct)(items)
                ReDim rawFiles2(lastIndex)

                Dim j As Integer
                For j = 0 To lastIndex
                    rawFiles2(j) = _
                      fileSpecStructure.readFromStream2(reader, MBversion)
                Next j
            End If
        End If

        If MBversion < AppConstants.SAVEDFILEVERSION_MB4 Then 'Only for MB3. The same
            '  information is saved elsewhere for MB4 and later.
            recalibSlope2 = reader.ReadDouble()
            Trace.Assert( _
              recalibSlope2 > 0.1 AndAlso recalibSlope2 < 10.0, _
              "PIL ASSERT. In deserialisation of MSQuantDocumentStructure; ." & _
              " recalibSlope has an unreasonable value: " & _
              recalibSlope2 & ".")

            recalibOffset2 = reader.ReadDouble()
        End If

        mascotFileStr = reader.ReadString()
        rawFileStr = reader.ReadString()

        'Changed PM_SER_DESER_CHECK 2008-11-25
        If MBversion >= AppConstants.SAVEDFILEVERSION_MB4 Then
            Dim marker As Integer = reader.ReadInt32()

            Trace.Assert(marker = MBversion, _
              "PIL ASSERT. The marker at the end of the MBx file, " & marker & _
              ", is not the expected value, " & MBversion & ". " & _
              "This indicates a bug in the program...")

            'Marker is to check that the serialisation and deserialisation 
            '  line up... It could be a constant value, but we choose to 
            '  use the MBx file version number instead...
        End If

        'myInt32Field = reader.ReadInt32()
        'myString = reader.ReadString()
        ' // and so on
    End Sub 'MSQuantDocumentStructure, deserialisation constructor.

    'Changed PM_FAST_SERIALISATION 2006-12-15
    'For MSQuantDocumentStructure.
    '*  For MSQuantDocumentStructure. For saving enough information for a       *
    '*  single parse (so opening it will get the same window/document).         *
    '*                                                                          *
    '*  Note: this is the only place where we use the built-in .NET             *
    '*        serialisation mechanism. Otherwise it was way too slow (by a      *
    '*        factor of 20 or more) and used much too much                      *
    '*        memory (probably reflection is used for each                      *
    '*        and every item).                                                  *
    '*                                                                          *
    Private Sub GetObjectData( _
      ByVal anInfo As SerializationInfo, _
      ByVal anInContext As StreamingContext) _
      Implements ISerializable.GetObjectData

        'Note: called indirectly as a result of saving
        '      a MB3/MB4 file - when BFormatter.Serialize() is  
        '      called, in saveAdoc(), file frmProteinList.vb.

        'SERMARK18. A marker. Keep it.

        Dim writer As SerializationWriter = New SerializationWriter
        Dim fVersion As Integer = fileVersion 'Note: stored in this 
        '  object. Indirect way to transfer this information, but
        '  is it the only way (except for a global variable) ???

        'Changed PM_FAST_SERIALISATION_AVOID_DOTNET 2006-12-19. Loop on the
        'client side. Makes it 20-40 times faster!!!!
        If True Then 'Block. Writing list.
            Trace.Assert(Not parsedProts3 Is Nothing, _
              "PIL ASSERT. parsedProts3 Is Nothing.")

            'Allow us to save in the old format - by not doing the stuff below.
            If fVersion >= AppConstants.SAVEDFILEVERSION_MB4 Then

                Dim filler As Integer = 0 'Note: negative values apparently
                '  do not work with optimized. And there can be a single
                '  protein in a saved parse so the only possible value is zero...
                writer.WriteOptimized(filler) 'Note: filler so we are
                '  compatible type/format wise with the old format. When
                '  we read: the very first read is shared between the old
                '  MB3 format and newer formats.

                'New format has a prefix.
                writer.Write("__MSQ_SAVEDPARSE__") 'Note: this does not
                '  necessarely appear physically in the beginning of the
                '  file. This depends on the SimmoTech library we are using.
                '  In fact all the strings are saved at the end of the file!

            End If

            Dim items As Integer = parsedProts3.Count()
            'This is our own encoding.

            Dim item As ProteinHitStructure
            For Each item In parsedProts3
                item.addToStream2(writer, fVersion)
        End If 'Block. Writing list.

        'Changed PM_SAVE_RAWFILE_MAPPING_MB4 2008-11-17
        'Persist dimension and raw file mapping.
        If True Then
            'As in persistExperimentSettings().

            experimentSettings2.addToStream2(writer, fVersion)
        End If 'Block. Dimension and raw file mapping.

        'Changed PM_SAVE_ALLRECALIB_MB4 2008-11-21
        If True Then
            'Write a recalibrator.
            recalibrator.addToStream2(writer, fVersion)
        End If

        'Changed PM_FAST_SERIALISATION_AVOID_DOTNET 2006-12-28. Loop on the
        'client side. Avoid invoking the .NET serialisation (BinaryFormatter).
        ''writer.WriteObject(rawFiles) 'Note: object! Will
        ' ''  be .NET serialisation.
        If True Then
            Dim items As Integer = rawFiles2.Length()
            'This is our own encoding.

            Dim someItem As fileSpecStructure
            For Each someItem In rawFiles2
                someItem.addToStream2(writer, fVersion)
            Next 'Through rawFiles
        End If

        'Changed PM_SAVE_ALLRECALIB_MB4 2008-11-21
        If fVersion < AppConstants.SAVEDFILEVERSION_MB4 Then 'Only for MB3. The same
            '  information is saved elsewhere for MB4 and later.

        End If


        'Changed PM_SER_DESER_CHECK 2008-11-25
        If fVersion >= AppConstants.SAVEDFILEVERSION_MB4 Then
            writer.Write(fVersion) 'Marker to check later at read time that
            '  the serialisation and deserialisation line up...
            '  It could be a constant value, but we choose to use the MBx file
            '  version number instead...
        End If

        anInfo.AddValue("data", writer.ToArray())
    End Sub 'GetObjectData(). For MSQuantDocumentStructure.

End Structure 'MSQuantDocumentStructure

Public Class docDefs
    'Empty. Do we need it? - encapsulate the two structures in it?

End Class 'docDefs



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