Difference between revisions of "Annotator Dataset Workflow Howto"

From NCBO Wiki
Jump to navigation Jump to search
(Undo revision 10255 by Palexand (Talk))
Line 48: Line 48:
 
<li>After the files are generated, they will need to be concatenated together. Additionally, the MGREP server will need to be restarted.</li>
 
<li>After the files are generated, they will need to be concatenated together. Additionally, the MGREP server will need to be restarted.</li>
 
</ul>
 
</ul>
 +
 +
  
 
== Mapping Data Population ==
 
== Mapping Data Population ==
 
<p>Mappings between ontologies can be used in the Annotator to find related terms. Loading the mapping information is currently a manual process, though this will be automated in the future. If you have mapping data you would like to include in annotator, please <a href="mailto:support@bioontology.org">contact NCBO</a>.</p>
 
<p>Mappings between ontologies can be used in the Annotator to find related terms. Loading the mapping information is currently a manual process, though this will be automated in the future. If you have mapping data you would like to include in annotator, please <a href="mailto:support@bioontology.org">contact NCBO</a>.</p>
 +
 +
== Chapter 2: Data Population - Concepts and Hierarchy ==
 +
<p><b>Introduction:</b> OBS application pulls the ontology and the concept data from BioPortal via BioPortal REST services, then extracts and computes the hierarchy information then stores in OBS Database.  Then this computed data is accessible via OBS REST services. The BioPortal REST URL is specified in <b>build.properties</b>.</p>
 +
<pre>
 +
bp.url.base= http://rest.bioontology.org
 +
</pre>
 +
<p>Data population is divided into two parts – 1. Concepts and 2. Hierarchy.  Please see below for the details.</p>
 +
 +
=== Concepts  and Direct Relation (level = 1) ===
 +
==== Pre-requisite in "status": ====
 +
<p>The ontology should be in valid status (<font color="red"><b>"status = 3"</b></font>) in obs_ontology table in OBS Database to start this process (i.e. This is the initial status from BioPortal when ontology is successfully parsed). This is also serves as a safety lock to avoid launching population again for the ontologies already in the process of population or already populated.</p>
 +
 +
==== Restlet calls available: ====
 +
<ol>
 +
<li>For all ontologies: populate all ontologies with valid status ("status = 3") in OBS DB<br/>
 +
<code>http://ncbodev-obs:8080/obs_hibernate/loaderBigConcepts/all</code></li>
 +
<li>For a specific ontology : populate the given ontology if "status = 3". Otherwise the data population process will complain that the status is invalid in the tomcat log and exit.<br/>
 +
<code>http://ncbodev-obs:8080/obs_hibernate/loaderBigConcepts/{ontology_versoin_id}</code></li>
 +
</ol>
 +
 +
==== Error Handling: ====
 +
<p>The error is logged both in tomcat catalina.out and DB (obs_error_queue table).</p>
 +
<ol>
 +
<li><b>Case 1: BioPortal REST Service is Down</b>
 +
<p>When you kick off the process (OBS Restlet call - either via web browser or shell script), it checks first if BioPortal REST service is alive. If the BioPortal REST service is down – the tomcat log will generate an error message about BioPortal REST service being down (But it does not change the ontology "status" field.  Just simply kick off the process again when BioPortal REST service is back up. If BioPortal REST service is down, no change in OBS database, therefore no need to clean up. See "Error Handling" for the "status" change scenario).</p></li>
 +
 +
<li><b>Case 2: Critical Error</b>
 +
<p>If the error is critical – RunTimeException and etc – the "status" the ontology in obs_ontology table becomes "99" and the data population process halt.</p></li>
 +
 +
<li><b>Case 3: Non-critical Error</b>
 +
<p>If the error is not critical, the "status" the ontology in obs_ontology table becomes "99" but the data population process still continues to populate the rest of the data.  An example for a non-critical error is a discrepancy between the data from two different BioPortal Restlet calls – i.e. Some of the root concepts from getRootConcepts call are missing in BioPortal (The list of concepts from getAllConcepts does not have some of the root concepts).</p></li>
 +
</ol>
 +
<p>In the case of case 2 & 3, data clean up may be necessary. Please see "3. Monitoring the Progress: Error Handling".</p>
 +
 +
 +
 +
