textbender.d.gene
Class Gene

java.lang.Object
  extended by Gene

@ThreadSafe
public final class Gene
extends Object

Utilities for working with genes.

See Also:
gene.mod

Field Summary
static String EMBEDDABLE_STUB_LOCAL_NAME
          Local name of stub elements that represent contained genes in embeddable forms.
static int G_INDEX_FLAG_DOUBLE_DASH
          G-index flag indicating a 'g' attribute value that begins '--'.
static int G_INDEX_FLAG_NONE
          G-index flag indicating that a node has no 'g' attribute.
static int G_INDEX_FLAG_SINGLE_DASH
          G-index flag indicating a 'g' attribute value that begins with a single '-'.
static int G_INDEX_FLAG_UNKNOWN
          G-index flag indicating an unrecognized 'g' attribute value.
 
Method Summary
static void abstract_embeddable(Element sequence, List<Element> gList)
          Tranforms a genetic-form sequence into an abstract form suitable for embeddable encoding.
static void adjustLeftPadding(Element element, int delta, StringBuilder b)
          Adjusts the left padding (leading space content) of an element.
static Element createG(String locus, Element gg, StringBuilder b)
          Creates an unattached gene meta-data ('g') element.
static Element createGG(Element metaData, StringBuilder b)
          Creates an unattached 'g' list ('gg') element.
static Element ensureGG(Element metaData, StringBuilder b)
          Returns a document's 'gg' element; if necessary creating it.
static void escape_embeddable(StringBuilder b)
          Tranforms an embeddable sequence from unescaped to escaped form.
static Element findGG(Element metaData)
          Finds a document's 'gg' element.
static boolean gIndexIsGene(int gIndex)
          Returns true iff gIndexOf >= 0, indicating a gene.
static boolean gIndexIsNonGenetic(int gIndex)
          Returns true iff gIndexOf indicates a non-genetic element; either G_INDEX_FLAG_SINGLE_DASH or G_INDEX_FLAG_DOUBLE_DASH.
static int gIndexOf(Element element)
          Returns the g-index of an element, derived from its 'g' attribute value.
static int gIndexOf(String g)
          Returns the g-index of a 'g' attribute value.
static int gIndexOfNode(Node node)
          Returns the g-index of a node.
static String gOf(int gIndex)
          Returns the g-index encoded as a string suitable for a 'g' attribute value.
static String gROf(Element element)
          Returns the effective 'gR' attribute of an element.
static boolean hasChildGene(Node node)
          Returns true iff the node has a child gene.
static boolean isGene(Element element)
          Returns true if the element is a gene.
static int linkG(Element g, Element sequenceElement, Element gg, int gIndex, StringBuilder b)
          Links a gene meta-data ('g') element into the document.
static Element selfOrAncestorAsGene(Node node)
          Returns the node if it is a gene; otherwise the nearest ancestor that is a gene.
static void unescape_embeddable(StringBuilder b)
          Tranforms an embeddable sequence from escaped to unescaped form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMBEDDABLE_STUB_LOCAL_NAME

public static final String EMBEDDABLE_STUB_LOCAL_NAME
Local name of stub elements that represent contained genes in embeddable forms. The namespace is always null.

See Also:
Constant Field Values

G_INDEX_FLAG_NONE

public static final int G_INDEX_FLAG_NONE
G-index flag indicating that a node has no 'g' attribute.

See Also:
gIndexOf(Element), Constant Field Values

G_INDEX_FLAG_UNKNOWN

public static final int G_INDEX_FLAG_UNKNOWN
G-index flag indicating an unrecognized 'g' attribute value.

See Also:
gIndexOf(String), Constant Field Values

G_INDEX_FLAG_SINGLE_DASH

public static final int G_INDEX_FLAG_SINGLE_DASH
G-index flag indicating a 'g' attribute value that begins with a single '-'.

See Also:
gIndexOf(String), gIndexIsNonGenetic(int), Constant Field Values

G_INDEX_FLAG_DOUBLE_DASH

public static final int G_INDEX_FLAG_DOUBLE_DASH
G-index flag indicating a 'g' attribute value that begins '--'.

See Also:
gIndexOf(String), gIndexIsNonGenetic(int), Constant Field Values
Method Detail

abstract_embeddable

public static void abstract_embeddable(Element sequence,
                                       List<Element> gList)
Tranforms a genetic-form sequence into an abstract form suitable for embeddable encoding.

Parameters:
sequence - genetic-form sequence
gList - list of gene meta-data ('g') elements in the document
See Also:
d/gene/note.xht#Abstraction

adjustLeftPadding

public static void adjustLeftPadding(Element element,
                                     int delta,
                                     StringBuilder b)
Adjusts the left padding (leading space content) of an element.

Parameters:
element - whose padding to adjust
delta - number of space characters to remove (negative) or add (positive)
b - string builder to use, overwriting its existing content

