API clients handle the underlying details of how network requests are made
and how responses are decoded.
We are using Core API
which is a format-independent Document Object Model for representing Web APIs.
It is recommended to use the Core API clients described below for a more robust
and intuitive way to interact with the JASPAR API rather than constructing HTTP
requests and decoding responses.
Currently, Core API provides three clients:
As a way of getting started, you can interact with the JASPAR API using the
sample calls provided below.
Command line client
# Install the command line client
$ pip install coreapi-cli
To interact with the API:
# Load the schema document
$ coreapi get https://jaspar.uio.no/api/v1/docs
# Interact with the API endpoint
$ coreapi action matrix list -p page=... -p page_size=... -p search=... -p order=... -p collection=... -p name=... -p tax_group=... -p tax_id=... -p tf_class=... -p tf_family=... -p data_type=... -p version=... -p release=...
# For example
coreapi action matrix list -p collection=CORE -p tax_group=vertebrates -p version=latest -p name=SMAD3
Python client
# Install the Python client library
$ pip install coreapi
To interact with the API:
import coreapi
# Initialize a client & load the schema document
client = coreapi.Client()
schema = client.get("https://jaspar.uio.no/api/v1/docs")
# Interact with the API endpoint
action = ["matrix", "list"]
params = {
"page": ...,
"page_size": ...,
"search": ...,
"order": ...,
"collection": ...,
"name": ...,
"tax_group": ...,
"tax_id": ...,
"tf_class": ...,
"tf_family": ...,
"data_type": ...,
"version": ...,
"release": ...,
}
result = client.action(schema, action, params=params)
# For example
params = {
"collection": 'CORE',
"name": 'SMAD3',
"tax_group": 'vertebrates',
"version": 'latest',
"release": '2018',
}
result = client.action(schema, action, params=params)
JavaScript client
<!-- Load the JavaScript client library -->
<script src="https://jaspar.uio.no/static/rest_framework/js/coreapi-0.1.0.js"></script>
<script src="https://jaspar.uio.no/api/v1/docs/schema.js"></script>
To interact with the API:
var coreapi = window.coreapi // Loaded by `coreapi.js`
var schema = window.schema // Loaded by `schema.js`
// Initialize a client
var client = new coreapi.Client()
// Interact with the API endpoint
var action = ["matrix", "list"]
var params = {
page: ...,
page_size: ...,
search: ...,
order: ...,
collection: ...,
name: ...,
tax_group: ...,
tax_id: ...,
tf_class: ...,
tf_family: ...,
data_type: ...,
version: ...,
release: ...,
}
client.action(schema, action, params).then(function(result) {
// Return value is in 'result'
})
Sample calls
These are sample calls to API from different languages. You can create the query url by using our Live API
$.ajax({
url: 'https://jaspar.uio.no/api/v1/matrix?format=jsonp',
dataType: 'jsonp',
jsonp: false,
jsonpCallback: 'callback',
success: function(data){
//Use data and do something
},
});
import requests, sys
query_url = "https://jaspar.uio.no/api/v1/matrix?format=json"
result = requests.get(query_url)
if not result.ok:
r.raise_for_status()
sys.exit()
decoded = result.json()
print(repr(decoded))
use strict;
use warnings;
use HTTP::Tiny;
my $http = HTTP::Tiny->new();
my $server = 'https://jaspar.uio.no/api/v1/';
my $ext = 'matrix?format=json';
my $response = $http->get($server.$ext, {
headers => { 'Content-type' => 'application/json' }
});
die "Failed!\n" unless $response->{success};
use JSON;
use Data::Dumper;
if(length $response->{content}) {
my $hash = decode_json($response->{content});
local $Data::Dumper::Terse = 1;
local $Data::Dumper::Indent = 1;
print Dumper $hash;
print "\n";
}
require 'net/http'
require 'uri'
server='https://jaspar.uio.no/api/v1/'
path = 'matrix?format=json'
url = URI.parse(server)
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(path, {'Content-Type' => 'application/json'})
response = http.request(request)
if response.code != "200"
puts "Invalid response: #{response.code}"
puts response.body
exit
end
require 'rubygems'
require 'json'
require 'yaml'
result = JSON.parse(response.body)
puts YAML::dump(result)
library(jsonlite)
url <- "https://jaspar.uio.no/api/v1/matrix?format=json"
result <- fromJSON(url)
#create a dataframe
df <- result$results
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
public class JASPARRest {
public static void main(String[] args) throws Exception {
String server = "https://jaspar.uio.no/api/v1/";
String ext = "matrix?format=json";
URL url = new URL(server + ext);
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection)connection;
httpConnection.setRequestProperty("Content-Type", "application/json");
InputStream response = connection.getInputStream();
int responseCode = httpConnection.getResponseCode();
if(responseCode != 200) {
throw new RuntimeException("Response code was not 200. Detected response was "+responseCode);
}
String output;
Reader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(response, "UTF-8"));
StringBuilder builder = new StringBuilder();
char[] buffer = new char[8192];
int read;
while ((read = reader.read(buffer, 0, buffer.length)) > 0) {
builder.append(buffer, 0, read);
}
output = builder.toString();
}
finally {
if (reader != null) try {
reader.close();
} catch (IOException logOrIgnore) {
logOrIgnore.printStackTrace();
}
}
System.out.println(output);
}
}
curl 'https://jaspar.uio.no/api/v1/matrix?format=json' -H 'Content-type:application/json'