com.hfg.bio.taxonomy.ncbi.NCBIGeneticCode 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.taxonomy.ncbi;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import com.hfg.bio.seq.translation.CodonTable;
import com.hfg.bio.seq.translation.TranslationTable;
import com.hfg.exception.ProgrammingException;
import com.hfg.util.io.StreamUtil;
import com.hfg.xml.XMLTag;
//------------------------------------------------------------------------------
/**
Reference genetic code information used by the NCBI.
@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 NCBIGeneticCode implements TranslationTable
{
private int mNCBIId;
private CodonTable mCodonTable;
private String mRsrc;
private static Map sLookupMap = new HashMap<>(34);
public static final NCBIGeneticCode UNSPECIFIED = new NCBIGeneticCode( 0, "rsrc/cod_unspecified.xml.gz");
public static final NCBIGeneticCode STANDARD = new NCBIGeneticCode( 1, "rsrc/cod_standard.xml.gz");
public static final NCBIGeneticCode VERTEBRATE_MITO = new NCBIGeneticCode( 2, "rsrc/cod_vertebrate_mito.xml.gz");
public static final NCBIGeneticCode YEAST_MITO = new NCBIGeneticCode( 3, "rsrc/cod_yeast_mito.xml.gz");
public static final NCBIGeneticCode MOLD_MITO = new NCBIGeneticCode( 4, "rsrc/cod_mold_mito.xml.gz");
public static final NCBIGeneticCode INVERTEBRATE_MITO = new NCBIGeneticCode( 5, "rsrc/cod_invertebrate_mito.xml.gz");
public static final NCBIGeneticCode CILIATE_NUCLEAR = new NCBIGeneticCode( 6, "rsrc/cod_ciliate_nuclear.xml.gz");
public static final NCBIGeneticCode ECHINODERM_MITO = new NCBIGeneticCode( 9, "rsrc/cod_echinoderm_mito.xml.gz");
public static final NCBIGeneticCode EUPLOTID_NUCLEAR = new NCBIGeneticCode(10, "rsrc/cod_euplotid_nuclear.xml.gz");
public static final NCBIGeneticCode BACTERIAL = new NCBIGeneticCode(11, "rsrc/cod_bacterial.xml.gz");
public static final NCBIGeneticCode ALT_YEAST_NUCLEAR = new NCBIGeneticCode(12, "rsrc/cod_alt_yeast_nuclear.xml.gz");
public static final NCBIGeneticCode ASCIDIAN_MITO = new NCBIGeneticCode(13, "rsrc/cod_ascidian_mito.xml.gz");
public static final NCBIGeneticCode ALT_FLATWORM_MITO = new NCBIGeneticCode(14, "rsrc/cod_alt_flatworm_mito.xml.gz");
public static final NCBIGeneticCode CHLOROPHYCEAN_MITO = new NCBIGeneticCode(16, "rsrc/cod_chlorophycean_mito.xml.gz");
public static final NCBIGeneticCode TREMATODE_MITO = new NCBIGeneticCode(21, "rsrc/cod_trematode_mito.xml.gz");
public static final NCBIGeneticCode SCENEDESMUS_MITO = new NCBIGeneticCode(22, "rsrc/cod_scenedesmus_obliquus_mito.xml.gz");
public static final NCBIGeneticCode THRAUSTOCHYTRIUM_MITO = new NCBIGeneticCode(23, "rsrc/cod_thraustochytrium_mito.xml.gz");
public static final NCBIGeneticCode RHABDOPLEURIDAE_MITO = new NCBIGeneticCode(24, "rsrc/cod_rhabdopleuridae_mito.xml.gz");
public static final NCBIGeneticCode CANDIDATE_DIVISION_SR1_MITO = new NCBIGeneticCode(25, "rsrc/cod_candidate_div_sr1_mito.xml.gz");
public static final NCBIGeneticCode PACHYSOLEN_TANNOPHILUS_NUCLEAR = new NCBIGeneticCode(26, "rsrc/cod_pachysolen_tannophilus_nuclear.xml.gz");
public static final NCBIGeneticCode KARYORELICT_NUCLEAR = new NCBIGeneticCode(27, "rsrc/cod_karyorelict_nuclear.xml.gz");
public static final NCBIGeneticCode CONDYLOSTOMA_NUCLEAR = new NCBIGeneticCode(28, "rsrc/cod_condylostoma_nuclear.xml.gz");
public static final NCBIGeneticCode MESODINIUM_NUCLEAR = new NCBIGeneticCode(29, "rsrc/cod_mesodinium_nuclear.xml.gz");
public static final NCBIGeneticCode PERITRICH_NUCLEAR = new NCBIGeneticCode(30, "rsrc/cod_peritrich_nuclear.xml.gz");
public static final NCBIGeneticCode BLASTOCRITHIDIA_NUCLEAR = new NCBIGeneticCode(31, "rsrc/cod_blastocrithidia_nuclear.xml.gz");
public static final NCBIGeneticCode BALANOPHORACEAE_NUCLEAR = new NCBIGeneticCode(32, "rsrc/cod_balanophoraceae_nuclear.xml.gz");
public static final NCBIGeneticCode CEPHALODISCIDAE_MITO = new NCBIGeneticCode(33, "rsrc/cod_cephalodiscidae_mito.xml.gz");
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
private NCBIGeneticCode(int inId, String inRsrc)
{
mNCBIId = inId;
mRsrc = inRsrc;
InputStream stream = getClass().getResourceAsStream(mRsrc);
if (null == stream)
{
throw new ProgrammingException("The rsrc " + mRsrc + " couldn't be found!?");
}
try
{
if (mRsrc.endsWith(".gz"))
{
stream = new GZIPInputStream(stream);
}
mCodonTable = new CodonTable(new XMLTag(stream));
}
catch (Exception e)
{
throw new ProgrammingException(e);
}
finally
{
StreamUtil.close(stream);
}
sLookupMap.put(inId, this);
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
public static NCBIGeneticCode getById(int inId)
{
return sLookupMap.get(inId);
}
//---------------------------------------------------------------------------
@Override
public String toString()
{
return name();
}
//---------------------------------------------------------------------------
public String name()
{
return mCodonTable.name();
}
//---------------------------------------------------------------------------
public int getId()
{
return mNCBIId;
}
//---------------------------------------------------------------------------
/**
Converts the specified codon (3 nucleotides) into a character representing
the corresponding amino acid.
@param inCodon 3-letter nucleotide (DNA or RNA) string to be translated
@return single letter amino acid
*/
public char translateCodon(String inCodon)
{
return mCodonTable.translateCodon(inCodon);
}
}