/****************************************************************************
* 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 spectrumClassifier, see also below *
* for documentation. *
* *
****************************************************************************/
/****************************************************************************
* CEBI *
* Software Development Group *
* Peter Mortensen *
* E-mail: NUKESPAMMERSdrmortensen@get2netZZZZZZ.dk *
* WWW: http://www.cebi.sdu.dk/ *
* *
* Program for post-processing of result from search in mass *
* spectrometric data. *
* *
* FILENAME: spectrumClassifier.cs *
* TYPE: CSHARP *
* *
* CREATED: PM 2003-08-21 Original VB file: Vrs 1.0. Cloned *
* from FinneganRawDataFileHandling.vb *
* *
* UPDATED: PM 2008-06-24 Translated to C#; \src\main\massbase\ *
* spectrumClassifier.vb. *
* *
****************************************************************************/
//Future:
// 1. Some rules (specified in datastructures or in the class itself)
// about some physically impossible ions, e.g. b1 ions for some
using System.Text.RegularExpressions; //For Regex.Match.
using System.Xml.Serialization; //For XmlArray and XmlArrayItem.
using System.Collections.Generic; //For Dictionary and List.
using System.Diagnostics; //For Trace. And its Assert.
//****************************************************************************
//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 / GUI</codetype>
//d$ </summary>
namespace massSpectrometryBase
{
//Changed PM_REFACTOR_FINNEGAN_MSMS 2003-08-18
//****************************************************************************
//d$ <summary>
//d$ Purpose:
//d$ For MS and MS-MS type of mass spectra.
//d$ </summary>
public enum spectrumTypeEnum
{
enumIsMSspectrum = 227,
enumIsFragmentSpectrum,
enumIsUndefinedSpectrumType
//For error detection.
} //spectrumTypeEnum
//Changed PM_MS3_DTASUPERCHARGE 2004-04-15
//Changed PM_MASCOT2_ZOOMSCAN_QUANT_FILTER 2004-03-16
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public enum spectrumSubTypeEnum
{
enumIsNormalMS = 239,
enumIsZoomMS,
//
enumIsFragmentMS3,
//Changed PM_ECD 2006-01-11
enumIsFragmentCID,
enumIsFragmentMPD,
enumIsFragmentECD,
//Changed PM_CID_FRAGMENTSUBTYPE 2006-04-19
//The only place where we still have these two is in reading in from the
// settings to support old versions, but the type is mapped to
// enumIsFragmentCID.
//enumIsFragmentNormal 'Phased out. Is the same as eFragmentCID
//enumIsFragmentCAD 'Phased out due to the name...
enumST_DoesNotApply
} //spectrumSubTypeEnum
//Changed PM_ECD 2006-01-11
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public enum sourceTypeEnum
{
enumLowResolution,
//Classic ion trap
enumBetterResolution,
//E.g. LTQ
enumHighResolution,
//E.g. QSTAR
enumUltraHighResolution,
//E.g FT and Orbitrap
enumSuperUltraHighResolution,
//Quantum mass spectrometer (future).
enumIsUndefinedSourceType
} //sourceTypeEnum
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
// [Serializable()]
public struct spectrumClassificationDefinitionsStructure
{
public string someExtraInfo;
[XmlArray("classificationList"),
XmlArrayItem(
typeof(classificationMatchingStructure),
ElementName = "classificationMatchingStructure",
IsNullable = false
)
]
public List<classificationMatchingStructure> classificationList2;
} //spectrumClassificationDefinitionsStructure
//Changed PM_GENERALISED_SPECTRUMCLASSIFICATION 2005-03-13
//****************************************************************************
//* <placeholder for header> *
//****************************************************************************
public struct classificationMatchingStructure
{
//When adding new fields: remember to set default value
//in defaultSpectrumClassificationItemFields()....
public string matchFirst;
public string matchSecond;
//Same as SpectrumClassificationStructure. Some redundancy here...
public spectrumTypeEnum mainClassification;
//Note: not only MS, also MS/MS.
public spectrumSubTypeEnum spectrumSubType3;
//The program will match lowest value first.
public int matchOrder;
// This field is actually used... - by sorting, class SortByMatchIndex.
//Changed PM_ECD 2006-01-11
public sourceTypeEnum defaultSource;
public string matchFirst_Source;
public string matchSecond_Source;
public sourceTypeEnum dataSource;
//Changed PM_DTASC_FRAGANDSOURCE_LABELS 2006-04-28
public string spectrumSubTypeAndFragmentationMechanismName;
public string dataSourceName;
} //classificationMatchingStructure
//Changed PM_MASCOT2_ZOOMSCAN_QUANT_FILTER 2004-03-16
//Later: move to the new class....
public struct SpectrumClassificationStructure
{
public spectrumTypeEnum mainClassification;
public spectrumSubTypeEnum spectrumSubType2; //Both MS and MS-MS ?
public string dataSourceName;
} //SpectrumClassificationStructure
//Changed PM_GENERALISED_SPECTRUMCLASSIFICATION 2005-03-13
//****************************************************************************
//* SUBROUTINE NAME: SortByMatchIndex *
//d$ <summary> N/A. ...
//d$ Note: xyz </summary>
class SortByMatchIndex :
System.Collections.Generic.IComparer<classificationMatchingStructure>
{
int
System.Collections.Generic.IComparer<classificationMatchingStructure>.Compare(
classificationMatchingStructure aItem1,
classificationMatchingStructure aItem2)
{
int toReturn = 0;
if (aItem1.matchOrder > aItem2.matchOrder)
{
toReturn = 1;
}
else
{
if (aItem1.matchOrder < aItem2.matchOrder)
{
toReturn = -1;
}
else
{
//Equal....
int peter9 = 9;
}
}
return toReturn;
} //Compare()
} //class SortByMatchIndex
//****************************************************************************
//d$ <summary>
//d$ Purpose: Classifies spectra. At the moment oriented towards
//d$ parsing of Finnigan spectrum headers.
//d$
//d$
//d$
//d$ <see cref="T:VBXMLDoc.CVBXMLDoc" />.
//d$ <applicationname>test_rawDataFileHandling</applicationname>
//d$ <author>Peter Mortensen</author>
//d$ <seealso>http://www.cebi.sdu.dk/</seealso>
//d$ <codetype>PLATFORM independent</codetype>
//d$ </summary>
public class spectrumClassifier
{
//Changed PM_GENERALISED_SPECTRUMCLASSIFICATION 2005-03-13
spectrumClassificationDefinitionsStructure mClassificationInfo;
bool mHasSortedClassifications;
//Changed PM_REFACTOR 2008-06-24
string mSpecClassificationFilename; //To avoid referencing the
// constant AppConstants.NEW_SPECCLASSIFICATION_FILENAME.
//****************************************************************************
//* SUBROUTINE NAME: New *
//d$ <summary> N/A </summary>
public spectrumClassifier(string aSpecClassificationFilename)
: base()
{
//aSpecClassificationFilename: only used in an error message.
//Is this necessary? Yes!
//InitializeComponent() Is this necessary??
//Add any initialization after the InitializeComponent() call
//Changed PM_REFACTOR 2008-06-24. A
mSpecClassificationFilename = aSpecClassificationFilename;
//Changed PM_GENERALISED_SPECTRUMCLASSIFICATION 2005-03-13
if (false)
{
spectrumClassifier.getDefaultClassifications2(
ref mClassificationInfo);
}
mHasSortedClassifications = false;
} //New()
//****************************************************************************
//* SUBROUTINE NAME: setClassificationInfo *
//d$ <summary> N/A </summary>
public void setClassificationInfo(
ref spectrumClassificationDefinitionsStructure
anInSpectrumClassificationDefinitions)
{
mClassificationInfo = anInSpectrumClassificationDefinitions;
//Just in case...
mClassificationInfo.classificationList2.Sort(new SortByMatchIndex());
} //setClassificationInfo()
//Changed PM_GENERALISED_SPECTRUMCLASSIFICATION 2005-03-13
//****************************************************************************
//* SUBROUTINE NAME: addClassificationMatch *
//d$ <summary> Convenience function for clients to add a new item
//d$ to the datastructure used for classification of spectra.
//d$ </summary>
private static void addClassificationMatch(
string anInMatchFirst,
string anInMatchSecond,
spectrumTypeEnum anInMainClassification,
spectrumSubTypeEnum anInspectrumSubType,
ref int anInOutMatchOrder,
sourceTypeEnum aDefaultSource,
string aMatchFirst_Source,
string aMatchSecond_Source,
sourceTypeEnum aDataSource,
string aSpectrumSubAndFragmentationMechanismName,
string aDataSourceName,
ref List<classificationMatchingStructure> anInOutList2)
{
//Changed PM_DTASC_FRAGANDSOURCE_LABELS 2006-04-28
//New parameters: aMSsubTypeAndFragmentationMechanismName, aDataSourceName.
classificationMatchingStructure newItem;
newItem.matchFirst = anInMatchFirst;
newItem.matchSecond = anInMatchSecond;
newItem.mainClassification = anInMainClassification;
newItem.spectrumSubType3 = anInspectrumSubType;
newItem.matchOrder = anInOutMatchOrder;
//Changed PM_ECD 2006-01-12
newItem.defaultSource = aDefaultSource;
newItem.matchFirst_Source = aMatchFirst_Source;
newItem.matchSecond_Source = aMatchSecond_Source;
newItem.dataSource = aDataSource;
//Changed PM_DTASC_FRAGANDSOURCE_LABELS 2006-04-28
newItem.spectrumSubTypeAndFragmentationMechanismName =
aSpectrumSubAndFragmentationMechanismName;
newItem.dataSourceName = aDataSourceName;
anInOutList2.Add(newItem);
anInOutMatchOrder += 1;
} //addClassificationMatch()
//Changed PM_ECD 2006-01-16
//****************************************************************************
//* SUBROUTINE NAME: getFragmentTypes *
//d$ <summary> .
//d$ </summary>
public Dictionary<string, string> getFragmentTypes()
{
//Keys are a combination of the fragment type and the
//source (e.g. LTQ or FT).
//
//Sample (key,value) pairs:
//
// "enumIsFragmentMS3_LTQ", "LTQ, CID MS3"
// "enumIsFragmentCID_LTQ", "LTQ, CID MS2"
// "enumIsFragmentCID_FT", "FT, CID MS2"
//Dim someHash As Hashtable = New Hashtable
Dictionary<string, string> toReturn = new Dictionary<string, string>();
string descrString = "";
foreach (classificationMatchingStructure curItem in
mClassificationInfo.classificationList2)
{
spectrumSubTypeEnum subType = curItem.spectrumSubType3;
string dataSourceName = curItem.dataSourceName;
//Changed PM_DTASC_FRAGANDSOURCE_LABELS 2006-04-28
bool useIt = true;
if (curItem.mainClassification !=
spectrumTypeEnum.enumIsFragmentSpectrum)
{
useIt = false;
}
else
{
descrString =
dataSourceName +
", " +
curItem.spectrumSubTypeAndFragmentationMechanismName;
}
if (useIt)
{
//Ignore MS types
//Changed PM_DTASC_FRAGANDSOURCE_LABELS 2006-05-01
string key = subType.ToString() + "_" + dataSourceName;
if (toReturn.ContainsKey(key))
{
//No need to count
//Dim oldCount As Integer = CInt(toReturn(AA))
//toReturn(AA) = oldCount + 1
int peter9 = 9;
}
else
{
toReturn.Add(key, descrString);
}
}
}
return toReturn;
} //getFragmentTypes()
//Changed PM_GENERALISED_SPECTRUMCLASSIFICATION 2005-03-13
//****************************************************************************
//* SUBROUTINE NAME: classify *
//d$ <summary> Classifies based on Finnigan spectrum header, MS or MS/MS
//d$ or MS3. There are also subtypes, e.g. full MS and SIM MS.
//d$ </summary>
public SpectrumClassificationStructure classify(ref string anInSpectrumHeader)
{
SpectrumClassificationStructure toReturn;
toReturn.mainClassification = spectrumTypeEnum.enumIsUndefinedSpectrumType;
toReturn.spectrumSubType2 = spectrumSubTypeEnum.enumST_DoesNotApply;
toReturn.dataSourceName = null;
Trace.Assert((mClassificationInfo.classificationList2 != null), "PIL ASSERT. Object mClassificationInfo.classificationList was not created....");
//AndAlso/short-circuit boolean is crucial here...
if ((anInSpectrumHeader != null) && anInSpectrumHeader.Length > 0)
{
if (!mHasSortedClassifications)
{
mClassificationInfo.classificationList2.Sort(new SortByMatchIndex());
mHasSortedClassifications = true;
}
bool matched = false;
foreach (classificationMatchingStructure curItem in
mClassificationInfo.classificationList2)
{
Match result = Regex.Match(anInSpectrumHeader, curItem.matchFirst);
if (result.Success)
{
if (curItem.matchSecond == "")
{
matched = true;
}
else
{
Match result2 =
Regex.Match(anInSpectrumHeader, curItem.matchSecond);
if (result2.Success)
{
matched = true;
}
}
}
if (matched)
{
toReturn.mainClassification = curItem.mainClassification;
toReturn.spectrumSubType2 = curItem.spectrumSubType3;
toReturn.dataSourceName = curItem.dataSourceName;
break; // TODO: might not be correct. Was : Exit For
}
}
if (!matched)
{
//Changed PM_INFINITELOOP_SPECCLASSIFY 2006-02-09
toReturn.mainClassification =
spectrumTypeEnum.enumIsUndefinedSpectrumType;
toReturn.spectrumSubType2 = spectrumSubTypeEnum.enumST_DoesNotApply;
toReturn.dataSourceName = null;
int spectrumNum = -999999;
//Later....
string msg =
"Unknown spectrum type for spectrum " +
spectrumNum +
", could not be derived from spectrum title '" +
anInSpectrumHeader +
" '";
//Interaction.MsgBox(msg);
System.Windows.Forms.MessageBox.Show(msg);
//Note: mSpecClassificationFilename contains
//AppConstants.NEW_SPECCLASSIFICATION_FILENAME.
string msg2 =
"Unknown spectrum type for spectrum " +
spectrumNum +
", could not be derived from " +
" spectrum title '" +
anInSpectrumHeader +
" '. " +
"The configuration file " +
mSpecClassificationFilename +
" does " +
"not contain information to recognise the spectrum type, " +
"MS or MS/MS. Edit " +
mSpecClassificationFilename +
".";
}
}
else
{
int peter7 = 7;
}
return toReturn;
} //classify()
//****************************************************************************
//* SUBROUTINE NAME: defaultClassifications *
//d$ <summary> Current program default classifications settings. Is used if
//d$ the appropriate XML file could not be found on disk.
//d$ To parameters, anInOutClassificationInfo. Real type of items
//d$ is classificationMatchingStructure.
//d$ </summary>
public static void getDefaultClassifications2(
ref spectrumClassificationDefinitionsStructure
anInOutSpectrumClassificationDefinitions)
{
anInOutSpectrumClassificationDefinitions.someExtraInfo = "xyz";
anInOutSpectrumClassificationDefinitions.classificationList2 =
new List<classificationMatchingStructure>();
//For notational convenience.
List<classificationMatchingStructure> ali =
anInOutSpectrumClassificationDefinitions.classificationList2;
if (true)
{
int matchOrder = 0;
//Let the match be the same as listed.
//asdasd() 'Add the rest from the standard CEBI file.
if (true)
{
//NSI part
//These two must come before the original ms2 - because they
//look very much like the original ms2...
if (true)
{
addClassificationMatch(
"ecd\\@",
"",
spectrumTypeEnum.enumIsFragmentSpectrum,
spectrumSubTypeEnum.enumIsFragmentECD,
ref matchOrder,
sourceTypeEnum.enumUltraHighResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"ECD MS2",
"FT",
ref ali);
addClassificationMatch(
"mpd\\@", "",
spectrumTypeEnum.enumIsFragmentSpectrum,
spectrumSubTypeEnum.enumIsFragmentMPD,
ref matchOrder,
sourceTypeEnum.enumUltraHighResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"MPD MS2",
"FT",
ref ali);
}
if (true)
{
//Replacement for frag normal comes first.
}
//NSI (Proxeon) specific
if (true)
{
addClassificationMatch(
"FTMS \\+ (p|c) NSI Full ms",
"",
spectrumTypeEnum.enumIsMSspectrum,
spectrumSubTypeEnum.enumIsNormalMS,
ref matchOrder,
sourceTypeEnum.enumUltraHighResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"***",
"***",
ref ali);
addClassificationMatch(
"FTMS \\+ (p|c) NSI d SIM ms",
"",
spectrumTypeEnum.enumIsMSspectrum,
spectrumSubTypeEnum.enumIsZoomMS,
ref matchOrder,
sourceTypeEnum.enumUltraHighResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"***",
"***",
ref ali);
}
//ESI (source??) specific
if (true)
{
addClassificationMatch(
"FTMS \\+ (p|c) ESI Full ms",
"",
spectrumTypeEnum.enumIsMSspectrum,
spectrumSubTypeEnum.enumIsNormalMS,
ref matchOrder,
sourceTypeEnum.enumUltraHighResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"***",
"***",
ref ali);
addClassificationMatch(
"FTMS \\+ (p|c) ESI d SIM ms",
"",
spectrumTypeEnum.enumIsMSspectrum,
spectrumSubTypeEnum.enumIsZoomMS,
ref matchOrder,
sourceTypeEnum.enumUltraHighResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"***",
"***",
ref ali);
}
addClassificationMatch(
"Full ms3",
"",
spectrumTypeEnum.enumIsFragmentSpectrum,
spectrumSubTypeEnum.enumIsFragmentMS3,
ref matchOrder,
sourceTypeEnum.enumUltraHighResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"CID MS3",
"LTQ",
ref ali);
//Used for ion-trap only acquisition.
addClassificationMatch(
"ITMS",
"d Z ms\\s",
spectrumTypeEnum.enumIsMSspectrum,
spectrumSubTypeEnum.enumIsZoomMS,
ref matchOrder,
sourceTypeEnum.enumBetterResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"***",
"***",
ref ali);
//Used for ion-trap only acquisition.
// enumIsFragmentNormal -> enumIsFragmentCID
addClassificationMatch(
"ITMS",
"Full ms2",
spectrumTypeEnum.enumIsFragmentSpectrum,
spectrumSubTypeEnum.enumIsFragmentCID,
ref matchOrder,
sourceTypeEnum.enumBetterResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"CID MS2",
"LTQ",
ref ali);
//Older note:
// 'Note trailing whitespace in order not to match "Full ms2" or "Full ms3".
//Ref 7
//Back stop (?).
addClassificationMatch(
"ITMS",
"",
spectrumTypeEnum.enumIsMSspectrum,
spectrumSubTypeEnum.enumIsNormalMS,
ref matchOrder,
sourceTypeEnum.enumBetterResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"***",
"***",
ref ali);
//Ref 8
//CID !
addClassificationMatch(
"FTMS",
"Full ms2",
spectrumTypeEnum.enumIsFragmentSpectrum,
spectrumSubTypeEnum.enumIsFragmentCID,
ref matchOrder,
sourceTypeEnum.enumUltraHighResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"CID MS2",
"FT",
ref ali);
//Ref 9
//Back stop (?).
addClassificationMatch(
"FTMS",
"SIM ms",
spectrumTypeEnum.enumIsMSspectrum,
spectrumSubTypeEnum.enumIsZoomMS,
ref matchOrder,
sourceTypeEnum.enumUltraHighResolution,
"",
"",
sourceTypeEnum.enumIsUndefinedSourceType,
"***",
"***",
ref ali);
} //Block.
} //Block.
} //getDefaultClassifications2()
} //class spectrumClassifier
} //namespace massSpectrometryBase
Generated by script codePublish.pl at 2009-01-05T15:20:59.