# Presentation: 498395

## Using a caCORE-like System

## Using a caCORE-like System

**Metadata Reuse**

**Create UML Model**

**Semantic Annotation**

**Transform UML Model into Metadata**

**SDK Code Generation**

**Compatibility Review**

**Create a Node on the Grid**

**Notes:**
Session III we cover

caGrid Node Installation (prerequsite)
Data Service Deployment on caGrid
Using caGrid data service API
Using caGrid Metadata APIs

## Using a caCORE-like System

**In this Lesson, we will cover:**
- How to use caCORE-like system’s Java API:
- Using ApplicationService interface
**There will be an exercise showing how an instance of gridPIR (a caCORE-like system) is queried using the ApplicationService interface.**

## Outline	

- Introduction to query/search concept in caCORE-like systems
- Programmatic Access to caCORE-like System
- Java API: The ApplicationService interface
- Exercise

## Introduction to  query/search mechanism in caCORE-like systems

- Employs an **object-in/object-out** mechanism
- Uses **query-by-example (QBE) **format**:** the inputs to the query methods are themselves domain objects and they provide the criteria for the query
- Allows traversal of the UML model
- Basic order of operation:
**Ensure** that the client application has **knowledge of the objects** in the information model
**Formulate** **the** **query criteria** using the domain objects
- Submit the query objects to the server and **specify** the **desired class of objects to be returned**
- Use and **manipulate the result set** as desired

**Notes:**
QBE dates back to 70s developed by IBM.

## ApplicationService Interface

**Nested searches:** One or more **criteria objects from the domain model** but determine the type of objects in the result set by **traversing a known path of associations** from the domain model
**Detached criteria searches:** **Hibernate detached criteria objects** to provide a greater level of control over the results of a search (such as Boolean operations etc.)
**Hibernate Query Language (HQL) searches:** HQL for the greatest flexibility in forming search criteria
**caBIG® Query Language (CQL) searches**

## ApplicationService Interface

**Invoke methods**
- getApplicationService() : ApplicationService
- getApplicationService(username :String, password :String) : ApplicationService
- getApplicationServiceFromUrl(url :String, username :String, password :String) : ApplicationService
**Query/Search methods**
- getQueryRowCount(criteria :Object, targetClassName :String):Integer
- search(targetClass :Class, objList :List<?>) : List<Object>
- search(targetClass :Class, obj :Object) : List<Object>
- search(path :String, objList :List<?>) : List<Object>
- search(path :String, obj :Object) : List<Object>
- query(detachedCriteria :DetachedCriteria, targetClassName :String) : List<Object>
- query(detachedCriteria :DetachedCriteria) : List<Object>
- query(hqlCriteria :HQLCriteria, targetClassName :String) : List<Object>
- query(hqlCriteria :HQLCriteria) : List<Object>
- query(cqlQuery :CQLQuery, targetClassName :String) : List<Object>
- query(cqlQuery :CQLQuery) : List<Object>

**Notes:**
Uses Java.util.List
Uses Java.lang.String

Allows invoking CQL/HQL queries

## ApplicationService Example 0 : Creating a service instance

- Create a remote ApplicationService instance
- //URL for remote gridPIR instance (production)
- String serviceURL="http://141.161.25.20:8080/gridPIR”;
- //Create the instance
- ApplicationService appService = ApplicationServiceProvider. *getApplicationServiceFromUrl*(serviceURL);

## Find Gene objects for gene name starting with "BRCA“:

Gene gene = new Gene();
//set criteria
gene.setName(“BRCA*”);

//invoke query using List search(Class targetClass, Object criteriaObject) 
List resultList = appService.search(Gene.class, gene);

//process results
for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {
	Gene returnedGene = (Gene) resultsIterator.next();
	//print attribute of returned Gene...

- Gene gene = new Gene();
- //set criteria
- gene.setName(“BRCA*”);
- //invoke query using List search(Class targetClass, Object criteriaObject)
- List resultList = appService.search(Gene.class, gene);
- //process results
- for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {
- 	Gene returnedGene = (Gene) resultsIterator.next();
- 	//print attribute of returned Gene...

**ApplicationService Example 1 : Query where search criteria and target from the same class**

## ApplicationService Example 1 : Query where search criteria and target from the same class

- Results**:**

## Find Protein objects for Breast cancer 1 gene (BRCA1):

Gene gene = new Gene();
//set criteria
gene.setName(“BRCA1”);							
//invoke query
List resultList = appService.search(Protein.class, gene);

//process results
for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {    Protein returnedProtein = (Protein) resultsIterator.next();...

- Gene gene = new Gene();
- //set criteria
- gene.setName(“BRCA1”);
- //invoke query
- List resultList = appService.search(Protein.class, gene);
- //process results
- for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {    Protein returnedProtein = (Protein) resultsIterator.next();...

**ApplicationService Example 2 : Query involving two associated classes**

**Notes:**
We set the criteria here by creating a Gene object with name “BRCA1”

Knowing the association between “Gene” and “Protein” classes, we use this traversal path and set target class as “Protein”.

This could be impossible if “association” did not exist.

## ApplicationService Example 2 : Query involving two associated classes

- Results**:**

## ApplicationService Example 2 : Query involving two associated classes

- Results include BRCA1 from “African clawed frog”, “Green puffer” and many more
- What if we want to restrict it to Human BRCA1?

## Find Protein objects for  
   Human Breast cancer 1 (BRCA1)

Gene gene = new Gene();
//set first criteria
gene.setName(“BRCA1”);
List geneCollection=new ArrayList();
geneCollection.add(gene);

//set second criteria				
Organism organism = new Organism();
organism.setScientificName(“Homo Sapiens”);
List organismCollection=new ArrayList();
organismCollection.add(organism);

-    _Human_ Breast cancer 1 (BRCA1)
- Gene gene = new Gene();
- //set first criteria
- gene.setName(“BRCA1”);
- List geneCollection=new ArrayList();
- geneCollection.add(gene);
- //set second criteria
- Organism organism = new Organism();
- organism.setScientificName(“Homo Sapiens”);
- List organismCollection=new ArrayList();
- organismCollection.add(organism);

**ApplicationService Example 3 : Query involving three classes**

## Find Protein objects for 
   Human BRCA1 (cont’d)		

// initialize protein object
Protein protein=new Protein();
protein.setGeneCollection(geneCollection);
protein.setOrganismCollection(organismCollection);

//invoke query
List resultList = appService.search(Protein.class, protein);

//process results
for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) { Protein returnedProtein = (Protein) resultsIterator.next();

-    _Human _BRCA1 (cont’d)
- // initialize protein object
- Protein protein=new Protein();
- protein.setGeneCollection(geneCollection);
- protein.setOrganismCollection(organismCollection);
- //invoke query
- List resultList = appService.search(Protein.class, protein);
- //process results
- for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) { Protein returnedProtein = (Protein) resultsIterator.next();

**ApplicationService Example 3 : Query involving three classes**

## ApplicationService Example 3 : Query involving two associated classes

- From Example 2, results include BRCA1 from “African clawed frog”, “Green puffer” and many more
- Is there a way to find what other organisms has homologs for BRCA1?

## Find Organism objects for gene BRCA1

//set criteria
Gene gene = new Gene();
gene.setName(“BRCA1”);	

//how do you get from Gene to Organism
String classPath=
	"edu.georgetown.pir.domain.Organism," + "edu.georgetown.pir.domain.Protein“);		
//invoke query
List resultList = appService.search(classPath, gene);
//process results
for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();){ 
	Organism returnedOrganism = (Organism) resultsIterator.next();		

- //set criteria
- Gene gene = new Gene();
- gene.setName(“BRCA1”);
- //how do you get from Gene to Organism
- String classPath=
- 	"edu.georgetown.pir.domain.Organism," + "edu.georgetown.pir.domain.Protein“);
- //invoke query
- List resultList = appService.search(classPath, gene);
- //process results
- for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();){
- 	Organism returnedOrganism = (Organism) resultsIterator.next();

**ApplicationService Example 4 : Query a information space traversal path **

## ApplicationService Example 4 : Query a information space traversal path 

- Results**:**

## Additional Information

- caCORE SDK Web Site:
- _[http://ncicb.nci.nih.gov/infrastructure/cacoresdk](http://ncicb.nci.nih.gov/infrastructure/cacoresdk)_

## Exercise

- Query a gridPIR instance using instructions located at:
- 	_[https://gforge.nci.nih.gov/docman/view.php/470/16575/08_Using_caCORE_like_system.doc](https://gforge.nci.nih.gov/docman/view.php/470/16575/08_Using_caCORE_like_system.doc)_