[MOBY-l] help with MobyXMLObject...
Ken Steube
steube at sdsc.edu
Tue Dec 30 20:59:53 UTC 2003
I included a working example for your XML, but a little explanation is
required:
A MOBY object is
<myCLASS namespace='myNS' id='myID' articleName='myNAME'>myVALUE</myCLASS>
so a MobyXmlObject $mobj returns five values
$mobj->class() myCLASS
$mobj->namespace() myNS
$mobj->id() myID
$mobj->articleName() myNAME
$mobj->value() myVALUE
If myVALUE includes XML, then these are separate MOBY objects. You
need to use MobyXmlObject to access these additional MOBY objects using
the $mobj->getIncludedObjects() call, which returns a list of new
MobyXmlObject objects corresponding to the included objects.
This is demonstrated in the included example.
Ken
On Tue, 30 Dec 2003, Michael Jensen wrote:
> I am trying to put a few services together into one script, so taking
> the output of one to another. I can get a few working together, but the
> getGOTerm service output has me stuck. Here is the output from the
> simple script just running this service and trying to get some of
> return values by themselves:
>
> <?xml version='1.0' encoding='UTF-8'?>
> <moby:MOBY xmlns:moby='http://www.biomoby.org/moby'
> xmlns='http://www.biomoby.org/moby'>
> <moby:Response moby:authority='illuminae.com'>
>
> <moby:queryResponse moby:queryID=''>
> <moby:Simple articleName='GO_Term_From_ID'>
> <moby:GO_Term namespace='GO'
> id='GO:0004623'>
> <moby:String
> namespace='' id='' articleName='Term'>phospholipase A2
> activity</moby:String>
> <moby:String
> namespace='' id='' articleName='Definition'>Catalysis of the reaction:
> phosphatidylcholine + H2O = 1-acylglycerophosphocholine + a
> carboxylate.</moby:String>
> </moby:GO_Term></moby:Simple>
> </moby:queryResponse>
>
> </moby:Response>
> </moby:MOBY>
>
>
> Found an input Simple object:
> Class 'moby:GO_Term'
> xml_tag 'GO_Term'
> Namespace 'GO'
> ID 'GO:0004623'
> Name ''
> Value ''
>
>
> So I can get the articleName and even the GO:00004623 out of the
> various elements, but I can't figure out how to get the values of the
> Term and Definition from within the tags (phospholipase A2 activity).
> My code is as follows:
>
> #!/usr/bin/perl
> ##### put in 0004623 from the command line for it to run on
> something#######
>
> use MOBY::Client::Central;
> use MOBY::Client::Service;
> use MobyXmlObject;
>
> ################## getGOTerm ##################
>
> my $Central = MOBY::Client::Central->new();
>
> my ($Services, $REG) = $Central->findService(
> authURI => 'www.illuminae.com',
> serviceName => 'getGoTerm',
> );
> unless ($Services) { print "Discovery failed: ", $REG->message;
> exit(1); }
>
> my $svc = $Services->[0];
> print "Executing service ", $svc->name, "\n", $svc->description, "\n\n";
> my $wsdl = $Central->retrieveService($svc);
> my $S = MOBY::Client::Service->new(service => $wsdl);
>
> my $result;
> foreach my $goterm(@ARGV) {
> $result = $S->execute(
> XMLinputlist => [ ['', qq{<Object namespace="go" id="$goterm"/>}]
> ]
> ) || 'No result';
> print $result, "\n";
> }
>
> my @simples = MobyXmlObject->getMobySimples($result);
> my @go_list;
>
> foreach my $s (@simples) {
> my $class = $s->class();
> my $namespace = $s->namespace();
> my $id = $s->id();
> my $name = $s->articleName();
> my $value = $s->valueTrimmed();
> my $xml_tag = $s->xml_tag();
> print qq{
> Found an input Simple object:
> Class '$class'
> xml_tag '$xml_tag'
> Namespace '$namespace'
> ID '$id'
> Name '$name'
> Value '$value'
> };
> }
>
> Note to run it you should pass in 0004623 or another go id.
>
> Any help would be greatly appreciated!
>
> THANKS!
>
> -Michael Jensen
> mdjgf8 at mizzou.edu
>
>
> _______________________________________________
> moby-l mailing list
> moby-l at biomoby.org
> http://biomoby.org/mailman/listinfo/moby-l
>
--
-------------------------------------
Ken Steube steube at sdsc.edu
San Diego Supercomputer Center @ UCSD
San Diego, California USA
-------------- next part --------------
use MobyXmlObject;
my $query = qq{<?xml version='1.0' encoding='UTF-8'?>
<moby:MOBY xmlns:moby='http://www.biomoby.org/moby' xmlns='http://www.biomoby.org/moby'>
<moby:Response moby:authority='illuminae.com'>
<moby:queryResponse moby:queryID=''>
<moby:Simple articleName='GO_Term_From_ID'>
<moby:GO_Term namespace='GO' id='GO:0004623'>
<moby:String namespace='' id='' articleName='Term'>phospholipase A2 activity</moby:String>
<moby:String namespace='' id='' articleName='Definition'>Catalysis of the reaction: phosphatidylcholine + H2O = 1-acylglycerophosphocholine + a carboxylate.</moby:String>
</moby:GO_Term>
</moby:Simple>
</moby:queryResponse>
</moby:Response>
</moby:MOBY>
};
my @simples = MobyXmlObject->getMobySimples($query);
foreach my $s (@simples) {
my ($class, $ns, $id) = ($s->class(), $s->namespace(), $s->id());
print "class=$class,ns=$ns,id=$id\n";
print " Included MOBY objects:\n";
foreach my $inc ($s->getIncludedObjects()) {
my $class = $inc->class();
my $name = $inc->articleName();
my $value = $inc->valueTrimmed();
print " class=$class,name=$name,value=$value\n"; next;
}
}
More information about the moby-l
mailing list