=== Indirect Relation Hierarchy (level > 1) ===
 +
==== Pre-requisite in "status": ====
 +
<p>The ontology should be in valid status (<font color="red"><b>"status = 14"</b></font>) in obs_ontology table in OBS Database to start this process (i.e.  "loaderBigConcepts" should have been completed for the given ontology). This is a safety lock to avoid launching population again for the ontologies already in the process of population or already populated.</p>
 +
 +
==== Pre-requisite in configuration: ====
 +
<p>Tomcat should be configured to run the stored procedures via JDBC. Please refer to Appendix C. (Tomcat - pre-requisite).</p>
 +
 +
==== Restlet calls available: ====
 +
<ol>
 +
<li>For all ontologies:  populate all ontologies with "status = 14"<br/>
 +
<code>http://ncbodev-obs:8080/obs_hibernate/loaderBigPaths/all</code></li>
 +
<li>B. For a specific ontology :  populate the given ontology if "status = 14".  Otherwise the data population process will complain that the status is invalid in the tomcat log and exit.<br/>
 +
<code>http://ncbodev-obs:8080/obs_hibernate/loaderBigPaths/{ontology_version_id}<br/>
 +
e.g. http://ncbodev-obs:8080/obs_hibernate/loaderBigPaths/40671</code></li>
 +
</ol>
 +
 +
=== Monitoring the progress ===
 +
<p>To monitor the progress, please see "status" field in obs_ontology table.</p>
 +
<table cellpadding="5" cellspacing="1">
 +
<tr bgcolor="#aaaaaa">
 +
<th>Restlets</th>
 +
<th>Status Required (valid status required to begin the process)</th>
 +
<th>Status Start -> Finish</th>
 +
</tr>
 +
<tr bgcolor="#eeeeee">
 +
<td>loaderBigConcepts</td>
 +
<td>3</td>
 +
<td>11 -> 14</td>
 +
</tr>
 +
<tr bgcolor="#eeeeee">
 +
<td>loaderBigPaths</td>
 +
<td>14</td>
 +
<td>21 -> 28</td>
 +
</tr>
 +
<tr bgcolor="#eeeeee">
 +
<td> </td>
 +
<td> </td>
 +
<td>(status value in obs_ontology table changes as progress continues)</td>
 +
</tr>
 +
</table>
 +
 +
==== Error Handling: ====
 +
<ul>
 +
<li>If there is any <font color="red"><b>error</b></font>, the status will be set to <font color="red"><b>99</b></font></li>
 +
<li>If critical error (e.g. BioPortal REST services down) occurs, the population process will stop and exit. But if it is NOT a critical error (e.g. if the semantic type description is not found from semantic look up table etc), it will mark the status to 99, log the error (both Tomcat log and DB obs_error_queue), but continue with the population.</li>
 +
<li>To restart the process, just run the script to clean up. The script will reset the status either to "3" or "14" depending on Concept clean up or Hierarchy clean up. (See Section II. Data Clean up)</li>
 +
</ul>
 +
 +
== Chapter 3: Data Clean up ==
 +
<p>Src is located in <b>obs_hibernate/db/sql/obs_db_cleanup.sql</b> – DO NOT RUN the entire script since this is just compiled list of commands.</p>
 +
 +
<pre>
 +
/*
 +
-----------------------------------------------------------------------
 +
to clean up or undo everything on one ontology, just run #1 and #2
 +
-----------------------------------------------------------------------
 +
1. Rollback BPConceptManager.
 +
Run this to rollback to initial state - to undo 'loaderConcepts' restlet
 +
*/
 +
 +
set @var_ontology_version_id := '39545';
 +
 +
 +
delete a.* from obs_relation a, obs_concept b, obs_ontology c
 +
where a.level = 1 and a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id;
 +
 +
delete a.* from obs_term a, obs_concept b, obs_ontology c
 +
where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id;
 +
 +
delete a.* from obs_semantic_type a, obs_concept b,  obs_ontology c 
 +
where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id;
 +
 +
delete a.* from obs_concept a, obs_ontology b
 +
where a.ontology_id = b.id and b.local_ontology_id = @var_ontology_version_id;
 +
 +
