Browse Source

Initial import of version 0.2

spficklin 15 years ago
parent
commit
d0e58eaf84
5 changed files with 771 additions and 0 deletions
  1. 103 0
      tripal_cv/charts.php
  2. 333 0
      tripal_cv/trees.php
  3. 10 0
      tripal_cv/tripal_cv.info
  4. 73 0
      tripal_cv/tripal_cv.install
  5. 252 0
      tripal_cv/tripal_cv.module

+ 103 - 0
tripal_cv/charts.php

@@ -0,0 +1,103 @@
+<?php
+
+//
+// Copyright 2009 Clemson University
+//
+
+/*************************************************************************
+*
+*/
+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);
+  $callback = $tripal_mod . "_cv_chart";
+
+  // now call the function in the module responsible for the chart.  This 
+  // should call the tripal_cv_count_chart with the proper parameters set
+  $opt = call_user_func_array($callback,$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[] = $chart_id;  // add the chart_id back into the json array
+
+  return drupal_json($json_arr);
+
+}
+
+/*************************************************************************
+*  name: tripal_cv_chart
+*  description:  
+*/
+function tripal_cv_count_chart($cnt_table, $fk_column,
+   $cnt_column, $filter = null, $title = '', $type = 'p3', $size='400x100') {
+
+   if(!$type){
+      $type = 'p3';
+   }
+
+   if(!$size){
+     $size = '400x100';
+   }
+
+   if(!$filter){
+      $filter = '(1=1)'; 
+   }
+
+   $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
+   ";    
+
+   $features = array();
+   $previous_db = db_set_active('chado');  // use chado database
+   $results = db_query($sql);
+   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;
+}

+ 333 - 0
tripal_cv/trees.php

@@ -0,0 +1,333 @@
+<?php
+
+//
+// Copyright 2009 Clemson University
+//
+
+/*************************************************************************
+*
+*/
+function tripal_cv_show_browser() {
+  
+   $content = drupal_get_form('tripal_cv_list_form');
+   $content .= "
+      <div id=\"cv_browser\"></div>
+   ";
+   return $content;
+}
+
+
+/*************************************************************************
+*
+*/
+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";
+
+     // 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,$tree_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);
+}
+
+
+/*************************************************************************
+*
+*/
+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,$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);
+}
+/*************************************************************************
+*  name:  tripal_cv_init_cv
+*  description:  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.
+*/
+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 = db_set_active('chado');
+   $results = db_query($sql,$cv_id);
+   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 = db_set_active('chado');
+         $cnt_results = db_query($cnt_sql,$term->cvterm_id);
+         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 (),
+      );
+   }
+
+   return $content;
+
+}
+/*************************************************************************
+*  name:  tripal_cv_get_term_children
+*  description:  This function returns the JSON array for the jsTree 
+*    jQuery code when expanding a term to view it's children.  
+*/
+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 = db_set_active('chado');
+   $results = db_query($sql,$cvterm_id);
+   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 = db_set_active('chado');
+         $cnt_results = db_query($cnt_sql,$term->subject_id);
+         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 = db_set_active('chado');
+      $children = db_fetch_object(db_query($sql,$term->subject_id));
+      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(),
+      );
+   }
+   $content[] = $cnt_sql;
+   return $content;
+}
+/*************************************************************************
+*
+*/
+function tripal_cv_init_browser($cv_id) {
+
+   $content  = "<div id=\"tripal_cv_term_box\" class=\"feature-info-box\">";
+   $content .= "<div class=\"tripal_expandableBox\">";
+   $content .= "<h3>Term Information</h3>";
+   $content .= "</div>";
+   $content .= "<div class=\"tripal_expandableBoxContent\">";
+   $content .= "<div id=\"cvterm_info\"></div></div>";
+   $content .= "<h3>Tree Browser</h3>";
+   $content .= "<div id=\"browser\"</div></div>";
+
+   drupal_json(array('update' => "$content"));
+}
+/*************************************************************************
+*
+*/
+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
+   $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 = db_set_active('chado');
+   $cvterm = db_fetch_object(db_query($sql,$cvterm_id));
+   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 = db_set_active('chado');
+   $results = db_query($sql,$cvterm_id);
+   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
+   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));
+}
+/*******************************************************************************
+*/
+
+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 = db_set_active('chado');  // use chado database
+   $results = db_query ($sql);
+   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;
+}

+ 10 - 0
tripal_cv/tripal_cv.info

@@ -0,0 +1,10 @@
+; $Id: tripal_cv.info,v 1.3 2009/12/05 06:11:56 ficklin Exp $
+name = Tripal CV
+description = The controlled vocabulary module for the Tripal package that integrates Drupal and GMOD chado. This module provides support for managing and viewing controlled vocabularies.
+core = 6.x
+project = tripal_cv
+package = Tripal
+version = "6.x-0.2b-m0.1"
+
+dependencies[] = tripal_core
+dependencies[] = tripal_db

