Created
September 28, 2012 09:35
-
-
Save timyates/3798887 to your computer and use it in GitHub Desktop.
Quick and dirty querying of the ensembl REST api with Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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