UPDATE obs_ontology set status = 3 where local_ontology_id = @var_ontology_version_id;
 +
 +
/*
 +
-----------------------------------------------------------------------
 +
2. Rollback BPPathManager.
 +
Run this to rollback - to undo 'loaderPaths' restlet 
 +
*/
 +
 +
set @var_ontology_version_id := '39545';
 +
 +
delete a.* from obs_relation a, obs_concept b, obs_ontology c
 +
where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id and a.level > 1;
 +
 +
delete a.* from obs_path_to_root a, obs_concept b, obs_ontology c
 +
where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id;
 +
 +
delete a.* from obs_path_to_leaf a, obs_concept b, obs_ontology c
 +
where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id;
 +
 +
UPDATE obs_ontology set status = 14 where local_ontology_id = @var_ontology_version_id;
 +
</pre>
 +
 +
 +
 +
== Appendix A: HTML TEST pages ==
 +
<code>
 +
http://ncbodev-obs:8080/test_obs.html  (OBS)<br/>
 +
http://ncbodev-obs:8080/test_oba.html (Annotator)
 +
</code>
 +
<p>For Annotator User Guide, please refer to:<br/>
 +
<code>
 +
http://www.bioontology.org/wiki/index.php/Annotator_User_Guide
 +
</code>
 +
 +
 +
== Appendix B: Useful SQL Queries for Monitoring and Validation ==
 +
Src is located in <b>obs_hibernate/db/sql/obs_db_cleanup.sql</b> (In the same script in the DB Clean up)
 +
 +
=== Number of concepts for a specific Ontology ===
 +
<pre>
 +
select count(*) from obs_concept a, obs_ontology b
 +
where a.ontology_id = b.id and b.local_ontology_id = '40261';
 +
</pre>
 +
 +
=== Number of total relations or path_to_root/leaf for a specific ontology (to see the progress) – by looking at how fast the number is growing ===
 +
<pre>
 +
select count(*) from obs_relation a, obs_concept b, obs_ontology c
 +
  where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = '40133' and a.level > 1;
 +
 +
select a.*, b.local_concept_id from obs_path_to_root a, obs_concept b, obs_ontology c
 +
where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = '40483';
 +
</pre>
 +
 +
=== Ontologies that have the status "Ready" (28) but have no concepts in obs_concept table ===
 +
<pre>
 +
SELECT o.*, c.ontology_id
 +
FROM obs_ontology o
 +
LEFT OUTER JOIN (
 +
    SELECT DISTINCT ontology_id FROM obs_concept
 +
) c ON o.id = c.ontology_id
 +
WHERE o.status = 28 AND c.ontology_id IS NULL;
 +
</pre>

Revision as of 14:35, 22 October 2010

Synchronize Ontology Data with Ontology Services

The ontologies and related data that will be used with the Annotator is gathered from the Ontology Services (part of BioPortal Core). This process should be run any time a new ontology (or a new version of an existing ontology) is added to the Ontology Services, though it could theoretically be run from a cron script or scheduled job.

  1. Remove out-dated ontologies from Annotator Database (e.g. older version of ontologies that does not in BioPortal anymore). By invoking this restlet, it will remove all the outdated ontology data and the associated entities such as concepts, terms, relations, semantic types and hierarchy information.

    See the list of ontologies/versions to be removed: http://ncbobioportal/obs/admin/ontologies/list/old
    Remove old ontologies: http://ncbobioportal/obs/admin/ontologies/remove

  2. Add new ontologies from BioPortal to Annotator. By invoking this restlet, it will add all the new ontology data and the associated entities such as concepts, terms, relations, semantic types and hierarchy information.

    See the list of ontologies/versions to be added: http://ncbobioportal/obs/admin/ontologies/list/new
    Add new ontologies: http://ncbobioportal/obs/admin/ontologies/add

  3. Populate Concepts (For details, please refer to Chapter 2.1)

    http://ncbobioportal/obs/loaderBigConcepts/all

  4. Populate Hierarchy (For details, please refer to Chapter 2.2)

    http://ncbobioportal/obs/loaderBigPaths/all

    To monitor the progress and view any errors, refer to:

    1. The "status" field in the table obs_ontology in Annotator DB (obs_hibernate database).
    2. Check the Tomcat log (/var/logs/tomcat6/catalina.out)

