Source code for MSQuant: srcTemplate.txt, MSQuant/msquant/Documents/srcTemplate.txt.

Table of contents page.

Home page for MSQuant.



Future:

  1. To VB templates: Case statement for an enum, including the fall-through assert.

============

To formal code standard:

  1. m as prefix for instance variables

  2. capital letters for constants

  3. a before parameter values

  4. ("value" always for properties)?

  5. Standard file header

  6. Don't rely on default values of variables, always use explicit
     initialisation at declaration. This will ease translation
     to other languages.

  7. Group public and private members, e.g. all public
     functions and subs first in a source file.

  8. enum as postfix for enum types. e as prefix for enumerators.

  9. End a structure name with "Structure". E.g.: peptideFilterStructure
  
 10. 
  

==================================================================================

Source code templates:


//Sections in this template:
//  1. VB (Visual Basic)
//  2. Perl

//Future (for this template file only):
//  1. Template for DOS Batch files (there are already some in COLANOTE.CPP)
//  2. VB part: Add New() to class


'==============================================================================


//C# part, begin

Normal source file:


/****************************************************************************
 * 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                   *
 * <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: Calculates isotope distributions for peptides and others,       *
 *          according to the algorithm given in:.                           *
 *                                                                          *
 ****************************************************************************/

/****************************************************************************
 *                               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:   isotopeDistribution.cs                                    *
 *    TYPE:       CSHARP                                                    *
 *                                                                          *
 * CREATED: PM 2008-01-24   Vrs 1.0.                                        *
 * UPDATED: PM 2008-xx-xx                                                   *
 *                                                                          *
 *                                                                          *
 ****************************************************************************/

'using System.xyz;


/****************************************************************************
 *    <placeholder for header>                                              *
 ****************************************************************************/
namespace xyz
{

    /****************************************************************************
     *    <placeholder for header>                                              *
     ****************************************************************************/
    public class xyz2


<more to fill in here>



    } //class xyz2

} //namespace xyz


Templates:

    For (for the "foreach" sample, see below):

      int len = mSequence.Length();
      for (int i = 0; i < len; i++)
      {
        if (i == 5) 
        {
          break;
        }
      } //for

    Case statement:

      int anIndex;
      double result;
      switch (anIndex) 
      {
          case 0:
              result = 1.2;
              break;
          case 1:
              result = 1.7;
              break;
          default:
              Trace.Assert(false, "PIL ASSERT. Select Case never fall-through");
              break;
      } //switch


    Type safe collections (of double in this example):

      Iterating:
        Generic.List<double> checkBoxInfoList ...
        foreach ( double someItem in checkBoxInfoList)
        {
            double yDiff = someItem;
            if (yDiff > 5.1) 
            {
              break;
            }
        } //Through checkBoxInfoList

      Building:
        int testVectorSize = 7;
        double someNewItem = 12.09;
        Generic.List<double> checkBoxInfoList2 = new Generic.List<double>();
        int lastIndex = testVectorSize - 1;
        int j;
        for (j = 0; j <= lastIndex; j += 1)
        {
            checkBoxInfoList2.Add(someNewItem);
        } //for


    Hash iteration, type safe:

      string keyWithMass = "xyz_2";
      double oldValue;
      double someBestScore = 23.81;
      
      Dictionary<string, double> bestScoreHash2 = new Dictionary<string, double>();
      if (bestScoreHash2.TryGetValue(keyWithMass, oldValue)) 
      {
          bestScoreHash2(keyWithMass) = someBestScore;
      }
      else 
      {
          bestScoreHash2.Add(keyWithMass, someBestScore);
      }
      
      Dictionary<string, double>.Enumerator hashEnumerator2 = bestScoreHash2.GetEnumerator();
      while (hashEnumerator2.MoveNext())
      {
          string curKey = hashEnumerator2.Current.Key;
          double curValue = hashEnumerator2.Current.Value;
      } //Hash iteration.



//C# part, end



//VB part, begin

Normal source file:

