[MOBY-l] Moby Client Example
Martin Senger
senger at ebi.ac.uk
Fri May 5 21:23:47 UTC 2006
Hi,
You can write moby client in two ways. The general one - when you do
not need generated Java objects - was demonstrated by Eddie in his reply.
This is the second way:
In order to use it, you need to generate moby data types (more about it
in
Moses: http://biomoby.open-bio.org/CVS_CONTENT/moby-live/Java/docs/Moses.html). Or
ask me for details.
Once you have them, you can process a response with a method like this
(this is a real example that I have just put together - the whole code for
this command-line client is attached, and it is also part of jMoby
samples):
public boolean useResponse (MobyJob response,
MobyPackage responseContext)
throws MobyException {
MobyObject[] gff = response.getDataSet ("gff");
for (int i = 0; i < gff.length; i++) {
BasicGFFSequenceFeature feature = (BasicGFFSequenceFeature)gff[i];
System.out.println ("\n" + feature.getId() + "\t" +feature.getNamespace());
System.out.println ("Frame: " + feature.get_frame());
System.out.println ("Source: " + feature.get_source());
System.out.println ("Method: " + feature.get_method());
System.out.println ("Reference: " + feature.get_reference());
System.out.println ("Strand: " + feature.get_strand());
System.out.println ("Score: " + feature.getMoby_score().getValue());
System.out.println ("Start: " + feature.getMoby_start().getValue());
System.out.println ("Stop: " + feature.getMoby_stop().getValue());
multi_key_value_pair[] pairs = feature.getMoby_column9_tag_value();
for (int j = 0; j < pairs.length; j++) {
System.out.print (pairs[j].get_key());
String[] values = pairs[j].get_the_value();
for (int k = 0; k < values.length; k++)
System.out.print ("\t" + values[k]);
System.out.println();
}
}
return true;
}
The attached sample code calles service
"getInsertionsAsGFFByAGICode". For an AGI_LocusCode "At1g44446", the
method above prints something like this:
T-DNA_LB.T-DNA.SAIL_326_H02.v1 ATH_Insert_number
Frame: '.'
Source: 'AtiDB'
Method: 'variation'
Reference: 1
Strand: '.'
Score: 5
Start: 16853268
Stop: 16853269
'Insertion' T-DNA_LB.T-DNA.SAIL_326_H02.v1
T-DNA_LB.T-DNA.SAIL_1238_D01.v1 ATH_Insert_number
Frame: '.'
Source: 'AtiDB'
Method: 'variation'
Reference: 1
Strand: '.'
Score: 5
Start: 16852562
Stop: 16852563
'Insertion' T-DNA_LB.T-DNA.SAIL_1238_D01.v1
... and more
With regards,
Martin
--
Martin Senger
email: martin.senger at gmail.com
skype: martinsenger
-------------- next part --------------
// TestExtractGFF.java
//
// Created: May 2006
//
// This file is a component of the BioMoby project.
// Copyright Martin Senger (martin.senger at gmail.com).
//
package org.jmoby.tutorial.client;
import org.biomoby.client.BaseClient;
import org.biomoby.shared.MobyException;
import org.biomoby.shared.MobyService;
import org.biomoby.shared.parser.MobyPackage;
import org.biomoby.shared.parser.MobyJob;
import org.biomoby.shared.datatypes.MobyObject;
import org.biomoby.client.MobyServiceLocator;
import org.biomoby.shared.datatypes.*;
/**
* This is an example of a client. It calls a Biomoby service
* "getInsertionsAsGFFByAGICode" it uses generated data types and it
* benefits from various features provided by the BaseClient
* class. <p>
*
* @author <A HREF="mailto:martin.senger at gmail.com">Martin Senger</A>
* @version $Id: TestExtractGFF.java,v 1.1 2006/05/05 21:11:46 senger Exp $
*/
public class TestExtractGFF
extends BaseClient {
// from the command-line
String serviceEndpoint;
MobyObject input;
/**************************************************************************
* Constructor. It expects arguments: AGI_Locus_code [service-endpoint].
*************************************************************************/
public TestExtractGFF (String[] args) {
input = new MobyObject();
String agiLocusCode = "At1g44446";
if (args.length > 0)
agiLocusCode = args[0];
input.setId (agiLocusCode);
input.setNamespace ("AGI_LocusCode");
if (args.length > 1)
serviceEndpoint = args[1];
}
/**************************************************************************
*
*************************************************************************/
public MobyServiceLocator getServiceLocator()
throws MobyException {
MobyService service = new MobyService ("getInsertionsAsGFFByAGICode");
if (serviceEndpoint != null)
service.setURL (serviceEndpoint);
return new MobyServiceLocator (service);
}
/**************************************************************************
*
*************************************************************************/
public boolean fillRequest (MobyJob request, MobyPackage inputContext)
throws MobyException {
request.setData (input);
return true;
}
/**************************************************************************
*
*************************************************************************/
public boolean useResponse (MobyJob response,
MobyPackage responseContext)
throws MobyException {
MobyObject[] gff = response.getDataSet ("gff");
for (int i = 0; i < gff.length; i++) {
BasicGFFSequenceFeature feature = (BasicGFFSequenceFeature)gff[i];
System.out.println ("\n" + feature.getId() + "\t" + feature.getNamespace());
System.out.println ("Frame: " + feature.get_frame());
System.out.println ("Source: " + feature.get_source());
System.out.println ("Method: " + feature.get_method());
System.out.println ("Reference: " + feature.get_reference());
System.out.println ("Strand: " + feature.get_strand());
System.out.println ("Score: " + feature.getMoby_score().getValue());
System.out.println ("Start: " + feature.getMoby_start().getValue());
System.out.println ("Stop: " + feature.getMoby_stop().getValue());
multi_key_value_pair[] pairs = feature.getMoby_column9_tag_value();
for (int j = 0; j < pairs.length; j++) {
System.out.print (pairs[j].get_key());
String[] values = pairs[j].get_the_value();
for (int k = 0; k < values.length; k++)
System.out.print ("\t" + values[k]);
System.out.println();
}
}
return true;
}
/**************************************************************************
*
*************************************************************************/
public static void main (String [] args) {
if (args.length > 2) {
System.err.println ("Usage: java TestExtractGFF [<AGI_LocusCode> [<service-endpoint>]]\n");
System.exit (1);
}
TestExtractGFF client = new TestExtractGFF (args);
try {
client.process();
} catch (MobyException e) {
System.err.println (e.getMessage());
System.exit (1);
}
}
}
More information about the moby-l
mailing list