/****************************************************************************
* 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: holds class PILmolecule, see below. *
* *
****************************************************************************/
/****************************************************************************
* 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: PILmolecule.cs *
* TYPE: CSHARP *
* *
* CREATED: PM 2008-01-24 Vrs 1.0. Translated from Visual Basic *
* to C# and transfered from DTASC to *
* the application. *
* UPDATED: PM 2008-xx-xx *
* *
* *
****************************************************************************/
//Future:
// 1. What about isotopes. Distribution of abundance of isotopes for
// each element. Even different sources/locations: biophere, Earth,
// Mars, Europa, Jupiter, comet, interstellar space, intergalactic space
// in the early universe age,
//
// 2.
//using System;
//using System.Collections.Generic;
using System.Text; //For StringBuilder
//****************************************************************************
//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://msdn.microsoft.com</seealso>
//d$ <codetype>PLATFORM independent</codetype>
//d$ </summary>
namespace massSpectrometryBase
{
public struct elementFreq
{
public int count;
public elementCodeEnum element;
} //elementFreq
/****************************************************************************
* <placeholder for header> *
****************************************************************************/
public struct elementalCompositionStructure
{
//Should these fields be a list instead??? The problem
//with single fields is ....
//
//Applying the zero-one-many principle.
//Later - and use List<elementFreq> instead.
//Real type: elementFreq
//public ArrayList elements;
//
//Remember to set in blankComposition() !!!
//For now:
public int carbons;
public int hydrogens;
public int nitrogens;
public int oxygens;
public int sulphors;
public int electrons;
public int phosphors;
} //elementalCompositionStructure
/****************************************************************************
* <placeholder for header> *
****************************************************************************/
public class PILmolecule
{
private PILperiodicTable mPeriodicTable;
//Central/primary data structure of this class
private elementalCompositionStructure mComposition;
private string mMoleculeName;
//Derived value. May be computed on demand.
private double mMass;
private bool mCompositionChanged;
//Starts at 1 for
private int mAdditionLength;
// a new molecule (unless it is empty). In the
// return value for newMoleculeByAddition() it is
// one higher than the current molecule. E.g. if
// peptides are built up by using
// newMoleculeByAddition() for each residue then
// this field is the number of residues (=length of
// the peptide).
//One of many constructors
//This one: accepting the most common elements
//****************************************************************************
//* SUBROUTINE NAME: New *
//d$ <summary>Constructor</summary>
public PILmolecule(
string anInName,
int aCarbons,
int aHydrogens,
int aNitrogens,
int aOxygens,
int aSulphors,
int aElectrons,
int aPhosphors,
ref PILperiodicTable aPeriodicTable)
: base()
{
//Is this necessary? Yes!
this.commonInit_Pre();
//Changed PM_REFACTOR 2008-01-29
this.init2(
anInName,
aCarbons,
aHydrogens,
aNitrogens,
aOxygens,
aSulphors,
aElectrons,
aPhosphors,
ref aPeriodicTable
);
} //Constructor, one of many.
//One of many constructors
//This one: accepting the most common elements
//****************************************************************************
//* SUBROUTINE NAME: New *
//d$ <summary>Constructor</summary>
public PILmolecule(
ref PILperiodicTable aPeriodicTable)
: base()
{
//Is this necessary? Yes!
this.commonInit_Pre();
//Changed PM_REFACTOR 2008-01-29
this.init2(
"",
0,
0,
0,
0,
0,
0,
0,
ref aPeriodicTable
);
} //Constructor, one of many.
//Changed PM_REFACTOR 2008-01-29
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
private void init2(
string anInName,
int aCarbons,
int aHydrogens,
int aNitrogens,
int aOxygens,
int aSulphors,
int aElectrons,
int aPhosphors,
ref PILperiodicTable aPeriodicTable)
{
mMoleculeName = anInName;
mPeriodicTable = aPeriodicTable;
mAdditionLength = 1;
//Detect empty molecule...
if (aCarbons == 0 &&
aHydrogens == 0 &&
aNitrogens == 0 &&
aOxygens == 0 &&
aSulphors == 0 &&
aElectrons == 0 &&
aPhosphors == 0 &&
true)
{
mAdditionLength = 0;
}
//C, H, N, O, S, P, electron.
//What about fields not set??
elementalCompositionStructure composition = this.blankComposition();
composition.carbons = aCarbons;
composition.hydrogens = aHydrogens;
composition.nitrogens = aNitrogens;
composition.oxygens = aOxygens;
composition.sulphors = aSulphors;
composition.electrons = aElectrons;
composition.phosphors = aPhosphors;
init(composition);
this.commonInit_Post();
} //init2()
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
private void init(elementalCompositionStructure aComposition)
{
mComposition = aComposition;
mCompositionChanged = true;
} //init()
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
private void commonInit_Pre()
{
mMass = -10.0;
mCompositionChanged = true;
//Needed?
} //commonInit_Pre()
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
private void commonInit_Post()
{
//What is this??
} //commonInit_Post()
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public elementalCompositionStructure getComposition()
{
return mComposition;
} //getComposition
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
private elementalCompositionStructure blankComposition()
{
elementalCompositionStructure toReturn;
//Later
//toReturn.elements = null;
toReturn.carbons = 0;
toReturn.hydrogens = 0;
toReturn.nitrogens = 0;
toReturn.oxygens = 0;
toReturn.sulphors = 0;
toReturn.electrons = 0;
toReturn.phosphors = 0;
return toReturn;
} //blankComposition()
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public double mass()
{
double toReturn = mMass;
//Default
if (mCompositionChanged)
{
mCompositionChanged = false;
//Would be loop if it was a list instead of fields...
mMass =
mComposition.carbons *
mPeriodicTable.elementMonoMass(elementCodeEnum.enumCarbon) +
mComposition.hydrogens *
mPeriodicTable.elementMonoMass(elementCodeEnum.enumHydrogen) +
mComposition.nitrogens *
mPeriodicTable.elementMonoMass(elementCodeEnum.enumNitrogen) +
mComposition.oxygens *
mPeriodicTable.elementMonoMass(elementCodeEnum.enumOxygen) +
mComposition.sulphors *
mPeriodicTable.elementMonoMass(elementCodeEnum.enumSulphur) +
mComposition.electrons *
mPeriodicTable.elementMonoMass(elementCodeEnum.enumElectron) +
mComposition.phosphors *
mPeriodicTable.elementMonoMass(elementCodeEnum.enumPhosphor) +
0.0;
toReturn = mMass;
}
else
{
//Return cached value
}
return toReturn;
} //mass
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public int compositionCode()
{
//Note: not cached.
int code =
1 * mComposition.carbons +
64 * mComposition.hydrogens +
4096 * mComposition.nitrogens +
65536 * mComposition.oxygens +
1048576 * mComposition.sulphors +
4194304 * mComposition.electrons +
16777216 * mComposition.phosphors +
0;
return code;
} //compositionCode()
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public PILmolecule newMoleculeByAddition(PILmolecule aMoleculeToAdd)
{
PILmolecule toReturn =
new PILmolecule(
this.mMoleculeName + aMoleculeToAdd.mMoleculeName,
this.mComposition.carbons + aMoleculeToAdd.mComposition.carbons,
this.mComposition.hydrogens + aMoleculeToAdd.mComposition.hydrogens,
this.mComposition.nitrogens + aMoleculeToAdd.mComposition.nitrogens,
this.mComposition.oxygens + aMoleculeToAdd.mComposition.oxygens,
this.mComposition.sulphors + aMoleculeToAdd.mComposition.sulphors,
this.mComposition.electrons + aMoleculeToAdd.mComposition.electrons,
this.mComposition.phosphors + aMoleculeToAdd.mComposition.phosphors,
ref this.mPeriodicTable);
//This can not be done through the constructor:
toReturn.mAdditionLength = this.mAdditionLength + aMoleculeToAdd.mAdditionLength;
return toReturn;
} //newMoleculeByAddition()
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public void addMolecule(PILmolecule aMoleculeToAdd)
{
this.mMoleculeName += aMoleculeToAdd.mMoleculeName; //Note:
// wasteful (memory efficiency). Perhaps use StringBuilder as
// representation instead?
this.mComposition.carbons += aMoleculeToAdd.mComposition.carbons;
this.mComposition.hydrogens += aMoleculeToAdd.mComposition.hydrogens;
this.mComposition.nitrogens += aMoleculeToAdd.mComposition.nitrogens;
this.mComposition.oxygens += aMoleculeToAdd.mComposition.oxygens;
this.mComposition.sulphors += aMoleculeToAdd.mComposition.sulphors;
this.mComposition.electrons += aMoleculeToAdd.mComposition.electrons;
this.mComposition.phosphors += aMoleculeToAdd.mComposition.phosphors;
//This can not be done through the constructor:
mAdditionLength += aMoleculeToAdd.mAdditionLength;
} //addMolecule()
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public static void headerForLineFormat(ref StringBuilder anInOutBuffer)
{
anInOutBuffer.Append("Name\t");
anInOutBuffer.Append("Mass [Da]\t");
anInOutBuffer.Append("C\t");
anInOutBuffer.Append("H\t");
anInOutBuffer.Append("N\t");
anInOutBuffer.Append("O\t");
anInOutBuffer.Append("S\t");
anInOutBuffer.Append("e\t");
anInOutBuffer.Append("P\t");
//anInOutBuffer.Append(ControlChars.Tab);
//anInOutBuffer.Append(ControlChars.CrLf);
anInOutBuffer.Append("\r\n");
} //headerForLineFormat
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public void lineFormat(ref StringBuilder anInOutBuffer)
{
anInOutBuffer.Append(mMoleculeName);
anInOutBuffer.Append("\t");
anInOutBuffer.Append(this.mass());
anInOutBuffer.Append("\t");
anInOutBuffer.Append(mComposition.carbons);
anInOutBuffer.Append("\t");
anInOutBuffer.Append(mComposition.hydrogens);
anInOutBuffer.Append("\t");
anInOutBuffer.Append(mComposition.nitrogens);
anInOutBuffer.Append("\t");
anInOutBuffer.Append(mComposition.oxygens);
anInOutBuffer.Append("\t");
anInOutBuffer.Append(mComposition.sulphors);
anInOutBuffer.Append("\t");
anInOutBuffer.Append(mComposition.electrons);
anInOutBuffer.Append("\t");
anInOutBuffer.Append(mComposition.phosphors);
anInOutBuffer.Append("\t");
//anInOutBuffer.Append(ControlChars.Tab);
//anInOutBuffer.Append(ControlChars.CrLf);
anInOutBuffer.Append("\r\n");
} //lineFormat()
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public string name()
{
return mMoleculeName;
} //name()
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public int additionLength()
{
return mAdditionLength;
} //additionLength()
} //class PILmolecule
} //namespace massSpectrometryBase
Generated by script codePublish.pl at 2009-01-05T15:20:59.