Tuesday, July 28, 2009

BioJava and Jython

Jython is an exciting project to implement a Python parser and environment in Java. One of it's more exciting aspects is the ability to directly call existing Java classes with no need to write an additional wrapper layer (as compared to the situation with CPython and existing C libraries). This means the complex libraries, like BioJava, can be easily utilized in a scripting environment.
The cookbook example of opening and reading a Genbank file can easily be translated into Jython:

#!/usr/bin/env jython

import sys
from java.io import *
from java.util import *
from org.biojava.bio import *
from org.biojava.bio.seq.db import *
from org.biojava.bio.seq.io import *
from org.biojava.bio.symbol import *

if __name__ == "__main__":
br = BufferedReader( FileReader( sys.argv[1] ) )
sequences = SeqIOTools.readGenbank(br)
while sequences.hasNext():
seq = sequences.nextSequence()
print seq.seqString()

No comments: