com.hfg.bio.seq.GenomicLocation 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;
import com.hfg.bio.HfgBioXML;
import com.hfg.bio.Strand;
import com.hfg.bio.seq.format.feature.genbank.GenBankFeatureLocation;
import com.hfg.bio.taxonomy.NCBITaxon;
import com.hfg.util.CompareUtil;
import com.hfg.util.StringUtil;
import com.hfg.xml.XMLTag;
//------------------------------------------------------------------------------
/**
Genomic location.
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding 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 GenomicLocation extends GenBankFeatureLocation
{
private String mBuild;
private NCBITaxon mTaxon;
private String mChromosome;
private String mContig;
private Strand mStrand;
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//--------------------------------------------------------------------------
public GenomicLocation()
{
super(null);
}
//--------------------------------------------------------------------------
public GenomicLocation(String inLocationString)
{
super(inLocationString);
}
//---------------------------------------------------------------------------
public GenomicLocation(XMLTag inXMLTag)
{
this();
inXMLTag.verifyTagName(HfgBioXML.GENOMIC_LOC_TAG);
setBuild(inXMLTag.getAttributeValue(HfgBioXML.BUILD_ATT));
if (inXMLTag.hasAttribute(HfgBioXML.CHROMOSOME_ATT))
{
setChromosome(inXMLTag.getAttributeValue(HfgBioXML.CHROMOSOME_ATT));
}
if (inXMLTag.hasAttribute(HfgBioXML.CONTIG_ATT))
{
setContig(inXMLTag.getAttributeValue(HfgBioXML.CONTIG_ATT));
}
if (inXMLTag.hasAttribute(HfgBioXML.TAXON_ATT))
{
setTaxon(NCBITaxon.getByTaxonId(Integer.parseInt(inXMLTag.getAttributeValue(HfgBioXML.TAXON_ATT))));
}
if (inXMLTag.hasAttribute(HfgBioXML.STRAND_ATT))
{
setStrand(Strand.valueOf(inXMLTag.getAttributeValue(HfgBioXML.STRAND_ATT)));
}
append(inXMLTag.getUnescapedContent());
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//--------------------------------------------------------------------------
@Override
public GenomicLocation clone()
{
GenomicLocation copy = (GenomicLocation) super.clone();
return copy;
}
//--------------------------------------------------------------------------
public XMLTag toXMLTag()
{
XMLTag tag = new XMLTag(HfgBioXML.GENOMIC_LOC_TAG);
if (StringUtil.isSet(getBuild()))
{
tag.setAttribute(HfgBioXML.BUILD_ATT, getBuild());
}
if (getTaxon() != null)
{
tag.setAttribute(HfgBioXML.TAXON_ATT, getTaxon().getTaxonId());
}
if (getChromosome() != null)
{
tag.setAttribute(HfgBioXML.CHROMOSOME_ATT, getChromosome());
}
if (getContig() != null)
{
tag.setAttribute(HfgBioXML.CONTIG_ATT, getContig());
}
if (getStrand() != null)
{
tag.setAttribute(HfgBioXML.STRAND_ATT, getStrand());
}
tag.setContent(toString());
return tag;
}
//--------------------------------------------------------------------------
public GenomicLocation setBuild(String inValue)
{
mBuild = inValue;
return this;
}
//--------------------------------------------------------------------------
public String getBuild()
{
return mBuild;
}
//--------------------------------------------------------------------------
public GenomicLocation setChromosome(String inValue)
{
mChromosome = inValue;
return this;
}
//--------------------------------------------------------------------------
public String getChromosome()
{
return mChromosome;
}
//--------------------------------------------------------------------------
public GenomicLocation setContig(String inValue)
{
mContig = inValue;
return this;
}
//--------------------------------------------------------------------------
public String getContig()
{
return mContig;
}
//--------------------------------------------------------------------------
public GenomicLocation setTaxon(NCBITaxon inValue)
{
mTaxon = inValue;
return this;
}
//--------------------------------------------------------------------------
public NCBITaxon getTaxon()
{
return mTaxon;
}
//--------------------------------------------------------------------------
public GenomicLocation setStrand(Strand inValue)
{
mStrand = inValue;
return this;
}
//--------------------------------------------------------------------------
public Strand getStrand()
{
return mStrand;
}
//--------------------------------------------------------------------------
public int compareTo(GenomicLocation inObj2)
{
int result = -1;
if (inObj2 != null)
{
result = CompareUtil.compare(getChromosome(), inObj2.getChromosome());
if (0 == result)
{
result = CompareUtil.compare(getContig(), inObj2.getContig());
}
if (0 == result)
{
result = super.compareTo(inObj2);
}
}
return result;
}
}