The core function of CaCOREperl is to provide an object based search capability to obtain caCORE server-hosted domain object data. It answers questions such as "How do I retrieve all chromosomes whose genes with a symbol of 'NAT2'"? In a typical search scenario, you start with certain information, usually some attributes of a certain domain object, and you want to find the domain objects that have these attributes, in addition, you want to look for other domain objects that are associated with these domain objects with the said attributes.
A search operation results in a remote webservice invocation to the caCORE server. The known information from the source object, such as a gene with symbol name "NAT2", is converted into request XML, and passed to the caCORE server. The caCORE server would parse the request, generate an internal query, and return the result in a response XML format. CaCOREperl then parses the response, and convert it into the target objects(s). Thus, CaCOREperl users only deal with domain objects, and do not have to deal with webservice request/response, and XML manipulations.
Use the getX method to retrieve associated object X with many-to-one relationships.
# search by association: many to one
my $chromo1 = $chromos[0];
print "start chromosome id=" . $chromo1->getId . "\n";
my $taxon = $chromo1->getTaxon;
print "find taxon: id= " . $taxon->getId . " scientificName=" . $taxon->getScientificName ."\n";
Use the getXCollection method to retrieve a list of associated object X with one-to-many relationships.
# test 3: use association: one to many
my @genes = $chromo1->getGeneCollection;
foreach my $gn (@genes) {
print "Gene: id= " . $gn->getId . " symbol=" . $gn->getSymbol . "\n";
}
my $num = $#genes + 1;
print "number of result: " . $num . "\n";
Note: these methods utlizes the ApplicationService->queryObject() method. The caCORE server automatically trims the result set to 1000. More detail in the subsequent discussion.
ApplicationService is a utility class 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 instance
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/cacore32/ws/caCOREService". The ApplicationService class exposes two methods:
queryObject and query for search. The ApplicationService is the fundamental class that all other search
methods utilize.
The following methods are supported in CaCORE::ApplicationService:
Description of parameters used in the above functions:
This following example retrieves all Chromosomes whose associated genes have a symbol of "NAT2" using the direct and basic search function of ApplicationService->queryObject(). This queryObject() function 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 gene associated with the chromosome.
use CaCORE::ApplicationService;
use CaCORE::CaBIO;
my $gene = new CaCORE::CaBIO::Gene;
$gene->setSymbol("NAT2");
my $appsvc = CaCORE::ApplicationService->
instance("http://cabio.nci.nih.gov/cacore32/ws/caCOREService");
my @chromos = $appsvc->queryObject("CaCORE::CaBIO::Chromosome", $gene);
The first parameter in the search method can be constructed as a "navigation path" that reflects how these objects are related to the target object. This example retrieves all the Taxons related to the Chromosomes that are related to a Gene object:
my @taxons = $appsvc->queryObject("CaCORE::CaBIO::Taxon,CaCORE::CaBIO::Chromosome", $gene);
foreach my $tx (@taxons){
print "id= " . $tx->getId . " scientificName=" . $tx->getScientificName ."\n";
}
Depending on the search criteria, a search may yield a large result set, which cause slower response time and increase the likelihood of failure. A throttle mechanism is provided by:
ApplicationService->query(targetClassName, knownSourceObject, startingIndex, requestedSize)
In the following example:
my @geneSet = $appsvc->query("CaCORE::CaBIO::Gene", $chromo1, 10, 20);
Note: By default, when calling ApplicationService->queryObject, the caCORE server automatically trim the resultset to 1000 objects if the there more than 1000. So in reality, if you want to retrieve anything beyond 1000, you must use ApplicationService->query.