com.hfg.bio.seq.translation.CodonUsage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.bio.seq.translation;
import com.hfg.util.StringUtil;
import com.hfg.xml.XMLTag;
//------------------------------------------------------------------------------
/**
Codon usage data container.
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------
public class CodonUsage
{
private Integer mNumber;
private Float mFreqPer1000;
private Float mBias;
public static final String XML_CODON_USAGE = "CodonUsage";
public static final String XML_NUMBER_ATT = "number";
public static final String XML_FREQ_PER_1000_ATT = "freqPer1000";
public static final String XML_BIAS_ATT = "bias";
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public CodonUsage()
{
}
//---------------------------------------------------------------------------
public CodonUsage(XMLTag inXMLTag)
{
inXMLTag.verifyTagName(XML_CODON_USAGE);
String numberString = inXMLTag.getAttributeValue(XML_NUMBER_ATT);
{
if (StringUtil.isSet(numberString))
{
try
{
setNumber(Integer.parseInt(numberString));
}
catch (Exception e)
{
throw new RuntimeException("The specified " + XML_NUMBER_ATT + " value "
+ StringUtil.singleQuote(numberString) + " couldn't be parsed!", e);
}
}
}
String freqString = inXMLTag.getAttributeValue(XML_FREQ_PER_1000_ATT);
{
if (StringUtil.isSet(freqString))
{
try
{
setFreqPer1000(Float.parseFloat(freqString));
}
catch (Exception e)
{
throw new RuntimeException("The specified " + XML_FREQ_PER_1000_ATT + " value "
+ StringUtil.singleQuote(freqString) + " couldn't be parsed!", e);
}
}
}
String biasString = inXMLTag.getAttributeValue(XML_BIAS_ATT);
{
if (StringUtil.isSet(biasString))
{
try
{
setBias(Float.parseFloat(biasString));
}
catch (Exception e)
{
throw new RuntimeException("The specified " + XML_BIAS_ATT + " value "
+ StringUtil.singleQuote(biasString) + " couldn't be parsed!", e);
}
}
}
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
/**
Specifies the number of times this codon was observed in the set of sequences.
@param inValue the number of times this codon was observed in the set of sequences
@return this CodonUsage object (for potential method chaining)
*/
public CodonUsage setNumber(Integer inValue)
{
mNumber = inValue;
return this;
}
//---------------------------------------------------------------------------
/**
Returns the number of times this codon was observed in the set of sequences.
@return the number of times this codon was observed in the set of sequences
*/
public Integer getNumber()
{
return mNumber;
}
//---------------------------------------------------------------------------
/**
Specifies the frequency (per 1000 codons) that this codon was observed in the set of sequences.
@param inValue the frequency (per 1000 codons) that this codon was observed in the set of sequences
@return this CodonUsage object (for potential method chaining)
*/
public CodonUsage setFreqPer1000(Float inValue)
{
mFreqPer1000 = inValue;
return this;
}
//---------------------------------------------------------------------------
/**
Returns the frequency (per 1000 codons) that this codon was observed in the set of sequences.
@return the frequency (per 1000 codons) that this codon was observed in the set of sequences
*/
public Float getFreqPer1000()
{
return mFreqPer1000;
}
//---------------------------------------------------------------------------
/**
Specifies the bias - the fraction of this codon's use as compared to the other codons that
code for the same amino acid.
@param inValue the fraction of this codon's use out of the total for all codons coding for the same amino acid
@return this CodonUsage object (for potential method chaining)
*/
public CodonUsage setBias(Float inValue)
{
mBias = inValue;
return this;
}
//---------------------------------------------------------------------------
/**
Returns the bias - the fraction of this codon's use as compared to the other codons that
code for the same amino acid.
@return the fraction of this codon's use out of the total for all codons coding for the same amino acid
*/
public Float getBias()
{
return mBias;
}
//---------------------------------------------------------------------------
public XMLTag toXMLTag()
{
XMLTag tag = new XMLTag(XML_CODON_USAGE);
if (getNumber() != null)
{
tag.setAttribute(XML_NUMBER_ATT, getNumber());
}
if (getFreqPer1000() != null)
{
tag.setAttribute(XML_FREQ_PER_1000_ATT, String.format("%.2f", getFreqPer1000()));
}
if (getBias() != null)
{
tag.setAttribute(XML_BIAS_ATT, String.format("%.2f", getBias()));
}
return tag;
}
}