Răsfoiți Sursa

Tripal CV now matches Drupal coding standards

Lacey Sanderson 12 ani în urmă
părinte
comite
b17e6167f0

+ 111 - 99
tripal_cv/charts.php

@@ -1,11 +1,15 @@
 <?php
 
+/**
+ * @file
+ * Tripal API for generating a Google Chart of count data
+ */
 
 /**
  * Generates JSON used for generating a Google chart of count data associated
  * with a controlled vocabulary.  An example would be features assigned to
- * Gene Ontology terms. 
- * 
+ * Gene Ontology terms.
+ *
  * To generate a chart, the progammer must first create a materialized view that
  * will generate count data for a given controlled vocabulary.  For example, the Tripal
  * Analysis GO creates a materialized view for counting Gene Ontology assignments
@@ -18,23 +22,23 @@
  *  tripal_[module_name]_cv_chart_[unique id]
  *
  * where [module_name] is the name of the tripal module (e.g. tripal_analyisis_go)
- * and [unique id] is some unique identifier that the contolling module 
+ * and [unique id] is some unique identifier that the contolling module
  * recognizes. This string is the $chart_id variable passed as the first argument
- * to the function.  For example, the Tripal GO Analysis module generates 
+ * to the function.  For example, the Tripal GO Analysis module generates
  * chart ids of the form:
- * 
+ *
  *  tripal_analysis_go_cv_chart_10_2_bp
- * 
+ *
  * In this case the module that will manage this chart is identified as 'tripal_analysis_go' and within
  * the [unique id] portion contains the
- * organism_id (e.g. 10), analysis_id (e.g. 2) and chart type (bp = biological process). 
+ * organism_id (e.g. 10), analysis_id (e.g. 2) and chart type (bp = biological process).
  *
  * Second, the programmer must then define a hook in the controlling module for setting
  * some options used to build the chart.  The hook has the form:  hook_cv_chart($chart_id).
  * This hook should accept the full $chart_id as the single parameter.  For the Tripal
- * Analysis GO module the hook is named:  tripal_analysis_go_cv_chart.  
+ * Analysis GO module the hook is named:  tripal_analysis_go_cv_chart.
  *
- * The array returned by this hook must have the following fields:  
+ * The array returned by this hook must have the following fields:
  *  - count_mview
  *      the name of the materialized view that contains the count data
  *      this materialized view must have at least two columns, one with the cvterm_id
@@ -53,37 +57,37 @@
  *  - type
  *      the type of chart to create (see Google Charts documenation). Leave
  *      blank for a pie chart.
- *  - size 
- *      the dimensions of the chart in pixels (see Google Charts documenations 
+ *  - size
+ *      the dimensions of the chart in pixels (see Google Charts documenations
  *      for exact size limitations).
  *
  * Example from the tripal_analysis_go module:
  * @code
- *  function tripal_analysis_go_cv_chart($chart_id){
- *  
+ *  function tripal_analysis_go_cv_chart($chart_id) {
+ *
  *    // The CV module will create the JSON array necessary for buillding a
  *    // pie chart using jgChart and Google Charts.  We have to pass to it
- *    // a table that contains count information, tell it which column 
+ *    // a table that contains count information, tell it which column
  *    // contains the cvterm_id and provide a filter for getting the
  *    // results we want from the table.
  *    $organism_id = preg_replace("/^tripal_analysis_go_cv_chart_(\d+)-(\d+)_(bp|cc|mf)$/","$1",$chart_id);
  *    $analysis_id = preg_replace("/^tripal_analysis_go_cv_chart_(\d+)-(\d+)_(bp|cc|mf)$/","$2",$chart_id);
  *    $type        = preg_replace("/^tripal_analysis_go_cv_chart_(\d+)-(\d+)_(bp|cc|mf)$/","$3",$chart_id);
- *  
+ *
  *    $sql = "SELECT * FROM {Analysis} WHERE analysis_id = %d";
  *    $previous_db = tripal_db_set_active('chado');  // use chado database
  *    $analysis = db_fetch_object(db_query($sql,$analysis_id));
- *    tripal_db_set_active($previous_db);  // now use drupal database  
- *   
- *    if(strcmp($type,'mf')==0){
+ *    tripal_db_set_active($previous_db);  // now use drupal database
+ *
+ *    if (strcmp($type,'mf')==0) {
  *       $class = 'molecular_function';
  *       $title = "Number of Molecular Function Terms From $analysis->name Analysis";
  *    }
- *    if(strcmp($type,'cc')==0){
+ *    if (strcmp($type,'cc')==0) {
  *       $class = 'cellular_component';
  *       $title = "Number of Cellular Component Terms From $analysis->name Analysis";
  *    }
- *    if(strcmp($type,'bp')==0){
+ *    if (strcmp($type,'bp')==0) {
  *       $class = 'biological_process';
  *       $title = "Number of Biological Process Terms From $analysis->name Analysis";
  *    }
@@ -92,14 +96,14 @@
  *       cvterm_id_column => 'cvterm_id',
  *       count_column     => 'feature_count',
  *       filter           => "
- *          CNT.organism_id = $organism_id AND 
- *          CNT.analysis_id = $analysis_id AND 
- *          CNT.cvterm_id IN ( 
- *            SELECT CVTR.subject_id 
- *            FROM {CVTerm_relationship} CVTR 
+ *          CNT.organism_id = $organism_id AND
+ *          CNT.analysis_id = $analysis_id AND
+ *          CNT.cvterm_id IN (
+ *            SELECT CVTR.subject_id
+ *            FROM {CVTerm_relationship} CVTR
  *              INNER JOIN CVTerm CVT on CVTR.object_id = CVT.cvterm_id
  *              INNER JOIN CV on CVT.cv_id = CV.cv_id
- *            WHERE CVT.name = '$class' AND  
+ *            WHERE CVT.name = '$class' AND
  *                   CV.name = '$class'
  *          )
  *       ",
@@ -123,19 +127,26 @@
  *
  * @ingroup tripal_cv
  */
