Explorar o código

added template for the organism references, anf fixed obo loader when missing default namespace

Stephen Ficklin %!s(int64=11) %!d(string=hai) anos
pai
achega
24cf39f91b

+ 4 - 4
tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc

@@ -17,9 +17,9 @@
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_modify_template_base_form($form_state = NULL, $mode) {
+function tripal_bulk_loader_modify_template_base_form(&$form_state = NULL, $mode) {
   $form = array();
-
+  
    // get template id from path and rebuild form
   if ($_GET['template_id']) {
     if (preg_match('/^\d+$/', $_GET['template_id'])) {
@@ -570,7 +570,7 @@ function tripal_bulk_loader_delete_template_base_form_submit($form, &$form_state
  *
  * @ingroup tripal_bulk_loader
  */
-function tripal_bulk_loader_import_export_template_form($form_state = NULL, $mode) {
+function tripal_bulk_loader_import_export_template_form(&$form_state = NULL, $mode) {
   $form = array();
 
   $form['mode'] = array(
@@ -687,6 +687,7 @@ function tripal_bulk_loader_import_export_template_form_submit($form, &$form_sta
 function tripal_bulk_loader_edit_template_record_form(&$form_state = NULL) {
   $form['#cache'] = TRUE; // Make sure the form is cached.
 
+
    // get template id from path
   $template_id = ($_GET['template_id'] !== NULL) ? $_GET['template_id'] : $form_state['values']['template_id'];
 
@@ -1595,7 +1596,6 @@ function tripal_bulk_loader_add_template_field_form_validate($form, $form_state)
       form_set_error('record_name', "New Record Name must be unique. '" . $form_state['values']['record_name'] . "' is not unique.");
     }
   }
-
 }
 
 /**

+ 37 - 8
tripal_cv/includes/obo_loader.inc

@@ -313,13 +313,37 @@ function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
   // parse the obo file
   $default_db = tripal_cv_obo_parse($file, $header, $jobid);
 
-  // add the CV for this ontology to the database
-  $defaultcv = tripal_cv_add_cv($header['default-namespace'][0], '');
-  if (!$defaultcv) {
-    tripal_cv_obo_quiterror('Cannot add namespace ' . $header['default-namespace'][0]);
+  // add the CV for this ontology to the database.  The v1.2 definition
+  // specifies a 'default-namespace' to be used if a 'namespace' is not
+  // present for each stanza.  Some ontologies have adopted the v1.4 method
+  // in their v1.2 files and not including it.
+  if (array_key_exists('default-namespace', $header)) {
+    $defaultcv = tripal_cv_add_cv($header['default-namespace'][0], '');
+    if (!$defaultcv) {
+      tripal_cv_obo_quiterror('Cannot add namespace ' . $header['default-namespace'][0]);
+    }
+    $newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;
   }
-  $newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;
-
+  // if the 'default-namespace' is missing
+  else {
+    
+    // look to see if an 'ontology' key is present.  It is part of the v1.4 
+    // specification so it shouldn't be in the file, but just in case
+    if (array_key_exists('ontology', $header)) {
+      $defaultcv = tripal_cv_add_cv(strtoupper($header['ontology'][0]), '');
+      if (!$defaultcv) {
+        tripal_cv_obo_quiterror('Cannot add namespace ' . strtoupper($header['ontology'][0]));
+      }
+      $newcvs[strtoupper(strtoupper($header['ontology'][0]))] = $defaultcv->cv_id;
+    }
+    else {
+      $defaultcv = tripal_cv_add_cv('_global', '');
+      $newcvs['_global'] = $defaultcv->cv_id;
+    }
+    watchdog('t_obo_loader', "This OBO is missing the 'default-namespace' header. It is not possible to determine which vocabulary terms without a 'namespace' key should go.  Instead, those terms will be placed in the '%vocab' vocabulary.", 
+      array('%vocab' => $defaultcv->name), WATCHDOG_WARNING);
+  }
+  
   // add any typedefs to the vocabulary first
   print "\nStep 2: Loading type defs...\n"; 
   tripal_cv_obo_load_typedefs($defaultcv, $newcvs, $default_db, $jobid);
@@ -465,7 +489,12 @@ function tripal_cv_obo_process_terms($defaultcv, $jobid = NULL, &$newcvs, $defau
  * @ingroup tripal_obo_loader
  */
 function tripal_cv_obo_process_term($term, $defaultcv, $is_relationship = 0, &$newcvs, $default_db) {
- 
+
+  // make sure we have a namespace for this term
+  if (!array_key_exists('namespace', $term) and !($defaultcv or $defaultcv == '')) {
+    tripal_cv_obo_quiterror("Cannot add the term: no namespace defined. " . $term['id'][0]);
+  }
+  
   // construct the term array for sending to the tripal_cv_add_cvterm function
   // for adding a new cvterm
   $t = array(); 
@@ -482,7 +511,7 @@ function tripal_cv_obo_process_term($term, $defaultcv, $is_relationship = 0, &$n
   }
   if (array_key_exists('is_obsolete', $term)) {
     $t['is_obsolete'] = $term['is_obsolete'][0];
-  } 
+  }
   
   // add the cvterm
   $cvterm = tripal_cv_add_cvterm($t, $defaultcv, $is_relationship, 1, $default_db); 

+ 4 - 0
tripal_organism/tripal_organism.module

@@ -149,6 +149,10 @@ function tripal_organism_theme() {
       'arguments' =>  array(NULL),
       'path' => drupal_get_path('module', 'tripal_organism') . '/theme'
     ),
+    'tripal_organism_references' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_organism_references',
+    ),
   );
 }
 /**