Create Dictionary File

All the terms will be created as dictionary file. (Data is coming from the obs_term table)

  • Location : The directory location is specified in build.properties
  • # Dictionary File path
    obs.dictionary.path=/usr/local/tomcat6/webapps/annotator/WEB-INF/resources/dictionary/
    
  • The dictionary file is generated in several chunks to avoid memory problems. There is a 1,000,000 term limit per file.
  • Generate the dictionary file:
  • http://ncbobioportal/obs/createDictionary/0
    
  • After the files are generated, they will need to be concatenated together. Additionally, the MGREP server will need to be restarted.


Mapping Data Population

Mappings between ontologies can be used in the Annotator to find related terms. Loading the mapping information is currently a manual process, though this will be automated in the future. If you have mapping data you would like to include in annotator, please <a href="mailto:support@bioontology.org">contact NCBO</a>.

Chapter 2: Data Population - Concepts and Hierarchy

Introduction: OBS application pulls the ontology and the concept data from BioPortal via BioPortal REST services, then extracts and computes the hierarchy information then stores in OBS Database. Then this computed data is accessible via OBS REST services. The BioPortal REST URL is specified in build.properties.

bp.url.base= http://rest.bioontology.org

Data population is divided into two parts – 1. Concepts and 2. Hierarchy. Please see below for the details.

Concepts and Direct Relation (level = 1)

Pre-requisite in "status":

The ontology should be in valid status ("status = 3") in obs_ontology table in OBS Database to start this process (i.e. This is the initial status from BioPortal when ontology is successfully parsed). This is also serves as a safety lock to avoid launching population again for the ontologies already in the process of population or already populated.

Restlet calls available:

  1. For all ontologies: populate all ontologies with valid status ("status = 3") in OBS DB
    http://ncbodev-obs:8080/obs_hibernate/loaderBigConcepts/all
  2. For a specific ontology : populate the given ontology if "status = 3". Otherwise the data population process will complain that the status is invalid in the tomcat log and exit.
    http://ncbodev-obs:8080/obs_hibernate/loaderBigConcepts/{ontology_versoin_id}

Error Handling:

The error is logged both in tomcat catalina.out and DB (obs_error_queue table).

  1. Case 1: BioPortal REST Service is Down

    When you kick off the process (OBS Restlet call - either via web browser or shell script), it checks first if BioPortal REST service is alive. If the BioPortal REST service is down – the tomcat log will generate an error message about BioPortal REST service being down (But it does not change the ontology "status" field. Just simply kick off the process again when BioPortal REST service is back up. If BioPortal REST service is down, no change in OBS database, therefore no need to clean up. See "Error Handling" for the "status" change scenario).

  2. Case 2: Critical Error

    If the error is critical – RunTimeException and etc – the "status" the ontology in obs_ontology table becomes "99" and the data population process halt.

  3. Case 3: Non-critical Error

    If the error is not critical, the "status" the ontology in obs_ontology table becomes "99" but the data population process still continues to populate the rest of the data. An example for a non-critical error is a discrepancy between the data from two different BioPortal Restlet calls – i.e. Some of the root concepts from getRootConcepts call are missing in BioPortal (The list of concepts from getAllConcepts does not have some of the root concepts).

In the case of case 2 & 3, data clean up may be necessary. Please see "3. Monitoring the Progress: Error Handling".


Indirect Relation Hierarchy (level > 1)

Pre-requisite in "status":

The ontology should be in valid status ("status = 14") in obs_ontology table in OBS Database to start this process (i.e. "loaderBigConcepts" should have been completed for the given ontology). This is a safety lock to avoid launching population again for the ontologies already in the process of population or already populated.

Pre-requisite in configuration:

Tomcat should be configured to run the stored procedures via JDBC. Please refer to Appendix C. (Tomcat - pre-requisite).

Restlet calls available:

  1. For all ontologies: populate all ontologies with "status = 14"
    http://ncbodev-obs:8080/obs_hibernate/loaderBigPaths/all
  2. B. For a specific ontology : populate the given ontology if "status = 14". Otherwise the data population process will complain that the status is invalid in the tomcat log and exit.
    http://ncbodev-obs:8080/obs_hibernate/loaderBigPaths/{ontology_version_id}
    e.g. http://ncbodev-obs:8080/obs_hibernate/loaderBigPaths/40671