-function tripal_cv_chart($chart_id){
-  // parse out the tripal module name from the chart_id to find out 
+function tripal_cv_chart($chart_id) {
+  // parse out the tripal module name from the chart_id to find out
   // which Tripal "hook" to call:
-  $tripal_mod = preg_replace("/^(tripal_.+?)_cv_chart_(.+)$/","$1",$chart_id);
+  $tripal_mod = preg_replace("/^(tripal_.+?)_cv_chart_(.+)$/", "$1", $chart_id);
   $callback = $tripal_mod . "_cv_chart";
 
   // now call the function in the module responsible for the chart to fill out
   // an options array needed by the tripal_cv_count_chart call below.
-  $opt = call_user_func_array($callback,array($chart_id));
+  $opt = call_user_func_array($callback, array($chart_id));
 
   // build the JSON array to return to the javascript caller
-  $json_arr = tripal_cv_count_chart($opt[count_mview],$opt[cvterm_id_column],
-     $opt[count_column],$opt[filter],$opt[title], $opt[type],$opt[size]);
+  $json_arr = tripal_cv_count_chart(
+    $opt['count_mview'],
+    $opt['cvterm_id_column'],
+    $opt['count_column'],
+    $opt['filter'],
+    $opt['title'],
+    $opt['type'],
+    $opt['size']
+  );
   $json_arr[] = $chart_id;  // add the chart_id back into the json array
 
   return drupal_json($json_arr);
@@ -154,7 +165,7 @@ function tripal_cv_chart($chart_id){
   *   two columns, one with the cvterm_id for each term, and a second
   *   column with the count (i.e. features assigned the term).
   * @param $fk_column
-  *   This is the name of the column in the $cnt_table that holds the 
+  *   This is the name of the column in the $cnt_table that holds the
   *   cvterm_id for each term.
   * @param $cnt_column
   *   The name of the column in the $cnt_table containing the counts
@@ -170,80 +181,81 @@ function tripal_cv_chart($chart_id){
   *   The size in pixels of the chart to be rendered. Default is 300x75. The
   *   size of the chart is constrained by Google charts.  See the Google
   *   chart documentation for exact limitations.
-  *  
-  * @return 
+  *
+  * @return
   *   An array that has the settings needed for Google Charts to creat the chart.
   *
   * @ingroup tripal_cv
   */
 function tripal_cv_count_chart($cnt_table, $fk_column,
-   $cnt_column, $filter = null, $title = '', $type = 'p3', $size='300x75') {
+  $cnt_column, $filter = NULL, $title = '', $type = 'p3', $size='300x75') {
+
+  if (!$type) {
+    $type = 'p3';
+  }
+
+  if (!$size) {
+    $size = '300x75';
+  }
+
+  if (!$filter) {
+    $filter = '(1=1)';
+  }
 
-   if(!$type){
-      $type = 'p3';
-   }
+  $is_pie = 0;
+  if (strcmp($type, 'p') == 0 or strcmp($type, 'p3') == 0) {
+    $is_pie = 1;
+  }
+  $sql = "
+    SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items
+    FROM {$cnt_table} CNT
+     INNER JOIN {cvterm} CVT on CNT.$fk_column = CVT.cvterm_id
+    WHERE $filter
+  ";
 
-   if(!$size){
-     $size = '300x75';
-   }
+  $features = array();
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $results = db_query($sql);
+  tripal_db_set_active($previous_db);  // now use drupal database
+  $data = array();
+  $axis = array();
+  $legend = array();
+  $total = 0;
+  $max = 0;
+  $i = 1;
+  while ($term = db_fetch_object($results)) {
 
-   if(!$filter){
-      $filter = '(1=1)'; 
-   }
+    if ($is_pie) {
+      $axis[] = "$term->name (" . number_format($term->num_items) . ")";
+      $data[] = array($term->num_items, 0, 0);
+    }
+    else {
+      $axis[] = "$term->name (" . number_format($term->num_items) . ")";
+      $data[] = array($term->num_items);
+      //$legend[] = "$term->name (" . number_format($term->num_items) . ")";
+    }
+    if ($term->num_items > $max) {
+      $max = $term->num_items;
+    }
+    $total += $term->num_items;
+    $i++;
+  }
+  // convert numerical values into percentages
+  foreach ($data as &$set) {
+    $set[0] = ($set[0] / $total) * 100;
+  }
+  $opt[] = array(
+    data => $data,
+    axis_labels => $axis,
+    legend => $legend,
+    size => $size,
+    type => $type,
 
-   $isPie = 0;
-   if(strcmp($type,'p')==0 or strcmp($type,'p3')==0){
-      $isPie = 1;
-   }
-   $sql = "
-      SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items
-      FROM {$cnt_table} CNT 
-       INNER JOIN {cvterm} CVT on CNT.$fk_column = CVT.cvterm_id 
-      WHERE $filter
-   ";    
+    bar_width     => 10,
+    bar_spacing   => 0,
+    title         => $title
+  );
+  //   $opt[] = $sql;
 
-   $features = array();
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $results = db_query($sql);
-   tripal_db_set_active($previous_db);  // now use drupal database
-   $data = array();
-   $axis = array();
-   $legend = array();
-   $total = 0;
-   $max = 0;
-   $i = 1;
-   while($term = db_fetch_object($results)){
-      
-      if($isPie){
-         $axis[] = "$term->name (".number_format($term->num_items).")";
-         $data[] = array($term->num_items,0,0);
-      } else {
-         $axis[] = "$term->name (".number_format($term->num_items).")";
-         $data[] = array($term->num_items);
-    //     $legend[] = "$term->name (".number_format($term->num_items).")";
-      }
-      if($term->num_items > $max){
-         $max = $term->num_items;
-      }
-      $total += $term->num_items;
-      $i++;
-   }
-   // convert numerical values into percentages
-   foreach($data as &$set){
-      $set[0] = ($set[0] / $total) * 100;
-   }
-   $opt[] = array(
-      data => $data,
-      axis_labels => $axis, 
-      legend => $legend,
-      size => $size, 
-      type => $type,
- 
-      bar_width     => 10, 
-      bar_spacing   => 0, 
-      title         => $title
-   );
-//   $opt[] = $sql;
-   
-   return $opt;
+  return $opt;
 }

+ 843 - 792
tripal_cv/obo_loader.php

@@ -1,866 +1,917 @@
 <?php
 
-/** 
+/**
+ * @file
+ * Tripal Ontology Loader
+ *
  * @defgroup tripal_obo_loader Tripal Ontology Loader
  * @ingroup tripal_cv
  */
- 
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_load_obo_v1_2_id($obo_id,$jobid = NULL){
-
-   // get the OBO reference
-   $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = %d";
-   $obo = db_fetch_object(db_query($sql,$obo_id));
-
-   // if the reference is for a remote URL then run the URL processing function
-   if(preg_match("/^http:\/\//",$obo->path) or preg_match("/^ftp:\/\//",$obo->path)){
-      tripal_cv_load_obo_v1_2_url($obo->name,$obo->path,$jobid,0);
-   } 
-   // if the reference is for a local file then run the file processing function
-   else {
-      // check to see if the file is located local to Drupal
-      $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $obo->path; 
-      if(file_exists($dfile)){
-         tripal_cv_load_obo_v1_2_file($obo->name,$dfile,$jobid,0);
-      } 
-      // if not local to Drupal, the file must be someplace else, just use
-      // the full path provided
-      else{
-         if(file_exists($obo->path)){
-            tripal_cv_load_obo_v1_2_file($obo->name,$obo->path,$jobid,0);
-         } else {
-            print "ERROR: counld not find OBO file: '$obo->path'\n";
-         }
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_load_obo_v1_2_id($obo_id, $jobid = NULL) {
+
+  // get the OBO reference
+  $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = %d";
+  $obo = db_fetch_object(db_query($sql, $obo_id));
+
+  // if the reference is for a remote URL then run the URL processing function
+  if (preg_match("/^http:\/\//", $obo->path) or preg_match("/^ftp:\/\//", $obo->path)) {
+    tripal_cv_load_obo_v1_2_url($obo->name, $obo->path, $jobid, 0);
+  }
+  // if the reference is for a local file then run the file processing function
+  else {
+    // check to see if the file is located local to Drupal
+    $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $obo->path;
+    if (file_exists($dfile)) {
+      tripal_cv_load_obo_v1_2_file($obo->name, $dfile , $jobid, 0);
+    }
+    // if not local to Drupal, the file must be someplace else, just use
+    // the full path provided
+    else {
+      if (file_exists($obo->path)) {
+        tripal_cv_load_obo_v1_2_file($obo->name, $obo->path, $jobid, 0);
       }
-   }  
+      else {
+        print "ERROR: counld not find OBO file: '$obo->path'\n";
+      }
+    }
+  }
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_load_obo_v1_2_file($obo_name,$file,$jobid = NULL,$is_new = 1){
-   $newcvs = array();
-
-   tripal_cv_load_obo_v1_2($file,$jobid,$newcvs);
-   if($is_new){
-      tripal_cv_load_obo_add_ref($obo_name,$file);
-   }
-   // update the cvtermpath table 
-   tripal_cv_load_update_cvtermpath($newcvs,$jobid);
-   print "Ontology Sucessfully loaded!\n";  
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_load_obo_v1_2_file($obo_name, $file, $jobid = NULL, $is_new = TRUE) {
+  $newcvs = array();
+
+  tripal_cv_load_obo_v1_2($file, $jobid, $newcvs);
+  if ($is_new) {
+    tripal_cv_load_obo_add_ref($obo_name, $file);
+  }
+
+  // update the cvtermpath table
+  tripal_cv_load_update_cvtermpath($newcvs, $jobid);
+  print "Ontology Sucessfully loaded!\n";
+
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_load_obo_v1_2_url($obo_name,$url,$jobid = NULL,$is_new = 1){
-
-   $newcvs = array();
-
-   // first download the OBO
-   $temp = tempnam(sys_get_temp_dir(),'obo_');
-   print "Downloading URL $url, saving to $temp\n";
-   $url_fh = fopen($url,"r");
-   $obo_fh = fopen($temp,"w");
-   if(!$url_fh){
-      tripal_cv_obo_quiterror("Unable to download the remote OBO file at $url. Could a firewall be blocking outgoing connections? ".
-            " if you are unable to download the file you may manually downlod the OBO file and use the web interface to ".
-            " specify the location of the file on your server.");
-      
-   }
-   while(!feof($url_fh)){
-      fwrite($obo_fh,fread($url_fh,255),255);
-   }
-   fclose($url_fh);
-   fclose($obo_fh);
-
-   // second, parse the OBO
-   tripal_cv_load_obo_v1_2($temp,$jobid,$newcvs);
-
-   // now remove the temp file
-   unlink($temp);
-
-   if($is_new){
-      tripal_cv_load_obo_add_ref($obo_name,$url);
-   }
-
-   // update the cvtermpath table 
-   tripal_cv_load_update_cvtermpath($newcvs,$jobid);
-
-   print "Ontology Sucessfully loaded!\n";
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_load_obo_v1_2_url($obo_name, $url, $jobid = NULL, $is_new = TRUE) {
+
+  $newcvs = array();
+
+  // first download the OBO
+  $temp = tempnam(sys_get_temp_dir(), 'obo_');
+  print "Downloading URL $url, saving to $temp\n";
+  $url_fh = fopen($url, "r");
+  $obo_fh = fopen($temp, "w");
+  if (!$url_fh) {
+    tripal_cv_obo_quiterror("Unable to download the remote OBO file at $url. Could a firewall be blocking outgoing connections? ".
+          " if you are unable to download the file you may manually downlod the OBO file and use the web interface to ".
+          " specify the location of the file on your server.");
+
+  }
+  while (!feof($url_fh)) {
+    fwrite($obo_fh, fread($url_fh, 255), 255);
+  }
+  fclose($url_fh);
+  fclose($obo_fh);
+
+  // second, parse the OBO
+  tripal_cv_load_obo_v1_2($temp, $jobid, $newcvs);
+
+  // now remove the temp file
+  unlink($temp);
+
+  if ($is_new) {
+    tripal_cv_load_obo_add_ref($obo_name, $url);
+  }
+
+  // update the cvtermpath table
+  tripal_cv_load_update_cvtermpath($newcvs, $jobid);
+
+  print "Ontology Sucessfully loaded!\n";
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_load_update_cvtermpath($newcvs,$jobid){
-
-   print "\nUpdating cvtermpath table.  This may take a while...\n";
-   foreach($newcvs as $namespace => $cvid){
-      tripal_cv_update_cvtermpath($cvid, $jobid);
-   }
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_load_update_cvtermpath($newcvs, $jobid) {
+
+  print "\nUpdating cvtermpath table.  This may take a while...\n";
+  foreach ($newcvs as $namespace => $cvid) {
+    tripal_cv_update_cvtermpath($cvid, $jobid);
+  }
 }
+
 /**
-*
-*/
-function tripal_cv_load_obo_add_ref($name,$path){
-   $isql = "INSERT INTO tripal_cv_obo (name,path) VALUES ('%s','%s')";
-   db_query($isql,$name,$path);
+ *
+ */
+function tripal_cv_load_obo_add_ref($name, $path) {
+  $isql = "INSERT INTO {tripal_cv_obo} (name,path) VALUES ('%s','%s')";
+  db_query($isql, $name, $path);
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_load_obo_v1_2($file,$jobid = NULL,&$newcvs) {
-
-   global $previous_db;
-
-   $header = array();
-   $obo = array();
-   
-   print "Opening File $file\n";
-
-   // set the search path
-   $previous_db = tripal_db_set_active('chado');
-
-   // make sure we have an 'internal' and a '_global' database
-   if(!tripal_cv_obo_add_db('internal')){
-      tripal_cv_obo_quiterror("Cannot add 'internal' database");
-   }
-   if(!tripal_cv_obo_add_db('_global')){
-      tripal_cv_obo_quiterror("Cannot add '_global' database");
-   }
-
-   // parse the obo file
-   tripal_cv_obo_parse($file,$obo,$header);
-
-   // add the CV for this ontology to the database
-   $defaultcv = tripal_cv_obo_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;
-
-   // add any typedefs to the vocabulary first
-   $typedefs = $obo['Typedef'];
-   foreach($typedefs as $typedef){
-      tripal_cv_obo_process_term($typedef,$defaultcv,$obo,1,$newcvs);  
-   }
-
-   // next add terms to the vocabulary
-   $terms = $obo['Term'];
-   if(!tripal_cv_obo_process_terms($terms,$defaultcv,$obo,$jobid,$newcvs)){
-      tripal_cv_obo_quiterror('Cannot add terms from this ontology');
-   }
-   return tripal_cv_obo_loader_done();
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
+  global $_tripal_cv_previous_db;
+
+  $header = array();
+  $obo = array();
+
+  print "Opening File $file\n";
+
+  // set the search path
+  $_tripal_cv_previous_db = tripal_db_set_active('chado');
+
+  // make sure we have an 'internal' and a '_global' database
+  if (!tripal_cv_obo_add_db('internal')) {
+    tripal_cv_obo_quiterror("Cannot add 'internal' database");
+  }
+  if (!tripal_cv_obo_add_db('_global')) {
+    tripal_cv_obo_quiterror("Cannot add '_global' database");
+  }
+
+  // parse the obo file
+  tripal_cv_obo_parse($file, $obo, $header);
+
+  // add the CV for this ontology to the database
+  $defaultcv = tripal_cv_obo_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;
+
+  // add any typedefs to the vocabulary first
+  $typedefs = $obo['Typedef'];
+  foreach ($typedefs as $typedef) {
+    tripal_cv_obo_process_term($typedef, $defaultcv, $obo, 1, $newcvs);
+  }
+
+  // next add terms to the vocabulary
+  $terms = $obo['Term'];
+  if (!tripal_cv_obo_process_terms($terms, $defaultcv, $obo, $jobid, $newcvs)) {
+    tripal_cv_obo_quiterror('Cannot add terms from this ontology');
+  }
+
+  return tripal_cv_obo_loader_done();
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_quiterror ($message){
-   print "ERROR: $message\n";
-   db_query("set search_path to public");  
-   exit;
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_quiterror($message) {
+
+  print "ERROR: $message\n";
+  db_query("set search_path to public");
+  exit;
+
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_loader_done (){
-   // return the search path to normal
-   tripal_db_set_active($previous_db);
-   db_query("set search_path to public");  
-   return '';
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_loader_done() {
+
+  // return the search path to normal
+  tripal_db_set_active($_tripal_cv_previous_db);
+  db_query("set search_path to public");
+
+  return '';
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_process_terms($terms,$defaultcv,$obo,$jobid=null,&$newcvs){
-
-   $i = 0;
-   $count = sizeof($terms);
-   $interval = intval($count * 0.01);
-   if($interval > 1){
-      $interval = 1;
-   }
-
-   foreach ($terms as $term){
-
-      // update the job status every 1% terms
-      if($jobid and $i % $interval == 0){
-         tripal_job_set_progress($jobid,intval(($i/$count)*50)); // we mulitply by 50 because parsing and loacing cvterms
-                                                                 // is only the first half.  The other half is updating
-      }                                                          // the cvtermpath table.
-
-      if(!tripal_cv_obo_process_term($term,$defaultcv,$obo,0,$newcvs)){
-         tripal_cv_obo_quiterror("Failed to process terms from the ontology");
-      }
-      $i++;
-   }
-   return 1;
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_process_terms($terms, $defaultcv, $obo, $jobid = NULL, &$newcvs) {
+
+  $i = 0;
+  $count = sizeof($terms);
+  $interval = intval($count * 0.01);
+  if ($interval > 1) {
+    $interval = 1;
+  }
+
+  foreach ($terms as $term) {
+
+    // update the job status every 1% terms
+    if ($jobid and $i % $interval == 0) {
+      tripal_job_set_progress($jobid, intval(($i / $count) * 50)); // we mulitply by 50 because parsing and loacing cvterms
+                                                                   // is only the first half.  The other half is updating
+    }                                                              // the cvtermpath table.
+
+    if (!tripal_cv_obo_process_term($term, $defaultcv, $obo, 0, $newcvs)) {
+      tripal_cv_obo_quiterror("Failed to process terms from the ontology");
+    }
+
+    $i++;
+  }
+  return 1;
 }
 
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_process_term($term,$defaultcv,$obo,$is_relationship=0,&$newcvs){
-
-   // add the cvterm
-   $cvterm = tripal_cv_obo_add_cvterm($term,$defaultcv,$is_relationship,1);     
-   if(!$cvterm){ 
-      tripal_cv_obo_quiterror("Cannot add the term " . $term['id'][0]);
-   }
-   if($term['namespace'][0]){
-      $newcvs[$term['namespace'][0]] = $cvterm->cv_id;
-   }
-
-   // now handle other properites
-   if(isset($term['is_anonymous'])){
-     //print "WARNING: unhandled tag: is_anonymous\n";
-   }
-   if(isset($term['alt_id'])){
-      foreach($term['alt_id'] as $alt_id){
-         if(!tripal_cv_obo_add_cvterm_dbxref($cvterm,$alt_id)){
-            tripal_cv_obo_quiterror("Cannot add alternate id $alt_id");
-         }
-      }
-   }
-   if(isset($term['subset'])){
-     //print "WARNING: unhandled tag: subset\n";
-   }
-   // add synonyms for this cvterm
-   if(isset($term['synonym'])){
-      if(!tripal_cv_obo_add_synonyms($term,$cvterm)){
-         tripal_cv_obo_quiterror("Cannot add synonyms");
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_process_term($term, $defaultcv, $obo, $is_relationship = 0, &$newcvs) {
+
+  // add the cvterm
+  $cvterm = tripal_cv_obo_add_cvterm($term, $defaultcv, $is_relationship, 1);
+  if (!$cvterm) {
+    tripal_cv_obo_quiterror("Cannot add the term " . $term['id'][0]);
+  }
+  if ($term['namespace'][0]) {
+    $newcvs[$term['namespace'][0]] = $cvterm->cv_id;
+  }
+
+  // now handle other properites
+  if (isset($term['is_anonymous'])) {
+    //print "WARNING: unhandled tag: is_anonymous\n";
+  }
+  if (isset($term['alt_id'])) {
+    foreach ($term['alt_id'] as $alt_id) {
+      if (!tripal_cv_obo_add_cvterm_dbxref($cvterm, $alt_id)) {
+        tripal_cv_obo_quiterror("Cannot add alternate id $alt_id");
       }
-   }
-   // reformat the deprecated 'exact_synonym, narrow_synonym, and broad_synonym'
-   // types to be of the v1.2 standard
-   if(isset($term['exact_synonym']) or isset($term['narrow_synonym']) or isset($term['broad_synonym'])){
-      if(isset($term['exact_synonym'])){
-         foreach ($term['exact_synonym'] as $synonym){
-
-            $new = preg_replace('/^\s*(\".+?\")(.*?)$/','$1 EXACT $2',$synonym);
-            $term['synonym'][] = $new;
-         }
+    }
+  }
+  if (isset($term['subset'])) {
+    //print "WARNING: unhandled tag: subset\n";
+  }
+  // add synonyms for this cvterm
+  if (isset($term['synonym'])) {
+    if (!tripal_cv_obo_add_synonyms($term, $cvterm)) {
+      tripal_cv_obo_quiterror("Cannot add synonyms");
+    }
+  }
+
+  // reformat the deprecated 'exact_synonym, narrow_synonym, and broad_synonym'
+  // types to be of the v1.2 standard
+  if (isset($term['exact_synonym']) or isset($term['narrow_synonym']) or isset($term['broad_synonym'])) {
+    if (isset($term['exact_synonym'])) {
+      foreach ($term['exact_synonym'] as $synonym) {
+        $new = preg_replace('/^\s*(\".+?\")(.*?)$/', '$1 EXACT $2', $synonym);
+        $term['synonym'][] = $new;
       }
-      if(isset($term['narrow_synonym'])){
-         foreach ($term['narrow_synonym'] as $synonym){
-            $new = preg_replace('/^\s*(\".+?\")(.*?)$/','$1 NARROW $2',$synonym);
-            $term['synonym'][] = $new;
-         }
+    }
+    if (isset($term['narrow_synonym'])) {
+      foreach ($term['narrow_synonym'] as $synonym) {
+        $new = preg_replace('/^\s*(\".+?\")(.*?)$/', '$1 NARROW $2', $synonym);
+        $term['synonym'][] = $new;
       }
-      if(isset($term['broad_synonym'])){
-         foreach ($term['broad_synonym'] as $synonym){
-            $new = preg_replace('/^\s*(\".+?\")(.*?)$/','$1 BROAD $2',$synonym);
-            $term['synonym'][] = $new;
-         }
-      } 
-
-      if(!tripal_cv_obo_add_synonyms($term,$cvterm)){
-         tripal_cv_obo_quiterror("Cannot add/update synonyms");
+    }
+    if (isset($term['broad_synonym'])) {
+      foreach ($term['broad_synonym'] as $synonym) {
+        $new = preg_replace('/^\s*(\".+?\")(.*?)$/', '$1 BROAD $2', $synonym);
+        $term['synonym'][] = $new;
       }
-   }
-   // add the comment to the cvtermprop table
-   if(isset($term['comment'])){
-      $comments = $term['comment'];
-      $j = 0;
-      foreach($comments as $comment){
-         if(!tripal_cv_obo_add_cvterm_prop($cvterm,'comment',$comment,$j)){
-            tripal_cv_obo_quiterror("Cannot add/update cvterm property");
-         }
-         $j++;
+    }
+
+    if (!tripal_cv_obo_add_synonyms($term, $cvterm)) {
+      tripal_cv_obo_quiterror("Cannot add/update synonyms");
+    }
+  }
+  // add the comment to the cvtermprop table
+  if (isset($term['comment'])) {
+    $comments = $term['comment'];
+    $j = 0;
+    foreach ($comments as $comment) {
+      if (!tripal_cv_obo_add_cvterm_prop($cvterm, 'comment', $comment, $j)) {
+        tripal_cv_obo_quiterror("Cannot add/update cvterm property");
       }
-   }    
-   // add any other external dbxrefs
-   if(isset($term['xref'])){
-      foreach($term['xref'] as $xref){
-         if(!tripal_cv_obo_add_cvterm_dbxref($cvterm,$xref)){
-            tripal_cv_obo_quiterror("Cannot add/update cvterm database reference (dbxref).");
-         }
+      $j++;
+    }
+  }
+  // add any other external dbxrefs
+  if (isset($term['xref'])) {
+    foreach ($term['xref'] as $xref) {
+      if (!tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref)) {
+        tripal_cv_obo_quiterror("Cannot add/update cvterm database reference (dbxref).");
       }
-   }
-   if(isset($term['xref_analog'])){
-      foreach($term['xref_analog'] as $xref){
-         if(!tripal_cv_obo_add_cvterm_dbxref($cvterm,$xref)){
-            tripal_cv_obo_quiterror("Cannot add/update cvterm database reference (dbxref).");
-         }
+    }
+  }
+  if (isset($term['xref_analog'])) {
+    foreach ($term['xref_analog'] as $xref) {
+      if (!tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref)) {
+        tripal_cv_obo_quiterror("Cannot add/update cvterm database reference (dbxref).");
       }
-   }
-   if(isset($term['xref_unk'])){
-      foreach($term['xref_unk'] as $xref){
-         if(!tripal_cv_obo_add_cvterm_dbxref($cvterm,$xref)){
-            tripal_cv_obo_quiterror("Cannot add/update cvterm database reference (dbxref).");
-         }
+    }
+  }
+  if (isset($term['xref_unk'])) {
+    foreach ($term['xref_unk'] as $xref) {
+      if (!tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref)) {
+        tripal_cv_obo_quiterror("Cannot add/update cvterm database reference (dbxref).");
       }
-   }
-
-   // add is_a relationships for this cvterm
-   if(isset($term['is_a'])){
-      foreach($term['is_a'] as $is_a){
-         if(!tripal_cv_obo_add_relationship($cvterm,$defaultcv,$obo,'is_a',$is_a,$is_relationship)){
-            tripal_cv_obo_quiterror("Cannot add relationship is_a: $is_a");
-         }
+    }
+  }
+
+  // add is_a relationships for this cvterm
+  if (isset($term['is_a'])) {
+    foreach ($term['is_a'] as $is_a) {
+      if (!tripal_cv_obo_add_relationship($cvterm, $defaultcv, $obo, 'is_a', $is_a, $is_relationship)) {
+        tripal_cv_obo_quiterror("Cannot add relationship is_a: $is_a");
       }
-   } 
-   if(isset($term['intersection_of'])){
-     //print "WARNING: unhandled tag: intersection_of\n";
-   }
-   if(isset($term['union_of'])){
-     //print "WARNING: unhandled tag: union_on\n";
-   }
-   if(isset($term['disjoint_from'])){
-     //print "WARNING: unhandled tag: disjoint_from\n";
-   }
-   if(isset($term['relationship'])){
-      foreach($term['relationship'] as $value){
-         $rel = preg_replace('/^(.+?)\s.+?$/','\1',$value);
-         $object = preg_replace('/^.+?\s(.+?)$/','\1',$value);
-         if(!tripal_cv_obo_add_relationship($cvterm,$defaultcv,$obo,$rel,$object,$is_relationship)){
-            tripal_cv_obo_quiterror("Cannot add relationship $rel: $object");
-         }
+    }
+  }
+  if (isset($term['intersection_of'])) {
+    //print "WARNING: unhandled tag: intersection_of\n";
+  }
+  if (isset($term['union_of'])) {
+    //print "WARNING: unhandled tag: union_on\n";
+  }
+  if (isset($term['disjoint_from'])) {
+    //print "WARNING: unhandled tag: disjoint_from\n";
+  }
+  if (isset($term['relationship'])) {
+    foreach ($term['relationship'] as $value) {
+      $rel = preg_replace('/^(.+?)\s.+?$/', '\1', $value);
+      $object = preg_replace('/^.+?\s(.+?)$/', '\1', $value);
+      if (!tripal_cv_obo_add_relationship($cvterm, $defaultcv, $obo, $rel, $object, $is_relationship)) {
+        tripal_cv_obo_quiterror("Cannot add relationship $rel: $object");
       }
-   }
-   if(isset($term['replaced_by'])){
-     //print "WARNING: unhandled tag: replaced_by\n";
-   }
-   if(isset($term['consider'])){
-     //print "WARNING: unhandled tag: consider\n";
-   }
-   if(isset($term['use_term'])){
-     //print "WARNING: unhandled tag: user_term\n";
-   }
-   if(isset($term['builtin'])){
-     //print "WARNING: unhandled tag: builtin\n";
-   }
-   return 1;
+    }
+  }
+  if (isset($term['replaced_by'])) {
+   //print "WARNING: unhandled tag: replaced_by\n";
+  }
+  if (isset($term['consider'])) {
+    //print "WARNING: unhandled tag: consider\n";
+  }
+  if (isset($term['use_term'])) {
+    //print "WARNING: unhandled tag: user_term\n";
+  }
+  if (isset($term['builtin'])) {
+    //print "WARNING: unhandled tag: builtin\n";
+  }
+  return 1;
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_add_db($dbname){
-
-   $db_sql = "SELECT * FROM {db} WHERE name ='%s'";
-   $db = db_fetch_object(db_query($db_sql,$dbname));
-   if(!$db){
-      if(!db_query("INSERT INTO {db} (name) VALUES ('%s')",$dbname)){
-         tripal_cv_obo_quiterror("Cannot create '$dbname' db in Chado.");
-      }      
-     $db = db_fetch_object(db_query($db_sql,$dbname));
-   }
-   return $db;
+ * Add a database record
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_add_db($dbname) {
+
+  $db_sql = "SELECT * FROM {db} WHERE name ='%s'";
+  $db = db_fetch_object(db_query($db_sql, $dbname));
+  if (!$db) {
+    if (!db_query("INSERT INTO {db} (name) VALUES ('%s')", $dbname)) {
+      tripal_cv_obo_quiterror("Cannot create '$dbname' db in Chado.");
+    }
+    $db = db_fetch_object(db_query($db_sql, $dbname));
+  }
+
+  return $db;
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_add_cv($name,$comment){
-
- // see if the CV (default-namespace) exists already in the database
-   $vocab = $name;
-   $remark = $comment;
-   $cv_sql = "SELECT * FROM {cv} WHERE name = '%s'";
-   $cv = db_fetch_object(db_query($cv_sql,$vocab));
-
-   // if the CV exists then update it, otherwise insert
-   if(!$cv){
-      $sql = "INSERT INTO {cv} (name,definition) VALUES ('%s','%s')";
-      if(!db_query($sql,$vocab,$remark)){
-         tripal_cv_obo_quiterror("Failed to create the CV record");
-      }
-      $cv = db_fetch_object(db_query($cv_sql,$vocab));
-   } else {
-      $sql = "UPDATE {cv} SET definition = '%s' WHERE name ='%s'";
-      if(!db_query($sql,$remark,$vocab)){
-         tripal_cv_obo_quiterror("Failed to update the CV record");
-      }
-      $cv = db_fetch_object(db_query($cv_sql,$vocab));
-   }
-   return $cv;
+ * Add a controlled vocab record
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_add_cv($name, $comment) {
+
+  // see if the CV (default-namespace) exists already in the database
+  $vocab = $name;
+  $remark = $comment;
+  $cv_sql = "SELECT * FROM {cv} WHERE name = '%s'";
+  $cv = db_fetch_object(db_query($cv_sql, $vocab));
+
+  // if the CV exists then update it, otherwise insert
+  if (!$cv) {
+    $sql = "INSERT INTO {cv} (name,definition) VALUES ('%s','%s')";
+    if (!db_query($sql, $vocab, $remark)) {
+      tripal_cv_obo_quiterror("Failed to create the CV record");
+    }
+    $cv = db_fetch_object(db_query($cv_sql, $vocab));
+  }
+  else {
+    $sql = "UPDATE {cv} SET definition = '%s' WHERE name ='%s'";
+    if (!db_query($sql, $remark, $vocab)) {
+      tripal_cv_obo_quiterror("Failed to update the CV record");
+    }
+    $cv = db_fetch_object(db_query($cv_sql, $vocab));
+  }
+
+  return $cv;
 }
 
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_add_relationship($cvterm,$defaultcv,$obo,$rel,$objname,$object_is_relationship=0){
-
-   // make sure the relationship cvterm exists
-   $term = array(
-      'name' => array($rel),
-      'id' => array($rel),
-      'definition' => array(''),
-      'is_obsolete' => array(0),
-   );
-   $relcvterm = tripal_cv_obo_add_cvterm($term,$defaultcv,1,0);
-   if(!$relcvterm){
-      tripal_cv_obo_quiterror("Cannot find or insert the relationship term: $rel\n");
-   }
-
-   // get the object term
-   $objterm = tripal_cv_obo_get_term($obo,$objname);
-   if(!$objterm) { 
-      tripal_cv_obo_quiterror("Could not find object term $objname\n"); 
-   }
-   $objcvterm = tripal_cv_obo_add_cvterm($objterm,$defaultcv,$object_is_relationship,1);
-   if(!$objcvterm){ 
-      tripal_cv_obo_quiterror("Cannot add/find cvterm");
-   }
-
-   // check to see if the cvterm_relationship already exists, if not add it
-   $cvrsql = "SELECT * FROM {cvterm_relationship} WHERE type_id = %d and subject_id = %d and object_id = %d";
-   if(!db_fetch_object(db_query($cvrsql,$relcvterm->cvterm_id,$cvterm->cvterm_id,$objcvterm->cvterm_id))){
-      $sql = "INSERT INTO {cvterm_relationship} ".
-             "(type_id,subject_id,object_id) VALUES (%d,%d,%d)";
-      if(!db_query($sql,$relcvterm->cvterm_id,$cvterm->cvterm_id,$objcvterm->cvterm_id)){
-         tripal_cv_obo_quiterror("Cannot add term relationship: '$cvterm->name' $rel '$objcvterm->name'");
-      }
-   }
-
-   return 1;
+ * Add a cvterm relationship
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $obo, $rel, $objname, $object_is_relationship = 0) {
+
+  // make sure the relationship cvterm exists
+  $term = array(
+    'name' => array($rel),
+    'id' => array($rel),
+    'definition' => array(''),
+    'is_obsolete' => array(0),
+  );
+  $relcvterm = tripal_cv_obo_add_cvterm($term, $defaultcv, 1, 0);
+  if (!$relcvterm) {
+    tripal_cv_obo_quiterror("Cannot find or insert the relationship term: $rel\n");
+  }
+
+  // get the object term
+  $objterm = tripal_cv_obo_get_term($obo, $objname);
+  if (!$objterm) {
+    tripal_cv_obo_quiterror("Could not find object term $objname\n");
+  }
+  $objcvterm = tripal_cv_obo_add_cvterm($objterm, $defaultcv, $object_is_relationship, 1);
+  if (!$objcvterm) {
+    tripal_cv_obo_quiterror("Cannot add/find cvterm");
+  }
+
+  // check to see if the cvterm_relationship already exists, if not add it
+  $cvrsql = "SELECT * FROM {cvterm_relationship} WHERE type_id = %d and subject_id = %d and object_id = %d";
+  if (!db_fetch_object(db_query($cvrsql, $relcvterm->cvterm_id, $cvterm->cvterm_id, $objcvterm->cvterm_id))) {
+    $sql = "INSERT INTO {cvterm_relationship} ".
+           "(type_id,subject_id,object_id) VALUES (%d,%d,%d)";
+    if (!db_query($sql, $relcvterm->cvterm_id, $cvterm->cvterm_id, $objcvterm->cvterm_id)) {
+      tripal_cv_obo_quiterror("Cannot add term relationship: '$cvterm->name' $rel '$objcvterm->name'");
+    }
+  }
+
+  return TRUE;
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_get_term($obo,$id){
-   foreach ($obo as $type){
-      foreach ($type as $term){
-         $accession = $term['id'][0];
-         if(strcmp($accession,$id)==0){
-            return $term;
-         }
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_get_term($obo, $id) {
+  foreach ($obo as $type) {
+    foreach ($type as $term) {
+      $accession = $term['id'][0];
+      if (strcmp($accession, $id)==0) {
+        return $term;
       }
-   }
-   return;
+    }
+  }
+
+  return FALSE;
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_add_synonyms($term,$cvterm){
-
-   // make sure we have a 'synonym_type' vocabulary
-   $sql = "SELECT * FROM {cv} WHERE name='synonym_type'";
-   $syncv = db_fetch_object(db_query($sql));
-   if(!$syncv){
-      $sql = "INSERT INTO {cv} (name,definition) VALUES ('synonym_type','')";
-      if(!db_query($sql)){
-         tripal_cv_obo_quiterror("Failed to add the synonyms type vocabulary");
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_add_synonyms($term, $cvterm) {
+
+  // make sure we have a 'synonym_type' vocabulary
+  $sql = "SELECT * FROM {cv} WHERE name='synonym_type'";
+  $syncv = db_fetch_object(db_query($sql));
+  if (!$syncv) {
+    $sql = "INSERT INTO {cv} (name,definition) VALUES ('synonym_type','')";
+    if (!db_query($sql)) {
+      tripal_cv_obo_quiterror("Failed to add the synonyms type vocabulary");
+    }
+    $syncv = db_fetch_object(db_query($sql));
+  }
+
+  // now add the synonyms
+  if (isset($term['synonym'])) {
+    foreach ($term['synonym'] as $synonym) {
+      // separate out the synonym definition and the synonym type
+      $def = preg_replace('/^\s*"(.*)"\s*.*$/', '\1', $synonym);
+      $type = drupal_strtolower(preg_replace('/^.*"\s+(.*?)\s+.*$/', '\1', $synonym));
+
+      // make sure the synonym type exists in the 'synonym_type' vocabulary
+      $cvtsql = "
+        SELECT *
+        FROM {cvterm} CVT
+           INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
+        WHERE CVT.name = '%s' and CV.name = '%s'
+      ";
+      $syntype = db_fetch_object(db_query($cvtsql, $type, 'synonym_type'));
+      if (!$syntype) {
+        // build a 'term' object so we can add the missing term
+        $term = array(
+           'name' => array($type),
+           'id' => array("internal:$type"),
+           'definition' => array(''),
+           'is_obsolete' => array(0),
+        );
+        $syntype = tripal_cv_obo_add_cvterm($term, $syncv, 0, 1);
+        if (!$syntype) {
+          tripal_cv_obo_quiterror("Cannot add synonym type: internal:$type");
+        }
       }
-      $syncv = db_fetch_object(db_query($sql));
-   }
-
-   // now add the synonyms
-   if(isset($term['synonym'])){
-      foreach($term['synonym'] as $synonym){
-         // separate out the synonym definition and the synonym type
-         $def = preg_replace('/^\s*"(.*)"\s*.*$/','\1',$synonym);
-         $type = strtolower(preg_replace('/^.*"\s+(.*?)\s+.*$/','\1',$synonym)); 
-
-         // make sure the synonym type exists in the 'synonym_type' vocabulary
-         $cvtsql = "
-            SELECT * 
-            FROM {cvterm} CVT
-               INNER JOIN {cv} CV ON CVT.cv_id = CV.cv_id
-            WHERE CVT.name = '%s' and CV.name = '%s'
-         ";
-         $syntype = db_fetch_object(db_query($cvtsql,$type,'synonym_type'));
-         if(!$syntype){
-            // build a 'term' object so we can add the missing term
-            $term = array(
-               'name' => array($type),
-               'id' => array("internal:$type"),
-               'definition' => array(''),
-               'is_obsolete' => array(0),
-            );
-            $syntype = tripal_cv_obo_add_cvterm($term,$syncv,0,1);
-            if(!$syntype){
-               tripal_cv_obo_quiterror("Cannot add synonym type: internal:$type");
-            }
-         }       
-
-         // make sure the synonym doesn't already exists
-         $sql = "
-            SELECT * 
-            FROM {cvtermsynonym} 
-            WHERE cvterm_id = %d and synonym = '%s'
-         ";
-         $syn = db_fetch_object(db_query($sql,$cvterm->cvterm_id,$def));
-         if(!$syn){
-            $sql = "INSERT INTO {cvtermsynonym} (cvterm_id,synonym,type_id)
-                    VALUES(%d,'%s',%d)";
-            if(!db_query($sql,$cvterm->cvterm_id,$def,$syntype->cvterm_id)){
-               tripal_cv_obo_quiterror("Failed to insert the synonym for term: $name ($def)");
-            }
-         } 
-
-         // now add the dbxrefs for the synonym if we have a comma in the middle
-         // of a description then this will cause problems when splitting os lets
-         // just change it so it won't mess up our splitting and then set it back
-         // later.
-//         $synonym = preg_replace('/(".*?),\s(.*?")/','$1,_$2',$synonym);
-//         $dbxrefs = preg_split("/, /",preg_replace('/^.*\[(.*?)\]$/','\1',$synonym));
-//         foreach($dbxrefs as $dbxref){
-//            $dbxref = preg_replace('/,_/',", ",$dbxref);
-//            if($dbxref){
-//               tripal_cv_obo_add_cvterm_dbxref($syn,$dbxref);
-//            }
-//         }
-      } 
-   }
-   return 1;
+
+      // make sure the synonym doesn't already exists
+      $sql = "
+        SELECT *
+        FROM {cvtermsynonym}
+        WHERE cvterm_id = %d and synonym = '%s'
+      ";
+      $syn = db_fetch_object(db_query($sql, $cvterm->cvterm_id, $def));
+      if (!$syn) {
+        $sql = "INSERT INTO {cvtermsynonym} (cvterm_id,synonym,type_id)
+                VALUES(%d,'%s',%d)";
+        if (!db_query($sql, $cvterm->cvterm_id, $def, $syntype->cvterm_id)) {
+          tripal_cv_obo_quiterror("Failed to insert the synonym for term: $name ($def)");
+        }
+      }
+
+      // now add the dbxrefs for the synonym if we have a comma in the middle
+      // of a description then this will cause problems when splitting os lets
+      // just change it so it won't mess up our splitting and then set it back
+      // later.
+      /**
+      $synonym = preg_replace('/(".*?),\s(.*?")/','$1,_$2',$synonym);
+      $dbxrefs = preg_split("/, /",preg_replace('/^.*\[(.*?)\]$/','\1',$synonym));
+      foreach ($dbxrefs as $dbxref) {
+       $dbxref = preg_replace('/,_/',", ",$dbxref);
+        if ($dbxref) {
+          tripal_cv_obo_add_cvterm_dbxref($syn,$dbxref);
+        }
+      }
+      */
+    }
+  }
+
+  return TRUE;
 }
 
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_parse($obo_file,&$obo,&$header){
-   $i = 0;
-   $in_header = 1;
-   $stanza = array();
-
-   // iterate through the lines in the OBO file and parse the stanzas
-   $fh = fopen($obo_file,'r');
-   while($line = fgets($fh)) {
-      $i++;
-
-      // remove newlines
-      $line = rtrim($line);  
-
-      // remove any special characters that may be hiding
-      $line = preg_replace('/[^(\x20-\x7F)]*/','', $line);
-
-      // skip empty lines
-      if(strcmp($line,'')==0) { continue; }
-
-      //remove comments from end of lines
-      $line = preg_replace('/^(.*?)\!.*$/','\1',$line);  // TODO: if the explamation is escaped
-
-      if(preg_match('/^\s*\[/',$line)){  // at the first stanza we're out of header
-         $in_header = 0;
-         // load the stanza we just finished reading
-         if(sizeof($stanza) > 0){
-            if(!isset($obo[$type])){
-               $obo[$type] = array();
-            }
-            if(!isset($obo[$type][$stanza['id'][0]])){
-               $obo[$type][$stanza['id'][0]] = $stanza;
-            } else {
-               array_merge($obo[$type][$stanza['id'][0]],$stanza);
-            }
-         } 
-         // get the stanza type:  Term, Typedef or Instance
-         $type = preg_replace('/^\s*\[\s*(.+?)\s*\]\s*$/','\1',$line);
-
-         // start fresh with a new array
-         $stanza = array();
-         continue;
+ * Actually parse the OBO file
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_parse($obo_file, &$obo, &$header) {
+  $i = 0;
+  $in_header = 1;
+  $stanza = array();
+
+  // iterate through the lines in the OBO file and parse the stanzas
+  $fh = fopen($obo_file, 'r');
+  while ($line = fgets($fh)) {
+    $i++;
+
+    // remove newlines
+    $line = rtrim($line);
+
+    // remove any special characters that may be hiding
+    $line = preg_replace('/[^(\x20-\x7F)]*/', '', $line);
+
+    // skip empty lines
+    if (strcmp($line, '') == 0) {
+      continue;
+    }
+
+    //remove comments from end of lines
+    $line = preg_replace('/^(.*?)\!.*$/', '\1', $line);  // TODO: if the explamation is escaped
+
+    if (preg_match('/^\s*\[/', $line)) {  // at the first stanza we're out of header
+      $in_header = 0;
+      // load the stanza we just finished reading
+      if (sizeof($stanza) > 0) {
+        if (!isset($obo[$type])) {
+          $obo[$type] = array();
+        }
+        if (!isset($obo[$type][$stanza['id'][0]])) {
+          $obo[$type][$stanza['id'][0]] = $stanza;
+        }
+        else {
+          array_merge($obo[$type][$stanza['id'][0]], $stanza);
+        }
       }
-      // break apart the line into the tag and value but ignore any escaped colons
-      preg_replace("/\\:/","|-|-|",$line); // temporarily replace escaped colons
-      $pair = explode(":",$line,2);
-      $tag = $pair[0];
-      $value = ltrim(rtrim($pair[1]));// remove surrounding spaces
-      $tag = preg_replace("/\|-\|-\|/","\:",$tag); // return the escaped colon
-      $value = preg_replace("/\|-\|-\|/","\:",$value);
-      if($in_header){
-         if(!isset($header[$tag])){
-            $header[$tag] = array();
-         }
-         $header[$tag][] = $value;
-      } else {
-         if(!isset($stanza[$tag])){
-            $stanza[$tag] = array();
-         }  
-         $stanza[$tag][] = $value;
-      }          
-   }
-   // now add the last term in the file
-   if(sizeof($stanza) > 0){
-      if(!isset($obo[$type])){
-         $obo[$type] = array();
+      // get the stanza type:  Term, Typedef or Instance
+      $type = preg_replace('/^\s*\[\s*(.+?)\s*\]\s*$/', '\1', $line);
+
+      // start fresh with a new array
+      $stanza = array();
+      continue;
+    }
+    // break apart the line into the tag and value but ignore any escaped colons
+    preg_replace("/\\:/", "|-|-|", $line); // temporarily replace escaped colons
+    $pair = explode(":", $line, 2);
+    $tag = $pair[0];
+    $value = ltrim(rtrim($pair[1]));// remove surrounding spaces
+    $tag = preg_replace("/\|-\|-\|/", "\:", $tag); // return the escaped colon
+    $value = preg_replace("/\|-\|-\|/", "\:", $value);
+    if ($in_header) {
+      if (!isset($header[$tag])) {
+        $header[$tag] = array();
       }
-      if(!isset($obo[$type][$stanza['id'][0]])){
-         $obo[$type][$stanza['id'][0]] = $stanza;
-      } else {
-         array_merge($obo[$type][$stanza['id'][0]],$stanza);
+      $header[$tag][] = $value;
+    }
+    else {
+      if (!isset($stanza[$tag])) {
+        $stanza[$tag] = array();
       }
-   }
+      $stanza[$tag][] = $value;
+    }
+  }
+  // now add the last term in the file
+  if (sizeof($stanza) > 0) {
+    if (!isset($obo[$type])) {
+      $obo[$type] = array();
+    }
+    if (!isset($obo[$type][$stanza['id'][0]])) {
+      $obo[$type][$stanza['id'][0]] = $stanza;
+    }
+    else {
+      array_merge($obo[$type][$stanza['id'][0]], $stanza);
+    }
+  }
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_add_cvterm_dbxref($cvterm,$xref){
-
-   $dbname = preg_replace('/^(.+?):.*$/','$1',$xref);
-   $accession = preg_replace('/^.+?:\s*(.*?)(\{.+$|\[.+$|\s.+$|\".+$|$)/','$1',$xref);
-   $description = preg_replace('/^.+?\"(.+?)\".*?$/','$1',$xref);
-   $dbxrefs = preg_replace('/^.+?\[(.+?)\].*?$/','$1',$xref);
-
-   if(!$accession){
-      tripal_cv_obo_quiterror();
-      watchdog('tripal_cv',"Cannot add a dbxref without an accession: '$xref'"
-         ,NULL,WATCHDOG_WARNING);
-      return 0;
-   }
-
-   // if the xref is a database link, handle that specially
-   if(strcmp($dbname,'http')==0){
-      $accession = $xref;
-      $dbname = 'URL';
-   }
-
-   // check to see if the database exists
-   $db = tripal_cv_obo_add_db($dbname);
-   if(!$db){
-      tripal_cv_obo_quiterror("Cannot find database '$dbname' in Chado.");
-   }
-
-   // now add the dbxref
-   $dbxref = tripal_cv_obo_add_dbxref($db->db_id,$accession,'',$description);
-   if(!$dbxref){ 
-      tripal_cv_obo_quiterror("Cannot find or add the database reference (dbxref)");
-   }
-
-   // finally add the cvterm_dbxref but first check to make sure it exists
-   $sql = "SELECT * from {cvterm_dbxref} WHERE cvterm_id = %d and dbxref_id = %d";
-   if(!db_fetch_object(db_query($sql,$cvterm->cvterm_id,$dbxref->dbxref_id))){            
-      $sql = "INSERT INTO {cvterm_dbxref} (cvterm_id,dbxref_id)".
-             "VALUES (%d,%d)";
-      if(!db_query($sql,$cvterm->cvterm_id,$dbxref->dbxref_id)){
-         tripal_cv_obo_quiterror("Cannot add cvterm_dbxref: $xref");
-      }
-   }
-   return 1;
+ * Add database reference to cvterm
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref) {
+
+  $dbname = preg_replace('/^(.+?):.*$/', '$1', $xref);
+  $accession = preg_replace('/^.+?:\s*(.*?)(\{.+$|\[.+$|\s.+$|\".+$|$)/', '$1', $xref);
+  $description = preg_replace('/^.+?\"(.+?)\".*?$/', '$1', $xref);
+  $dbxrefs = preg_replace('/^.+?\[(.+?)\].*?$/', '$1', $xref);
+
+  if (!$accession) {
+    tripal_cv_obo_quiterror();
+    watchdog('tripal_cv', "Cannot add a dbxref without an accession: '$xref'", NULL, WATCHDOG_WARNING);
+    return FALSE;
+  }
+
+  // if the xref is a database link, handle that specially
+  if (strcmp($dbname, 'http') == 0) {
+    $accession = $xref;
+    $dbname = 'URL';
+  }
+
+  // check to see if the database exists
+  $db = tripal_cv_obo_add_db($dbname);
+  if (!$db) {
+    tripal_cv_obo_quiterror("Cannot find database '$dbname' in Chado.");
+  }
+
+  // now add the dbxref
+  $dbxref = tripal_cv_obo_add_dbxref($db->db_id, $accession, '', $description);
+  if (!$dbxref) {
+    tripal_cv_obo_quiterror("Cannot find or add the database reference (dbxref)");
+  }
+
+  // finally add the cvterm_dbxref but first check to make sure it exists
+  $sql = "SELECT * from {cvterm_dbxref} WHERE cvterm_id = %d and dbxref_id = %d";
+  if (!db_fetch_object(db_query($sql, $cvterm->cvterm_id, $dbxref->dbxref_id))) {
+    $sql = "INSERT INTO {cvterm_dbxref} (cvterm_id,dbxref_id)".
+           "VALUES (%d,%d)";
+    if (!db_query($sql, $cvterm->cvterm_id, $dbxref->dbxref_id)) {
+      tripal_cv_obo_quiterror("Cannot add cvterm_dbxref: $xref");
+    }
+  }
+
+  return TRUE;
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_add_cvterm_prop($cvterm,$property,$value,$rank){
-
-   // make sure the 'cvterm_property_type' CV exists
-   $cv = tripal_cv_obo_add_cv('cvterm_property_type','');
-   if(!$cv){ 
-      tripal_cv_obo_quiterror("Cannot add/find cvterm_property_type cvterm");
-   }
-
-   // get the property type cvterm.  If it doesn't exist then we want to add it
-   $sql = "
-        SELECT * 
-        FROM {cvterm} CVT INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
-        WHERE CVT.name = '%s' and CV.name = '%s'
-   ";
-   $cvproptype = db_fetch_object(db_query($sql,$property,'cvterm_property_type'));
-   if(!$cvproptype){
-      $term = array(
-         'name' => array($property),
-         'id' => array("internal:$property"),
-         'definition' => array(''),
-         'is_obsolete' => array(0),
-      );
-      $cvproptype = tripal_cv_obo_add_cvterm($term,$cv,0,0);
-      if(!$cvproptype){  
-         tripal_cv_obo_quiterror("Cannot add cvterm property: internal:$property");
-      }
-   }
-
-
-   // remove any properties that currently exist for this term.  We'll reset them
-   if($rank == 0){
-      $sql = "DELETE FROM {cvtermprop} WHERE cvterm_id = %d";
-      db_query($sql,$cvterm->cvterm_id);
-   }
-
-   // now add the property
-   $sql = "INSERT INTO {cvtermprop} (cvterm_id,type_id,value,rank) ".
-          "VALUES (%d, %d, '%s',%d)";
-   if(!db_query($sql,$cvterm->cvterm_id,$cvproptype->cvterm_id,$value,$rank)){
-      tripal_cv_obo_quiterror("Could not add property $property for term\n");
-   }
-   return 1;
+ * Add property to CVterm
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_add_cvterm_prop($cvterm, $property, $value, $rank) {
+
+  // make sure the 'cvterm_property_type' CV exists
+  $cv = tripal_cv_obo_add_cv('cvterm_property_type', '');
+  if (!$cv) {
+    tripal_cv_obo_quiterror("Cannot add/find cvterm_property_type cvterm");
+  }
+
+  // get the property type cvterm.  If it doesn't exist then we want to add it
+  $sql = "
+      SELECT *
+      FROM {cvterm} CVT INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
+      WHERE CVT.name = '%s' and CV.name = '%s'
+  ";
+  $cvproptype = db_fetch_object(db_query($sql, $property, 'cvterm_property_type'));
+  if (!$cvproptype) {
+    $term = array(
+      'name' => array($property),
+      'id' => array("internal:$property"),
+      'definition' => array(''),
+      'is_obsolete' => array(0),
+    );
+    $cvproptype = tripal_cv_obo_add_cvterm($term, $cv, 0, 0);
+    if (!$cvproptype) {
+      tripal_cv_obo_quiterror("Cannot add cvterm property: internal:$property");
+    }
+  }
+
+
+  // remove any properties that currently exist for this term.  We'll reset them
+  if ($rank == 0) {
+    $sql = "DELETE FROM {cvtermprop} WHERE cvterm_id = %d";
+    db_query($sql, $cvterm->cvterm_id);
+  }
+
+  // now add the property
+  $sql = "INSERT INTO {cvtermprop} (cvterm_id,type_id,value,rank) ".
+        "VALUES (%d, %d, '%s',%d)";
+  if (!db_query($sql, $cvterm->cvterm_id, $cvproptype->cvterm_id, $value, $rank)) {
+    tripal_cv_obo_quiterror("Could not add property $property for term\n");
+  }
+
+  return TRUE;
+
 }
+
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_add_cvterm($term,$defaultcv,$is_relationship = 0,$update = 1){
-
-   // get the term properties
-   $id = $term['id'][0];
-   $name = $term['name'][0];
-   $cvname = $term['namespace'][0];
-   $definition = preg_replace('/^\"(.*)\"/','\1',$term['def'][0]);
-   $is_obsolete = 0;
-   if(isset($term['is_obsolete'][0]) and  strcmp($term['is_obsolete'][0],'true')==0){
-     $is_obsolete = 1;
-   }
-   if(!$cvname){
-      $cvname = $defaultcv->name;
-   }
-   // make sure the CV name exists
-   $cv = tripal_cv_obo_add_cv($cvname,'');
-   if(!$cv){
-      tripal_cv_obo_quiterror("Cannot find namespace '$cvname' when adding/updating $id");
-   }
-
-   // this SQL statement will be used a lot to find a cvterm so just set it
-   // here for easy reference below.
-   $cvtermsql = "SELECT CVT.name, CVT.cvterm_id, DB.name as dbname, DB.db_id 
-                  FROM {cvterm} CVT
-                    INNER JOIN {dbxref} DBX on CVT.dbxref_id = DBX.dbxref_id
-                    INNER JOIN {db} DB on DBX.db_id = DB.db_id
-                    INNER JOIN {cv} CV on CV.cv_id = CVT.cv_id
-                  WHERE CVT.name = '%s' and DB.name = '%s'";  
-
-   // get the accession and the database from the cvterm
-   if(preg_match('/^.+?:.*$/',$id)){
-      $accession = preg_replace('/^.+?:(.*)$/','\1',$id);
-      $dbname = preg_replace('/^(.+?):.*$/','\1',$id);
-   } 
-   if($is_relationship and !$dbname){
-      $accession = $id;
-      // because this is a relationship cvterm first check to see if it 
-      // exists in the relationship ontology. If it does then return the cvterm.
-      //  If not then set the dbname to _global and we'll add it or find it there
-      $cvterm = db_fetch_object(db_query($cvtermsql,$name,'OBO_REL'));
-      if($cvterm){
-         return $cvterm;
-      } else {
-         // next check if this term is in the _global ontology.  If it is then
-         // return it no matter what the original CV
-         $dbname = '_global';
-
-         $cvterm = db_fetch_object(db_query($cvtermsql,$name,$dbname));
-         if($cvterm){
-            return $cvterm;
-         }
-      }
-   }
-   if(!$is_relationship and !$dbname){
-      tripal_cv_obo_quiterror("A database identifier is missing from the term: $id");
-   }
-
-   // check to see if the database exists. 
-   $db = tripal_cv_obo_add_db($dbname);
-   if(!$db){
-      tripal_cv_obo_quiterror("Cannot find database '$dbname' in Chado.");
-   }
-
-
-   // if the cvterm doesn't exist then add it otherwise just update it
-   $cvterm = db_fetch_object(db_query($cvtermsql,$name,$dbname));
-   if(!$cvterm){
-      // check to see if the dbxref exists if not, add it
-      $dbxref =  tripal_cv_obo_add_dbxref($db->db_id,$accession);
-      if(!$dbxref){
-         tripal_cv_obo_quiterror("Failed to find or insert the dbxref record for cvterm, $name (id: $accession), for database $dbname");
+ *
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_add_cvterm($term, $defaultcv, $is_relationship = 0, $update = 1) {
+
+  // get the term properties
+  $id = $term['id'][0];
+  $name = $term['name'][0];
+  $cvname = $term['namespace'][0];
+  $definition = preg_replace('/^\"(.*)\"/', '\1', $term['def'][0]);
+  $is_obsolete = 0;
+  if (isset($term['is_obsolete'][0]) and  strcmp($term['is_obsolete'][0], 'true') == 0) {
+    $is_obsolete = 1;
+  }
+  if (!$cvname) {
+    $cvname = $defaultcv->name;
+  }
+
+  // make sure the CV name exists
+  $cv = tripal_cv_obo_add_cv($cvname, '');
+  if (!$cv) {
+    tripal_cv_obo_quiterror("Cannot find namespace '$cvname' when adding/updating $id");
+  }
+
+  // this SQL statement will be used a lot to find a cvterm so just set it
+  // here for easy reference below.
+  $cvtermsql = "SELECT CVT.name, CVT.cvterm_id, DB.name as dbname, DB.db_id
+                FROM {cvterm} CVT
+                  INNER JOIN {dbxref} DBX on CVT.dbxref_id = DBX.dbxref_id
+                  INNER JOIN {db} DB on DBX.db_id = DB.db_id
+                  INNER JOIN {cv} CV on CV.cv_id = CVT.cv_id
+                WHERE CVT.name = '%s' and DB.name = '%s'";
+
+  // get the accession and the database from the cvterm
+  if (preg_match('/^.+?:.*$/', $id)) {
+    $accession = preg_replace('/^.+?:(.*)$/', '\1', $id);
+    $dbname = preg_replace('/^(.+?):.*$/', '\1', $id);
+  }
+  if ($is_relationship and !$dbname) {
+    $accession = $id;
+    // because this is a relationship cvterm first check to see if it
+    // exists in the relationship ontology. If it does then return the cvterm.
+    //  If not then set the dbname to _global and we'll add it or find it there
+    $cvterm = db_fetch_object(db_query($cvtermsql, $name, 'OBO_REL'));
+    if ($cvterm) {
+      return $cvterm;
+    }
+    else {
+      // next check if this term is in the _global ontology.  If it is then
+      // return it no matter what the original CV
+      $dbname = '_global';
+
+      $cvterm = db_fetch_object(db_query($cvtermsql, $name, $dbname));
+      if ($cvterm) {
+        return $cvterm;
       }
-
-      // check to see if the dbxref already has an entry in the cvterm table
-      $sql = "SELECT * FROM {cvterm} WHERE dbxref_id = %d";
-      $check = db_fetch_object(db_query($sql,$dbxref->dbxref_id));
-
-      if(!$check){
-         // now add the cvterm
-         $sql = "
-            INSERT INTO {cvterm} (cv_id, name, definition, dbxref_id, 
-               is_obsolete, is_relationshiptype) 
-            VALUES (%d,'%s','%s',%d,%d,%d)
-         ";
-         if(!db_query($sql,$cv->cv_id,$name,$definition,
-             $dbxref->dbxref_id,$is_obsolete,$is_relationship)){
-            if(!$is_relationship){
-               tripal_cv_obo_quiterror("Failed to insert the term: $name ($dbname)");
-            } else {
-               tripal_cv_obo_quiterror("Failed to insert the relationship term: $name (cv: " . $cvname . " db: $dbname)");
-            }
-         }  
-         if(!$is_relationship){
-            print "Added CV term: $name ($dbname)\n";
-         } else {
-            print "Added relationship CV term: $name ($dbname)\n";
-         }
+    }
+  }
+  if (!$is_relationship and !$dbname) {
+    tripal_cv_obo_quiterror("A database identifier is missing from the term: $id");
+  }
+
+  // check to see if the database exists.
+  $db = tripal_cv_obo_add_db($dbname);
+  if (!$db) {
+    tripal_cv_obo_quiterror("Cannot find database '$dbname' in Chado.");
+  }
+
+
+  // if the cvterm doesn't exist then add it otherwise just update it
+  $cvterm = db_fetch_object(db_query($cvtermsql, $name, $dbname));
+  if (!$cvterm) {
+    // check to see if the dbxref exists if not, add it
+    $dbxref =  tripal_cv_obo_add_dbxref($db->db_id, $accession);
+    if (!$dbxref) {
+      tripal_cv_obo_quiterror("Failed to find or insert the dbxref record for cvterm, $name (id: $accession), for database $dbname");
+    }
+
+    // check to see if the dbxref already has an entry in the cvterm table
+    $sql = "SELECT * FROM {cvterm} WHERE dbxref_id = %d";
+    $check = db_fetch_object(db_query($sql, $dbxref->dbxref_id));
+
+    if (!$check) {
+      // now add the cvterm
+      $sql = "
+          INSERT INTO {cvterm} (cv_id, name, definition, dbxref_id,
+             is_obsolete, is_relationshiptype)
+          VALUES (%d,'%s','%s',%d,%d,%d)
+      ";
+      if (!db_query($sql, $cv->cv_id, $name, $definition,
+        $dbxref->dbxref_id, $is_obsolete, $is_relationship)) {
+        if (!$is_relationship) {
+          tripal_cv_obo_quiterror("Failed to insert the term: $name ($dbname)");
+        }
+        else {
+          tripal_cv_obo_quiterror("Failed to insert the relationship term: $name (cv: " . $cvname . " db: $dbname)");
+        }
       }
-      elseif($check and strcmp($check->name,$name)!=0){
-         // this dbxref_id alrady exists in the database but the name is 
-         // different.  We will trust that the OBO is correct and that there
-         // has been a name change for this dbxref, so we'll update
-         $sql = "
-            UPDATE {cvterm} SET name = '%s', definition = '%s',
-               is_obsolete = %d, is_relationshiptype = %d 
-            WHERE dbxref_id = %d
-         ";
-         if(!db_query($sql,$name,$definition,$is_obsolete,$is_relationship,$dbxref->dbxref_id)){
-            if(!$is_relationship){
-               tripal_cv_obo_quiterror("Failed to update the term: $name ($dbname)");
-            } else {
-               tripal_cv_obo_quiterror("Failed to update the relationship term: $name (cv: " . $cvname . " db: $dbname)");
-            }
-         } 
-         if(!$is_relationship){
-            print "Updated CV term: $name ($dbname)\n";
-         } else {
-            print "Updated relationship CV term: $name ($dbname)\n";
-         }
+      if (!$is_relationship) {
+        print "Added CV term: $name ($dbname)\n";
       }
-      elseif($check and strcmp($check->name,$name)==0){
-         // this entry already exists. We're good, so do nothing
+      else {
+        print "Added relationship CV term: $name ($dbname)\n";
       }
-      $cvterm = db_fetch_object(db_query($cvtermsql,$name,$dbname));
-   }
-   elseif($update) { // update the cvterm
+    }
+    elseif ($check and strcmp($check->name, $name)!=0) {
+      // this dbxref_id alrady exists in the database but the name is
+      // different.  We will trust that the OBO is correct and that there
+      // has been a name change for this dbxref, so we'll update
       $sql = "
-         UPDATE {cvterm} SET name='%s', definition='%s',
-            is_obsolete = %d, is_relationshiptype = %d
-         WHERE cvterm_id = %d
+          UPDATE {cvterm} SET name = '%s', definition = '%s',
+             is_obsolete = %d, is_relationshiptype = %d
+          WHERE dbxref_id = %d
       ";
-      if(!db_query($sql,$term['name'][0],$definition,
-          $is_obsolete,$is_relationship,$cvterm->cvterm_id)){
-         tripal_cv_obo_quiterror("Failed to update the term: $name");
-      }  
-      $cvterm = db_fetch_object(db_query($cvtermsql,$name,$dbname));         
-      if(!$is_relationship){
-         print "Updated CV term: $name ($dbname)\n";
-      } else {
-         print "Updated relationship CV term: $name ($dbname)\n";
+      if (!db_query($sql, $name, $definition, $is_obsolete, $is_relationship, $dbxref->dbxref_id)) {
+        if (!$is_relationship) {
+          tripal_cv_obo_quiterror("Failed to update the term: $name ($dbname)");
+        }
+        else {
+          tripal_cv_obo_quiterror("Failed to update the relationship term: $name (cv: " . $cvname . " db: $dbname)");
+        }
+      }
+      if (!$is_relationship) {
+        print "Updated CV term: $name ($dbname)\n";
       }
-   }
-   // return the cvterm
-   return $cvterm;
+      else {
+        print "Updated relationship CV term: $name ($dbname)\n";
+      }
+    }
+    elseif ($check and strcmp($check->name, $name)==0) {
+      // this entry already exists. We're good, so do nothing
+    }
+    $cvterm = db_fetch_object(db_query($cvtermsql, $name, $dbname));
+  }
+  elseif ($update) { // update the cvterm
+    $sql = "
+       UPDATE {cvterm} SET name='%s', definition='%s',
+          is_obsolete = %d, is_relationshiptype = %d
+       WHERE cvterm_id = %d
+    ";
+    if (!db_query($sql, $term['name'][0], $definition,
+      $is_obsolete, $is_relationship, $cvterm->cvterm_id)) {
+      tripal_cv_obo_quiterror("Failed to update the term: $name");
+    }
+    $cvterm = db_fetch_object(db_query($cvtermsql, $name, $dbname));
+    if (!$is_relationship) {
+      print "Updated CV term: $name ($dbname)\n";
+    }
+    else {
+      print "Updated relationship CV term: $name ($dbname)\n";
+    }
+  }
+
+  // return the cvterm
+  return $cvterm;
 }
 
 /**
-*
-* @ingroup tripal_obo_loader
-*/
-function tripal_cv_obo_add_dbxref($db_id,$accession,$version='',$description=''){
-
-   // check to see if the dbxref exists if not, add it
-   $dbxsql = "SELECT dbxref_id FROM {dbxref} WHERE db_id = %d and accession = '%s'";
-   $dbxref = db_fetch_object(db_query($dbxsql,$db_id,$accession));
-   if(!$dbxref){
-      $sql = "
-         INSERT INTO {dbxref} (db_id, accession, version, description)
-         VALUES (%d,'%s','%s','%s')
-      ";
-      if(!db_query($sql,$db_id,$accession,$version,$description)){
-         tripal_cv_obo_quiterror("Failed to insert the dbxref record $accession");
-      }
-      print "Added Dbxref accession: $accession\n";
-      $dbxref = db_fetch_object(db_query($dbxsql,$db_id,$accession));
-   }
-   return $dbxref;
+ * Add Database Reference
+ * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_add_dbxref($db_id, $accession, $version='', $description='') {
+
+  // check to see if the dbxref exists if not, add it
+  $dbxsql = "SELECT dbxref_id FROM {dbxref} WHERE db_id = %d and accession = '%s'";
+  $dbxref = db_fetch_object(db_query($dbxsql, $db_id, $accession));
+  if (!$dbxref) {
+    $sql = "
+       INSERT INTO {dbxref} (db_id, accession, version, description)
+       VALUES (%d,'%s','%s','%s')
+    ";
+    if (!db_query($sql, $db_id, $accession, $version, $description)) {
+      tripal_cv_obo_quiterror("Failed to insert the dbxref record $accession");
+    }
+    print "Added Dbxref accession: $accession\n";
+    $dbxref = db_fetch_object(db_query($dbxsql, $db_id, $accession));
+  }
+  return $dbxref;
 
 }
 

+ 371 - 341
tripal_cv/trees.php

@@ -1,22 +1,29 @@
 <?php
 
 /**
-*
-* @ingroup tripal_cv
-*/
+ * @file
+ * @todo Stephen describe this file
+ */
+
+/**
+ * Renders the cv_list form
+ *
+ * @ingroup tripal_cv
+ */
 function tripal_cv_show_browser() {
-  
-   $content = drupal_get_form('tripal_cv_list_form');
-   $content .= "
-      <div id=\"cv_browser\"></div>
-   ";
-   return $content;
+
+  $content = drupal_get_form('tripal_cv_list_form');
+  $content .= "
+    <div id=\"cv_browser\"></div>
+  ";
+
+  return $content;
 }
 
 
 /**
  * Generates JSON used for generating an exapandable tree of terms from
- * a controlled vocabulary that has associated counts. 
+ * a controlled vocabulary that has associated counts.
  *
  * The progammer must first create a materialized view that
  * will generate count data for a given controlled vocabulary.  For example, the Tripal
@@ -30,24 +37,24 @@ function tripal_cv_show_browser() {
  *  tripal_[module_name]_cv_tree_[unique id]
  *
  * where [module_name] is the name of the tripal module (e.g. tripal_analyisis_go)
- * and [unique id] is some unique identifier that the contolling module 
+ * and [unique id] is some unique identifier that the contolling module
  * recognizes. This string is the $tree_id variable passed as the first argument
- * to the function.  For example, the Tripal GO Analysis module generates 
+ * to the function.  For example, the Tripal GO Analysis module generates
  * tree ids of the form:
- * 
+ *
  *  tripal_analysis_go_cv_tree_10_2_bp
- * 
+ *
  * In this case the module that will manage this tree is identified as 'tripal_analysis_go' and within
  * the [unique id] portion contains the
- * organism_id (e.g. 10), analysis_id (e.g. 2) and tree type (bp = biological process). 
+ * organism_id (e.g. 10), analysis_id (e.g. 2) and tree type (bp = biological process).
  *
  * Second, the programmer must then define a hook in the controlling module for setting
  * some options used to build the chart.  The hook has the form:  hook_cv_tree($tree_id).
  * This hook should accept the full $tree_id as the single parameter.  For the Tripal
- * Analysis GO module the hook is named:  tripal_analysis_go_cv_tree.  
+ * Analysis GO module the hook is named:  tripal_analysis_go_cv_tree.
  *
- * The array returned by this hook must have the following fields: 
- *  - cv_id 
+ * The array returned by this hook must have the following fields:
+ *  - cv_id
  *      the cv_id for the controlled vocabulary
  *  - count_mview
  *      the name of the materialized view that contains the count data
@@ -68,22 +75,22 @@ function tripal_cv_show_browser() {
  *
  * Example from the tripal_analysis_go module:
  * @code
- *  function tripal_analysis_go_cv_tree($tree_id){
- * 
+ *  function tripal_analysis_go_cv_tree($tree_id) {
+ *
  *   $organism_id = preg_replace("/^tripal_analysis_go_cv_tree_(\d+)-(\d+)_(bp|cc|mf)$/","$1",$tree_id);
  *   $analysis_id = preg_replace("/^tripal_analysis_go_cv_tree_(\d+)-(\d+)_(bp|cc|mf)$/","$2",$tree_id);
  *   $type        = preg_replace("/^tripal_analysis_go_cv_tree_(\d+)-(\d+)_(bp|cc|mf)$/","$3",$tree_id);
- * 
- *   if(strcmp($type,'mf')==0){
+ *
+ *   if(strcmp($type,'mf')==0) {
  *      $class = 'molecular_function';
  *   }
- *   if(strcmp($type,'cc')==0){
+ *   if(strcmp($type,'cc')==0) {
  *      $class = 'cellular_component';
  *   }
- *   if(strcmp($type,'bp')==0){
+ *   if(strcmp($type,'bp')==0) {
  *      $class = 'biological_process';
  *   }
- * 
+ *
  *   $options = array(
  *      cv_id            => tripal_cv_get_cv_id($class),
  *      count_mview      => 'go_count_analysis',
@@ -108,350 +115,373 @@ function tripal_cv_show_browser() {
  *
  * @ingroup tripal_cv
  */
-function tripal_cv_tree($tree_id){
-  // parse out the tripal module name from the chart_id to find out 
+function tripal_cv_tree($tree_id) {
+  // parse out the tripal module name from the chart_id to find out
   // which Tripal "hook" to call:
-  $tripal_mod = preg_replace("/^(tripal_.+?)_cv_tree_(.+)$/","$1",$tree_id);
-  if($tripal_mod){
-     $callback = $tripal_mod . "_cv_tree";
+  $tripal_mod = preg_replace("/^(tripal_.+?)_cv_tree_(.+)$/", "$1", $tree_id);
+  if ($tripal_mod) {
+    $callback = $tripal_mod . "_cv_tree";
 
-     // now call the function in the module responsible for the tree.  This 
-     // should call the tripal_cv_init_cv with the proper parameters set for
-     // getting the cv_id of the vocabulary to use
-     $opt = call_user_func_array($callback,array($tree_id));
+    // now call the function in the module responsible for the tree.  This
+    // should call the tripal_cv_init_cv with the proper parameters set for
+    // getting the cv_id of the vocabulary to use
+    $opt = call_user_func_array($callback, array($tree_id));
 
-     // we only need to return the cv_id for this function call.
-     $json_array[] = $opt[cv_id];
+    // we only need to return the cv_id for this function call.
+    $json_array[] = $opt['cv_id'];
   }
+
   $json_array[] = $tree_id;
   return drupal_json($json_array);
 }
 
 
 /**
-*
-* @ingroup tripal_cv
-*/
+ *
+ * @ingroup tripal_cv
+ */
 function tripal_cv_update_tree() {
-   $content = array();
-   $ontology = 'sequence';
-
-   # get the id of the term to look up
-   $cv = check_plain($_REQUEST['cv']);
-   $term = check_plain($_REQUEST['term']);
-   $tree_id = check_plain($_REQUEST['tree_id']);
-
-   # get the options needed for this tree from the tripal module that 
-   # wants to create the tree
-   $tripal_mod = preg_replace("/^(tripal_.+?)_cv_tree_(.+)$/","$1",$tree_id);
-   if($tripal_mod){
-      $callback = $tripal_mod . "_cv_tree";
-      $opt = call_user_func_array($callback,array($tree_id));
-   }
-
-   # get the CV root terms
-   if(strcmp($term,'root')==0){
-      if(!$cv){
-        $cv = $opt[cv_id];
-      }
-      $content = tripal_cv_init_tree($cv,$opt[count_mview],
-         $opt[cvterm_id_column],$opt[count_column],$opt[filter],$opt[label]);
-   } 
-   # get the children terms
-   else {
-      $content = tripal_cv_get_term_children($term,$opt[count_mview],
-         $opt[cvterm_id_column],$opt[count_column],$opt[filter],$opt[label]);
-   }
-   drupal_json($content);
+  $content = array();
+  $ontology = 'sequence';
+
+  // get the id of the term to look up
+  $cv = check_plain($_REQUEST['cv']);
+  $term = check_plain($_REQUEST['term']);
+  $tree_id = check_plain($_REQUEST['tree_id']);
+
+  // get the options needed for this tree from the tripal module that
+  // wants to create the tree
+  $tripal_mod = preg_replace("/^(tripal_.+?)_cv_tree_(.+)$/", "$1", $tree_id);
+  if ($tripal_mod) {
+    $callback = $tripal_mod . "_cv_tree";
+    $opt = call_user_func_array($callback, array($tree_id));
+  }
+
+  // get the CV root terms
+  if (strcmp($term, 'root')==0) {
+    if (!$cv) {
+      $cv = $opt['cv_id'];
+    }
+    $content = tripal_cv_init_tree($cv, $opt['count_mview'],
+      $opt['cvterm_id_column'], $opt['count_column'], $opt['filter'], $opt['label']);
+
+  // get the children terms
+  }
+  else {
+    $content = tripal_cv_get_term_children($term, $opt['count_mview'],
+      $opt['cvterm_id_column'], $opt['count_column'], $opt['filter'], $opt['label']);
+  }
+
+  drupal_json($content);
 }
+
 /**
-* Generates JSON needed for jsTree Root-level Branches
-*
-* This function returns the JSON array for the jsTree 
-*    jQuery code that builds a tree for browsing the ontology.  This function
-*    should be called to generate the root level branches of the tree.
-*
-* @ingroup tripal_cv
-*/
-function tripal_cv_init_tree($cv_id,$cnt_table = null, $fk_column = null,
-   $cnt_column = null, $filter = null, $label = null) {
-
-   // get the list of root terms for the provided CV
-   $sql = "
-      SELECT *
-      FROM {cv_root_mview} CRM
-      WHERE cv_id = %d
-   ";
-   $previous_db = tripal_db_set_active('chado');
-   $results = db_query($sql,$cv_id);
-   tripal_db_set_active($previous_db); 
-
-   // prepare the SQL statement that will allow us to pull out count 
-   // information for each term in the tree.
-   if($cnt_table){
-      if(!$filter){
-         $filter = '(1=1)'; 
+ * Generates JSON needed for jsTree Root-level Branches
+ *
+ * This function returns the JSON array for the jsTree
+ *    jQuery code that builds a tree for browsing the ontology.  This function
+ *    should be called to generate the root level branches of the tree.
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_init_tree($cv_id, $cnt_table = NULL, $fk_column = NULL,
+  $cnt_column = NULL, $filter = NULL, $label = NULL) {
+
+  // get the list of root terms for the provided CV
+  $sql = "
+    SELECT *
+    FROM {cv_root_mview} CRM
+    WHERE cv_id = %d
+  ";
+  $previous_db = tripal_db_set_active('chado');
+  $results = db_query($sql, $cv_id);
+  tripal_db_set_active($previous_db);
+
+  // prepare the SQL statement that will allow us to pull out count
+  // information for each term in the tree.
+  if ($cnt_table) {
+    if (!$filter) {
+      $filter = '(1=1)';
+    }
+    $cnt_sql = "
+       SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items
+       FROM {$cnt_table} CNT
+        INNER JOIN cvterm CVT on CNT.$fk_column = CVT.cvterm_id
+       WHERE $filter AND CVT.cvterm_id = %d
+       ORDER BY $cnt_column desc
+    ";
+  }
+
+  while ($term = db_fetch_object($results)) {
+    $name = $term->name;
+    $count = 0;
+    if ($cnt_table) {
+      $previous_db = tripal_db_set_active('chado');
+      $cnt_results = db_query($cnt_sql, $term->cvterm_id);
+      tripal_db_set_active($previous_db);
+      while ($cnt = db_fetch_object($cnt_results)) {
+        $count += $cnt->cnt;
       }
-      $cnt_sql = "
-         SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items
-         FROM {$cnt_table} CNT 
-          INNER JOIN cvterm CVT on CNT.$fk_column = CVT.cvterm_id 
-         WHERE $filter AND CVT.cvterm_id = %d
-         ORDER BY $cnt_column desc
-      ";
-   }
- 
-   while ($term = db_fetch_object($results)) {
-      $name = $term->name;
-      $count = 0;
-      if($cnt_table){
-         $previous_db = tripal_db_set_active('chado');
-         $cnt_results = db_query($cnt_sql,$term->cvterm_id);
-         tripal_db_set_active($previous_db); 
-         while($cnt = db_fetch_object($cnt_results)){
-            $count += $cnt->cnt;
-         }
-         if($count > 0){
-            $name .= " ($count $label(s))";
-         }
-      } 
-      $content[] = array(
-           'attributes' => array (
-           'id' => $term->cvterm_id,
-        ),
-        state => 'closed',
-        data => $name,
-        children => array (),
-      );
-   }
+      if ($count > 0) {
+        $name .= " ($count $label(s))";
+      }
+    }
+    $content[] = array(
+      'attributes' => array(
+        'id' => $term->cvterm_id,
+      ),
+      'state' => 'closed',
+      'data' => $name,
+      'children' => array(),
+    );
+  }
 
-   return $content;
+  return $content;
 
 }
+
 /**
-*  Generates SON needed for jsTree -expanding a term to view children
-*
-*  This function returns the JSON array for the jsTree 
-*    jQuery code when expanding a term to view it's children.
-*
-* @ingroup tripal_cv_api
-*/
-function tripal_cv_get_term_children($cvterm_id,$cnt_table = null, 
-   $fk_column = null,$cnt_column = null, $filter = null, $label = null) {
-   # get the children for the term provided
-   $sql = "
-      SELECT CVTR.cvterm_relationship_id,CVTR.subject_id,
-         CVT1.name as subject_name, CVT3.name as type_name, CVTR.type_id, 
-         CVT2.name as object_name,CVTR.object_id 
-      FROM {cvterm_relationship} CVTR
-         INNER JOIN CVTerm CVT1 on CVTR.subject_id = CVT1.cvterm_id
-         INNER JOIN CVTerm CVT2 on CVTR.object_id = CVT2.cvterm_id
-         INNER JOIN CVTerm CVT3 on CVTR.type_id = CVT3.cvterm_id
-         INNER JOIN CV on CV.cv_id = CVT1.cv_id
-      WHERE CVTR.object_id = %d
-      ORDER BY CVT1.name
-   ";
-   $previous_db = tripal_db_set_active('chado');
-   $results = db_query($sql,$cvterm_id);
-   tripal_db_set_active($previous_db);
-
-
-   // prepare the SQL statement that will allow us to pull out count 
-   // information for each term in the tree.
-   if($cnt_table){
-      if(!$filter){
-         $filter = '(1=1)'; 
+ *  Generates SON needed for jsTree -expanding a term to view children
+ *
+ *  This function returns the JSON array for the jsTree
+ *    jQuery code when expanding a term to view it's children.
+ *
+ * @ingroup tripal_cv_api
+ */
+function tripal_cv_get_term_children($cvterm_id, $cnt_table = NULL,
+  $fk_column = NULL, $cnt_column = NULL, $filter = NULL, $label = NULL) {
+
+  // get the children for the term provided
+  $sql = "
+    SELECT CVTR.cvterm_relationship_id,CVTR.subject_id,
+       CVT1.name as subject_name, CVT3.name as type_name, CVTR.type_id,
+       CVT2.name as object_name,CVTR.object_id
+    FROM {cvterm_relationship} CVTR
+       INNER JOIN CVTerm CVT1 on CVTR.subject_id = CVT1.cvterm_id
+       INNER JOIN CVTerm CVT2 on CVTR.object_id = CVT2.cvterm_id
+       INNER JOIN CVTerm CVT3 on CVTR.type_id = CVT3.cvterm_id
+       INNER JOIN CV on CV.cv_id = CVT1.cv_id
+    WHERE CVTR.object_id = %d
+    ORDER BY CVT1.name
+  ";
+  $previous_db = tripal_db_set_active('chado');
+  $results = db_query($sql, $cvterm_id);
+  tripal_db_set_active($previous_db);
+
+
+  // prepare the SQL statement that will allow us to pull out count
+  // information for each term in the tree.
+  if ($cnt_table) {
+    if (!$filter) {
+      $filter = '(1=1)';
+    }
+    $cnt_sql = "
+       SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items
+       FROM {$cnt_table} CNT
+        INNER JOIN cvterm CVT on CNT.$fk_column = CVT.cvterm_id
+       WHERE $filter AND CVT.cvterm_id = %d
+       ORDER BY $cnt_column desc
+    ";
+  }
+
+  // populate the JSON content array
+  while ($term = db_fetch_object($results)) {
+    // count the number of items per term if requested
+    $name = $term->subject_name;
+    $count = 0;
+    if ($cnt_table) {
+      $previous_db = tripal_db_set_active('chado');
+      $cnt_results = db_query($cnt_sql, $term->subject_id);
+      tripal_db_set_active($previous_db);
+      while ($cnt = db_fetch_object($cnt_results)) {
+        $count += $cnt->num_items;
+      }
+      if ($count > 0) {
+        $name .= " (" . number_format($count) . " $label)";
+
+        // check if we have any children if so then set the value
+        $previous_db = tripal_db_set_active('chado');
+        $children = db_fetch_object(db_query($sql, $term->subject_id));
+        tripal_db_set_active($previous_db);
+        $state = 'leaf';
+        if ($children) {
+          $state = 'closed';
+        }
+        $content[] = array(
+          'attributes' => array(
+            'id' => $term->subject_id,
+          ),
+          'state' => $state,
+          'data' => $name,
+          'children' => array(),
+        );
       }
-      $cnt_sql = "
-         SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items
-         FROM {$cnt_table} CNT 
-          INNER JOIN cvterm CVT on CNT.$fk_column = CVT.cvterm_id 
-         WHERE $filter AND CVT.cvterm_id = %d
-         ORDER BY $cnt_column desc
-      ";
-   }
-   // populate the JSON content array
-   while ($term = db_fetch_object($results)) {
-      // count the number of items per term if requested
-      $name = $term->subject_name;
-      $count = 0;
-      if($cnt_table){
-         $previous_db = tripal_db_set_active('chado');
-         $cnt_results = db_query($cnt_sql,$term->subject_id);
-         tripal_db_set_active($previous_db); 
-         while($cnt = db_fetch_object($cnt_results)){
-            $count += $cnt->num_items;
-         }
-         if($count > 0){
-            $name .= " (".number_format($count)." $label)";
-            // check if we have any children if so then set the value
-            $previous_db = tripal_db_set_active('chado');
-            $children = db_fetch_object(db_query($sql,$term->subject_id));
-            tripal_db_set_active($previous_db);
-            $state = 'leaf';
-            if($children){
-               $state = 'closed';
-            }
-            $content[] = array(
-               'attributes' => array (
-                  'id' => $term->subject_id,
-               ),
-               state => $state,
-               data => $name,
-               children => array(),
-            );
-         }
-      } else {
-         // check if we have any children if so then set the value
-         $previous_db = tripal_db_set_active('chado');
-         $children = db_fetch_object(db_query($sql,$term->subject_id));
-         tripal_db_set_active($previous_db);
-         $state = 'leaf';
-         if($children){
-            $state = 'closed';
-         }
-         $content[] = array(
-            'attributes' => array (
-               'id' => $term->subject_id,
-            ),
-            state => $state,
-            data => $name,
-            children => array(),
-         );
+    }
+    else {
+      // check if we have any children if so then set the value
+      $previous_db = tripal_db_set_active('chado');
+      $children = db_fetch_object(db_query($sql, $term->subject_id));
+      tripal_db_set_active($previous_db);
+      $state = 'leaf';
+      if ($children) {
+        $state = 'closed';
       }
-   }
-   $content[] = $cnt_sql;
-   return $content;
+      $content[] = array(
+        'attributes' => array(
+           'id' => $term->subject_id,
+        ),
+        'state' => $state,
+        'data' => $name,
+        'children' => array(),
+      );
+    }
+  }
+  $content[] = $cnt_sql;
+
+  return $content;
 }
+
 /**
-* 
-* @ingroup tripal_cv
-*/
+ * @todo Stephen: describe what this function does
+ * @ingroup tripal_cv
+ */
 function tripal_cv_init_browser($cv_id) {
 
-   $content = "
-        <div id=\"tripal_cv_cvterm_info_box\">
-           <a href=\"#\" onclick=\"$('#tripal_cv_cvterm_info_box').hide()\" style=\"float: right\">Close [X]</a>
-           <h3>Term Information</h3>
-           <div id=\"tripal_cv_cvterm_info\"></div>
-        </div>
-        <div id=\"tripal_ajaxLoading\" style=\"display:none\">
-           <div id=\"loadingText\">Loading...</div>
-           <img src=\"$url\">
-        </div> 
-         <h3>Tree Browser</h3>
-        <div id=\"browser\"</div></div>
-   ";
-
-   drupal_json(array('update' => "$content"));
+  $content = "
+    <div id=\"tripal_cv_cvterm_info_box\">
+      <a href=\"#\" onclick=\"$('#tripal_cv_cvterm_info_box').hide()\" style=\"float: right\">Close [X]</a>
+      <h3>Term Information</h3>
+      <div id=\"tripal_cv_cvterm_info\"></div>
+    </div>
+    <div id=\"tripal_ajaxLoading\" style=\"display:none\">
+      <div id=\"loadingText\">Loading...</div>
+      <img src=\"$url\">
+    </div>
+    <h3>Tree Browser</h3>
+    <div id=\"browser\"</div>
+    </div>
+  ";
+
+  drupal_json(array('update' => "$content"));
+
 }
+
 /**
-*
-* @ingroup tripal_cv
-*/
-function tripal_cv_cvterm_info($cvterm_id){
-
-   # get the id of the term to look up
-   $cv = check_plain($_REQUEST['cv']);
-   $tree_id = check_plain($_REQUEST['tree_id']);
-
-   // first get any additional information to add to the cvterm
-   if(strcmp($tree_id,'undefined')!=0){
-      $tripal_mod = preg_replace("/^(tripal_.+?)_cv_tree_(.+)$/","$1",$tree_id);
-      if($tripal_mod){
-         $callback = $tripal_mod . "_cvterm_add";
-         $opt = call_user_func_array($callback,array($cvterm_id,$tree_id));
-      }
-   }
-
-   $sql = "
-      SELECT CVT.name as cvtermname, CVT.definition, CV.name as cvname,
-         DBX.accession,DB.urlprefix,DB.db_id,DB.name as dbname
-      FROM {CVTerm} CVT
-        INNER JOIN CV on CVT.cv_id = CV.cv_id
-        INNER JOIN dbxref DBX on CVT.dbxref_id = DBX.dbxref_id
-        INNER JOIN DB on DBX.db_id = DB.db_id
-      WHERE CVT.cvterm_id = %d
-   ";
-   $previous_db = tripal_db_set_active('chado');
-   $cvterm = db_fetch_object(db_query($sql,$cvterm_id));
-   tripal_db_set_active($previous_db);
-   $sql = "
-      SELECT CVTS.synonym, CVT.name as cvname
-      FROM {cvtermsynonym} CVTS
-        INNER JOIN cvterm CVT on CVTS.type_id = CVT.cvterm_id
-      WHERE CVTS.cvterm_id = %d
-    
-   ";
-   $previous_db = tripal_db_set_active('chado');
-   $results = db_query($sql,$cvterm_id);
-   tripal_db_set_active($previous_db);
-   while($synonym = db_fetch_object($results)){
-      $synonym_rows .= "<b>$synonym->cvname:</b>  $synonym->synonym<br>";
-   }
-   $accession = $cvterm->accession;
-   if($cvterm->urlprefix){
-      $accession = "<a href=\"$cvterm->urlprefix$cvterm->accession\">$cvterm->accession</a>";
-   }
-   $content = "
-      <div id=\"cvterm\">
-      <table>
-        <tr><th>Term</th><td>$cvterm->cvtermname</td></tr>
-        <tr><th>Accession</th><td>$accession</td></tr>
-        <tr><th>Ontology</th><td>$cvterm->cvname</td></tr>
-        <tr><th>Definition</th><td>$cvterm->definition</td></tr>
-        <tr><th>Synonyms</th><td>$synonym_rows</td></tr>
-        <tr><th>Internal ID</th><td>$cvterm_id</td></tr> 
-   ";
-
-   // now add in any additional options from a hook
-   if($opt){
-      foreach ($opt as $key=>$value){
-         $content .= "<tr><th>$key</th><td>$value</td>";
-      }
-   }
-
-   // close out the information table
-   $content .= "
-      </table>
-      </div>
-   ";
-   drupal_json(array('update' => $content));
+ * Describe a cvterm (Rendered)
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cvterm_info($cvterm_id) {
+
+  // get the id of the term to look up
+  $cv = check_plain($_REQUEST['cv']);
+  $tree_id = check_plain($_REQUEST['tree_id']);
+
+  // first get any additional information to add to the cvterm
+  if (strcmp($tree_id, 'undefined') != 0) {
+    $tripal_mod = preg_replace("/^(tripal_.+?)_cv_tree_(.+)$/", "$1", $tree_id);
+    if ($tripal_mod) {
+      $callback = $tripal_mod . "_cvterm_add";
+      $opt = call_user_func_array($callback, array($cvterm_id, $tree_id));
+    }
+  }
+
+  $sql = "
+    SELECT CVT.name as cvtermname, CVT.definition, CV.name as cvname,
+       DBX.accession,DB.urlprefix,DB.db_id,DB.name as dbname
+    FROM {CVTerm} CVT
+      INNER JOIN CV on CVT.cv_id = CV.cv_id
+      INNER JOIN dbxref DBX on CVT.dbxref_id = DBX.dbxref_id
+      INNER JOIN DB on DBX.db_id = DB.db_id
+    WHERE CVT.cvterm_id = %d
+  ";
+  $previous_db = tripal_db_set_active('chado');
+  $cvterm = db_fetch_object(db_query($sql, $cvterm_id));
+  tripal_db_set_active($previous_db);
+
+  $sql = "
+    SELECT CVTS.synonym, CVT.name as cvname
+    FROM {cvtermsynonym} CVTS
+      INNER JOIN cvterm CVT on CVTS.type_id = CVT.cvterm_id
+    WHERE CVTS.cvterm_id = %d
+
+  ";
+  $previous_db = tripal_db_set_active('chado');
+  $results = db_query($sql, $cvterm_id);
+  tripal_db_set_active($previous_db);
+  while ($synonym = db_fetch_object($results)) {
+    $synonym_rows .= "<b>$synonym->cvname:</b>  $synonym->synonym<br />";
+  }
+
+  $accession = $cvterm->accession;
+  if ($cvterm->urlprefix) {
+    $accession = "<a href=\"$cvterm->urlprefix$cvterm->accession\">$cvterm->accession</a>";
+  }
+
+  $content = "
+    <div id=\"cvterm\">
+    <table>
+      <tr><th>Term</th><td>$cvterm->cvtermname</td></tr>
+      <tr><th>Accession</th><td>$accession</td></tr>
+      <tr><th>Ontology</th><td>$cvterm->cvname</td></tr>
+      <tr><th>Definition</th><td>$cvterm->definition</td></tr>
+      <tr><th>Synonyms</th><td>$synonym_rows</td></tr>
+      <tr><th>Internal ID</th><td>$cvterm_id</td></tr>
+  ";
+
+  // now add in any additional options from a hook
+  if ($opt) {
+    foreach ($opt as $key => $value) {
+      $content .= "<tr><th>$key</th><td>$value</td>";
+    }
+  }
+
+  // close out the information table
+  $content .= "
+    </table>
+    </div>
+  ";
+  drupal_json(array('update' => $content));
 }
+
 /**
-*
-* @ingroup tripal_cv
-*/
+ * Form listing CVs
+ *
+ * @ingroup tripal_cv
+ */
 function tripal_cv_list_form($form_state) {
 
-   // get a list of db from chado for user to choose
-    $sql = "
-      SELECT DISTINCT CV.name,CV.cv_id
-      FROM {cvterm_relationship} CVTR
-         INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
-         INNER JOIN CV on CV.cv_id = CVT.cv_id
-   ";
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $results = db_query ($sql);
-   tripal_db_set_active($previous_db);
-   $blastdbs = array();
-   $cvs[''] = '';
-   while ($cv = db_fetch_object($results)){
-      $cvs[$cv->cv_id] = $cv->name;
-   }
-
-   $form['db_options'] = array(
-      '#type' => 'value',
-      '#value' => $cvs
-   );        
-   $form['cv_list'] = array(
-      '#title' => t('CVs with relationships'),
-      '#type' => 'select',
-      '#description' => t('Choose the controlled vocabulary to browse'),
-      '#options' => $form['db_options']['#value'],
-      '#attributes' => array(
-         'onChange' => "return tripal_cv_init_browser(this)",
-      )
-   );
-   return $form;
+  // get a list of db from chado for user to choose
+  $sql = "
+    SELECT DISTINCT CV.name,CV.cv_id
+    FROM {cvterm_relationship} CVTR
+       INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
+       INNER JOIN CV on CV.cv_id = CVT.cv_id
+  ";
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  $results = db_query($sql);
+  tripal_db_set_active($previous_db);
+
+  $blastdbs = array();
+  $cvs[''] = '';
+  while ($cv = db_fetch_object($results)) {
+    $cvs[$cv->cv_id] = $cv->name;
+  }
+
+  $form['db_options'] = array(
+    '#type' => 'value',
+    '#value' => $cvs
+  );
+
+  $form['cv_list'] = array(
+    '#title' => t('CVs with relationships'),
+    '#type' => 'select',
+    '#description' => t('Choose the controlled vocabulary to browse'),
+    '#options' => $form['db_options']['#value'],
+    '#attributes' => array(
+      'onChange' => "return tripal_cv_init_browser(this)",
+    )
+  );
+
+  return $form;
 }

+ 306 - 300
tripal_cv/tripal_cv.api.inc

@@ -1,15 +1,18 @@
 <?php
 
 /**
+ * @file
+ * Controlled Vocabulary API
+ *
  * @defgroup tripal_cv_api CV Module API
  * @ingroup tripal_api
  * @ingroup tripal_cv
  * This module provides a set of functions to simplify working with
  * controlled vocabularies.  Most of the API functions deal with retrieving
- * terms or their parent vocabularies.  
- * 
+ * terms or their parent vocabularies.
+ *
  * However, the API also supports
- * generation of trees for browsing a vocabulary as well as generation of 
+ * generation of trees for browsing a vocabulary as well as generation of
  * pie graphs for display of hierarchical counts of terms.  Version 0.3b of
  * Tripal provides a feature browser and a feature summary chart uses
  * the API functions provided here.  But in general charts and trees can be
@@ -27,7 +30,7 @@
  *   Chado controlled vocabulary object
  *
  * The controlled vocabulary is selected using tripal_core_chado select and as such the
- * $select_values array parameter meant to uniquely identify the controlled vocab to be 
+ * $select_values array parameter meant to uniquely identify the controlled vocab to be
  * returned follows the same form as when using tripal_core_chado_select directly.
  *
  * Example Usage:
@@ -39,55 +42,57 @@
  * @endcode
  *  The above code selects the feature_property cv and returns the following object:
  * @code
-    $cv_object = stdClass Object ( 
+    $cv_object = stdClass Object (
       [cv_id] => 13
       [name] => feature_property
-      [definition] => 
-    ); 
+      [definition] =>
+    );
  * @endcode
  *
  * @ingroup tripal_cv_api
  */
-function tripal_cv_get_cv ($select_values) {
+function tripal_cv_get_cv($select_values) {
 
   $columns = array(
-    'cv_id', 
-    'name', 
-    'definition', 
+    'cv_id',
+    'name',
+    'definition',
   );
   $results = tripal_core_chado_select('cv', $columns, $select_values);
   if (sizeof($results) == 1) {
     return $results[0];
-  } elseif (empty($results)) {
-    watchdog('tripal_cv', 
+  }
+  elseif (empty($results)) {
+    watchdog('tripal_cv',
       'tripal_cv_get_cv: No cv matches criteria values:%values',
       array('%values' => print_r($select_values, TRUE)),
       WATCHDOG_WARNING
     );
     return FALSE;
-  } else {
-    watchdog('tripal_cv', 
+  }
+  else {
+    watchdog('tripal_cv',
       'tripal_cv_get_cv: 2+ cvs match criteria values:%values',
       array('%values' => print_r($select_values, TRUE)),
       WATCHDOG_WARNING
     );
   }
-  
+
 }
 
 // Purpose: To retrieve a chado cv object
-// @param $where_options 
+// @param $where_options
 //   @code
 //        array(
-//													<column_name> => array(
-//														'type' => <type of column: INT/STRING>,
-//														'value' => <the vlaue you want to filter on>,
-//														'exact' => <if TRUE use =; if FALSE use ~>,
-//													)
-//				)
+//                          <column_name> => array(
+//                            'type' => <type of column: INT/STRING>,
+//                            'value' => <the vlaue you want to filter on>,
+//                            'exact' => <if TRUE use =; if FALSE use ~>,
+//                          )
+//        )
 // @endcode
 //
-// @return 
+// @return
 //   Chado cv object with all fields from the chado cv table
 //
 // @ingroup tripal_cv_api
@@ -99,24 +104,25 @@ function tripal_cv_get_cv ($select_values) {
  *
  * @param $name
  *  The name of the cv to be returned
- * @return 
+ * @return
  *   The cv object for the specified CV name
  *
- * @ingroup tripal_cv_api 
+ * @ingroup tripal_cv_api
  */
-function tripal_cv_get_cv_by_name ($name) {
-	$previous_db = tripal_db_set_active('chado');	
-   $r = db_fetch_object(db_query("SELECT * FROM cv WHERE name = '%s'",$name));
-   tripal_db_set_active($previous_db);
+function tripal_cv_get_cv_by_name($name) {
 
-  return $r;
+  $previous_db = tripal_db_set_active('chado');
+  $r = tripal_core_chado_select('cv', array('*'), array('name' => $name));
+  tripal_db_set_active($previous_db);
+
+  return $r[0];
 }
 
 /**
  * Retrieve the cv object for the specified CV id
  *
  * NOTE: This function is deprecated.
- * @see tripal_core_chado_generate_vars
+ * @see tripal_core_chado_generate_vars()
  *
  * @param $cv_id
  *   The unique identifier for the cv retrieve
@@ -126,10 +132,11 @@ function tripal_cv_get_cv_by_name ($name) {
  *
  * @ingroup tripal_cv_api
  */
-function tripal_cv_get_cv_by_id ($cv_id) {
-	$previous_db = tripal_db_set_active('chado');	
-   $r = db_fetch_object(db_query("SELECT * FROM cv WHERE cv_id = %d",$cv_id));
-   tripal_db_set_active($previous_db);
+function tripal_cv_get_cv_by_id($cv_id) {
+
+  $previous_db = tripal_db_set_active('chado');
+  $r = tripal_core_chado_select('cv', array('*'), array('cv_id' => $cv_id));
+  tripal_db_set_active($previous_db);
 
   return $r;
 }
@@ -137,21 +144,17 @@ function tripal_cv_get_cv_by_id ($cv_id) {
 /**
  * Create an options array to be used in a form element which provides a list of all chado cvs
  *
- * @return 
+ * @return
  *   An array(cv_id => name) for each cv in the chado cv table
  *
  * @ingroup tripal_cv_api
  */
 function tripal_cv_get_cv_options() {
 
-  $previous_db = tripal_db_set_active('chado');
-  $result = db_query(
-    "SELECT cv_id, name FROM cv"
-  );
-  tripal_db_set_active($previous_db);
+  $results = tripal_core_chado_select('cv', array('cv_id', 'name'), array());
 
   $options = array();
-  while ( $r = db_fetch_object($result) ) {
+  foreach ($results as $r) {
     $options[$r->cv_id] = $r->name;
   }
 
@@ -169,41 +172,41 @@ function tripal_cv_get_cv_options() {
  * @param $cv_name
  *   the name of the CV
  *
- * @return 
+ * @return
  *   cvterm object
  *
  * @ingroup tripal_cv_api
  */
-function tripal_cv_get_cvterm_by_name ($name, $cv_id=0,$cv_name='tripal') {
+function tripal_cv_get_cvterm_by_name($name, $cv_id = 0, $cv_name = 'tripal') {
 
   if ($cv_id) {
     $values = array(
        'name' => $name,
        'cv_id' => $cv_id,
     );
-    $r = tripal_core_chado_select('cvterm',array('*'),$values);
-  } 
-  elseif($cv_name){
+    $r = tripal_core_chado_select('cvterm', array('*'), $values);
+  }
+  elseif ($cv_name) {
     $values = array(
-       'name' => $name,
-       'cv_id' => array(
-          'name' => $cv_name,
-       ),
+      'name' => $name,
+      'cv_id' => array(
+        'name' => $cv_name,
+      ),
     );
-    $r = tripal_core_chado_select('cvterm',array('*'),$values);
+    $r = tripal_core_chado_select('cvterm', array('*'), $values);
   }
   else {
     $values = array(
-       'name' => $name,
+      'name' => $name,
     );
-    $r = tripal_core_chado_select('cvterm',array('*'),$values);
+    $r = tripal_core_chado_select('cvterm', array('*'), $values);
   }
-  
-  if(!$r){
-     return FALSE;
+
+  if (!$r) {
+    return FALSE;
   }
-  if(count($r) > 0){
-     return FALSE;
+  if (count($r) > 0) {
+    return FALSE;
   }
   return $r[0];
 }
@@ -211,32 +214,27 @@ function tripal_cv_get_cvterm_by_name ($name, $cv_id=0,$cv_name='tripal') {
 /**
  * Create an options array to be used in a form element
  *   which provides a list of all chado cvterms
- * 
- * @param $cv_id 
+ *
+ * @param $cv_id
  *   The chado cv_id;
  *   only cvterms with the supplied cv_id will be returned
- * @return 
- *   An array(cvterm_id => name) 
+ * @return
+ *   An array(cvterm_id => name)
  *   for each cvterm in the chado cvterm table where cv_id=that supplied
  *
  * @ingroup tripal_cv_api
  */
 function tripal_cv_get_cvterm_options($cv_id = 0) {
 
-  $previous_db = tripal_db_set_active('chado');
   if ($cv_id > 0) {
-  	$result = db_query(
-    	"SELECT cvterm_id, name FROM cvterm WHERE cv_id=%d", $cv_id
-  	);
-  } else {
-  	$result = db_query(
-    	"SELECT cvterm_id, name FROM cvterm"
-  	);
+    $results = tripal_core_chado_select('cvterm', array('cvterm_id', 'name'), array('cv_id' => $cv_id));
+  }
+  else {
+    $results = tripal_core_chado_select('cvterm', array('cvterm_id', 'name'), array());
   }
-  tripal_db_set_active($previous_db);
 
   $options = array();
-  while ( $r = db_fetch_object($result) ) {
+  foreach ($results as $r) {
     $options[$r->cvterm_id] = $r->name;
   }
 
@@ -252,7 +250,7 @@ function tripal_cv_get_cvterm_options($cv_id = 0) {
  * @return
  *    Array describing the cvterm table
  *
- * @ingroup tripal_schema_api 
+ * @ingroup tripal_schema_api
  */
 function tripal_cv_chado_cvterm_schema() {
   $description = array();
@@ -263,251 +261,259 @@ function tripal_cv_chado_cvterm_schema() {
           'cv_id' => 'cv_id',
         ),
   );
-      
+
   $description['foreign keys']['dbxref'] = array(
         'table' => 'dbxref',
         'columns' => array(
           'dbxref_id' => 'dbxref_id',
         ),
-  ); 
+  );
 
   return $description;
 }
 
 /**
-* Adds a controlled vocabular to the CV table of Chado.
-*
-* @param $name
-*   The name of the controlled vocabulary. These are typically all lower case
-*   with no special characters other than an undrescore (for spaces).
-* @param $comment
-*   A description or definition of the vocabulary.
-*
-* @return
-*   An object populated with fields from the newly added database.
-*
-* @ingroup tripal_cv_api
-*/
-function tripal_cv_add_cv($name,$comment){
-
- // see if the CV (default-namespace) exists already in the database
-   $vocab = $name;
-   $remark = $comment;
-   $cv_sql = "SELECT * FROM {cv} WHERE name = '%s'";
-   $cv = db_fetch_object(db_query($cv_sql,$vocab));
-
-   // if the CV exists then update it, otherwise insert
-   if(!$cv){
-      $sql = "INSERT INTO {cv} (name,definition) VALUES ('%s','%s')";
-      if(!db_query($sql,$vocab,$remark)){
-         watchdog('tripal_cv', "Failed to create the CV record",NULL,WATCHDOG_WARNING);
-         return 0;
-      }
-      $cv = db_fetch_object(db_query($cv_sql,$vocab));
-   } else {
-      $sql = "UPDATE {cv} SET definition = '%s' WHERE name ='%s'";
-      if(!db_query($sql,$remark,$vocab)){
-         watchdog('tripal_cv', "Failed to update the CV record",NULL,WATCHDOG_WARNING);
-         return 0;
-      }
-      $cv = db_fetch_object(db_query($cv_sql,$vocab));
-   }
-   return $cv;
+ * Adds a controlled vocabular to the CV table of Chado.
+ *
+ * @param $name
+ *   The name of the controlled vocabulary. These are typically all lower case
+ *   with no special characters other than an undrescore (for spaces).
+ * @param $comment
+ *   A description or definition of the vocabulary.
+ *
+ * @return
+ *   An object populated with fields from the newly added database.
+ *
+ * @ingroup tripal_cv_api
+ */
+function tripal_cv_add_cv($name, $comment) {
+
+  // see if the CV (default-namespace) exists already in the database
+  $vocab = $name;
+  $remark = $comment;
+  $cv_sql = "SELECT * FROM {cv} WHERE name = '%s'";
+  $cv = db_fetch_object(db_query($cv_sql, $vocab));
+
+  // if the CV exists then update it, otherwise insert
+  if (!$cv) {
+    $sql = "INSERT INTO {cv} (name,definition) VALUES ('%s','%s')";
+    if (!db_query($sql, $vocab, $remark)) {
+      watchdog('tripal_cv', "Failed to create the CV record", NULL, WATCHDOG_WARNING);
+      return FALSE;
+    }
+    $cv = db_fetch_object(db_query($cv_sql, $vocab));
+  }
+  else {
+    $sql = "UPDATE {cv} SET definition = '%s' WHERE name ='%s'";
+    if (!db_query($sql, $remark, $vocab)) {
+      watchdog('tripal_cv', "Failed to update the CV record", NULL, WATCHDOG_WARNING);
+      return FALSE;
+    }
+    $cv = db_fetch_object(db_query($cv_sql, $vocab));
+  }
+
+  return $cv;
 }
+
 /**
-*  Add's a CV term to the cvterm table.  If the parent CV does not exist then
-*  that too is added to the CV table.  If the cvterm is a relationship term
-*  then the $is_relationship argument should be set.  The function will try
-*  to first find the relationship in the relationship ontology for updating and
-*  if it can't be found will add the relationship to the __global CV.  All terms
-*  must also have a corresponding database.  This is specified in the term's
-*  ID just before the colon (e.g. GO:003824).  If the database does not exist
-*  in the DB table then it will be added automatically.  The accession (the 
-*  value just after the colon in the term's ID) will be added to the dbxref 
-*  table.  If the CVterm already exists and $update is set (default) then the
-*  cvterm is updated.  If the CVTerm already exists and $update is not set, then
-*  no changes are made and the CVTerm object is returned.
-*
-* @param $term
-*   An associative array with the following keys: 'id', 'name' and 'namespace',
-*   'is_obsolete', and 'def'.  Where 'id' is the term accession, 'name' is the 
-*   term name, 'namespace' is the CV name for the term, 'def' is the term 
-*   definition and 'is_obsolete' is present and set to 1 if the term is defunct.
-*   The 'id' must be of the form <DB>:<ACCESSION>, where <DB> is the name of
-*   the database to which the cvterm belongs and the <ACCESSION> is the 
-*   term's accession number in the database.
-* @param $defaultcv
-*   Optional. The CV name to which the term 
-*   belongs.  If this arugment is null or not provided then the function tries
-*   to find a record in the CV table with the same name provided in the 
-*   $term[namespace].  If this field is provided then it overrides what the 
-*   value in $term[namespace] 
-* @param $is_relationship
-*   If this term is a relationship term then this value should be 1.
-* @param $update
-*   By default this is set to 1.  If the term exists it is automatically updated.
-* @param $dbname
-*   In some cases the database name will not be part of the $term['id'] and it
-*   needs to be explicitly set.  Use this argument only if the database name
-*   cannot be specififed in the term ID (e.g. <DB>:<ACCESSION>).
-*
-* @return
-*   A CVTerm object  
-*
-* @ingroup tripal_cv_api
-*/
-function tripal_cv_add_cvterm($term,$defaultcv='',$is_relationship = 0,$update = 1,$dbname=NULL){
-
-   // get the term properties
-   $id = $term['id'];
-   $name = $term['name'];
-   $cvname = $term['namespace'];
-   $definition = preg_replace('/^\"(.*)\"/','\1',$term['def']);
-   $is_obsolete = 0;
-   if(isset($term['is_obsolete']) and  strcmp($term['is_obsolete'],'true')==0){
-     $is_obsolete = 1;
-   }
-   if(!$name and !$id){
-      watchdog('tripal_cv', "Cannot find cvterm without 'id' or 'name'",NULL,WATCHDOG_WARNING);
-      return 0;
-   }
-   if(!$id){
-      $id = $name;
-   }
-   if(!$name){
-      $name = $id;
-   }
-   if(!$cvname){
-      $cvname = $defaultcv;
-   }
-   // make sure the CV name exists
-   $cv = tripal_cv_add_cv($cvname,'');
-   if(!$cv){
-      watchdog('tripal_cv', "Cannot find namespace '$cvname' when adding/updating $id",NULL,WATCHDOG_WARNING);
-      return 0;
-   }
-
-   // this SQL statement will be used a lot to find a cvterm so just set it
-   // here for easy reference below.  Because CV terms can change their names
-   // but accessions don't change, the following SQL finds cvterms based on
-   // their accession rather than the name
-   $cvtermsql = "SELECT CVT.name, CVT.cvterm_id, DB.name as dbname, DB.db_id 
-                  FROM {cvterm} CVT
-                    INNER JOIN {dbxref} DBX on CVT.dbxref_id = DBX.dbxref_id
-                    INNER JOIN {db} DB on DBX.db_id = DB.db_id
-                    INNER JOIN {cv} CV on CV.cv_id = CVT.cv_id
-                  WHERE DBX.accession = '%s' and DB.name = '%s'";  
-
-   // get the accession and the database from the cvterm
-   if($dbname){
-      $accession = $id;
-   }
-   elseif(preg_match('/^.+?:.*$/',$id)){
-      $accession = preg_replace('/^.+?:(.*)$/','\1',$id);
-      $dbname = preg_replace('/^(.+?):.*$/','\1',$id);
-   } 
-   if($is_relationship and !$dbname){
-      $accession = $id;
-      // because this is a relationship cvterm first check to see if it 
-      // exists in the relationship ontology. If it does then return the cvterm.
-      //  If not then set the dbname to _global and we'll add it or find it there
-      $cvterm = db_fetch_object(db_query($cvtermsql,$accession,'OBO_REL'));
-      if($cvterm){
-         return $cvterm;
-      } else {
-         // next check if this term is in the _global ontology.  If it is then
-         // return it no matter what the original CV
-         $dbname = '_global';
-
-         $cvterm = db_fetch_object(db_query($cvtermsql,$accesion,$dbname));
-         if($cvterm){
-            return $cvterm;
-         }
+ *  Add's a CV term to the cvterm table.  If the parent CV does not exist then
+ *  that too is added to the CV table.  If the cvterm is a relationship term
+ *  then the $is_relationship argument should be set.  The function will try
+ *  to first find the relationship in the relationship ontology for updating and
+ *  if it can't be found will add the relationship to the __global CV.  All terms
+ *  must also have a corresponding database.  This is specified in the term's
+ *  ID just before the colon (e.g. GO:003824).  If the database does not exist
+ *  in the DB table then it will be added automatically.  The accession (the
+ *  value just after the colon in the term's ID) will be added to the dbxref
+ *  table.  If the CVterm already exists and $update is set (default) then the
+ *  cvterm is updated.  If the CVTerm already exists and $update is not set, then
+ *  no changes are made and the CVTerm object is returned.
+ *
+ * @param $term
+ *   An associative array with the following keys: 'id', 'name' and 'namespace',
+ *   'is_obsolete', and 'def'.  Where 'id' is the term accession, 'name' is the
+ *   term name, 'namespace' is the CV name for the term, 'def' is the term
+ *   definition and 'is_obsolete' is present and set to 1 if the term is defunct.
+ *   The 'id' must be of the form <DB>:<ACCESSION>, where <DB> is the name of
+ *   the database to which the cvterm belongs and the <ACCESSION> is the
+ *   term's accession number in the database.
+ * @param $defaultcv
+ *   Optional. The CV name to which the term
+ *   belongs.  If this arugment is null or not provided then the function tries
+ *   to find a record in the CV table with the same name provided in the
+ *   $term[namespace].  If this field is provided then it overrides what the
+ *   value in $term[namespace]
+ * @param $is_relationship
+ *   If this term is a relationship term then this value should be 1.
+ * @param $update
+ *   By default this is set to 1.  If the term exists it is automatically updated.
+ * @param $dbname
+ *   In some cases the database name will not be part of the $term['id'] and it
+ *   needs to be explicitly set.  Use this argument only if the database name
+ *   cannot be specififed in the term ID (e.g. <DB>:<ACCESSION>).
+ *
+ * @return
+ *   A CVTerm object
+ *
+ * @ingroup tripal_cv_api
+ */
+function tripal_cv_add_cvterm($term, $defaultcv='', $is_relationship = 0, $update = 1, $dbname=NULL) {
+
+  // get the term properties
+  $id = $term['id'];
+  $name = $term['name'];
+  $cvname = $term['namespace'];
+  $definition = preg_replace('/^\"(.*)\"/', '\1', $term['def']);
+  $is_obsolete = 0;
+  if (isset($term['is_obsolete']) and  strcmp($term['is_obsolete'], 'true') == 0) {
+    $is_obsolete = 1;
+  }
+  if (!$name and !$id) {
+    watchdog('tripal_cv', "Cannot find cvterm without 'id' or 'name'", NULL, WATCHDOG_WARNING);
+    return 0;
+  }
+  if (!$id) {
+    $id = $name;
+  }
+  if (!$name) {
+    $name = $id;
+  }
+  if (!$cvname) {
+    $cvname = $defaultcv;
+  }
+  // make sure the CV name exists
+  $cv = tripal_cv_add_cv($cvname, '');
+  if (!$cv) {
+    watchdog('tripal_cv', "Cannot find namespace '$cvname' when adding/updating $id", NULL, WATCHDOG_WARNING);
+    return 0;
+  }
+
+  // this SQL statement will be used a lot to find a cvterm so just set it
+  // here for easy reference below.  Because CV terms can change their names
+  // but accessions don't change, the following SQL finds cvterms based on
+  // their accession rather than the name
+  $cvtermsql = "SELECT CVT.name, CVT.cvterm_id, DB.name as dbname, DB.db_id
+                FROM {cvterm} CVT
+                  INNER JOIN {dbxref} DBX on CVT.dbxref_id = DBX.dbxref_id
+                  INNER JOIN {db} DB on DBX.db_id = DB.db_id
+                  INNER JOIN {cv} CV on CV.cv_id = CVT.cv_id
+                WHERE DBX.accession = '%s' and DB.name = '%s'";
+
+  // get the accession and the database from the cvterm
+  if ($dbname) {
+    $accession = $id;
+  }
+  elseif (preg_match('/^.+?:.*$/', $id)) {
+    $accession = preg_replace('/^.+?:(.*)$/', '\1', $id);
+    $dbname = preg_replace('/^(.+?):.*$/', '\1', $id);
+  }
+  if ($is_relationship and !$dbname) {
+    $accession = $id;
+    // because this is a relationship cvterm first check to see if it
+    // exists in the relationship ontology. If it does then return the cvterm.
+    //  If not then set the dbname to _global and we'll add it or find it there
+    $cvterm = db_fetch_object(db_query($cvtermsql, $accession, 'OBO_REL'));
+    if ($cvterm) {
+      return $cvterm;
+    }
+    else {
+      // next check if this term is in the _global ontology.  If it is then
+      // return it no matter what the original CV
+      $dbname = '_global';
+
+      $cvterm = db_fetch_object(db_query($cvtermsql, $accesion, $dbname));
+      if ($cvterm) {
+        return $cvterm;
       }
-   }
-   if(!$is_relationship and !$dbname){
-      watchdog('tripal_cv', "A database identifier is missing from the term: $id",NULL,WATCHDOG_WARNING);
-      return 0;
-   }
+    }
+  }
+  if (!$is_relationship and !$dbname) {
+    watchdog('tripal_cv', "A database identifier is missing from the term: $id", NULL, WATCHDOG_WARNING);
+    return 0;
+  }
 
-   // add the database. The function will just return the DB object if the
-   // database already exists. 
-   $db = tripal_db_add_db($dbname);
-   if(!$db){
-      watchdog('tripal_cv', "Cannot find database '$dbname' in Chado.",NULL,WATCHDOG_WARNING);
-      return 0;
-   }
+  // add the database. The function will just return the DB object if the
+  // database already exists.
+  $db = tripal_db_add_db($dbname);
+  if (!$db) {
+    watchdog('tripal_cv', "Cannot find database '$dbname' in Chado.", NULL, WATCHDOG_WARNING);
+    return 0;
+  }
 
 
-   // if the cvterm doesn't exist then add it otherwise just update it
-   $cvterm = db_fetch_object(db_query($cvtermsql,$accession,$dbname));
-   if(!$cvterm){
-      // check to see if the dbxref exists if not, add it
-      $dbxref =  tripal_db_add_dbxref($db->db_id,$accession);
-      if(!$dbxref){
-         watchdog('tripal_cv', "Failed to find or insert the dbxref record for cvterm, $name (id: $accession), for database $dbname",NULL,WATCHDOG_WARNING);
-         return 0;
-      }
+  // if the cvterm doesn't exist then add it otherwise just update it
+  $cvterm = db_fetch_object(db_query($cvtermsql, $accession, $dbname));
+  if (!$cvterm) {
+    // check to see if the dbxref exists if not, add it
+    $dbxref =  tripal_db_add_dbxref($db->db_id, $accession);
+    if (!$dbxref) {
+      watchdog('tripal_cv', "Failed to find or insert the dbxref record for cvterm, $name (id: $accession), for database $dbname", NULL, WATCHDOG_WARNING);
+      return 0;
+    }
 
-      // check to see if the dbxref already has an entry in the cvterm table
-      $sql = "SELECT * FROM {cvterm} WHERE dbxref_id = %d";
-      $check = db_fetch_object(db_query($sql,$dbxref->dbxref_id));
-      if(!$check){
-         // now add the cvterm
-         $sql = "
-            INSERT INTO {cvterm} (cv_id, name, definition, dbxref_id, 
-               is_obsolete, is_relationshiptype) 
-            VALUES (%d,'%s','%s',%d,%d,%d)
-         ";
-         if(!db_query($sql,$cv->cv_id,$name,$definition,
-             $dbxref->dbxref_id,$is_obsolete,$is_relationship)){
-            if(!$is_relationship){
-               watchdog('tripal_cv', "Failed to insert the term: $name ($dbname)",NULL,WATCHDOG_WARNING);
-               return 0;
-            } else {
-               watchdog('tripal_cv', "Failed to insert the relationship term: $name (cv: " . $cvname . " db: $dbname)",NULL,WATCHDOG_WARNING);
-               return 0;
-            }
-         }  
-      }
-      // if the dbxref already exists check to make sure it exists for the correct databaes name
-      // if it does then we're good and we don't need to do anything
-      elseif($check and strcmp($check->name,$name)==0){
-         // this entry already exists. We're good, so do nothing
-      }
-      // if the dbxref exists but does not map to the same database name
-      elseif($check and strcmp($check->name,$name)!=0){
-         watchdog('tripal_cv', "The dbxref already exists in the cvterm table. DBXREF ID: $dbxref->dbxref_id, ACCESSION: $accession. DB:  '".$dbxref->db_name ."'. term '$name'. The requested db was '$dbname'",NULL,WATCHDOG_WARNING);
-         return 0;
-      }
-      $cvterm = db_fetch_object(db_query($cvtermsql,$name,$dbname));
-      if(!$is_relationship){
-         print "Added CV term: $name ($dbname)\n";
-      } else {
-         print "Added relationship CV term: $name ($dbname)\n";
-      }
-   }
-   elseif($update) { // update the cvterm
+    // check to see if the dbxref already has an entry in the cvterm table
+    $sql = "SELECT * FROM {cvterm} WHERE dbxref_id = %d";
+    $check = db_fetch_object(db_query($sql, $dbxref->dbxref_id));
+    if (!$check) {
+      // now add the cvterm
       $sql = "
-         UPDATE {cvterm} SET name='%s', definition='%s',
-            is_obsolete = %d, is_relationshiptype = %d
-         WHERE cvterm_id = %d
+        INSERT INTO {cvterm} (cv_id, name, definition, dbxref_id,
+           is_obsolete, is_relationshiptype)
+        VALUES (%d,'%s','%s',%d,%d,%d)
       ";
-      if(!db_query($sql,$term['name'],$definition,
-          $is_obsolete,$is_relationship,$cvterm->cvterm_id)){
-         watchdog('tripal_cv', "Failed to update the term: $name",NULL,WATCHDOG_WARNING);
-         return 0;
-
-      }  
-      $cvterm = db_fetch_object(db_query($cvtermsql,$name,$dbname));         
-      if(!$is_relationship){
-         print "Updated CV term: $name ($dbname)\n";
-      } else {
-         print "Updated relationship CV term: $name ($dbname)\n";
+      if (!db_query($sql, $cv->cv_id, $name, $definition, $dbxref->dbxref_id, $is_obsolete, $is_relationship)) {
+        if (!$is_relationship) {
+          watchdog('tripal_cv', "Failed to insert the term: $name ($dbname)", NULL, WATCHDOG_WARNING);
+          return 0;
+        }
+        else {
+          watchdog('tripal_cv', "Failed to insert the relationship term: $name (cv: " . $cvname . " db: $dbname)", NULL, WATCHDOG_WARNING);
+          return 0;
+        }
       }
-   }
-   // return the cvterm
-   return $cvterm;
+    }
+    // if the dbxref already exists check to make sure it exists for the correct databaes name
+    // if it does then we're good and we don't need to do anything
+    elseif ($check and strcmp($check->name, $name) == 0) {
+      // this entry already exists. We're good, so do nothing
+    }
+    // if the dbxref exists but does not map to the same database name
+    elseif ($check and strcmp($check->name, $name) != 0) {
+      watchdog(
+        'tripal_cv',
+        "The dbxref already exists in the cvterm table. DBXREF ID: $dbxref->dbxref_id, ACCESSION: $accession. DB:  '" . $dbxref->db_name . "'. term '$name'. The requested db was '$dbname'",
+        NULL,
+        WATCHDOG_WARNING);
+      return FALSE;
+    }
+    $cvterm = db_fetch_object(db_query($cvtermsql, $name, $dbname));
+    if (!$is_relationship) {
+      print "Added CV term: $name ($dbname)\n";
+    }
+    else {
+      print "Added relationship CV term: $name ($dbname)\n";
+    }
+  }
+  elseif ($update) { // update the cvterm
+    $sql = "
+       UPDATE {cvterm} SET name='%s', definition='%s',
+          is_obsolete = %d, is_relationshiptype = %d
+       WHERE cvterm_id = %d
+    ";
+    if (!db_query($sql, $term['name'], $definition, $is_obsolete, $is_relationship, $cvterm->cvterm_id)) {
+      watchdog('tripal_cv', "Failed to update the term: $name", NULL, WATCHDOG_WARNING);
+      return FALSE;
+    }
+    $cvterm = db_fetch_object(db_query($cvtermsql, $name, $dbname));
+    if (!$is_relationship) {
+      print "Updated CV term: $name ($dbname)\n";
+    }
+    else {
+      print "Updated relationship CV term: $name ($dbname)\n";
+    }
+  }
+  // return the cvterm
+  return $cvterm;
 }
 
 

+ 11 - 0
tripal_cv/tripal_cv.coder_ignores.txt

@@ -0,0 +1,11 @@
+; The file should be formatted this way :
+; file:line:warning-type
+; where warning-type is one of security, style, sql, i18n, comment, etc.
+
+; This query selects from a non-drupal schema where the database prefixes are not
+; applied and thus the curcly brackets ({}) are not needed
+tripal_cv.module:1059:sql
+
+; Need to use POST since this is part of a JS callback
+tripal_cv.module:407:security
+tripal_cv.module:813:security

+ 124 - 124
tripal_cv/tripal_cv.install

@@ -1,150 +1,150 @@
 <?php
 
 /**
-*  Implementation of hook_install();
-*
-* @ingroup tripal_cv
-*/
-function tripal_cv_install(){
-
-   // create the module's data directory
-   tripal_create_moddir('tripal_cv');
-
-   // Add the materialized view needed to keep track of the 
-   // 
-   $previous_db = tripal_db_set_active('chado');
-   if (db_table_exists('cv_root_mview')) {
-      $sql = "DROP TABLE cv_root_mview";
-      db_query($sql);
-   }
-   tripal_db_set_active($previous_db);
-
-   // Create the MView
-   tripal_add_mview(
-      // view name
-      'cv_root_mview',
-      // module name  
-      'tripal_cv',
-      // table name
-      'cv_root_mview',
-      // table schema
-      'name character varying(1024), cvterm_id integer, cv_id integer, 
-       cv_name character varying(255)',
-      // indexed columns
-      'cvterm_id, cv_id',
-      // SQL statement that populates the view
-      'SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
-       FROM {cvterm_relationship} CVTR
-         INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
-         INNER JOIN CV on CV.cv_id = CVT.cv_id
-       WHERE CVTR.object_id not in
-         (SELECT subject_id FROM {cvterm_relationship}) ',
-      // special index
-      ''
-   );
-
-   // create the tables that correlate OBO files/references with a chado CV
-   drupal_install_schema('tripal_cv');
-   tripal_cv_add_obo_defaults();
-}
+ * @file
+ * Contains functions executed only on install/uninstall of this module
+ */
+
 /**
-*  This update adds the new tripal_obo table.  This is an upgrade from
-*  Tripal version 0.2
-*
-* @ingroup tripal_cv
-*/
-
-function tripal_cv_update_6000(){
-   drupal_install_schema('tripal_cv');
-   tripal_cv_add_obo_defaults();
-   $ret = array(
-      '#finished' => 1,
-   );
-   
-   return $ret;
+ * Implementation of hook_install().
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_install() {
+
+  // create the module's data directory
+  tripal_create_moddir('tripal_cv');
+
+  // Add the materialized view needed to keep track of the
+  //
+  $previous_db = tripal_db_set_active('chado');
+  if (db_table_exists('cv_root_mview')) {
+    $sql = "DROP TABLE cv_root_mview";
+    db_query($sql);
+  }
+  tripal_db_set_active($previous_db);
+
+  // Create the MView
+  tripal_add_mview(
+    // view name
+    'cv_root_mview',
+    // module name
+    'tripal_cv',
+    // table name
+    'cv_root_mview',
+    // table schema
+    'name character varying(1024), cvterm_id integer, cv_id integer,
+     cv_name character varying(255)',
+    // indexed columns
+    'cvterm_id, cv_id',
+    // SQL statement that populates the view
+    'SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
+     FROM {cvterm_relationship} CVTR
+       INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
+       INNER JOIN CV on CV.cv_id = CVT.cv_id
+     WHERE CVTR.object_id not in
+       (SELECT subject_id FROM {cvterm_relationship}) ',
+    // special index
+    ''
+  );
+
+  // create the tables that correlate OBO files/references with a chado CV
+  drupal_install_schema('tripal_cv');
+  tripal_cv_add_obo_defaults();
 }
+
 /**
-* Implementation of hook_uninstall()
-*
-* @ingroup tripal_cv
-*/
-function tripal_cv_uninstall(){
-
-	// remove the materialized view
-   $mview = tripal_mviews_get_mview_id('cv_root_mview');
-   if($mview){
-	   tripal_mviews_action('delete',$mview);
-	}
-
-   drupal_uninstall_schema('tripal_cv');
+ *  This update adds the new tripal_obo table.  This is an upgrade from
+ *  Tripal version 0.2
+ *
+ * @ingroup tripal_cv
+ */
+
+function tripal_cv_update_6000() {
+  drupal_install_schema('tripal_cv');
+  tripal_cv_add_obo_defaults();
+  $ret = array(
+    '#finished' => 1,
+  );
+
+  return $ret;
 }
 
 /**
- * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
- * before installation
+ * Implementation of hook_uninstall().
  *
  * @ingroup tripal_cv
  */
-function tripal_cv_requirements($phase) {
-   $requirements = array();
-   if ($phase == 'install') {
-      if (!function_exists('tripal_create_moddir')) {
-         $requirements ['tripal_cv'] = array(
-            'title' => "tripal_cv",
-            'value' => "Required modules must be installed first before Tripal CV module can be installed",
-            'severity' => REQUIREMENT_ERROR,
-         );
-      }
-   }
-   return $requirements;
+function tripal_cv_uninstall() {
+
+  // remove the materialized view
+  $mview = tripal_mviews_get_mview_id('cv_root_mview');
+  if ($mview) {
+    tripal_mviews_action('delete', $mview);
+  }
+
+  drupal_uninstall_schema('tripal_cv');
 }
+
 /**
-* Implementation of hook_schema().
-*
-* @ingroup tripal_cv
-*/
+ * Implementation of hook_schema().
+ *
+ * @ingroup tripal_cv
+ */
 function tripal_cv_schema() {
-   $schema = tripal_cv_get_schemas();
-   return $schema;
+  $schema = tripal_cv_get_schemas();
+  return $schema;
 }
+
 /**
-* This function simply defines all tables needed for the module to work
-* correctly.  By putting the table definitions in a separate function we 
-* can easily provide the entire list for hook_install or individual
-* tables for an update.
-*
-* @ingroup tripal_cv
-*/
-function tripal_cv_get_schemas (){  
+ * This function simply defines all tables needed for the module to work
+ * correctly.  By putting the table definitions in a separate function we
+ * can easily provide the entire list for hook_install or individual
+ * tables for an update.
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_get_schemas() {
   $schema = array();
 
   $schema['tripal_cv_obo'] = array(
-      'fields' => array(
-         'obo_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
-         'name'  => array('type' => 'varchar','length' => 255),
-         'path'   => array('type' => 'varchar','length' => 1024),
-      ),
-      'indexes' => array(
-         'obo_id' => array('obo_id'),
-       ),
-      'primary key' => array('obo_id'),
+    'fields' => array(
+      'obo_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
+      'name'  => array('type' => 'varchar', 'length' => 255),
+      'path'   => array('type' => 'varchar', 'length' => 1024),
+    ),
+    'indexes' => array(
+      'obo_id' => array('obo_id'),
+    ),
+    'primary key' => array('obo_id'),
   );
+
   return $schema;
 }
+
 /**
-* Add's defaults to the tripal_cv_obo table
-*
-* @ingroup tripal_cv
-*/
-function tripal_cv_add_obo_defaults(){
-   // insert commonly used ontologies into the tables
-   $isql = "INSERT INTO tripal_cv_obo (name,path) VALUES ('%s','%s')";
-   db_query($isql,'Chado Feature Properties',drupal_get_path('module','tripal_cv').'/feature_property.obo');
-   db_query($isql,'Relationship Ontology','http://www.obofoundry.org/ro/ro.obo');
-   db_query($isql,'Sequence Ontology','http://song.cvs.sourceforge.net/*checkout*/song/ontology/so.obo');
-   db_query($isql,'Gene Ontology','http://www.geneontology.org/ontology/gene_ontology.obo');
-   db_query($isql,'Cell Ontology','http://obo.cvs.sourceforge.net/obo/obo/ontology/anatomy/cell_type/cell.obo?rev=HEAD');
-   db_query($isql,'Plant Structure Ontology','http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_anatomy.obo?view=co');  
-   db_query($isql,'Plant Growth and Development Stages Ontology','http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_temporal.obo?view=co');
+ * Add's defaults to the tripal_cv_obo table
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_add_obo_defaults() {
+
+  // insert commonly used ontologies into the tables
+  $ontologies = array(
+    array('Chado Feature Properties', drupal_get_path('module', 'tripal_cv') . '/feature_property.obo'),
+    array('Relationship Ontology', 'http://www.obofoundry.org/ro/ro.obo'),
+    array('Sequence Ontology', 'http://song.cvs.sourceforge.net/*checkout*/song/ontology/so.obo'),
+    array('Gene Ontology', 'http://www.geneontology.org/ontology/gene_ontology.obo'),
+    array('Cell Ontology', 'http://obo.cvs.sourceforge.net/obo/obo/ontology/anatomy/cell_type/cell.obo?rev=HEAD'),
+    array('Plant Structure Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_anatomy.obo?view=co'),
+    array('Plant Growth and Development Stages Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_temporal.obo?view=co')
+  );
+  foreach ($ontologies as $o) {
+    db_query(
+      "INSERT INTO {tripal_cv_obo} (name,path) VALUES ('%s','%s')",
+      $o[0],
+      $o[1]
+    );
+  }
 
 }

Fișier diff suprimat deoarece este prea mare
+ 481 - 472
tripal_cv/tripal_cv.module


+ 20 - 20
tripal_cv/tripal_cv.views.inc

@@ -6,7 +6,7 @@
  *  chado/tripal db tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
@@ -17,7 +17,7 @@
  */
 
 require_once('views/cvterm.views.inc');
-require_once('views/cv.views.inc'); 
+require_once('views/cv.views.inc');
 /**
  * Implements hook_views_data()
  *
@@ -26,7 +26,7 @@ require_once('views/cv.views.inc');
  * @return
  *   a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  *
@@ -34,23 +34,23 @@ require_once('views/cv.views.inc');
  */
 function tripal_cv_views_data() {
   $data = array();
-  
+
   //Function is contained in includes/cvterm.views.inc
   //Returns the data array for the chado cvterm table
   $data = array_merge($data, retrieve_cvterm_views_data());
-  
+
   //Function is contained in includes/cv.views.inc
   //Returns the data array for the chado cv table
   $data = array_merge($data, retrieve_cv_views_data());
-  
+
   return $data;
 }
- 
+
 /**
  * Implements hook_views_handlers()
  *
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  *
  * @return: An array of handler definitions
@@ -58,25 +58,25 @@ function tripal_cv_views_data() {
  * @ingroup tripal_cv_views
  */
 function tripal_cv_views_handlers() {
- return array(
-   'info' => array(
-     'path' => drupal_get_path('module', 'tripal_cv') . '/views/handlers',
-   ),
-   'handlers' => array(
-     'views_handler_field_tf_boolean' => array(
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'tripal_cv') . '/views/handlers',
+    ),
+    'handlers' => array(
+      'views_handler_field_tf_boolean' => array(
        'parent' => 'views_handler_field',
-     ),
-   ),
- );
+      ),
+    ),
+  );
 }
 
 /**
  *
  * @ingroup tripal_cv_views
  */
-function tripal_cv_views_default_views () {
+function tripal_cv_views_default_views() {
   $views = array();
-  
+
   // Main default view
   // List all cvterms based on cv
   $view = new view;
@@ -366,6 +366,6 @@ function tripal_cv_views_default_views () {
     'name' => 'navigation',
   ));
   $views[$view->name] = $view;
-  
+
   return $views;
 }

+ 67 - 67
tripal_cv/views/cv.views.inc

@@ -1,9 +1,9 @@
 <?php
 
 /**
- * Prupose: this function returns a portion of the data array 
+ * Prupose: this function returns a portion of the data array
  *   which describes the cv table, it's fields and any joins between it and other tables
- * @see tripal_cv_views_data() --in tripal_cv.views.inc
+ * @see tripal_cv_views_data()
  *
  * TABLE: cv
  * @code
@@ -19,75 +19,75 @@
  * @ingroup tripal_cv_views
  */
 function retrieve_cv_views_data() {
-  $data = array();
+$data = array();
 
-  // Basic table definition
-  $data['cv']['table'] = array(
-    'field' => 'cv_id',
-    'title' => 'Chado CV (Controlled Vocabulary)',
-    'group' => 'Chado CV',
-    'help' => 'Controlled vocabularies existing in the Chado Database',
-    'database' => 'chado'
-  );
+// Basic table definition
+$data['cv']['table'] = array(
+'field' => 'cv_id',
+'title' => 'Chado CV (Controlled Vocabulary)',
+'group' => 'Chado CV',
+'help' => 'Controlled vocabularies existing in the Chado Database',
+'database' => 'chado'
+);
 
-  // Define relationships between this table and others
-  $data['cv']['table']['join'] = array(
-     'cvterm' => array(
-       'left_field' => 'cv_id',
-       'field' => 'cv_id',
-     ),
-  );
+// Define relationships between this table and others
+$data['cv']['table']['join'] = array(
+'cvterm' => array(
+'left_field' => 'cv_id',
+'field' => 'cv_id',
+),
+);
 
-  // Table Field Definitions----------------------
-  // Field: cv_id (primary key)
-  $data['cv']['cv_id'] = array(
-    'title' => t('CV ID'),
-    'help' => t('The primary key of the controlled vocabulary.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-  ); 
-  
-  //Field: name (varchar -255)
-  $data['cv']['name'] = array(
-    'title' => 'Vocabulary Name',
-    'field' => array(
-       'handler' => 'views_handler_field',
-       'click sortable' => TRUE,
-     ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_chado_select_string',
-     ),
-     'argument' => array(
-       'handler' => 'views_handler_argument_string',
-     ),
-  );
+// Table Field Definitions----------------------
+// Field: cv_id (primary key)
+$data['cv']['cv_id'] = array(
+'title' => t('CV ID'),
+'help' => t('The primary key of the controlled vocabulary.'),
+'field' => array(
+'handler' => 'views_handler_field_numeric',
+'click sortable' => TRUE,
+),
+'filter' => array(
+'handler' => 'views_handler_filter_numeric',
+),
+'sort' => array(
+'handler' => 'views_handler_sort',
+),
+);
 
-  //Field: definition (text)
-  $data['cv']['definition'] = array(
-    'title' => 'Vocabulary Definition',
-    'field' => array(
-       'handler' => 'views_handler_field',
-       'click sortable' => TRUE,
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_string',
-     ),
-     'argument' => array(
-       'handler' => 'views_handler_argument_string',
-     ),
-  );
+//Field: name (varchar -255)
+$data['cv']['name'] = array(
+'title' => 'Vocabulary Name',
+'field' => array(
+'handler' => 'views_handler_field',
+'click sortable' => TRUE,
+),
+'sort' => array(
+'handler' => 'views_handler_sort',
+),
+'filter' => array(
+'handler' => 'views_handler_filter_chado_select_string',
+),
+'argument' => array(
+'handler' => 'views_handler_argument_string',
+),
+);
 
-  return $data;
+//Field: definition (text)
+$data['cv']['definition'] = array(
+'title' => 'Vocabulary Definition',
+'field' => array(
+'handler' => 'views_handler_field',
+'click sortable' => TRUE,
+),
+'filter' => array(
+'handler' => 'views_handler_filter_string',
+),
+'argument' => array(
+'handler' => 'views_handler_argument_string',
+),
+);
+
+return $data;
 
 }

+ 122 - 121
tripal_cv/views/cvterm.views.inc

@@ -1,9 +1,10 @@
 <?php
 
 /**
- * Purpose: this function returns the portion of the data array 
+ * @file
+ * Purpose: this function returns the portion of the data array
  *   which describes the cv table, it's fields and any joins between it and other tables
- * @see tripal_cv_views_data() --in tripal_cv.views.inc
+ * @see tripal_cv_views_data()
  *
  * BASE TABLE: cvterm
  * @code
@@ -27,129 +28,129 @@
  */
 function retrieve_cvterm_views_data() {
 
-  // Basic table definition
-  $data['cvterm']['table']['group'] = 'Chado CV Terms';
-  $data['cvterm']['table']['base'] = array(
-    'field' => 'cvterm_id',
-    'title' => 'Chado CV Terms (Controlled Vocabulary)',
-    'help' => 'Controlled Vocabularies (CVs) are the main way Chado controls content.',
-    'database' => 'chado'
-  );
+// Basic table definition
+$data['cvterm']['table']['group'] = 'Chado CV Terms';
+$data['cvterm']['table']['base'] = array(
+'field' => 'cvterm_id',
+'title' => 'Chado CV Terms (Controlled Vocabulary)',
+'help' => 'Controlled Vocabularies (CVs) are the main way Chado controls content.',
+'database' => 'chado'
+);
 
-  // Define relationships between this table and others
-   $data['cvterm']['table']['join'] = array(
-     'feature' => array(
-       'left_field' => 'type_id',
-       'field' => 'cvterm_id',
-     ),
-     'library' => array(
-       'left_field' => 'type_id',
-       'field' => 'cvterm_id',
-     ),
-     'stock' => array(
-       'left_field' => 'type_id',
-       'field' => 'cvterm_id',
-     ),
-     'nd_reagent' => array(
-       'left_field' => 'type_id',
-       'field' => 'cvterm_id',
-     ),
-   );
+// Define relationships between this table and others
+$data['cvterm']['table']['join'] = array(
+'feature' => array(
+'left_field' => 'type_id',
+'field' => 'cvterm_id',
+),
+'library' => array(
+'left_field' => 'type_id',
+'field' => 'cvterm_id',
+),
+'stock' => array(
+'left_field' => 'type_id',
+'field' => 'cvterm_id',
+),
+'nd_reagent' => array(
+'left_field' => 'type_id',
+'field' => 'cvterm_id',
+),
+);
 
- // Table Field Definitions----------------------
- // Field: cvterm_id (primary key)
- $data['cvterm']['cvterm_id'] = array(
-   'title' => t('CV Term ID'),
-   'help' => t('The primary kep of controlled vocabulary terms.'),
-   'field' => array(
-     'handler' => 'views_handler_field_numeric',
-     'click sortable' => TRUE,
-    ),
-   'filter' => array(
-     'handler' => 'views_handler_filter_numeric',
-   ),
-   'sort' => array(
-     'handler' => 'views_handler_sort',
-   ),
- );
- 
- //Field: cv_id (foreign key: cv)
- //  join between cv table and this one in cv.views.inc
- 
- // Field: Name (varchar 1024)
-  $data['cvterm']['name'] = array(
-     'title' => 'Name',
-     'help' => 'The term name',
-     'field' => array(
-     'handler' => 'views_handler_field',
-       'click sortable' => TRUE,
-     ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_string',
-     ),
-     'argument' => array(
-       'handler' => 'views_handler_argument_string',
-     ),
-   );
+// Table Field Definitions----------------------
+// Field: cvterm_id (primary key)
+$data['cvterm']['cvterm_id'] = array(
+'title' => t('CV Term ID'),
+'help' => t('The primary kep of controlled vocabulary terms.'),
+'field' => array(
+'handler' => 'views_handler_field_numeric',
+'click sortable' => TRUE,
+),
+'filter' => array(
+'handler' => 'views_handler_filter_numeric',
+),
+'sort' => array(
+'handler' => 'views_handler_sort',
+),
+);
 
-   // Field: Definition (text)
-   $data['cvterm']['definition'] = array(
-     'title' => 'Definition',
-     'help' => 'A definition of this term',
-     'field' => array(
-       'handler' => 'views_handler_field',
-       'click sortable' => TRUE,
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_string',
-     ),
-     'argument' => array(
-       'handler' => 'views_handler_argument_string',
-     ),
-   );
+//Field: cv_id (foreign key: cv)
+//  join between cv table and this one in cv.views.inc
 
-   // Field: dbxref_id (foreign key: dbxref)
-   //  join between dbxref table and this one in tripal_db/views/dbxref.views.inc
-   
-   // Field: is_obsolete (integer: 1/0)
-   $data['cvterm']['is_obsolete'] = array(
-     'title' => 'Is Obsolete',
-     'help' => 'Whether this term is obsolete or not.',
-     'field' => array(
-       'handler' => 'views_handler_field_boolean',
-       'click sortable' => TRUE,
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_string',
-       'label' => t('Is Obsolete?'),
-       'type' => 'yes-no',
-     ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
-   );
+// Field: Name (varchar 1024)
+$data['cvterm']['name'] = array(
+'title' => 'Name',
+'help' => 'The term name',
+'field' => array(
+'handler' => 'views_handler_field',
+'click sortable' => TRUE,
+),
+'sort' => array(
+'handler' => 'views_handler_sort',
+),
+'filter' => array(
+'handler' => 'views_handler_filter_string',
+),
+'argument' => array(
+'handler' => 'views_handler_argument_string',
+),
+);
 
-   // Field: is_relationshiptype (integer: 1/0)
-   $data['cvterm']['is_relationshiptype'] = array(
-     'title' => 'Is Relationship',
-     'help' => 'Whether this term describes a relationship or not.',
-     'field' => array(
-       'handler' => 'views_handler_field_boolean',
-       'click sortable' => TRUE,
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_chado_boolean',
-       'label' => t('Is Relationship Type?'),
-       'type' => 'yes-no',
-     ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
-    );
-  
-  return $data;
+// Field: Definition (text)
+$data['cvterm']['definition'] = array(
+'title' => 'Definition',
+'help' => 'A definition of this term',
+'field' => array(
+'handler' => 'views_handler_field',
+'click sortable' => TRUE,
+),
+'filter' => array(
+'handler' => 'views_handler_filter_string',
+),
+'argument' => array(
+'handler' => 'views_handler_argument_string',
+),
+);
+
+// Field: dbxref_id (foreign key: dbxref)
+//  join between dbxref table and this one in tripal_db/views/dbxref.views.inc
+
+// Field: is_obsolete (integer: 1/0)
+$data['cvterm']['is_obsolete'] = array(
+'title' => 'Is Obsolete',
+'help' => 'Whether this term is obsolete or not.',
+'field' => array(
+'handler' => 'views_handler_field_boolean',
+'click sortable' => TRUE,
+),
+'filter' => array(
+'handler' => 'views_handler_filter_string',
+'label' => t('Is Obsolete?'),
+'type' => 'yes-no',
+),
+'sort' => array(
+'handler' => 'views_handler_sort',
+),
+);
+
+// Field: is_relationshiptype (integer: 1/0)
+$data['cvterm']['is_relationshiptype'] = array(
+'title' => 'Is Relationship',
+'help' => 'Whether this term describes a relationship or not.',
+'field' => array(
+'handler' => 'views_handler_field_boolean',
+'click sortable' => TRUE,
+),
+'filter' => array(
+'handler' => 'views_handler_filter_chado_boolean',
+'label' => t('Is Relationship Type?'),
+'type' => 'yes-no',
+),
+'sort' => array(
+'handler' => 'views_handler_sort',
+),
+);
+
+return $data;
 
 }

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff