MirMaid API tutorial

There are two different ways of accessing the MirMaid programmatically

  1. Use Ruby's ActiveRecord based models to access a local version of miRmaid on your own computer. For this you need a local installation of miRmaid.
  2. Use the REST interface to query MiRMaid via the http-protocol. Most programming languages have standard REST client libraries. We demonstrate the REST-interface from a ruby and perl client. You can use this method without installing any miRmaid code or data on your local computer.

The REST interface is obviously slower and slightly less powerful than using ActiveRecord directly.

To illustrate we have created a bunch of example tasks, ranging from the very simple to the more complex. The beauty of miRmaid is that even the more complex queries can be performed using just a few lines of fairly clear and understandable code.

Example tasks

Getting the comment annotation for cel-let-7 precursor

The output should look something like:

"let-7 is found on chromosome X in Caenorhabditis elegans [1] and pairs to sites within the 3' untranslated region (UTR) of target mRNAs, specifying the
translational repression of these mRNAs and triggering the transition to late-larval and adult stages [2]. "

Getting the mature sequences for hsa-mir-21 precursor

The output should look something like:

["CAACACCAGUCGAUGGGCUGU", "UAGCUUAUCAGACUGAUGUUGA"]

list the number of miR-17 family precursors in different species, grouped by taxonomy

The output should look something like:

{"Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Aves;"=>
  {"Gallus gallus"=>6},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Metatheria;"=>
  {"Monodelphis domestica"=>4},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Primates;Atelidae;"=>
  {"Lagothrix lagotricha"=>5, "Ateles geoffroyi"=>6},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Amphibia;"=>
  {"Xenopus tropicalis"=>8, "Xenopus laevis"=>2},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Ruminantia;"=>
  {"Bos taurus"=>8},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Suina;"=>
  {"Sus scrofa"=>4},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Carnivora;"=>
  {"Canis familiaris"=>8},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Primates;Lemuridae;"=>
  {"Lemur catta"=>3},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Rodentia;"=>
  {"Mus musculus"=>8, "Rattus norvegicus"=>7},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Prototheria;"=>
  {"Ornithorhynchus anatinus"=>6},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Primates;Cercopithecidae;"=>
  {"Macaca mulatta"=>8, "Macaca nemestrina"=>6},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Primates;Cebidae;"=>
  {"Saguinus labiatus"=>6},
"Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Mammalia;Primates;Hominidae;"=>
  {"Homo sapiens"=>8,
   "Gorilla gorilla"=>6,
   "Pan troglodytes"=>8,
   "Pongo pygmaeus"=>6,
   "Pan paniscus"=>6},
 "Metazoa;Bilateria;Deuterostoma;Chordata;Vertebrata;Pisces;"=>
  {"Fugu rubripes"=>4, "Tetraodon nigroviridis"=>4, "Danio rerio"=>8}}

RUBY

Local : ActiveRecord

This example requires that you have installed a local copy of miRmaid.

require '../config/environment' # depending on the work dir of your script
 
### 1) Getting the comment annotation for cel-let-7 precursor
puts Precursor.find_by_name("cel-let-7").comment
 
### 2) Getting the mature sequences for hsa-mir-21 precursor
puts Precursor.find_by_name("hsa-mir-21").matures.map{|x| x.sequence}
# => ["CAACACCAGUCGAUGGGCUGU", "UAGCUUAUCAGACUGAUGUUGA"]
 
### 3) list the number of miR-17 family precursors in different species, grouped by taxonomy
require 'pp'
mir17_family_members = Precursor.find_by_name("hsa-mir-17").precursor_family.precursors # 145 precursors
mir17_in_species = Hash.new{|h,k| h[k] = Hash.new(0)} # hash of hashes
mir17_family_members.each{|x| mir17_in_species[x.species.taxonomy][x.species.name] += 1}
pp mir17_in_species # pretty print

For some versions of ruby you get warnings from an external module (act_as_ferret) included miRmaid. This can safely be ignored. The warnings look like this:

~/.gem/ruby/1.8/gems/acts_as_ferret-0.4.4/lib/class_methods.rb:155: warning: parenthesize argument(s) for future version
...

Web service : REST

require 'rubygems'
require "activeresource" # install with sudo gem install activeresource
URL = "http://current.mirmaid.org/"
class Precursor < ActiveResource::Base; self.site = URL; end
class Mature < ActiveResource::Base; self.site = URL; end
class Species < ActiveResource::Base; self.site = URL; end 
 
### 1) Getting the comment annotation for cel-let-7 precursor
puts Precursor.find("cel-let-7").comment
 
### 2) Getting the mature sequences for hsa-mir-21 precursor
puts Mature.find(:all, :from => "/precursors/hsa-mir-21/matures").map{|x| x.sequence}
 
### 3) List the number of miR-17 family precursors in different species, grouped by taxonomy
require 'pp'
 mir17_family_members = Precursor.find(:all,:from=>"/precursor_families/mir-17/precursors");nil # 145 precursors
 mir17_in_species = Hash.new{|h,k| h[k] = Hash.new(0)} # hash of hashes
 mir17_family_members.each do |x|
   spc = Species.find(:one,:from=>"/precursors/#{x.id}/species")
   mir17_in_species[spc.taxonomy][spc.name] += 1
end
pp mir17_in_species # pretty print

PERL

Web service : REST

use strict;
# The following modules can be installed easily with 'cpan'
use REST::Client;
use XML::Simple;
use Data::Dumper;
 
my $client = REST::Client->new();
# NoAttr  : ignore "type" attributes
# KeyAttr : no folding, array elements are by default folded to a hash based on the attributes "name","key","id"
# ForceArray: Force array representation of miRMaid REST objects
my $xs = XML::Simple->new(NoAttr=>1,KeyAttr=>[],ForceArray=>['mature','precursor','species']);
$client->setHost("http://current.mirmaid.org");
 
print "### 1) Getting the comment annotation for cel-let-7 precursor\n";
$client->GET('/precursors/cel-let-7.xml');
my $precursor = $xs->XMLin($client->responseContent());
print $precursor->{'comment'}."\n";
 
print "### 2A) Getting the mature sequences for hsa-mir-21 precursor\n";
$client->GET('/precursors/hsa-mir-21/matures.xml');
my $matures = $xs->XMLin($client->responseContent())->{'mature'};
foreach my $m (@$matures) { print $m->{'sequence'}."\n" }
 
print "### 2B) Getting the mature sequences for hsa-mir-1271 precursor\n";
$client->GET('/precursors/hsa-mir-1271/matures.xml');
my $matures = $xs->XMLin($client->responseContent())->{'mature'};
foreach my $m (@$matures) { print $m->{'sequence'}."\n" }
 
print "### 3) List the number miR-17 family precursors in different species, grouped by taxonomy\n";
$client->GET('/precursor_families/mir-17/precursors.xml');
my $mir17_family_members = $xs->XMLin($client->responseContent())->{'precursor'};
my $mir17_in_species = {};
foreach my $prec (@$mir17_family_members) {
  $client->GET('/precursors/'.$prec->{'id'}.'/species.xml');
  my $spc = $xs->XMLin($client->responseContent());
  $mir17_in_species->{$spc->{'taxonomy'}}->{$spc->{'name'}} += 1;
}
print Dumper($mir17_in_species);

 
Back to top
api_tutorial.txt · Last modified: 2010/07/21 16:10 by anders.jacobsen