D2P2 Online Data API

What can I get from the webservice?

You can access the D2P2 assignments programatically via a simple JSON web API from various programming languages. Retrieving assignments based on sequence and accession ID are currently supported. If you have sequence IDs from the originating genomes these should be recognised as well as UniProt accession.

Can I download or make my own figures?

Currently we don't facilitate the arbitrary production of the D2P2 style figures for use with your own data offline. However, if you wish to receive your data in figure form, or wish to have some control over figure production we do offer some options.

The default URL for producing a D2P2 figure in HTML is of the form:
http://d2p2.pro/cgi/archpic.cgi?seqids=P04637

You can use the form below to build a figure with more than one sequence viewed alongside each other and retreive what the URL looks like

What does the response data look like?

Following your request for data you will receive a JSON object mapping your query accession IDs or sequences to the assignment data. The following gives an overview of the data to be expected. The example from the code given above is examined, all results are for that of the p53 protein in human, UniProt ID P04637.

The JSON Response

    {
      "P04637": [
        [
          "P04637",
          "Uniprot",
          {
              "structure": {
                "weak": [],
                "strong": [
                  [
                    "p53 tetramerization domain",
                    "47719",
                    "1.31e-11",
                    null,
                    null,
                    null,
                    "319-357"
                  ],
                  [
                    "p53-like transcription factors",
                    "49417",
                    "1.16e-90",
                    "p53 DNA-binding domain-like",
                    "81314",
                    "4.08e-09",
                    "97-287"
                  ]
                ]
              },
              "disorder": {
                "conflict": [0,0,0,0,...],
                "consensus": [9,9,9,8,8,0,0,0,7...],
                "disranges": [ ["Pred#1", "1", "10"], ["Pred#2", "1","10"]... ],
                "consranges": [ ["1","10"], ["12","24"]... ]
              }
          }
        ]
      ]
    }
    

The JSON Explained

Lines 2-38 each query maps to a list of possible matching results, for more than one result we have multiple entries for different genomes for a given ID or sequence.

Lines 3-37 each entry for a query value is made up of a list of the form:

Sequence IDGenome or Sequence Library NameAssignment JSON Object
P04637Uniprot{ structure: {...}, disorder: {...} }

Line 8 the SUPERFAMILY assignments with weaker support, specifically the E-value for the superfamily classification is lower than 0.0001. If data was provided here it would be of the same form as the strong support section.

Lines 9-28 are the SUPERFAMILY assignments with strong support.

Lines 10-18 and 19-27 are the SUPERFAMILY assignments for the given protein. The fields take on the following form:

Superfamily NameSupfam.org Superfamily ID NumberE-value for Superfamily AssignmentFamily NameSupfam.org Family ID NumberE-value for Family AssignmentAssignment Region (inclusive of residues)
p53 tetramerization domain477191.31e-11nullnullnull319-357
p53 like transcription factors494711.16e-90p53 DNA-binding domain-like813144.08e-0997-287

What code do I need?

In each of the examples below I demonstrate how to output the predicted disordered regions as a table.

The following Perl code makes use of the Mojolicious HTTP user agent. I've chosen this package as it's easy to install and doesn't have any dependencies on the rest of CPAN. Additionally the Mojo UserAgent is equipped to deal with JSON without other libraries.

Perl 5

#!/usr/bin/env perl
use strict;
use warnings;
use feature ':5.10';

use Mojo::UserAgent;

my $ua = Mojo::UserAgent->new;
my $response = $ua->get('http://d2p2.pro/api/seqid/["P04637"]')->res->json;

foreach my $record (@{$response->{'P04637'}[0][2]{'disorder'}{'disranges'}}) {
    say join "\t", @{$record};
}
            

Perl 6

#!/usr/bin/env perl6
use v6;

use LWP::Simple;
use JSON::Tiny;

sub url-encode (Str $string) {
    return $string.subst(/<-[ A..Z a..z 0..9 \- _ \. ~ ]>/, *.ord.fmt("%%%02X"), :g);
}

my $www = LWP::Simple.new;

my %response = from-json($www.get("http://d2p2.pro/api/seqid/" ~ url-encode('["P04637"]')));
for %response{'P04637'}[0][2]{'disorder'}{'disranges'}[*] -> @record {
    say @record.join("\t");
}
        
#/usr/bin/env python
import json
import urllib2

#This example uses the POST method, for GET you can
#put the ["P04637"] as part of the URL as /api/seqid/["P04637"]
#this is interpreted as a GET request of the form ?seqids=["P04637"]

data = 'seqids=["P04637"]'
request = urllib2.Request('http://d2p2.pro/api/seqid', data)
response = json.loads(urllib2.urlopen(request).read())

for record in response['P04637'][0][2]['disorder']['disranges']:
    print "\t".join(record)
            

In older versions of Ruby (1.8) you will need to install the json gem with rubygems. For newer versions the json package should already be available.

#/usr/bin/env ruby
require "net/http"
require "uri"
require "rubygems"
require "json"

