Various Web APIs for biology has been open to the public in the WABI(Web API for Biology). It is possible to access various databases and analysis program easily by using Web API. This tutorial introduces a way of using REST service in DDBJ.
  1. What service is available?
  2. How to access REST services?
    2. 1 Access with Perl
    2. 2 Access with Java
    2. 3 Access with C
    2. 4 Access with Ruby
    2. 5 Access with Python
    2. 6 Access with C#
  3. How do I call a method with parameters in multiple lines?
  4. How do I call a method with parameters including non alphanumeric character?
  5. How do I call a method with asynchronous?
  6. How do I call a method via a proxy server?
  7. Make workflow
    7. 1 With Perl
    7. 2 With Java
  8. REST and SOAP

1. What service is available?

The service list is in the "Available services" in the top page. The detailed information of each service can be retrieved by clicking on the links.

2. How to access REST services?

REST service can be used by not only web browser but also programming language such as Perl or Java. To access REST service, please specify the URL for REST [http://xml.nig.ac.jp/rest/Invoke], and following parameters.
service: Service name(required)
method: Method name(required)
parameters: parameters of a method you want to call(optional)

This system is recommended to use POST method. However GET method is also possible if the parameter length does not exceed the limit of GET method.
http://xml.nig.ac.jp/rest/Invoke?service=ServiceName&method=MethodName&param.....
Please click here if you have questions or proposals, etc.

2.1 Access with Perl

Jump to Active Perl Install guide: for Unix for Windows

Introduce a way of retrieval of a DDBJ entry. Specify accession number to get a DDBJ entry in the getDDBJEntry method of GetEntry. Followings are the examples using LWP and Socket. .
With LWP.
use LWP::UserAgent;
$ua = new LWP::UserAgent;

# make request
$req = new HTTP::Request POST => 'http://xml.ddbj.nig.ac.jp/rest/Invoke';
$req->content_type('application/x-www-form-urlencoded');
# set parameters
$req->content('service=GetEntry&method=getDDBJEntry&accession=AB000100');

# send request and get response.
$res = $ua->request($req);
# If you want to get a large result. It is better to write to a file directly.
# $res = $ua->request($req,'file_name.txt');

# show response.
print $res->content;
With socket.
use Socket;
use FileHandle;

# set hostname
$con_host = "xml.nig.ac.jp";
#set port number.
$con_port = 80;
#set service location
$path = "/rest/Invoke";
#set parameter.
$query = "service=GetEntry&method=getDDBJEntry&accession=AB000100";

$len = length($query);

# make socket
$ip = inet_aton($con_host) || die "host($con_host) not found.\n";
$sockaddr = pack_sockaddr_in($con_port, $ip);
socket(SOCKET, PF_INET, SOCK_STREAM, 0) || die "socket error.\n";

# make connection
connect(SOCKET, $sockaddr) || die "connect $con_host $con_port error.\n";
autoflush SOCKET (1);

# send http request.
print SOCKET "POST $path HTTP/1.0\n";
print SOCKET "User-Agent: perl/socket\n";
print SOCKET "Content-Type: application/x-www-form-urlencoded\n";
print SOCKET "Content-Length: $len\n\n";
print SOCKET $query."\n";

# show response.
while (chomp($buf=<SOCKET>)) {
  print "$buf\n";
}

# socket close
close(SOCKET);

2.2 Access with Java

Introduce a way of retrieval of a DDBJ entry. Specify accession number to get a DDBJ entry in the getDDBJEntry method of GetEntry. Followings are the examples using Socket and URLConnection.
With socket.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.net.URL;
import java.net.URLConnection;

public class Rest {

	public static void main(String[] args) throws IOException {
		Socket socket = null;
		//set hostname
		String addr = "xml.ddbj.nig.ac.jp";

		//set use port
		int port = 80;

		//set service path
		String path = "/rest/Invoke";
		//set parameter
		String query = "service=GetEntry&method=getDDBJEntry&accession=AB000100";

		//open socket
		socket = new Socket(addr, port);

		//send query
		BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		PrintStream pw = new PrintStream(socket.getOutputStream());
		pw.print("POST " + path + " HTTP/1.0\n");
		pw.print("Content-Type: application/x-www-form-urlencoded\n");
		pw.print("User-Agent: java/socket\n");
		pw.print("Content-Length:" + query.length() + "\n\n");
		pw.print(query);

		//get result
		String l = null;
		while ((l=br.readLine())!=null) {
			System.out.println(l);
		}
		pw.close();
		br.close();
	}
}
With URLConnection.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.net.URL;
import java.net.URLConnection;

public class Rest {

	public static void main(String[] args) throws IOException {
		//set URL
		URL url = new URL("http://xml.nig.ac.jp/rest/Invoke");

		//set parameter
		String query = "service=GetEntry&method=getDDBJEntry&accession=AB000100";

		//make connection
		URLConnection urlc = url.openConnection();

		//use post mode
		urlc.setDoOutput(true);
		urlc.setAllowUserInteraction(false);

		//send query
		PrintStream ps = new PrintStream(urlc.getOutputStream());
		ps.print(query);
		ps.close();

		//get result
		BufferedReader br = new BufferedReader(new InputStreamReader(urlc
				.getInputStream()));
		String l = null;
		while ((l=br.readLine())!=null) {
			System.out.println(l);
		}
		br.close();
	}
}
Please click here if you have questions or proposals, etc.

2.3 Access with C

Introduce a way of retrieval of a DDBJ entry. Specify accession number to get a DDBJ entry in the getDDBJEntry method of GetEntry. Following is an example using Socket.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/param.h>
#include <sys/uio.h>
#include <unistd.h>

#define BUF_LEN 256

int main(){
	int s;
	struct hostent *servhost;
	struct sockaddr_in server;
	struct servent *service;
	
	char send_buf[BUF_LEN];
	//host name
	char host[BUF_LEN] = "xml.nig.ac.jp";
	//path
	char path[BUF_LEN] = "/rest/Invoke";
	//port number
	unsigned short port = 80;
	char query[BUF_LEN] = "service=GetEntry&method=getDDBJEntry&accession=AB000100";
        
	//get IP adddres from host
	servhost = gethostbyname(host);
	bzero(&server, sizeof(server)); 

	server.sin_family = AF_INET;
	bcopy(servhost->h_addr, &server.sin_addr, servhost->h_length);
	server.sin_port = htons(port);

	//make socket
	s = socket(AF_INET, SOCK_STREAM, 0);

	//make connection
	connect(s, (struct sockaddr *)&server, sizeof(server));

	//send data
	sprintf(send_buf, "POST %s HTTP/1.0\n", path);
	write(s, send_buf, strlen(send_buf));

	sprintf(send_buf, "Host: %s:%d\n", host, port);
	write(s, send_buf, strlen(send_buf));

	sprintf(send_buf, "Content-Type: application/x-www-form-urlencoded\n");
	write(s, send_buf, strlen(send_buf));

	sprintf(send_buf, "User-Agent: c/socket\n");
	write(s, send_buf,strlen(send_buf));

	sprintf(send_buf, "Content-Length: %d \n\n", strlen(query));
	write(s, send_buf, strlen(send_buf));

	sprintf(send_buf, "%s", query);
	write(s, send_buf, strlen(send_buf));

	//get your result
	while (1){
	    char buf[BUF_LEN];
	    int read_size;
	    read_size = read(s, buf, BUF_LEN);
	    if ( read_size > 0 ){
	        write(1, buf, read_size);
	    } else {
	        break;
	    }
	}
	close(s);
	return 0;
}

2.4 Access with Ruby

Introduce a way of retrieval of a DDBJ entry. Specify accession number to get a DDBJ entry in the getDDBJEntry method of GetEntry. Following is an example using Socket.
require "socket"

#set hostname
host = "xml.nig.ac.jp"
#set port
port = "80"
#set pass
path = "/rest/Invoke"
#set query
query = "service=GetEntry&method=getDDBJEntry&accession=AB000100"

#make connection
socket = TCPSocket.open(host,port)

#send query
socket.write "POST "+ path + " HTTP/1.0\n"
socket.write "Content-Type: application/x-www-form-urlencoded\n"
socket.write "User-Agent: ruby/socket\n"
socket.write "Content-Length:" + query.size.to_s +  "\n\n"
socket.write query

#get result
while s=socket.gets
	print(s)
end
socket.close
Please click here if you have questions or proposals, etc.

2.5 Access with Python

Introduce a way of retrieval of a DDBJ entry. Specify accession number to get a DDBJ entry in the getDDBJEntry method of GetEntry. Following is an example using Socket.
import socket

#set server
host = "xml.nig.ac.jp"
port =  80

#set API server
url = "/rest/Invoke"

#set parameter
query = "service=GetEntry&method=getDDBJEntry&accession=AB000200"

#make connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
	sock.connect((host, port))
	sock.send("POST " + url + " HTTP/1.0\n")
	sock.send("Content-Type: application/x-www-form-urlencoded\n")
	sock.send("User-Agent: python/socket\n")
	sock.send("Content-Length:" + `len(query)` + "\n\n")
	sock.send(query)
except socket.error, e:
	print 'Error: %s' % e

while 1:
	rcvmsg = sock.recv(1024)
	print rcvmsg,
	if rcvmsg == '':
		break
sock.close

2.6 Access with C#

Introduce a way of retrieval of a DDBJ entry. Specify accession number to get a DDBJ entry in the getDDBJEntry method of GetEntry. Following is the example using Socket.
using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;

public class GetEntryREST{
	public static void Main(string[] args) {
		/* specify host, url, port number and parameter */
		string host = "xml.nig.ac.jp";
		string url = "/rest/Invoke";
		int port = 80;
		string query = "service=GetEntry&method=getDDBJEntry&accession=AB000200";
		
		/* Retrieve IP from host name*/
		IPHostEntry hostEntry = Dns.GetHostEntry(host);
		IPAddress address = hostEntry.AddressList[0];

		IPEndPoint ipe = new IPEndPoint(address, port);
	
		/* Make connection*/
		Socket socket  = 
			new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
		socket.Connect(ipe);

		string request = "POST " + url + " HTTP/1.0\n";
		request += "User-Agent: C#/socket\n";
		request += "Content-Type: application/x-www-form-urlencoded\n";
		request += "Content-Length:" + query.Length + "\n\n";
		request += query;

		Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
		Byte[] bytesReceived = new Byte[256];
		
		/*send query*/
		socket.Send(bytesSent, bytesSent.Length, 0);
		
		/* print result*/
		int bytes = 0;
		do{
			bytes = socket.Receive(bytesReceived, bytesReceived.Length, 0);
			Console.Write(Encoding.ASCII.GetString(bytesReceived, 0, bytes));
		}while (bytes > 0);

		socket.Close();
	}
}
Please click here if you have questions or proposals, etc.

3. How do I call a method with parameters in multiple lines?

If you want to call a method with parameter in multiple lines like query sequence in Blast or ClustalW, please specify line feed code as '\n' as follows.
query= "atgccagtcataaagttcttcgaagctaagtcgcttgtcgacgccgagaaggggaaagca\ngttgt...
If you use Perl, please enclose the query characters with not ['] but ["] as follows.
use LWP::UserAgent;
$ua = new LWP::UserAgent;

# make request
$req = new HTTP::Request POST => 'http://xml.ddbj.nig.ac.jp/rest/Invoke';
$req->content_type('application/x-www-form-urlencoded');
# set parameters
$query = "gtggcgagatcagttgttgtctctgcagaagccgtttactcccatgaaggcgaatacgta\n";
$query .= "ggcgatcacgttctagtagatgaggggcttgtaaagtccattagcagaggcgaacctcat\n";

$req->content("service=Blast&method=searchSimple&program=blastn&database=ddbjphg&query=$query");

# send request and get response.
$res = $ua->request($req);
# If you want to get a large result. It is better to write to a file directly.
# $res = $ua->request($req,'file_name.txt');

# show response.
print $res->content;

4. How do I call a method with parameters including non alphanumeric character?

If you want to call a method with parameters including non alphanumeric character like 'Homo sapiens', please encode it. The know-how is introduced in CookBook.
1. Encode query with Perl
2. Encode query with Java
3. Encode query with C
4. Encode query with C#
5. Encode query with Ruby
6. Encode query with Python

5. How do I call a method with asynchronous?

In general, the connection between client and server has to be keep established while the program is calling REST service. However it is also possible to call it asynchronously. You can make use of client resources efficiently by using asynchronous call. The name of asynchronous methods has a rule which ends with "Async" (e.g. Blast:searchSimpleAsync). Request ID is returned from asynchronous method. You can retrieve the result of asynchronous execution from RequestManager:getAsyncResult method with the request ID. The result can be retrieved for two months or less. Following example is a way of asynchronous execution.
Step 1. Call asynchronous service.
use LWP::UserAgent;
$ua = new LWP::UserAgent;

# make request
$req = new HTTP::Request POST => 'http://xml.ddbj.nig.ac.jp/rest/Invoke';
$req->content_type('application/x-www-form-urlencoded');
# set parameters
$query = "MSSRIARALALVVTLLHLTRLALSTCPAACHCPLEAPKCAPGVGLVRDGCGCCKVCAKQL";
$req->content("service=Blast&method=searchSimpleAsync&program=blastp&database=SWISS&query=$query");

# send request and get response.
$res = $ua->request($req);

# show response.
print $res->content;
Output is just "Request ID" and it is required to get the result.
Your requestId is:20090611092939466
To get a result, call RequestManager:getAsyncResult with your request ID (like 20070717144558241).

Step 2. Get a result.
use LWP::UserAgent;
$ua = new LWP::UserAgent;

# make request
$req = new HTTP::Request POST => 'http://xml.ddbj.nig.ac.jp/rest/Invoke';
$req->content_type('application/x-www-form-urlencoded');
# set parameters
$req->content('service=RequestManager&method=getAsyncResult&requestId=20090611092939466');

# send request and get response.
$res = $ua->request($req);

# show response.
print $res->content;
If your job has completed you will get the actual result of a service, otherwise you will just get the message "Your job has not been completed yet.".

6. How do I call a method via a proxy server?

A know-how about using proxy server is introduced in CookBook.
1 Access with Perl(LWP)
2 Access with Perl(Socket)
3 Access with Java(URLConnection)
4 Access with Java(Socket)
5 Access with C(Socket)
6 Access with Ruby(Socket)
7 Access with Python(Socket)
Please click here if you have questions or proposals, etc.

7. Make workflow

New workflow can be generated by combining public services. Workflow can be carried out a function which is not able to realize by a single service. Parser function which extract a part of result or edit a result may be required. There are many kinds of DNA data derived from many species in DDBJ. Therefore introduce a workflow which searches species which has similar human gene.

Web API used by this workflow: ARSA Blast GetEntry
Workflow input: The name of a human gene (example ABO, ALDH2, ACTA1)
Workflow output: Species name which has orthologue, its accession number and degree of similarity of sequence.
Flow:
  1. Search against DDBJ by the name of a human gene.
  2. Retrieve DNA sequence of top hit entry.
  3. Execute BLAST with DNA sequence.
  4. Get accession number and similarity score.
  5. Retrieve species name from accession number.
  6. Print result.
This tutorial introduces ways of both Perl and Java.

7.1. With Perl

Following code uses LWP. First of all, retrieve accession number list which has specified gene name by using searchByXMLPath of ARSA. Please click here for details of ARSA.
use LWP::UserAgent;
$ua = new LWP::UserAgent;

#set specified gene name
$gene = $ARGV[0];

# 1. Search DDBJ by using gene name
$request = new HTTP::Request POST => 'http://xml.ddbj.nig.ac.jp/rest/Invoke';
$request->content_type('application/x-www-form-urlencoded');

#target: Sequence length is bettween 300bp and 1000bp.
#        Feature key is CDS.
#        Gene qualifire is same as specified gene name.
$queryPath = "/ENTRY/DDBJ/division=='HUM' AND (/ENTRY/DDBJ/length>=300 AND /ENTRY/DDBJ/length<=1000) ";
$queryPath .= "AND (/ENTRY/DDBJ/feature-table/feature{/f_key = 'CDS' AND ";
$queryPath .= "/f_quals/qualifier{/q_name = 'gene' AND /q_value=='$gene'}})";

# set retrievable result as primari-accession.
$request->content("service=ARSA&method=searchByXMLPath&queryPath=$queryPath
		&returnPath=/ENTRY/DDBJ/primary-accession&offset=1&count=100");

$arsa_result = $ua->request($request)->content;
@arsa_result_lines = split(/\n/, $arsa_result);
$arsa_result_num = substr($arsa_result_lines[0], 18);
# If result is no hit, print message and exit.
if($arsa_result_num == 0) {
	print "There is no entry of $gene.";
	exit(0);
}

Retrieve DNA sequence of top hit entry by using getFASTA_DDBJEntry of GetEntry.
$rep_accession = $arsa_result_lines[2];
$request->content("service=GetEntry&method=getFASTA_DDBJEntry&accession=$rep_accession");
$dna_seq = $ua->request($request)->content;

Execute blastn by using searchParam of Blast with step2's sequence. Specified option is -e 0.0001 -m 8 -b 50 -v 50. It means "Extract top 50 hit which E-value is more than 0.0001.". The reference databases are specified as follows. ddbjpri(primates) ddbjrod(rodents) ddbjmam(mammals) ddbjvrt(vertebrates ) ddbjinv(invertebrates).
$request->content("service=Blast&method=searchParam&program=blastn&database=ddbjpri ddbjrod ddbjmam ddbjvrt
		 ddbjinv&query=$dna_seq&param=-m 8 -b 50 -v 50 -e 0.0001");
$blast_result = $ua->request($request)->content;

Extract both accession number and similarity score from BLAST result. This step does not use Web API and extract a part of result or edit a result. Please click here to see the details of each column in the BLAST tab delimited format which is generated by -m 8 option.
@blast_result_lines = split(/\n/, $blast_result);
@parsed_blast_result = ();
for($i = 0; $i < $#blast_result_lines; $i++) {
	$line = $blast_result_lines[$i];
	@cols = split(/\t/, $line);
	$accession = substr($cols[1], 0, index($cols[1], '|'));
	$parsed_blast_result[$i][0] = $accession;
	$parsed_blast_result[$i][1] = $cols[2];
}

Retrieve species name by using searchByXMLPath of ARSA. If the plural subjects whose species name are same are in the result, the highest similarity score is used.
%organism_accession = ();
for($i = 0; $i < $#parsed_blast_result; $i++) {
	$request->content("service=ARSA&method=searchByXMLPath&queryPath=/ENTRY/DDBJ/primary-accession==
		'$parsed_blast_result[$i][0]'&returnPath=/ENTRY/DDBJ/organism&offset=1&count=100");
	$organism = $ua->request($request)->content;
	@organism_lines = split(/\n/, $organism);
	$organism = $organism_lines[2];
	if(!defined($organism_accession{$organism})) {
		$organism_accession{$organism} = "$parsed_blast_result[$i][0]\t$parsed_blast_result[$i][1]";
	}
}

Print result.
print "DDBJ entries: $arsa_result_num\n";
print "Representative accession: $rep_accession\n";
print "Organism name\tDDBJ accession number\tSequence similarity\n";
foreach $key (sort keys %organism_accession) {
	print "$key\t$organism_accession{$key}\n";
}

How to execute workflow
Download program and unpack. Give gene name as argument. (Last update: Sep 11 2009)
perl WorkFlowExampleRest.pl ABO

DDBJ entries: 107
Representative accession: AY611640
Organism name   DDBJ accession number   Sequence simi
Cebus apella apella     FJ377683        94.94
Cebus apella paraguayanus       FJ377685        94.94
Cebus olivaceus FJ377691        95.30
Gorilla gorilla AY138476        98.98
Hylobates agilis        AB196683        97.69
Hylobates lar   AB196692        97.69
Macaca fascicularis     AF100981        95.79
Macaca fuscata  AB041528        95.92
Macaca mulatta  AF094693        95.95
Pan paniscus    AB041757        98.23
Pan troglodytes AY138471        98.55
Papio anubis    AF019417        96.38
Saguinus oedipus        AY091958        92.33

7.2. With Java

Following code uses URLConnection. First of all, make a method "getResult". This workflow accesses WABI's REST service by this method.
	/**
	 * Method for access REST
	 * @param query
	 * service name、method name and parameter for exection rest
	 * @return
	 * execution result
	 * @throws IOException
	 */
	private String getResult(String query) throws IOException {
		String baseURL = "http://xml.nig.ac.jp/rest/Invoke";
		URL url = new URL(baseURL);
		URLConnection urlc = url.openConnection();
		urlc.setDoOutput(true);
		urlc.setAllowUserInteraction(false);
		PrintStream ps = new PrintStream(urlc.getOutputStream());
		ps.print(query);
		ps.close();
		BufferedReader br = new BufferedReader(new InputStreamReader(urlc
				.getInputStream()));

		StringBuffer sb = new StringBuffer();
		String line = null;
		while ((line = br.readLine()) != null) {
			sb.append(line+"\n");
		}
		br.close();
		return sb.toString();
	}

Retrieve accession number list which has specified gene name from searchByXMLPath of ARSA. Please click here for details of ARSA.
	/*target: Sequence length is bettween 300bp and 1000bp.
        Feature key is CDS.
        Gene qualifire is same as specified gene name.*/
	String queryPath = "/ENTRY/DDBJ/division=='HUM' AND (/ENTRY/DDBJ/length>=300 AND "
			+ "/ENTRY/DDBJ/length<=1000) ";
	queryPath += "AND (/ENTRY/DDBJ/feature-table/feature{/f_key = 'CDS' AND ";
	queryPath += "/f_quals/qualifier{/q_name = 'gene' AND /q_value=='"+geneName+"'}})";
	String query = "service=ARSA&method=searchByXMLPath&queryPath="
			+ queryPath
			+ "&returnPath=/ENTRY/DDBJ/primary-accession&offset=1&count=100";
	//Execute ARSA
	String arsaResult = getResult(query);
	String[] arsaResultLines = arsaResult.split("\n");
	//Get hit count
	int arsaResultNum = Integer.parseInt(arsaResultLines[0].replaceAll(
			"hitscount       =", "").trim());
	//If there is no hit, print a message and exit
	if (arsaResultNum == 0) {
		System.out.println("There is no entry of $gene.");
		System.exit(0);
	}

Retrieve DNA sequence of top hit entry by using getFASTA_DDBJEntry of GetEntry.
	//Retrieve DNA sequence of first fit.
	String repAccession = arsaResultLines[2];
	query = "service=GetEntry&method=getFASTA_DDBJEntry&accession="
			+ repAccession;
	String dnaSeq = getResult(query);

Execute blastn by using searchParam of Blast with step2's sequence. Specified option is -e 0.0001 -m 8 -b 50 -v 50. It means "Extract top 50 hit which E-value is more than 0.0001.". The reference databases are specified as follows. ddbjpri(primates) ddbjrod(rodents) ddbjmam(mammals) ddbjvrt(vertebrates ) ddbjinv(invertebrates).
	//Execute blastn with step3's sequence
	query = "service=Blast&method=searchParam&program=blastn&database=ddbjpri ddbjrod ddbjmam ddbjvrt "
			+ "ddbjinv&query=" + dnaSeq + "&param=-m 8 -b 50 -v 50 -e 0.0001";
	String blastResult = getResult(query);

Extract both accession number and similarity score from BLAST result. This step does not use Web API and extract a part of result or edit a result. Please click here to see the details of each column in the BLAST tab delimited format which is generated by -m 8 option.
	String blastResultLines[] = blastResult.split("\n");
	Vector parsedBlastResult = new Vector();
	for (int i = 0; i < blastResultLines.length; i++) {
		String cols[] = blastResultLines[i].split("\t");
		String accession = cols[1].substring(0, cols[1].indexOf("|"));
		String[] result = { accession, cols[2] };
		parsedBlastResult.add(result);
	}

Retrieve species name by using searchByXMLPath of ARSA. If the plural subjects whose species name are same are in the result, the highest similarity score is used.
	//Retrieve species from accession number.
	Hashtable organismAccession = new Hashtable();
	for (int i = 0; i < parsedBlastResult.size(); i++) {
		String[] parsed = (String[]) parsedBlastResult.elementAt(i);
		query = "service=ARSA&method=searchByXMLPath&queryPath=/ENTRY/DDBJ/primary-accession=='"
				+ parsed[0]
				+ "'&returnPath=/ENTRY/DDBJ/organism&offset=1&count=100";
		String organism = getResult(query);
		String[] organismLines = organism.split("\n");
		organism = organismLines[2];
		//If same organism name hits, use first hit.
		if (!organismAccession.containsKey(organism)) {
			organismAccession.put(organism, parsed[0] + "\t" + parsed[1]);
		}
	}

Print result.
	// Print Result
	System.out.println("DDBJ entries: " + arsaResultNum);
	System.out.println("Representative accession: " + repAccession);
	System.out
			.println("Organism name\tDDBJ accession number\tSequence similarity");
	String[] keys = new String[organismAccession.size()];
	Enumeration enu = organismAccession.keys();
	int count = 0;
	while (enu.hasMoreElements()) {
		keys[count] = (String) enu.nextElement();
		++count;
	}
	Arrays.sort(keys);
	for (int i = 0; i < keys.length; i++) {
		System.out.println(keys[i] + "\t"
				+ (String) organismAccession.get(keys[i]));
	}

How to execute workflow
Download program and compile. Give gene name as argument. (Last update:Sep 11 2009)
javac WorkFlowExampleRest.java
java WorkFlowExampleRest ABO

DDBJ entries: 107
Representative accession: AY611640
Organism name   DDBJ accession number   Sequence simi
Cebus apella apella     FJ377683        94.94
Cebus apella paraguayanus       FJ377685        94.94
Cebus olivaceus FJ377691        95.30
Gorilla gorilla AY138476        98.98
Hylobates agilis        AB196683        97.69
Hylobates lar   AB196692        97.69
Macaca fascicularis     AF100981        95.79
Macaca fuscata  AB041528        95.92
Macaca mulatta  AF094693        95.95
Pan paniscus    AB041757        98.23
Pan troglodytes AY138471        98.55
Papio anubis    AF019417        96.38
Saguinus oedipus        AY091958        92.33

8. REST and SOAP

Web API for Biology (WABI) provides both SOAP and REST service. Click here for details.
Please click here if you have questions or proposals, etc.