createG

public static Element createG(String locus,
                              Element gg,
                              StringBuilder b)
Creates an unattached gene meta-data ('g') element.

Parameters:
locus - of the gene
gg - the meta-data 'gg' element, to which caller will attach new 'g' element
b - string builder to use, overwriting its existing content

createGG

public static Element createGG(Element metaData,
                               StringBuilder b)
Creates an unattached 'g' list ('gg') element.

Parameters:
metaData - the document's meta-data element, to which caller will attach new 'gg' element
b - string builder to use, overwriting its existing content
See Also:
ensureGG(Element,StringBuilder)

ensureGG

public static Element ensureGG(Element metaData,
                               StringBuilder b)
Returns a document's 'gg' element; if necessary creating it.

Parameters:
metaData - the document's meta-data element
b - string builder to use, overwriting its existing content
See Also:
createGG(Element,StringBuilder), findGG(Element)

escape_embeddable

public static void escape_embeddable(StringBuilder b)
Tranforms an embeddable sequence from unescaped to escaped form.

Parameters:
b - string builder containing the unescaped sequence
See Also:
unescape_embeddable(StringBuilder), d/gene/note.xht#Escaping

findGG

public static Element findGG(Element metaData)
Finds a document's 'gg' element.

Parameters:
metaData - the document's meta-data element
Returns:
'gg' element, or null if none found
See Also:
ensureGG(Element,StringBuilder)

gIndexIsNonGenetic

public static boolean gIndexIsNonGenetic(int gIndex)
Returns true iff gIndexOf indicates a non-genetic element; either G_INDEX_FLAG_SINGLE_DASH or G_INDEX_FLAG_DOUBLE_DASH.


gIndexIsGene

public static boolean gIndexIsGene(int gIndex)
Returns true iff gIndexOf >= 0, indicating a gene.


gIndexOf

public static int gIndexOf(Element element)
Returns the g-index of an element, derived from its 'g' attribute value.

Returns:
g-index or flag per gIndexOf(String); or G_INDEX_FLAG_NONE if the element has no 'g' attribute
See Also:
gIndexOfNode(Node)

gIndexOfNode

public static int gIndexOfNode(Node node)
Returns the g-index of a node.

Returns:
g-index or flag per gIndexOf(String); or G_INDEX_FLAG_NONE if the node has no 'g' attribute

gIndexOf

public static int gIndexOf(String g)
Returns the g-index of a 'g' attribute value.

Returns:
g-index (>= 0) if the 'g' attribute designates a gene; else a flag (< 0): G_INDEX_FLAG_UNKNOWN, G_INDEX_FLAG_SINGLE_DASH, or G_INDEX_FLAG_DOUBLE_DASH
See Also:
gIndexOf(Element), gOf(int)

gOf

public static String gOf(int gIndex)
Returns the g-index encoded as a string suitable for a 'g' attribute value.

See Also:
gIndexOf(String)

gROf

public static String gROf(Element element)
Returns the effective 'gR' attribute of an element.

Parameters:
element - e.g. a meta-data 'gg' or ancestor 'a' element
Returns:
'gR' attribute value if present, else "0"

hasChildGene

public static boolean hasChildGene(Node node)
Returns true iff the node has a child gene. Where the node is itself a gene, true indicates a parent gene; false a leaf.


isGene

public static boolean isGene(Element element)
Returns true if the element is a gene. An element is a gene if it has a g-index.

See Also:
gIndexOf(Element)

linkG

public static int linkG(Element g,
                        Element sequenceElement,
                        Element gg,
                        int gIndex,
                        StringBuilder b)
Links a gene meta-data ('g') element into the document. Linkage entails 1) appending the 'g' element to the 'gg' list; and 2) setting the 'g' attribute of the sequenceElement to point to it.

Parameters:
g - gene meta-data element
sequenceElement - element that will become the gene; it should itself be attached in the document, or the namespace prefix lookup may fail
gg - the meta-data 'gg' element
gIndex - prior count of 'g' elements, and offset for the newly created 'g' element, in 'gg' list
b - string builder to use, overwriting its existing content
Returns:
g-index offset of the newly created 'g' element in 'gg' list (same as passed in)
See Also:
createG(String,Element,StringBuilder)

selfOrAncestorAsGene

public static Element selfOrAncestorAsGene(Node node)
Returns the node if it is a gene; otherwise the nearest ancestor that is a gene.

Parameters:
node - reference node, which may be null
Returns:
node, or its nearest ancestor gene, or null

unescape_embeddable

public static void unescape_embeddable(StringBuilder b)
Tranforms an embeddable sequence from escaped to unescaped form.

Parameters:
b - string builder containing the escaped sequence
See Also:
escape_embeddable(StringBuilder), d/gene/note.xht#Escaping