uri = URI('http://d2p2.pro/api/seqid')
request = Net::HTTP.post_form(uri, 'seqids' => '["P04637"]')
response = JSON.parse(request.body)

response['P04637'][0][2]['disorder']['disranges'].each do | record |
    puts record.join("\t")
end
            
#!/usr/bin/env R

library('rjson');

response = fromJSON(readLines('http://d2p2.pro/api/seqid/["P04637"]', warn=FALSE));

for (record in response$P04637[[1]][[3]]$disorder$disranges) { 
    print(paste(record,sep="\t"));
}
            
#/usr/bin/env php
<?php

$response = json_decode(file_get_contents('http://d2p2.pro/api/seqid/["P04637"]'),true);

foreach ($response['P04637'][0][2]['disorder']['disranges'] as $record) {
    echo implode("\t",$record);
    echo "\n";
}

?>
            

This Java example creates a class for requesting D2P2 data. I make use of Codehaus' Jackson high performance JSON parser. There is no trivial Java library for dealing with JSON, usually you have to define a full object oriented schema of the JSON to be vivified into full Java objects. However, you can ask Jackson to use a default schema which does something relatively sensible.

import org.codehaus.jackson.map.ObjectMapper;

import java.net.URL;
import java.net.MalformedURLException;
import java.net.URLConnection;
import java.io.*;
import java.util.*;

public class D2P2Request {
        
    private URL url = null;
    private URLConnection con = null;
    private Map results = null;
    
    public Map getResults() {
        return results;
    }

    public D2P2Request(ArrayList ids) {
        buildURL(ids);
        connect();
        parse();
    }

    public void buildURL(ArrayList ids) {
        StringBuilder built_url = new StringBuilder("http://d2p2.pro/api/seqid/[");
        for (String id: ids) {
            built_url.append("\"");
            built_url.append(id);
            built_url.append("\",");
        }
        built_url.replace(built_url.lastIndexOf(","), built_url.lastIndexOf(",") + 1, "]");

        try {
            this.url = new URL(built_url.toString());
        } catch (MalformedURLException e) {
            System.err.println("D2P2 request URL was malformed.");
            System.exit(1);
        }

    }

    public void connect () {
        try {
            this.con = this.url.openConnection();
            this.con.setDoInput(true);  
        } catch (IOException e) {
            System.err.println("Couldn't connect to the D2P2 service.");
            System.exit(1);
        }
    }

    public void parse () {
        ObjectMapper mapper = new ObjectMapper();
        try {
            this.results = mapper.readValue(this.con.getInputStream(), Map.class);
        } catch (IOException e) {
            System.err.println("The response from D2P2 couldn't be parsed by Jackson.");
            System.exit(1);
        }

        if (this.results.get("error") != null) {
            String error = (String) results.get("error");
            System.out.println("D2P2 reports error: "+error);
            System.exit(1);
        }
    }

    public static void main(String args[]) {

        //Specify the list of sequence IDs you wish to retreive assignments for
        ArrayList seqids = new ArrayList();
        seqids.add("P04637");

        //Construct a D2P2Request and get the results
        D2P2Request request = new D2P2Request(seqids);
        Map results = request.getResults();
        

        ArrayList matched_assignments = (ArrayList) results.get("P04637");
        ArrayList assignments = (ArrayList) matched_assignments.get(0);
        String id  = (String) assignments.get(0);
        String genome  = (String) assignments.get(1);
        Map assignment_types = (Map) assignments.get(2);
        Map disorder_assignments = (Map) assignment_types.get("disorder");
        ArrayList disorder_ranges = (ArrayList) disorder_assignments.get("disranges");
        System.out.println(disorder_ranges.get(0));

    }
}
            

If you wish to embed D2P2 data directly into your own web resource this can be acheived client side with something like the following JavaScript. I make extensive use of jQuery in this example, if you are using another JS framework please submit an equivalent example.

<!DOCTYPE html>
<html>
    <head>
        <!-- Use jQuery to make it easy to do a CORS AJAX request for the data from d2p2.pro-->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>
        //Make a CORS cross domain AJAX request
        $.getJSON('http://d2p2.pro/api/seqid/["P04637"]', function(data) {
          var records = [];
          //Build a set of table rows with the disordered region predictions
          $.each(data['P04637'][0][2]['disorder']['disranges'], function(key,val) {
            records.push('<tr id="' + key + '"><td>' + val[0] + '</td><td>' + val[1] + '&rarr;' + val[2] + '</td></tr>');
          });

          //Inject the records into the <body> tag inside a table with all the results
          //Change the appendTo('body') to any jQuery identifier for where you wish 
          //to inject the results in your website
          $('<table/>', {
            'class': 'disorder-ranges',
            html: records.join('')
          }).appendTo('body');
        }); 
        </script>
    </head>
    <body>
    </body>
</html>
            

The following are hints at how you might start using the D2P2 API with closed languages we can't fully support.

Mathematica

response = Import["http://d2p2.pro/api/seqid/['P04637']", "JSON"];