+ 73 - 0
tripal_cv/tripal_cv.install

@@ -0,0 +1,73 @@
+<?php
+
+/*******************************************************************************
+*  Implementation of hook_install();
+*/
+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 = db_set_active('chado');
+   if (db_table_exists('cv_root_mview')) {
+      $sql = "DROP TABLE cv_root_mview";
+      db_query($sql);
+   }
+   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
+      ''
+   );
+
+}
+
+/*******************************************************************************
+* Implementation of hook_uninstall()
+*/
+function tripal_cv_uninstall(){
+
+	// remove the materialized view
+   $mview = tripal_mviews_get_mview_id('cv_root_mview');
+   if($mview){
+	   tripal_mviews_action('delete',$mview);
+	}
+}
+
+/*******************************************************************************
+ * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
+ * before installation
+ */
+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;
+}

+ 252 - 0
tripal_cv/tripal_cv.module

@@ -0,0 +1,252 @@
+<?php
+
+require_once "charts.php";
+require_once "trees.php";
+
+//
+// Copyright 2009 Clemson University
+//
+/*************************************************************************
+*
+*/
+function tripal_cv_init(){
+
+   // add the tripal_cv JS and CSS
+   drupal_add_css(drupal_get_path('theme', 'tripal').
+                                  '/css/tripal_cv.css');
+   drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_cv.js');
+
+   // add the jsTree JS and CSS
+   drupal_add_css(drupal_get_path('theme', 'tripal').'/js/jsTree/source/tree_component.css');
+   drupal_add_js (drupal_get_path('theme', 'tripal').'/js/jsTree/source/_lib.js');
+   drupal_add_js (drupal_get_path('theme', 'tripal').'/js/jsTree/source/tree_component.js');
+}
+/*************************************************************************
+*
+*/
+function tripal_cv_menu() {
+   $items = array();
+
+   $items['admin/tripal/tripal_cv'] = array(
+     'title' => 'CV',
+     'description' => 'Manage integration of Chado controlled vocabularies',
+     'page callback' => 'drupal_get_form',
+     'page arguments' => array('tripal_cv_admin'),
+     'access arguments' => array('administer site configuration'),
+     'type' => MENU_NORMAL_ITEM,
+   );
+
+   $items['tripal_cv_chart'] = array(
+      'path' => 'tripal_cv_chart',
+      'title' => t('CV Chart'),
+      'page callback' => 'tripal_cv_chart',
+      'page arguments' => array(1),
+      'access arguments' => array('access content'),
+      'type' => MENU_CALLBACK
+   );
+
+   $items['tripal_cv_tree'] = array(
+      'path' => 'tripal_cv_tree',
+      'title' => t('CV Term Viewer'),
+      'page callback' => 'tripal_cv_tree',
+      'page arguments' => array(1),
+      'access arguments' => array('access content'),
+      'type' => MENU_CALLBACK
+   );
+   // menu items for working with the CV module tree browser
+   /*
+   $items['cv_browser'] = array(
+      'title' => t('CV Relationship Browser'),
+      'page callback' => 'tripal_cv_show_browser',
+      'access arguments' => array('access chado_cv content'),
+      'type' => MENU_NORMAL_ITEM
+   );
+   */
+   $items['tripal_cv_init_browser'] = array(
+      'path' => 'tripal_cv_init_browser',
+      'title' => t('CV Browser'),
+      'page callback' => 'tripal_cv_init_browser',
+      'page arguments' => array(1),
+      'access arguments' => array('access content'),
+      'type' => MENU_CALLBACK
+   );
+   // menu item for interaction with the tree
+   $items['tripal_cv_update_tree'] = array(
+      'path' => 'tripal_cv_update_tree',
+      'title' => t('CV Tree'),
+      'page callback' => 'tripal_cv_update_tree',
+      'page arguments' => array(2,3),
+      'access arguments' => array('access content'),
+      'type' => MENU_CALLBACK
+   );
+
+   // menu items for working with terms
+   $items['tripal_cv_cvterm_info'] = array(
+      'path' => 'tripal_cv_cvterm_info',
+      'title' => t('CV Term Viewer'),
+      'page callback' => 'tripal_cv_cvterm_info',
+      'page arguments' => array(1),
+      'access arguments' => array('access content'),
+      'type' => MENU_CALLBACK
+   );
+
+   $items['tripal_cv_cvterm_edit'] = array(
+      'path' => 'tripal_cv_edit',
+      'title' => t('CV Term Editor'),
+      'page callback' => 'tripal_cv_cvterm_edit',
+      'page arguments' => array(1),
+      'access arguments' => array('edit chado_cv content'),
+      'type' => MENU_CALLBACK
+   );
+
+   return $items;
+}
+/*******************************************************************************
+ *  The following function proves access control for users trying to
+ *  perform actions on data managed by this module
+ */
+function chado_cv_access($op, $node, $account){
+  if ($op == 'create') {
+      return user_access('create chado_cv content', $account);
+   }
+
+   if ($op == 'update') {
+      if (user_access('edit chado_cv content', $account)) {
+         return TRUE;
+      }
+   }
+   if ($op == 'delete') {
+      if (user_access('delete chado_cv content', $account)) {
+         return TRUE;
+      }
+   }
+   if ($op == 'view') {
+      if (user_access('access chado_cv content', $account)) {
+         return TRUE;
+      }
+   }
+   return FALSE;
+}
+/*******************************************************************************
+*  Set the permission types that the chado module uses.  Essentially we
+*  want permissionis that protect creation, editing and deleting of chado
+*  data objects
+*/
+function tripal_cv_perm(){
+   return array(
+      'access chado_cv content',
+      'create chado_cv content',
+      'delete chado_cv content',
+      'edit chado_cv content',
+   );
+}
+
+/*************************************************************************
+*
+*/
+function tripal_cv_admin () {
+	$form['update_cvtermpath'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Chado cvtermpath')
+   );
+   $form['update_cvtermpath']['description'] = array(
+       '#type' => 'item',
+       '#value' => t("Submit a job to update chado cvtermpath table."),
+       '#weight' => 1,
+   );
+   $form['update_cvtermpath']['button'] = array(
+      '#type' => 'submit',
+      '#value' => t('Update cvtermpath'),
+      '#weight' => 2,
+   );
+   return system_settings_form($form);
+}
+
+/*************************************************************************
+*
+*/
+function tripal_cv_admin_validate($form, &$form_state) {
+   global $user;
+	// -------------------------------------
+   // Submit a job to update cvtermpath
+   $job_args = array();
+   if ($form_state['values']['op'] == t('Update cvtermpath')) {
+      tripal_add_job('Update cvtermpath','tripal_cv',
+         'tripal_cv_update_cvtermpath',$job_args,$user->uid);
+   }
+}
+
+/***********************************************************
+ * Update the cvtermpath table
+ */
+function tripal_cv_update_cvtermpath($dummy = NULL, $job_id = NULL) {
+
+   print "\nUpdating cvtermpath...\n";
+
+   $previous_db = db_set_active('chado');
+   $sql = "SELECT * FROM fill_cvtermpath('biological_process')";
+   db_query($sql);         
+   $sql = "SELECT * FROM fill_cvtermpath('molecular_function')";
+   db_query($sql);
+   $sql = "SELECT * FROM fill_cvtermpath('cellular_component')";
+   db_query($sql);
+   db_set_active($previous_db);
+   return;
+
+}
+
+/*******************************************************************************
+ *  We need to let drupal know about our theme functions and their arguments.
+ *  We create theme functions to allow users of the module to customize the
+ *  look and feel of the output generated in this module
+ */
+function tripal_cv_theme () {
+   return array(
+      'tripal_cv_cvterm_edit' => array (
+         'arguments' => array('cvterm'),
+      ),
+   );
+}
+
+/*************************************************************************
+*/
+function tripal_cv_get_cv_id($cv_name){
+
+   $sql = "
+      SELECT cv_id FROM {cv} WHERE name = '%s'
+   ";
+   $previous_db = db_set_active('chado');
+   $cv = db_fetch_object(db_query($sql,$cv_name));
+   db_set_active($previous_db);
+   return $cv->cv_id;
+}
+/*************************************************************************
+*
+*/
+function tripal_cv_cvterm_edit($cvterm_id){
+   $sql = "
+      SELECT CVT.name as cvtermname, CVT.definition, CV.name as cvname
+      FROM {CVTerm} CVT
+        INNER JOIN CV on CVT.cv_id = CV.cv_id
+      WHERE CVT.cvterm_id = %d
+   ";
+   $previous_db = db_set_active('chado');
+   $cvterm = db_fetch_object(db_query($sql,$cvterm_id));
+   db_set_active($previous_db);
+   return theme('tripal_cv_cvterm_edit',$cvterm);
+}
+/*************************************************************************
+*
+*/
+function theme_tripal_cv_cvterm_edit(&$cvterm){
+   $output = "
+      <div id=\"cvterm\">
+      <table>
+        <tr><th>Term</th><td>$cvterm->cvtermname</td></tr>
+        <tr><th>Vocabulary</th><td>$cvterm->cvname</td></tr>
+        <tr><th>Definition</th><td>$cvterm->definition</td></tr>
+      </table>
+      </div>
+   ";
+   return $output;
+}