'****************************************************************************
'* Copyright (C) 2005 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: Template for the Visual Basic codestandard for PIL              *
'*          software development projects.                                  *
'*          Holds class rawDataFileHandling, see below for documentation.   *
'*                                                                          *
'* The second box contains administrative information. "TYPE" can either be *
'* xyz.                                                                     *
'* Words in all uppercase letters, like FILE, are to be                     *
'* regarded as keywords so tools (e.g. Perl) can later be used to           *
'* automatically extract information.                                       *
'****************************************************************************

'****************************************************************************
'*                               CEBI                                       *
'*                    Software Development Group                            *
'*                         Peter Mortensen                                  *
'*                E-mail: pmortensen@bmb.sdu.dk                             *
'*                 WWW: http://www.cebi.sdu.dk/                             *
'*                                                                          *
'*  Program for ........                                                    *
'*                                                                          *
'*    FILENAME:   thisscrp.vb                                               *
'*    TYPE:  VISUAL_STUDIO_MACRO, VISUAL_BASIC, VSA, VISUAL_BASIC_UNITTESTVBA, PERL_SCRIPT_DRIVER, PERL_SCRIPT  *
'*                                                                          *
'* CREATED: PM 2003-06-10   Vrs 1.0.                                        *
'* UPDATED: PM 2005-xx-xx                                                   *
'*                                                                          *
'****************************************************************************

Option Strict On
Option Explicit On

'Imports System.xyz

'****************************************************************************
'''<summary>
'''  Purpose: namespace general description
'''  <see cref="T:VBXMLDoc.CVBXMLDoc" />.
'''  <isUnitTest></isUnitTest>
'''  <applicationname>test_rawDataFileHandling</applicationname>
'''  <author>Peter Mortensen</author>
'''  <seealso>http://www.cebi.sdu.dk/</seealso>
'''  <codetype>PLATFORM independent / GUI</codetype>
'''</summary>
namespace someNameSpace


    '****************************************************************************
    '*  CLASS NAME:   xyz                                                       *
    '''<summary>
    '''  Purpose: general description
    '''  <see cref="T:VBXMLDoc.CVBXMLDoc" />.
    '''  <applicationname>test_rawDataFileHandling</applicationname>
    '''  <author>Peter Mortensen</author>
    '''  <seealso>http://www.cebi.sdu.dk/</seealso>
    '''  <codetype>PLATFORM independent / GUI</codetype>
    '''</summary>
    Public NotInheritable/MustInherit Class xyz
        Inherits CEmployee


        '****************************************************************************
        '*  SUBROUTINE NAME:   New                                                  *
        '''<summary>Constructor</summary>
        Public Sub New()
            MyBase.New() 'Is this necessary? Yes!

            'InitializeComponent()    Is this necessary??
        End Sub 'New()


        '****************************************************************************
        '*  SUBROUTINE NAME:   myXYZ                                                *
        '''<summary>
        '''  Purpose: general description
        '''  <see cref="T:VBXMLDoc.CVBXMLDoc" />.
        '''</summary>
        '''<param name="RemoveMode">
        '''  Parameter of type <see cref="T:System.Object" />
        '''</param>
        '''<param name="aCount">
        '''  Parameter of type <see cref="T:Extensibility.ex_ConnectMode" />.
        '''</param>
        '''<remarks>
        '''  <para>
        '''  </para>
        '''  <para>
        '''  </para>
        '''  <seealso cref="E:EnvDTE.BuildEvents.OnBuildDone" /> event. This
        '''</remarks>
        '****************************************************************************
        Public Overridable/NotOverridable/MustOverride/Overrides Sub myXYZ(ByVal aRemoveMode As Extensibility.ex_DisconnectMode, ByVal aCount as Integer)
            Dim temp7 As Integer = 7
        End Sub


        '****************************************************************************
        '*  SUBROUTINE NAME:   shortFunc                                            *
        '''<summary> N/A </summary>
        '****************************************************************************
        Public Sub shortFunc(ByVal aShort1 As Integer, ByVal aShort2 As Integer)
            Dim temp8 As Integer = 8
        End Sub

    End Class 'xyz


End Namespace 'someNameSpace



'==============================================================================

Unit test source file:

'****************************************************************************
'* Copyright (C) Protein Interaction Group                                  *
'* Confidential and preliminary. Do not use without express permission.     *
'*                                                                          *
'* Purpose: Unittest for Class rawDataFileHandling.                         *
'*                                                                          *
'****************************************************************************

