Top Page


The UTGB Toolkit has a built-in support for data mapping, called lens, between XML/JSON/Silk/Relational data to Java class objects. Our Lens utility automatically detects public fileds in your class definition, and maps data souces to the object instances.

An Quick Example (XML to Objects)

Supporse you have the following XML data (saved as gene.xml) describing a gene object:

<gene id="1">

To parse this XML data, you have to describe a Gene class with public fields corresponding to the XML elements:

class Gene 
  public int id;
  public String name;
  public String chr;
  public String strand;
  public long start;
  public long end;
  // public default constructor
  public Gene() {}


By using Lens.loadXML(target class, input reader) method, you can create an instance of the Gene object from the XML file (gene.xml):

BufferedReader xmlReader = new BufferedReader(new FileReader("gene.xml"));
Gene gene = Lens.loadXML(Gene.class, xmlReader);

// == 1
// == "gene1"
// gene.chr == "chr1"
// gene.start == 1000
// gene.end == 4000

UTGB automatically converts string data appeared in the XML file into appropriate data type (integer, String, etc. ) by seeing field or setter methods in the class definition.

Mapping Database Query Results to Java Objects

When your data is stored in an SQLite database, you have to use SQL queries to retreive data.

Table Data


Sample Code

// get database access of mydb. This id is specified in the config/ file
DatabaseAccess dbAccess = UTGBMaster.getDatabaseAccess("mydb");

// execute an SQL query, then bind the result rows to Gene object
List<Gene> result = 
     String.format("select * from gene where start >= %d order by start", start), 

// draw the gene objects to some image
for(Gene eachGene : result)
   // ... do some drawings

Mapping to Nested Objects

  • genelist.xml
  • <genelist>
     <description>gene list</description>
     <gene id="1">
     <gene id="2">

class GeneList 
   public List<Gene> gene;
   public String description;

BufferedReader xmlReader = new BufferedReader(new FileReader("genelist.xml"));
GeneList geneList = Lens.loadXML(GeneList.class, xmlReader);

// Output object as JSON
// Output object as Silk