com.hfg.bio.seq.PlasmidMapSettings 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 java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.hfg.bio.molbio.RestrictionEnzyme;
import com.hfg.bio.seq.format.feature.BasicFeatureKey;
import com.hfg.bio.seq.format.feature.FeatureKey;
import com.hfg.graphics.FontUtil;
import com.hfg.graphics.units.GfxSize;
import com.hfg.graphics.units.Pixels;
import com.hfg.html.attribute.HTMLColor;
import com.hfg.setting.Settings;
import com.hfg.setting.StringListSetting;
import com.hfg.setting.StringMapSetting;
import com.hfg.setting.StringSetting;
import com.hfg.util.StringUtil;
import com.hfg.util.collection.CollectionUtil;
import com.hfg.util.collection.OrderedSet;
//------------------------------------------------------------------------------
/**
* Settings for generating a plasmid map.
*
* @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 PlasmidMapSettings extends Settings
{
private static final String WIDTH = "width";
private static final String HEIGHT = "height";
private static final String BACKBONE_RADIUS = "backboneRadius";
private static final String FONT = "font";
private static final String TITLE_STYLE = "titleStyle";
private static final String SUBTITLE_STYLE = "subtitleStyle";
private static final String PADDING = "padding";
private static final String TICK_LENGTH = "tickLength";
private static final String TICK_STYLE = "tickStyle";
private static final String TICK_LABEL_FONT = "tickLabelFont";
private static final String FEATURE_TYPES = "featureTypes";
private static final String FEATURE_COLOR_MAP = "featureColorMap";
private static final String FEATURE_LABEL_FONT = "featureLabelFont";
private static final String FEATURE_HEIGHT = "featureHeight";
private static final String FEATURE_STYLE = "featureStyle";
private static final String RESTRICTION_ENZYMES = "restrictionEnzymes";
private static final String RESTRICTION_ENZYME_LABEL_FONT = "restrictionEnzymeLabelFont";
private static final String RESTRICTION_ENZYME_STEM_LENGTH = "restrictionEnzymeStemLength";
private static final String RESTRICTION_ENZYME_STEM_STYLE = "restrictionEnzymeStemStyle";
private static GfxSize sDefaultWidth = new Pixels(900);
private static GfxSize sDefaultHeight = new Pixels(900);
private static GfxSize sDefaultBackboneRadius = new Pixels(300);
private static Font sDefaultFont = Font.decode("Arial-PLAIN-10");
private static String sDefaultTitleStyle = "font-size:20px; font-weight:400;";
private static String sDefaultSubtitleStyle = "font-size:12px;";
private static GfxSize sDefaultPadding = new Pixels(40);
private static GfxSize sDefaultTickLength = new Pixels(8);
private static String sDefaultTickStyle = "stroke-width:2px; stroke:#000000;";
private static Font sDefaultTickLabelFont = Font.decode("Arial-PLAIN-8");
private static List sDefaultFeatureTypes = new ArrayList<>(4);
private static String sDefaultFeatureStyle = "stroke-width:1px; stroke:#666666; opacity:0.45";
private static GfxSize sDefaultFeatureHeight = new Pixels(20);
private static Font sDefaultFeatureLabelFont = Font.decode("Arial-PLAIN-8");
private static List sDefaultRestrictionEnzymes = null;
private static Font sDefaultRestrictionEnzymeLabelFont = Font.decode("Arial-ITALIC-7");
private static GfxSize sDefaultRestrictionEnzymeStemLength = new Pixels(30);
private static String sDefaultRestrictionEnzymeStemStyle = "stroke-width:1px; stroke:#ff0000; opacity:0.35";
private static Map sDefaultFeatureColorMap = new HashMap<>(4);
static
{
sDefaultFeatureTypes.add("CDS");
sDefaultFeatureTypes.add("rep_origin");
sDefaultFeatureTypes.add("regulatory");
sDefaultFeatureColorMap.put(new BasicFeatureKey("CDS"), HTMLColor.CORNSILK);
sDefaultFeatureColorMap.put(new BasicFeatureKey("rep_origin"), HTMLColor.LIGHT_GREEN);
sDefaultFeatureColorMap.put(new BasicFeatureKey("regulatory"), HTMLColor.LIGHT_BLUE);
}
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public PlasmidMapSettings()
{
}
//---------------------------------------------------------------------------
@Override
protected void init()
{
super.init();
add(new StringSetting(WIDTH));
add(new StringSetting(HEIGHT));
add(new StringSetting(BACKBONE_RADIUS));
add(new StringSetting(FONT));
add(new StringSetting(TITLE_STYLE));
add(new StringSetting(SUBTITLE_STYLE));
add(new StringSetting(PADDING));
add(new StringSetting(TICK_LENGTH));
add(new StringSetting(TICK_STYLE));
add(new StringSetting(TICK_LABEL_FONT));
add(new StringListSetting(FEATURE_TYPES));
add(new StringMapSetting(FEATURE_COLOR_MAP));
add(new StringSetting(FEATURE_LABEL_FONT));
add(new StringSetting(FEATURE_HEIGHT));
add(new StringSetting(FEATURE_STYLE));
add(new StringListSetting(RESTRICTION_ENZYMES));
add(new StringSetting(RESTRICTION_ENZYME_LABEL_FONT));
add(new StringSetting(RESTRICTION_ENZYME_STEM_LENGTH));
add(new StringSetting(RESTRICTION_ENZYME_STEM_STYLE));
setWidth(sDefaultWidth);
setHeight(sDefaultHeight);
setBackboneRadius(sDefaultBackboneRadius);
setFont(sDefaultFont);
setTitleStyle(sDefaultTitleStyle);
setSubTitleStyle(sDefaultSubtitleStyle);
setPadding(sDefaultPadding);
setTickLength(sDefaultTickLength);
setTickStyle(sDefaultTickStyle);
setTickLabelFont(sDefaultTickLabelFont);
setFeatureTypes(sDefaultFeatureTypes);
setFeatureColorMap(sDefaultFeatureColorMap);
setFeatureLabelFont(sDefaultFeatureLabelFont);
setFeatureStyle(sDefaultFeatureStyle);
setFeatureHeight(sDefaultFeatureHeight);
setRestrictionEnzymes(sDefaultRestrictionEnzymes);
setRestrictionEnzymeLabelFont(sDefaultRestrictionEnzymeLabelFont);
setRestrictionEnzymeStemLength(sDefaultRestrictionEnzymeStemLength);
setRestrictionEnzymeStemStyle(sDefaultRestrictionEnzymeStemStyle);
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setWidth(GfxSize inValue)
{
get(WIDTH).setValue(inValue != null ? inValue.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public GfxSize getWidth()
{
String stringValue = (String) get(WIDTH).getValue();
return (StringUtil.isSet(stringValue) ? GfxSize.allocate(stringValue) : null);
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setHeight(GfxSize inValue)
{
get(HEIGHT).setValue(inValue != null ? inValue.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public GfxSize getHeight()
{
String stringValue = (String) get(HEIGHT).getValue();
return (StringUtil.isSet(stringValue) ? GfxSize.allocate(stringValue) : null);
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setBackboneRadius(GfxSize inValue)
{
get(BACKBONE_RADIUS).setValue(inValue != null ? inValue.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public GfxSize getBackboneRadius()
{
String stringValue = (String) get(BACKBONE_RADIUS).getValue();
return (StringUtil.isSet(stringValue) ? GfxSize.allocate(stringValue) : null);
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setPadding(GfxSize inValue)
{
get(PADDING).setValue(inValue != null ? inValue.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public GfxSize getPadding()
{
String stringValue = (String) get(PADDING).getValue();
return (StringUtil.isSet(stringValue) ? GfxSize.allocate(stringValue) : null);
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setFont(Font inValue)
{
CharSequence value = null;
if (inValue != null)
{
value = FontUtil.encode(inValue);
}
get(FONT).setValue(value != null ? value.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public Font getFont()
{
Font value = null;
String stringValue = (String) get(FONT).getValue();
if (StringUtil.isSet(stringValue))
{
value = Font.decode(stringValue);
}
return value;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setTitleStyle(String inValue)
{
get(TITLE_STYLE).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public String getTitleStyle()
{
String value = (String) get(TITLE_STYLE).getValue();
return (StringUtil.isSet(value) ? value : "");
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setSubTitleStyle(String inValue)
{
get(SUBTITLE_STYLE).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public String getSubTitleStyle()
{
String value = (String) get(SUBTITLE_STYLE).getValue();
return (StringUtil.isSet(value) ? value : "");
}
//---------------------------------------------------------------------------
public PlasmidMapSettings setTickLength(GfxSize inValue)
{
get(TICK_LENGTH).setValue(inValue != null ? inValue.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public GfxSize getTickLength()
{
String stringValue = (String) get(TICK_LENGTH).getValue();
return (StringUtil.isSet(stringValue) ? GfxSize.allocate(stringValue) : null);
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setTickStyle(String inValue)
{
get(TICK_STYLE).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public String getTickStyle()
{
String value = (String) get(TICK_STYLE).getValue();
return (StringUtil.isSet(value) ? value : "");
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setTickLabelFont(Font inValue)
{
CharSequence value = null;
if (inValue != null)
{
value = FontUtil.encode(inValue);
}
get(TICK_LABEL_FONT).setValue(value != null ? value.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public Font getTickLabelFont()
{
Font value = null;
String stringValue = (String) get(TICK_LABEL_FONT).getValue();
if (StringUtil.isSet(stringValue))
{
value = Font.decode(stringValue);
}
return value;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings clearFeatureTypes()
{
get(FEATURE_TYPES).setValue(null);
return this;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings addFeatureType(String inValue)
{
List featureTypes = getFeatureTypes();
if (null == featureTypes)
{
featureTypes = new ArrayList<>(1);
}
featureTypes.add(inValue);
setFeatureTypes(featureTypes);
return this;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setFeatureTypes(List inValue)
{
get(FEATURE_TYPES).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public List getFeatureTypes()
{
return (List) get(FEATURE_TYPES).getValue();
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setFeatureColorMap(Map inValue)
{
Map stringMap = null;
if (CollectionUtil.hasValues(inValue))
{
stringMap = new HashMap<>(inValue.size());
for (FeatureKey key : inValue.keySet())
{
stringMap.put(key.name(), inValue.get(key).toString());
}
}
get(FEATURE_COLOR_MAP).setValue(stringMap);
return this;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public Map getFeatureColorMap()
{
Map map = null;
Map stringMap = (Map) get(FEATURE_COLOR_MAP).getValue();
if (CollectionUtil.hasValues(stringMap))
{
map = new HashMap<>(stringMap.size());
for (String key : stringMap.keySet())
{
map.put(new BasicFeatureKey(key), HTMLColor.valueOf(stringMap.get(key)));
}
}
return map;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setFeatureLabelFont(Font inValue)
{
CharSequence value = null;
if (inValue != null)
{
value = FontUtil.encode(inValue);
}
get(FEATURE_LABEL_FONT).setValue(value != null ? value.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public Font getFeatureLabelFont()
{
Font value = null;
String stringValue = (String) get(FEATURE_LABEL_FONT).getValue();
if (StringUtil.isSet(stringValue))
{
value = Font.decode(stringValue);
}
return value;
}
//---------------------------------------------------------------------------
public PlasmidMapSettings setFeatureHeight(GfxSize inValue)
{
get(FEATURE_HEIGHT).setValue(inValue != null ? inValue.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public GfxSize getFeatureHeight()
{
String stringValue = (String) get(FEATURE_HEIGHT).getValue();
return (StringUtil.isSet(stringValue) ? GfxSize.allocate(stringValue) : null);
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setFeatureStyle(String inValue)
{
get(FEATURE_STYLE).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public String getFeatureStyle()
{
String value = (String) get(FEATURE_STYLE).getValue();
return (StringUtil.isSet(value) ? value : "");
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings addRestrictionEnzyme(RestrictionEnzyme inValue)
{
List stringList = (List) get(RESTRICTION_ENZYMES).getValue();
if (CollectionUtil.hasValues(stringList))
{
OrderedSet set = new OrderedSet<>(stringList);
set.add(inValue.name());
stringList = new ArrayList<>(set);
}
else
{
stringList = new ArrayList<>(1);
stringList.add(inValue.name());
}
get(RESTRICTION_ENZYMES).setValue(stringList);
return this;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setRestrictionEnzymes(List inValue)
{
List stringList = null;
if (CollectionUtil.hasValues(inValue))
{
stringList = new ArrayList<>(inValue.size());
for (RestrictionEnzyme re : inValue)
{
stringList.add(re.name());
}
}
get(RESTRICTION_ENZYMES).setValue(stringList);
return this;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public List getRestrictionEnzymes()
{
List stringList = (List) get(RESTRICTION_ENZYMES).getValue();
List restrictionEnzymes = null;
if (CollectionUtil.hasValues(stringList))
{
for (String name : stringList)
{
RestrictionEnzyme re = RestrictionEnzyme.valueOf(name);
if (re != null)
{
if (null == restrictionEnzymes)
{
restrictionEnzymes = new ArrayList<>(20);
}
restrictionEnzymes.add(re);
}
}
}
return restrictionEnzymes;
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setRestrictionEnzymeLabelFont(Font inValue)
{
CharSequence value = null;
if (inValue != null)
{
value = FontUtil.encode(inValue);
}
get(RESTRICTION_ENZYME_LABEL_FONT).setValue(value != null ? value.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public Font getRestrictionEnzymeLabelFont()
{
Font value = null;
String stringValue = (String) get(RESTRICTION_ENZYME_LABEL_FONT).getValue();
if (StringUtil.isSet(stringValue))
{
value = Font.decode(stringValue);
}
return value;
}
//---------------------------------------------------------------------------
public PlasmidMapSettings setRestrictionEnzymeStemLength(GfxSize inValue)
{
get(RESTRICTION_ENZYME_STEM_LENGTH).setValue(inValue != null ? inValue.toString() : null);
return this;
}
//---------------------------------------------------------------------------
public GfxSize getRestrictionEnzymeStemLength()
{
String stringValue = (String) get(RESTRICTION_ENZYME_STEM_LENGTH).getValue();
return (StringUtil.isSet(stringValue) ? GfxSize.allocate(stringValue) : null);
}
//---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public PlasmidMapSettings setRestrictionEnzymeStemStyle(String inValue)
{
get(RESTRICTION_ENZYME_STEM_STYLE).setValue(inValue);
return this;
}
//---------------------------------------------------------------------------
public String getRestrictionEnzymeStemStyle()
{
String value = (String) get(RESTRICTION_ENZYME_STEM_STYLE).getValue();
return (StringUtil.isSet(value) ? value : "");
}
}