'****************************************************************************
'*                               PIL                                        *
'*                    Software Development Group                            *
'*                         Peter Mortensen                                  *
'*                E-mail: pmortensen@bmb.sdu.dk                             *
'*                 WWW: http://www.pil.sdu.dk/                              *
'*                                                                          *
'*  Program for ........                                                    *
'*                                                                          *
'*    FILENAME:   thisscrp.vb                                               *
'*    TYPE:       VISUAL_BASIC_UNITTESTVBA                                  *
'*                                                                          *
'* CREATED: PM 2003-06-10   Vrs 1.0.                                        *
'* UPDATED: PM 1998-xx-xx                                                   *
'*                                                                          *
'****************************************************************************

Imports System
Imports NUnit.Framework

'****************************************************************************
'''<summary>
'''  Purpose: namespace general description
'''  <see cref="T:VBXMLDoc.CVBXMLDoc" />.
'''  <isUnitTest></isUnitTest>
'''  <applicationname>test_rawDataFileHandling</applicationname>
'''  <author>Peter Mortensen</author>
'''  <seealso>http://www.cebi.sdu.dk/</seealso>
'''  <codetype>PLATFORM independent / GUI</codetype>
'''</summary>
Namespace someNameSpace


    '****************************************************************************
    '''<summary>
    '''  Purpose: general description
    '''  <see cref="T:VBXMLDoc.CVBXMLDoc" />.
    '''  <isUnitTest></isUnitTest>
    '''  <applicationname>test_rawDataFileHandling</applicationname>
    '''  <author>Peter Mortensen</author>
    '''  <seealso>http://www.cebi.sdu.dk/</seealso>
    '''  <codetype>PLATFORM independent / GUI</codetype>
    '''</summary>
    <TestFixture()> _
    Public Class xyzTest


        '****************************************************************************
        '*  SUBROUTINE NAME:   test1                                                *
        '''<summary> Unittest for xyz </summary>
        <Test()> _
        Public Sub test1()
            Dim temp11 As Integer = 11
        End Sub 'test1()

    End Class 'xyzTest

End Namespace 'someNameSpace



'==============================================================================


Templates:

    Function/procedure header placeholder:
        '****************************************************************************
        '*    <placeholder for header>                                              *
        '****************************************************************************


    Case statement:
        Dim anIndex As Integer
        Dim result As Double
        Select Case anIndex
            Case 0
                result = 1.2
            Case 1
                result = 1.7
            Case Else
                Trace.Assert(False, _
                  "PIL ASSERT. Select Case never fall-through")
        End Select

    For ("Step 1" can usually be omitted):
        dim lastIndex as Integer = testVectorSize - 1
        Dim j As Integer
        For j = 0 To lastIndex Step 1
             If testVector(j).mainSearchType = SEARCH_TYPE_SEQUENCETAG Then
                 doharm()
                 Exit For
             End If 
        Next j

    Collection iteration:
        Dim pept As MolecularSharedStructures.PeptideHitStructure
        For Each pept In prot.pepts
            If pept.verified Then
                countVerified += 1
                Exit For
            End If
        Next

    Type safe collections (of checkBoxItemStructure in this example):

        Dim checkBoxInfoList As Generic.List(Of checkBoxItemStructure) = _
          new Generic.List(Of checkBoxItemStructure)
        Dim someItem As checkBoxItemStructure
        For Each someItem In checkBoxInfoList
            Dim yDiff As Integer = someItem.ySize
        Next 'Through checkBoxInfoList


        Dim checkBoxInfoList As Generic.List(Of checkBoxItemStructure) = _
          new Generic.List(Of checkBoxItemStructure)
        dim lastIndex as Integer = testVectorSize - 1
        Dim j As Integer
        For j = 0 To lastIndex Step 1
            checkBoxInfoList.Add(someNewItem)
        Next j


    Hash iteration, old, not type safe:
        Dim hashEnumerator As IDictionaryEnumerator = bestScoreHash.GetEnumerator()
        While (hashEnumerator.MoveNext())
            Dim key As Integer = CInt(hashEnumerator.Key)
            Dim curPep2 As peptideCorrStruct = _
              DirectCast(hashEnumerator.Value, peptideCorrStruct)
        End While

        'how to iterate hashes, add to source code template; "srcTemplate.txt".
        'From <http://www.cs.mu.oz.au/SE-projects/s340gh/FAQ/csharpfaq.txt>:
        'foreach (DictionaryEntry entry in table) // writes values of
        '                                    Hashtable(called) 'table' to the console
        'Console.WriteLine("Key = {0}, Value={1}\n", entry.Key,
        'entry.Value);
        'From <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfusingforeachwithcollections.asp>:
        '                                     foreach (ItemType item in myCollection)
        'myCollection must meet the following requirements:
        'The collection type:
        'Must be one of the types: interface, class, or struct.
        'Must include an instance method named GetEnumerator that returns a type, for example, Enumerator (explained below).
        'The type Enumerator (a class or struct) must contain:
        'A property named Current that returns ItemType or a type that can be converted to it. The property accessor returns the current element of the collection.
        'A bool method, named MoveNext, that increments the item counter and returns true if there are more items in the collection.


    Hash iteration, type safe:

        Dim bestScoreHash2 As Dictionary( _
          Of String, bestPeptScoreStructure) = _
            New Dictionary( _
             Of String, bestPeptScoreStructure)

        If bestScoreHash2.TryGetValue(keyWithMass, oldValue) Then
          bestScoreHash2(keyWithMass) = someBestScore
        Else
          bestScoreHash2.Add(keyWithMass, someBestScore)
        End If

        Dim hashEnumerator2 As Dictionary( _
          Of Integer, bestPeptScoreStructure).Enumerator = _
            bestScoreHash2.GetEnumerator()

        While hashEnumerator2.MoveNext()
           Dim curKey As Integer = hashEnumerator2.Current.Key
           Dim curValue As bestPeptScoreStructure = _
              hashEnumerator2.Current.Value

        End While 'Hash iteration.



    Compile time checking:
        Option Strict On    'Changed PM_OPTIONSTRICT 2003-02-13
        Option Explicit On  'Changed PM_OPTIONEXPLICIT 2003-02-13

    try/catch:

        Try
            stream = New FileStream(aMascotWiffFileAss.MascotFileStr, FileMode.Open, FileAccess.Read)
        Catch exceptionObject As Exception
            AppCommon2.displayStandardExceptionInfo( _
              exceptionObject, _
              "Could not open file " & aMascotWiffFileAss.MascotFileStr)
            Exit Sub
        End Try

      or if common function does not exist:

          Try
              stream = New FileStream(aMascotWiffFileAss.MascotFileStr, FileMode.Open, FileAccess.Read)
          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


#endif //VB part, end.


//Perl part, begin

#!perl
#!/usr/bin/perl

#############################################################################
# Copyright (C) 2003 PIL                                                    #
# Confidential and preliminary. Do not use without express permission.      #
#                                                                           #
# Purpose: xyz.                                                             #
#                                                                           #
#############################################################################

#############################################################################
#                             PIL                                           #
#                 Software Development Group                                #
#                        Peter Mortensen                                    #
#                  E-mail: pmortensen@bmb.sdu.dk                            #
#                   WWW: http://www.pil.sdu.dk/                             #
#                                                                           #
#  Program for ......................................                       #
#                                                                           #
#    FILENAME:   xyz.pl                                                     #
#                                                                           #
# CREATED: PM 2003-xx-xx                                                    #
# UPDATED: PM 2003-xx-xx                                                    #
#                                                                           #
#                                                                           #
#                                                                           #
#                                                                           #
#############################################################################

#############################################################################
# Future:
#   1.


#Configuration
$matchingIons = 7;


print "\n\n---------------------------------------------------------------\n";


##############################################################
# Function: xyz
#   Purpose:
#   Note:
#
##############################################################
sub xyz
{
    local( $x, $y) = @_;

    $toReturn = $x;
    $toReturn = $y;


    $toReturn = "";
    $toReturn;
}

&xyz( $matchingIons, $matchingIons);

#endif //Perl part, end.

    

    

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