Package com.compomics.util.general
Class MassCalc
java.lang.Object
com.compomics.util.general.MassCalc
This class takes care of mass calculation, based on a sequence
in IUPAC format.
By default it can handle monoisotopic biochemical element masses and monoisotopic single-letter amino acid masses.
The object can be customized with your own mass lists through the use of a properties file, or by directly passing a HashMap.
Please note: if you decide on your own lists, be sure to follow the following guidelines:
By default it can handle monoisotopic biochemical element masses and monoisotopic single-letter amino acid masses.
The object can be customized with your own mass lists through the use of a properties file, or by directly passing a HashMap.
Please note: if you decide on your own lists, be sure to follow the following guidelines:
- An element (key in properties file or HashMap) can be ONE or TWO letters. The first ALWAYS has to be UPPERCASE, the optional second ALWAYS has to be lowercase.
- A value has to be a parseable number for a properties file, or a Double instance for the HashMap. No other formats are accepted!
- Author:
- Lennart Martens
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndex for the monoisotopic aminoacid masses.static final intIndex for the monoisotopic masses of the biochemically relevant elements.static final intIndex for the monoisotopic nucleotide masses.static final intValue for the self-defined masses. -
Constructor Summary
ConstructorsConstructorDescriptionMassCalc()Default constructor.MassCalc(int aMassListIdentifier) This constructor allows you to specify an identifier to select a element list to use for calculating a mass.This constructor allows the caller to supplement (or to replace elements in) a built-in elementlist with a HashMap of its own design.This constructor allows the caller to use an elementlist of its own making.This constructor allows the caller to initialize the elementlist with a HashMap of its own design. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculateMass(String aFormula) This method attempts to calculate the mass of a chemical formula.static voidThe main method can be used for command-line usage of this class.
-
Field Details
-
MONOELEMENTS
public static final int MONOELEMENTSIndex for the monoisotopic masses of the biochemically relevant elements.- See Also:
-
MONOAA
public static final int MONOAAIndex for the monoisotopic aminoacid masses.- See Also:
-
MONONUCLEOTIDES
public static final int MONONUCLEOTIDESIndex for the monoisotopic nucleotide masses.- See Also:
-
SELFDEFINED
public static final int SELFDEFINEDValue for the self-defined masses.- See Also:
-
-
Constructor Details
-
MassCalc
public MassCalc()Default constructor. The mass list to be used defaults to the monoisotopic masses for biochemically relevant elements. -
MassCalc
public MassCalc(int aMassListIdentifier) This constructor allows you to specify an identifier to select a element list to use for calculating a mass.
Please use the finalo vriables on this class as identifiers!- Parameters:
aMassListIdentifier- int with the identifier for the elementlist to use.
-
MassCalc
This constructor allows the caller to use an elementlist of its own making. Simply passing the filename of the file suffices.- Parameters:
aFilename- String with the name of the file to be loaded. NOTE! this file must be located in the classpath and mst be a simple properties file!
-
MassCalc
This constructor allows the caller to initialize the elementlist with a HashMap of its own design.
This HashMap needs be structured in the following way:
- KEY can be one or two letters, the first has to be uppercase, the second and optional letter has to be lowercase.
- VALUE must be a Double value
- Parameters:
aElementList- HashMap with the elementlist to use.
-
MassCalc
This constructor allows the caller to supplement (or to replace elements in) a built-in elementlist with a HashMap of its own design.
This HashMap needs be structured in the following way:
- KEY can be one or two letters, the first has to be uppercase, the second and optional letter has to be lowercase.
- VALUE must be a Double value
- Parameters:
aMassListIdentifier- int with the identifier for the built-in elementlist to use.aSupplElementList- HashMap with the supplementary elementlist to use.
-
-
Method Details
-
calculateMass
This method attempts to calculate the mass of a chemical formula. It cannot calculate the mass of an element if it is not known to this class (i.e.: if it does not occur in the Properties instance). In that case it will flag an exception.- Parameters:
aFormula- String with the chemical formula (or bruto formula) of the compound in question.- Returns:
- double with the mass of the compound.
- Throws:
UnknownElementMassException- when one of the composing elements' mass is unknown to the class.
-
main
The main method can be used for command-line usage of this class. The parameters should be (a) chemical (or bruto) formula(e) to calculate the mass for.- Parameters:
args- String[] at least one chemical formula should be specified, up to as much as you can cramp into a single command-line.
-