com.hfg.bio.glyco.Monosaccharide 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.glyco;
import java.awt.Color;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import com.hfg.chem.Charge;
import com.hfg.chem.Element;
import com.hfg.chem.IonizableGroup;
import com.hfg.chem.Molecule;
import com.hfg.graphics.Shape;
import com.hfg.svg.SvgAttr;
import com.hfg.svg.SvgCircle;
import com.hfg.svg.SvgNode;
import com.hfg.svg.SvgPolygon;
import com.hfg.svg.SvgRect;
import com.hfg.graphics.ColorUtil;
import com.hfg.util.CompareUtil;
import com.hfg.util.StringUtil;
//------------------------------------------------------------------------------
/**
Monosaccharide values.
@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 Monosaccharide extends Molecule
{
//##########################################################################
// PUBLIC FIELDS
//##########################################################################
// Hexoses
/**
Generic hexose.
*/
public static final Monosaccharide Hexose = new Monosaccharide("Hexose", "Hex", Shape.CIRCLE, Color.WHITE);
public static final Monosaccharide Galactose = new Monosaccharide("Galactose", "Gal", Shape.CIRCLE, new Color(255, 255, 0)); // Yellow
public static final Monosaccharide Glucose = new Monosaccharide("Glucose", "Glc", Shape.CIRCLE, new Color(0, 0, 250)); // Blue
public static final Monosaccharide Mannose = new Monosaccharide("Mannose", "Man", Shape.CIRCLE, new Color(0, 200, 50)); // Green
// Deoxysugar (hexose or pentose without a hydroxyl group at the 6-position or the 2-position)
public static final Monosaccharide Fucose = new Monosaccharide("Fucose", "Fuc", Shape.TRIANGLE, new Color(250, 0, 0)); // Red
// Pentoses
public static final Monosaccharide Xylose = new Monosaccharide("Xylose", "Xyl", Shape.STAR, new Color(250, 234, 213)); // Orange
// Amino sugar (hexose with an N-acetylated amino group at the 2-position)
public static final Monosaccharide HexNAc = new Monosaccharide("Hexosamine", "HexNac", Shape.SQUARE, Color.WHITE);
public static final Monosaccharide GalNAc = new Monosaccharide("N-acetyl-D-galactosamine", "GalNAc", Shape.SQUARE, new Color(255, 255, 0)); // Yellow
public static final Monosaccharide GlcNAc = new Monosaccharide("N-acetyl-D-glucosamine", "GlcNAc", Shape.SQUARE, new Color(0, 0, 250)); // Blue
public static final Monosaccharide ManNAc = new Monosaccharide("N-Acetylmannosamine", "ManNAc", Shape.SQUARE, new Color(0, 200, 50)); // Green
// Sialic acids
public static final Monosaccharide NeuAc = new Monosaccharide("N-Acetylneuraminic acid", "NeuAc", Shape.DIAMOND, new Color(200, 0, 200)); // Purple
public static final Monosaccharide NeuGc = new Monosaccharide("N-glycolylneuraminic acid", "NeuGc", Shape.DIAMOND, new Color(233, 255, 255)); // Light blue
public static final Monosaccharide KDN = new Monosaccharide("Deaminated neuraminic acid", "KDN", Shape.DIAMOND, new Color(0, 200, 50)); // Green
public static final Monosaccharide GlcA = new Monosaccharide("D-Glucuronic acid", "GlcA", Shape.DIAMOND, new Color(0, 0, 250)); // Blue
//##########################################################################
// PRIVATE FIELDS
//##########################################################################
private String mName;
private String mAbbrev;
private Color mColor;
private Shape mShape;
// This declaration has to come before the public constants below.
private static Set sValues = new HashSet<>();
static
{
Hexose.addAtoms(Element.CARBON, 6)
.addAtoms(Element.HYDROGEN, 12)
.addAtoms(Element.OXYGEN, 6)
.lock()
.register();
Galactose.addAtoms(Element.CARBON, 6)
.addAtoms(Element.HYDROGEN, 12)
.addAtoms(Element.OXYGEN, 6)
.lock()
.register();
Glucose.addAtoms(Element.CARBON, 6)
.addAtoms(Element.HYDROGEN, 12)
.addAtoms(Element.OXYGEN, 6)
.lock()
.register();
Mannose.addAtoms(Element.CARBON, 6)
.addAtoms(Element.HYDROGEN, 12)
.addAtoms(Element.OXYGEN, 6)
.lock()
.register();
Fucose.addAtoms(Element.CARBON, 6)
.addAtoms(Element.HYDROGEN, 12)
.addAtoms(Element.OXYGEN, 5)
.lock()
.register();
Xylose.addAtoms(Element.CARBON, 5)
.addAtoms(Element.HYDROGEN, 10)
.addAtoms(Element.OXYGEN, 5)
.lock()
.register();
HexNAc.addAtoms(Element.CARBON, 8)
.addAtoms(Element.HYDROGEN, 15)
.addAtoms(Element.NITROGEN, 1)
.addAtoms(Element.OXYGEN, 6)
.lock()
.register();
GalNAc.addAtoms(Element.CARBON, 8)
.addAtoms(Element.HYDROGEN, 15)
.addAtoms(Element.NITROGEN, 1)
.addAtoms(Element.OXYGEN, 6)
.lock()
.register();
GlcNAc.addAtoms(Element.CARBON, 8)
.addAtoms(Element.HYDROGEN, 15)
.addAtoms(Element.NITROGEN, 1)
.addAtoms(Element.OXYGEN, 6)
.lock()
.register();
ManNAc.addAtoms(Element.CARBON, 8)
.addAtoms(Element.HYDROGEN, 15)
.addAtoms(Element.NITROGEN, 1)
.addAtoms(Element.OXYGEN, 6)
.lock()
.register();
NeuAc.addAtoms(Element.CARBON, 11)
.addAtoms(Element.HYDROGEN, 19)
.addAtoms(Element.NITROGEN, 1)
.addAtoms(Element.OXYGEN, 9)
.addKa(new IonizableGroup(6.3E-3, Charge.NEUTRAL)) // pKa 2.2
// .addKa(new IonizableGroup(2.5E-3, Charge.NEUTRAL)) // pKa 2.6
.lock()
.register();
NeuGc.addAtoms(Element.CARBON, 11)
.addAtoms(Element.HYDROGEN, 19)
.addAtoms(Element.NITROGEN, 1)
.addAtoms(Element.OXYGEN, 10)
.lock()
.register();
KDN.addAtoms(Element.CARBON, 9)
.addAtoms(Element.HYDROGEN, 16)
.addAtoms(Element.OXYGEN, 9)
.lock()
.register();
GlcA.addAtoms(Element.CARBON, 6)
.addAtoms(Element.HYDROGEN, 10)
.addAtoms(Element.OXYGEN, 7)
.lock()
.register();
}
//##########################################################################
// CONSTRUCTORS
//##########################################################################
//--------------------------------------------------------------------------
private Monosaccharide(String inName, String inAbbrev)
{
mName = inName;
mAbbrev = inAbbrev;
}
//--------------------------------------------------------------------------
private Monosaccharide(String inName, String inAbbrev, Shape inShape, Color inColor)
{
this(inName, inAbbrev);
mShape = inShape;
mColor = inColor;
}
//##########################################################################
// PUBLIC METHODS
//##########################################################################
//--------------------------------------------------------------------------
public static Monosaccharide valueOf(String inString)
{
Monosaccharide value = null;
if (StringUtil.isSet(inString))
{
for (Monosaccharide monosaccharide : sValues)
{
if (monosaccharide.name().equalsIgnoreCase(inString)
|| monosaccharide.getAbbrev().equals(inString))
{
value = monosaccharide;
break;
}
}
}
return value;
}
//--------------------------------------------------------------------------
public static Monosaccharide[] values()
{
return sValues.toArray(new Monosaccharide[sValues.size()]);
}
//--------------------------------------------------------------------------
/**
Puts the Monosaccharide into the Set of unique Monosaccharide returned by Monosaccharide.values().
*/
public void register()
{
if (! isLocked())
{
throw new RuntimeException("Only locked Monosaccharides can be added to the values list!");
}
sValues.add(this);
}
//--------------------------------------------------------------------------
@Override
public Monosaccharide addAtoms(Element inElement, int inCount)
{
return (Monosaccharide) super.addAtoms(inElement, inCount);
}
//--------------------------------------------------------------------------
@Override
public Monosaccharide addAtoms(Element inElement, float inCount)
{
return (Monosaccharide) super.addAtoms(inElement, inCount);
}
//--------------------------------------------------------------------------
@Override
public Monosaccharide lock()
{
return (Monosaccharide) super.lock();
}
//--------------------------------------------------------------------------
public String name()
{
return mName;
}
//--------------------------------------------------------------------------
public String getAbbrev()
{
return mAbbrev;
}
//--------------------------------------------------------------------------
public Shape getShape()
{
return mShape;
}
//--------------------------------------------------------------------------
public Color getColor()
{
return mColor;
}
//--------------------------------------------------------------------------
@Override
public Monosaccharide addKa(IonizableGroup inValue)
{
return (Monosaccharide) super.addKa(inValue);
}
//--------------------------------------------------------------------------
@Override
public String toString()
{
return mAbbrev;
}
//--------------------------------------------------------------------------
public SvgNode toSVGNode()
{
SvgNode svgNode = null;
if (Shape.SQUARE.equals(getShape()))
{
svgNode = new SvgRect().setWidth(10).setHeight(10);
}
else if (Shape.CIRCLE.equals(getShape()))
{
svgNode = new SvgCircle().setR(5);
}
else if (Shape.DIAMOND.equals(getShape()))
{
List points = new ArrayList<>(4);
points.add(new Point2D.Float(0, 5));
points.add(new Point2D.Float(5, 10));
points.add(new Point2D.Float(10, 5));
points.add(new Point2D.Float(5, 0));
svgNode = new SvgPolygon(points);
}
else if (Shape.TRIANGLE.equals(getShape()))
{
List points = new ArrayList<>(3);
points.add(new Point2D.Float(0, 10));
points.add(new Point2D.Float(10, 10));
points.add(new Point2D.Float(5, 0));
svgNode = new SvgPolygon(points);
}
if (svgNode != null)
{
svgNode.setAttribute(SvgAttr.title, name());
svgNode.addStyle(SvgAttr.stroke + ": #000000");
svgNode.addStyle(SvgAttr.strokeWidth + ":1");
if (getColor() != null)
{
svgNode.addStyle(SvgAttr.fill + ": #" + ColorUtil.colorToHex(getColor()));
}
}
return svgNode;
}
//--------------------------------------------------------------------------
@Override
public int compareTo(Object inObj2)
{
int result = -1;
if (inObj2 != null)
{
if (inObj2 instanceof Monosaccharide)
{
Monosaccharide monosaccharide2 = (Monosaccharide) inObj2;
result = CompareUtil.compare(getAbbrev(), monosaccharide2.getAbbrev());
}
else
{
result = CompareUtil.compare(hashCode(), inObj2.hashCode());
}
}
return result;
}
}