CaCORE

 view release on metacpan or  search on metacpan

examples/caBIOtest.pl  view on Meta::CPAN


# test CaBIO 5: throttle mechanism
# 
# The ApplicationService->query method is provides a mechanism to allow you to control
# the size of the resultset.
# In this test, we only retrieve 20 genes starting from number 10.
# 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 beyong 1000, you must use ApplicationService->query
#
print "test CaBIO 5: throttle search: return 20 gene objects starting from position 10.\n";
my @geneSet;
eval{
	#
	# this call is similar to that of test1, except the query method has added 2 more parameters
	# Parameter 1 indicates target class, Chromosome, to be retrieved
	# Parameter 2 indicates search criteria. In this case, is the genes associated with the chromosome.
	# Paremeter 3 indicates the requested start index
	# Parameter 4 indicates the requested size
	#
	@geneSet = $appsvc->query("CaCORE::CaBIO::Gene", $chromo1, 10, 20);
};
warn "Test CaBIO 5 failed. Error:\n" . $@ if $@;
foreach my $gne (@geneSet) {
	print "Gene: id= " . $gne->getId;
	if( defined($gne->getSymbol) ) { print "  symbol=" . $gne->getSymbol . "\n"; }
	else { print "\n"; }
}
my $num2 = $#geneSet + 1;
print "number of result: " . $num2 . "\n";

# test CaBIO 6: time data type
#
# The search criteria is a date type, the CaCORE server is rather picky on the format
# The format should be: yyyy-mm-ddTzz:00:00:000Z
#	yyyy - year
#	mm - month
#	dd - day of month
#	zz - time zone
#
print "test CaBIO 6: testing ClinicalTrialProtocol with date type criteria\n";
my $ctp = new CaCORE::CaBIO::ClinicalTrialProtocol;
$ctp->setCurrentStatusDate("2004-03-12T05:00:00.000Z");
my @ctps;
eval{
	@ctps = $appsvc->queryObject("CaCORE::CaBIO::ClinicalTrialProtocol", $ctp);
};
warn "Test CaBIO 6 failed. Error:\n" . $@ if $@;
foreach my $a (@ctps){
	if ($a->getId){ 
		print "ClinicalTrialProtocol id= " . $a->getId . "\n";

	}
}
# test CaBIO 7: Query by Big Id
#
print "test CaBIO 1: query by Big Id\n";

# instantiate a SecurityToken domain object and sets the value of symbol attribute to NAT2.
$gene = new CaCORE::CaBIO::Gene;
$gene->setBigid("hdl://2500.1.PMEUQUCCL5/ONSXKL4KEL");

# 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 "Chromosome id=" . $chromo->getId . " number=" . $chromo->getNumber . "\n";
}


print "Test completed.\n";




( run in 1.744 second using v1.01-cache-2.11-cpan-97f6503c9c8 )