Monitoring the progress

To monitor the progress, please see "status" field in obs_ontology table.

Restlets Status Required (valid status required to begin the process) Status Start -> Finish
loaderBigConcepts 3 11 -> 14
loaderBigPaths 14 21 -> 28
(status value in obs_ontology table changes as progress continues)

Error Handling:

  • If there is any error, the status will be set to 99
  • If critical error (e.g. BioPortal REST services down) occurs, the population process will stop and exit. But if it is NOT a critical error (e.g. if the semantic type description is not found from semantic look up table etc), it will mark the status to 99, log the error (both Tomcat log and DB obs_error_queue), but continue with the population.
  • To restart the process, just run the script to clean up. The script will reset the status either to "3" or "14" depending on Concept clean up or Hierarchy clean up. (See Section II. Data Clean up)

Chapter 3: Data Clean up

Src is located in obs_hibernate/db/sql/obs_db_cleanup.sql – DO NOT RUN the entire script since this is just compiled list of commands.

/* 
	----------------------------------------------------------------------- 
 	to clean up or undo everything on one ontology, just run #1 and #2	
 	-----------------------------------------------------------------------
 	1. Rollback BPConceptManager. 											
 	Run this to rollback to initial state - to undo 'loaderConcepts' restlet	
*/

set @var_ontology_version_id := '39545'; 


delete a.* from obs_relation a, obs_concept b, obs_ontology c 
	where a.level = 1 and a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id;

delete a.* from obs_term a, obs_concept b, obs_ontology c 
	where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id;
	
delete a.* from obs_semantic_type a, obs_concept b,  obs_ontology c   
	where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id;

delete a.* from obs_concept a, obs_ontology b
	where a.ontology_id = b.id and b.local_ontology_id = @var_ontology_version_id;
	
UPDATE obs_ontology set status = 3 where local_ontology_id = @var_ontology_version_id;

/* 
	----------------------------------------------------------------------- 	
 	2. Rollback BPPathManager. 											
 	Run this to rollback - to undo 'loaderPaths' restlet  		 			
*/

set @var_ontology_version_id := '39545'; 

delete a.* from obs_relation a, obs_concept b, obs_ontology c 
	where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id and a.level > 1;
	
delete a.* from obs_path_to_root a, obs_concept b, obs_ontology c 
	where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id;
	
delete a.* from obs_path_to_leaf a, obs_concept b, obs_ontology c 
	where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = @var_ontology_version_id;
	
UPDATE obs_ontology set status = 14 where local_ontology_id = @var_ontology_version_id;		


Appendix A: HTML TEST pages

http://ncbodev-obs:8080/test_obs.html (OBS)
http://ncbodev-obs:8080/test_oba.html (Annotator)

For Annotator User Guide, please refer to:
http://www.bioontology.org/wiki/index.php/Annotator_User_Guide

Appendix B: Useful SQL Queries for Monitoring and Validation

Src is located in obs_hibernate/db/sql/obs_db_cleanup.sql (In the same script in the DB Clean up)

Number of concepts for a specific Ontology

select count(*) from obs_concept a, obs_ontology b
	where a.ontology_id = b.id and b.local_ontology_id = '40261';

Number of total relations or path_to_root/leaf for a specific ontology (to see the progress) – by looking at how fast the number is growing

	
select count(*) from obs_relation a, obs_concept b, obs_ontology c
  where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = '40133' and a.level > 1;

select a.*, b.local_concept_id from obs_path_to_root a, obs_concept b, obs_ontology c 
	where a.concept_id = b.id and b.ontology_id = c.id and c.local_ontology_id = '40483';

Ontologies that have the status "Ready" (28) but have no concepts in obs_concept table

SELECT o.*, c.ontology_id
FROM obs_ontology o
LEFT OUTER JOIN (
    SELECT DISTINCT ontology_id FROM obs_concept
) c ON o.id = c.ontology_id
WHERE o.status = 28 AND c.ontology_id IS NULL;