CaCORE
view release on metacpan or search on metacpan
examples/caBIOtest.pl view on Meta::CPAN
#!/usr/bin/perl -w
# works with Axis 1.2
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use CaCORE::ApplicationService;
use CaCORE::CaBIO;
use CaCORE::Security;
use CaCORE::CaDSR;
#
# ApplicationService is a utility classs that encapsulates webservice invocation to caCORE server.
# ApplicationService object follows the Singleton pattern, in that each program will ONLY contain one instance
# of such class.
# The URL being passed to the intance method is the service endpoint of the caCORE webservice.
# If no such URL is provided in the program, it will default to the caCORE production server, "http://cabio.nci.nih.gov/cacore30/ws/caCOREService"
#
my $appsvc = CaCORE::ApplicationService->instance("http://cabio.nci.nih.gov/cacore32/ws/caCOREService");
# test CaBIO 1: use ApplicationService
#
# This test retrieves all Chromosomes whoses associated genes have a symbol of "NAT2" using the direct
# and basic search function of ApplicationService->queryObject
#
print "test CaBIO 1: use ApplicationService to search Gene given a gene symbol attribute\n";
# instantiate a Gene domain object and sets the value of symbol attribute to NAT2.
my $gene = new CaCORE::CaBIO::Gene;
$gene->setSymbol("NAT2");
my @chromos;
# the eval...warn... construct is recommended, if error is encountered during webservice call, this will
# trap the exception and allows for error handling, and prevent the program from exiting.
eval{
#
# This call encapsulates the webservice invocation to the caCORE server, and converts
# the returned XML into list of Chromosome objects
# Parameter 1 indicates target class, Chromosome, to be retrieved
# Parameter 2 indicates search criteria. In this case, is the genes associated with the chromosome.
#
@chromos = $appsvc->queryObject("CaCORE::CaBIO::Chromosome", $gene);
};
warn "Test CaBIO 1 failed. Error:\n" . $@ if $@; # some exception handling
# iterate thru results
foreach my $chromo (@chromos){
print "id= " . $chromo->getId . " number=" . $chromo->getNumber . "\n";
}
# test CaBIO 2: use association: many to one
#
# This test retrieves the Taxon object that is associated with a Chromosome object via a get method
#
print "test CaBIO 2: navigation by association: many to one\n";
print "\tSearch for the associated taxon given a chromosome object.\n";
# Our starting point is a chromosome object obtained from test 1
my $chromo1 = $chromos[0];
print "start chromosome id=" . $chromo1->getId . "\n";
my $taxon;
eval{
#
# The Taxon is associated with Chromosome via a one to many relationship
# i.e., one taxon is associated with many chromosomes
# The Chromosome->getTaxon is implemented as a ApplicationService->queryObject as in test 1
( run in 0.971 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )