Skip to content

Instantly share code, notes, and snippets.

@timyates
Created September 28, 2012 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timyates/3798887 to your computer and use it in GitHub Desktop.
Save timyates/3798887 to your computer and use it in GitHub Desktop.
Quick and dirty querying of the ensembl REST api with Groovy
@Grab( 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2' )
import groovyx.net.http.RESTClient
// A connection to ensembl
def ensembl = new RESTClient( 'http://beta.rest.ensembl.org/' )
// Get a list of species
def spec = ensembl.get( path:'info/species',
query:[ 'content-type':'application/json' ] )
// Find the species with "baker's yeast" as an alias
String species = spec.data.species.findResult { "baker's yeast" in it.aliases ? it.name : null }
// Get all the assemblies for this species
def assembly = ensembl.get( path:"assembly/info/$species",
query:[ 'content-type':'application/json' ] )
List assemblies = assembly.data.top_level_seq_region_names
// For each assembly, try and get the assembly info for it
// (Currently the API fails for non-chromosomal assemblies)
List chromosomes = assemblies.findAll {
// Need to limit to 3 requests per second (max)
Thread.sleep( 400 )
print '.'
try {
ensembl.get( path:"assembly/info/$species/$it", query:[ 'content-type':'application/json' ] )
} catch( e ) { false }
}
println "\n$species has chromosomes $chromosomes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment