GroovyShell and interactive scripting

Johannes contacted me this weekend and asked about the GroovyShell in the new Epos release, so I decided to create a small screencast that demonstrates the functionality.

The Epos GroovyShell can be used to write scripts (in groovy) directly within Epos, and it gives you drag&drop access to your data.

The screencast demonstrates a very simple script that takes a set of sequences and counts the different characters (A,C,G and T in this case).


def dist = [:]
sequences.each{ s ->
    def string = s.getSequenceString()
    string.each { c->
        dist[c.toUpperCase()] = dist[c.toUpperCase()] == null ? 1 : dist[c.toUpperCase()]+1
    }            
}
dist.each{
    println it.key+" = "+it.value
}

This relies on the sequences variable, which is a list of sequences directly imported from the Epos workspace.
The second thing we do is using JFreeChart (which is included in the epos distribution) and an external library, the GroovyChartBuilder, to create and show a little plot from the distribution we created. Here is the full script.

You can read more about the groovy shell in the epos wiki.


import com.thecoderscorner.groovychart.chart.ChartBuilder
import org.jfree.chart.ChartPanel
import java.awt.Color
import epos.ui.huds.*

def dist = [:]
sequences.each{ s ->
    def string = s.getSequenceString()
    string.each { c->
        dist[c.toUpperCase()] = dist[c.toUpperCase()] == null ? 1 : dist[c.toUpperCase()]+1
    }            
}
dist.each{
    println it.key+" = "+it.value
}
ChartBuilder cb = new ChartBuilder();
def pieChart = cb.piechart3d(title: "Character Distribution") {
    defaultPieDataset {
        dist.keySet().each{ key ->
            "${key}"(dist[key])                        
        }
    }
    antiAlias = true
    backgroundPaint(Color.WHITE)
}

HudFactory.showHUD(component, "Characters", new ChartPanel(pieChart.chart))

Leave a Reply