Selaa lähdekoodia

Debugging Tripal CV module and created API function for feature relationships

spficklin 12 vuotta sitten
vanhempi
commit
b6444c78ad

+ 34 - 11
tripal_core/api/tripal_core.api.inc

@@ -1414,7 +1414,7 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
   }
 
   // now build the SQL and prepared SQL statements. We may not use
-  // the prepared statement if it wasn't requested in the options of if the
+  // the prepared statement if it wasn't requested in the options or if the
   // argument in a where statement has multiple values.
   if (empty($where)) {
     // sometimes want to select everything
@@ -1717,8 +1717,10 @@ function tripal_core_chado_get_foreign_key($table_desc, $field, $values, $option
  *     may generate more queries then is desired.  Provide an array specifying the
  *     fields to include.  For example, if including the cvterm, cv and dbxref records
  *     for a property the following array would work:
+ *     
  *        array('type_id' => array('cv_id' => 1, 'dbxref_id' => 1)).
- *     Typicall, to expadn a property, this function would also include the db record
+ *        
+ *     Typically, to expand a property, this function would also include the db record
  *     through the db_id foreign key with the dbxref and db tables, but becuase
  *     it is not included in the array it will not be included in the results.
  * @return
@@ -2004,14 +2006,35 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
  * @param $to_expand
  *   The name of the field/table/node to be expanded
  * @param $table_options
- *   An array containing options for the base table.  For example, an
- *   option of 'order_by' may be used to sort results in the base table
- *   if more than one are returned.  The options must be compatible with
- *   the options accepted by the tripal_core_chado_select() function.
- *   Additionally,  The option 'return_array' can be provided to force
- *   the function to expand tables as an array. Default behavior is to expand
- *   a table as single record if only one record exists or to expand as an array if
- *   multiple records exist.
+ *   - order_by:
+ *     An array containing options for the base table.  For example, an
+ *     option of 'order_by' may be used to sort results in the base table
+ *     if more than one are returned.  The options must be compatible with
+ *     the options accepted by the tripal_core_chado_select() function.
+ *   - return_array: 
+ *     Additionally,  The option 'return_array' can be provided to force
+ *     the function to expand tables as an array. Default behavior is to expand
+ *     a table as single record if only one record exists or to expand as an array if
+ *     multiple records exist.
+ *   - include_fk:
+ *     an array of FK relationships to follow. By default, the
+ *     tripal_core_chado_select function will follow all FK relationships but this
+ *     may generate more queries then is desired slowing down this function call when
+ *     there are lots of FK relationships to follow.  Provide an array specifying the
+ *     fields to include.  For example, if expanding a property table (e.g. featureprop)
+ *     and you want the CV and accession but do not want the DB the following
+ *     array would work:
+ *        $table_options =  array(
+ *          'include_fk' => array(
+ *            'type_id' => array(
+ *              'cv_id' => 1, 
+ *              'dbxref_id' => 1,
+ *            )
+ *          )
+ *        );
+ *        
+ *     The above array will expand the 'type_id' of the property table but only 
+ *     further expand the cv_id and the dbxref_id and will go no further.
  * @return
  *   A chado object supplemented with the field/table/node requested to be expanded.
  *   If the type is a table and it has already been expanded no changes is made to the
@@ -3465,7 +3488,7 @@ function tripal_core_get_chado_version($exact = FALSE, $warn_if_unsupported = FA
     $exact_version = "1.11";
     if ($warn_if_unsupported) {
       drupal_set_message(t("WARNING: Tripal does not fully support Chado version less than v1.11.  If you are certain this is v1.11
-         of if Chado was installed using an earlier version of Tripal then all is well. If not please upgrade to v1.11 or later"),
+         or if Chado was installed using an earlier version of Tripal then all is well. If not please upgrade to v1.11 or later"),
          'warning');
     }
   }

+ 8 - 2
tripal_core/includes/chado_install.php

@@ -96,6 +96,7 @@ function tripal_core_install_chado($action) {
       }
       else {
         print "Installation (Step 1 of 2) Problems!  Please check output above for errors.\n";
+        exit;
       }
       $success = tripal_core_install_sql($init_file);
       if ($success) {
@@ -103,6 +104,7 @@ function tripal_core_install_chado($action) {
       }
       else {
         print "Installation (Step 2 of 2) Problems!  Please check output above for errors.\n";
+        exit;
       }
       chado_query($vsql,'1.2'); # set the version
     }
@@ -120,6 +122,7 @@ function tripal_core_install_chado($action) {
     }
     else {
       print "Upgrade (Step 1 of 2) problems!  Please check output above for errors.\n";
+      exit;
     }
     $success = tripal_core_install_sql($init_file);
     if ($success) {
@@ -127,6 +130,7 @@ function tripal_core_install_chado($action) {
     }
     else {
       print "Upgrade (Step 2 of 2) problems!  Please check output above for errors.\n";
+      exit;
     }
     chado_query($vsql,'1.2'); # set the version
   }
@@ -140,6 +144,7 @@ function tripal_core_install_chado($action) {
       }
       else {
         print "Installation (Step 1 of 2) Problems!  Please check output above for errors.\n";
+        exit;
       }
       $success = tripal_core_install_sql($init_file);
       if ($success) {
@@ -147,6 +152,7 @@ function tripal_core_install_chado($action) {
       }
       else {
         print "Installation (Step 2 of 2) Problems!  Please check output above for errors.\n";
+        exit;
       }
     }
     else {
@@ -365,9 +371,10 @@ function tripal_core_install_sql($sql_file) {
       }
       if (!$result) {
         $error  = pg_last_error();
-        print "FAILED!!\nError Message:\nSQL $i, $in_string: $query\n$error\n";        
+        print "FAILED. Line  $i, $in_string\n$error:\n$query\n\n";        
         tripal_core_chado_install_done();
         $success = 0;
+        return $success;
       }
       $query = '';
     }
@@ -385,5 +392,4 @@ function tripal_core_chado_install_done() {
 
   // return the search path to normal
   db_query("set search_path to public");
-
 }

+ 2 - 2
tripal_core/tripal_core.module

@@ -110,7 +110,7 @@ function tripal_core_menu() {
     'description' => 'Installs the Chado database tables, views, etc., inside the current Drupal database',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_core_chado_load_form'),
-    'access arguments' => array('access administration pages'),
+    'access arguments' => array('install chado'),
     'type' => MENU_NORMAL_ITEM,
   );
 
@@ -238,7 +238,7 @@ function tripal_core_menu() {
  * @ingroup tripal_core
  */
 function tripal_core_perm() {
-  return array();
+  return array('install chado');
 }
 
 /**

+ 55 - 2
tripal_cv/api/tripal_cv.api.inc

@@ -123,7 +123,7 @@ function tripal_cv_get_cv_by_name($name) {
  * @see tripal_core_chado_generate_vars()
  *
  * @param $cv_id
- *   The unique identifier for the cv retrieve
+ *   The unique identifier for the cv to retrieve
  *
  * @return
  *   An object describing the cv
@@ -136,10 +136,36 @@ function tripal_cv_get_cv_by_id($cv_id) {
 
   return $r;
 }
+/**
+ * Retrieve the cv id for the specified CV by name
+ *
+ * NOTE: This function is deprecated.
+ * @see tripal_core_chado_generate_vars()
+ *
+ * @param $cv_name
+ *   The unique name for the cv to retrieve
+ *
+ * @return
+ *   The numeric cv ID
+ *
+ * @ingroup tripal_cv_api
+ */
+function tripal_cv_get_cv_id($cv_name) {
+
+  $sql = "
+    SELECT cv_id FROM {cv} WHERE name = '%s'
+  ";
+  $cv = db_fetch_object(chado_query($sql, $cv_name));
+
+  return $cv->cv_id;
+}
 
 /**
- * Create an options array to be used in a form element which provides a list of all chado cvs
+ * Create an options array to be used in a form element which provides a 
+ * list of all chado cvs
  *
+ * NOTE: This function is deprecated as of Tripal v1.0
+ * 
  * @return
  *   An array(cv_id => name) for each cv in the chado cv table
  *
@@ -238,7 +264,34 @@ function tripal_cv_get_cvterm_options($cv_id = 0) {
 
 }
 
+/**
+ * Updates the cvtermpath table of Chado for the specified CV.
+ *
+ * @param $cv_id
+ *   The chado cv_id;
+ * @param $job_id
+ *   This function is intended to be used with the Tripal Jobs API.
+ *   When this function is called as a job the $job_id is automatically
+ *   passed to this function.
+ * @return
+ *   TRUE on success FALSE on failure
+ *
+ * @ingroup tripal_cv_api
+ */
+function tripal_cv_update_cvtermpath($cvid, $job_id = NULL) {
+  // TODO: need better error checking in this function
+
+  // first get the controlled vocabulary name:
+  $cv = db_fetch_object(chado_query("SELECT * FROM {cv} WHERE cv_id = %d", $cvid));
+  print "\nUpdating cvtermpath for $cv->name...\n";
+
+  // now fill the cvtermpath table
+  // @coder-ignore: using a function rather then tablename therefore table prefixing doesn't apply
+  $sql = "SELECT * FROM fill_cvtermpath('%s')";
+  $success = chado_query($sql, $cv->name); 
 
+  return TRUE;
+}
 
 /**
  * Adds a controlled vocabular to the CV table of Chado.

+ 171 - 2
tripal_cv/includes/obo_loader.inc

@@ -1,5 +1,171 @@
 <?php
 
+/**
+ * Purpose: Provides the form to load an already existing controlled
+ *  Vocabulary into chado
+ *
+  * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_form(&$form_state = NULL) {
+
+  // get a list of db from chado for user to choose
+  $sql = "SELECT * FROM {tripal_cv_obo} ORDER BY name";
+  $results = db_query($sql);
+
+  $obos = array();
+  $obos[] = '';
+  while ($obo = db_fetch_object($results)) {
+//    $obos[$obo->obo_id] = "$obo->name  | $obo->path";
+    $obos[$obo->obo_id] = $obo->name;
+  }
+
+  $form['obo_existing'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Use a Saved Ontology OBO Reference')
+  );
+
+  $form['obo_new'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Use a New Ontology OBO Reference')
+  );
+
+  $form['obo_existing']['existing_instructions']= array(
+    '#value' => t('The Ontology OBO files listed in the drop down below have been automatically added upon
+                   installation of the Tripal CV module or were added from a previous upload.  Select
+                   an OBO, then click the submit button to load the vocabulary into the database.  If the
+                   vocabularies already exist then the ontology will be updated.'),
+    '#weight'        => -1
+  );
+
+  $form['obo_existing']['obo_id'] = array(
+    '#title' => t('Ontology OBO File Reference'),
+    '#type' => 'select',
+    '#options' => $obos,
+    '#weight'        => 0
+  );
+
+  $form['obo_new']['path_instructions']= array(
+    '#value' => t('Provide the name and path for the OBO file.  If the vocabulary OBO file
+                   is stored local to the server provide a file name. If the vocabulry is stored remotely,
+                   provide a URL.  Only provide a URL or a local file, not both.'),
+    '#weight'        => 0
+  );
+
+  $form['obo_new']['obo_name']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('New Vocabulary Name'),
+    '#description'   => t('Please provide a name for this vocabulary.  After upload, this name will appear in the drop down
+                           list above for use again later.'),
+    '#weight'        => 1
+  );
+
+  $form['obo_new']['obo_url']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('Remote URL'),
+    '#description'   => t('Please enter a URL for the online OBO file.  The file will be downloaded and parsed.
+                           (e.g. http://www.obofoundry.org/ro/ro.obo'),
+    '#default_value' => $default_desc,
+    '#weight'        => 2
+  );
+
+  $form['obo_new']['obo_file']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('Local File'),
+    '#description'   => t('Please enter the full system path for an OBO definition file, or a path within the Drupal
+                           installation (e.g. /sites/default/files/xyz.obo).  The path must be accessible to the
+                           server on which this Drupal instance is running.'),
+    '#default_value' => $default_desc,
+    '#weight'        => 3
+  );
+
+  $form['submit'] = array(
+    '#type'         => 'submit',
+    '#value'        => t('Submit'),
+    '#weight'       => 5,
+    '#executes_submit_callback' => TRUE,
+  );
+
+  $form['#redirect'] = 'admin/tripal/tripal_cv/obo_loader';
+
+  return $form;
+}
+
+/**
+ * Purpose: The submit function for the load ontology form. It registers a
+ *   tripal job to run the obo_loader.php script
+ *
+   * @ingroup tripal_obo_loader
+ */
+function tripal_cv_obo_form_submit($form, &$form_state) {
+  global $user;
+
+  $obo_id =  $form_state['values']['obo_id'];
+  $obo_name =  $form_state['values']['obo_name'];
+  $obo_url =  $form_state['values']['obo_url'];
+  $obo_file  = $form_state['values']['obo_file'];
+
+  $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = %d";
+  $obo = db_fetch_object(db_query($sql, $obo_id));
+
+  if ($obo_id) {
+    $args = array($obo_id);
+    tripal_add_job("Load OBO $obo->name", 'tripal_cv',
+       "tripal_cv_load_obo_v1_2_id", $args, $user->uid);
+  }
+  else {
+    if ($obo_url) {
+      $args = array($obo_name, $obo_url);
+      tripal_add_job("Load OBO $obo_name", 'tripal_cv',
+        "tripal_cv_load_obo_v1_2_url", $args, $user->uid);
+    }
+    elseif ($obo_file) {
+      $args = array($obo_name, $obo_file);
+      tripal_add_job("Load OBO $obo_name", 'tripal_cv',
+        "tripal_cv_load_obo_v1_2_file", $args, $user->uid);
+    }
+  }
+}
+
+/**
+ * Form for re-doing the cvterm path
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cvtermpath_form() {
+
+  // get a list of db from chado for user to choose
+  $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
+  $results = chado_query($sql);
+
+  $cvs = array();
+  $cvs[] = '';
+  while ($cv = db_fetch_object($results)) {
+    $cvs[$cv->cv_id] = $cv->name;
+  }
+
+  $form['cvid'] = array(
+    '#title' => t('Controlled Vocabulary/Ontology Name'),
+    '#type' => 'select',
+    '#options' => $cvs,
+    '#description' => t('The Chado cvtermpath is a database table that provides lineage for ontology terms 
+      and is useful for quickly finding any ancestor parent of a term.  This table must be populated for each
+      ontology.  Select a controlled vocabulary for which you would like to upate the cvtermpath.'),
+  );
+
+  $form['description'] = array(
+    '#type' => 'item',
+    '#value' => t("Submit a job to update chado cvtermpath table."),
+    '#weight' => 1,
+  );
+
+  $form['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Update cvtermpath'),
+    '#weight' => 2,
+  );
+
+  return $form;
+}
 /**
  * @file
  * Tripal Ontology Loader
@@ -48,15 +214,18 @@ function tripal_cv_load_obo_v1_2_id($obo_id, $jobid = NULL) {
  */
 function tripal_cv_load_obo_v1_2_file($obo_name, $file, $jobid = NULL, $is_new = TRUE) {
   $newcvs = array();
-
+  
+  // TODO: need better error detection
+  
   tripal_cv_load_obo_v1_2($file, $jobid, $newcvs);
   if ($is_new) {
     tripal_cv_load_obo_add_ref($obo_name, $file);
   }
+  print "Ontology Sucessfully loaded!\n";
 
   // update the cvtermpath table
   tripal_cv_load_update_cvtermpath($newcvs, $jobid);
-  print "Ontology Sucessfully loaded!\n";
+  
 
 }
 

+ 1 - 254
tripal_cv/includes/tripal_cv_admin.inc

@@ -641,181 +641,6 @@ function tripal_cv_cvterm_callback() {
   );
 }
 
-///////////////////////////////
-// Ontology Loader
-//////////////////////////////
-
-/**
- * Purpose: Provides the form to load an already existing controlled
- *  Vocabulary into chado
- *
-  * @ingroup tripal_obo_loader
- */
-function tripal_cv_obo_form(&$form_state = NULL) {
-
-  // get a list of db from chado for user to choose
-  $sql = "SELECT * FROM {tripal_cv_obo} ORDER BY obo_id";
-  $results = db_query($sql);
-
-  $obos = array();
-  $obos[] = '';
-  while ($obo = db_fetch_object($results)) {
-    $obos[$obo->obo_id] = "$obo->name  | $obo->path";
-  }
-
-  $form['obo_existing'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Use a Saved Ontology OBO Reference')
-  );
-
-  $form['obo_new'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Use a New Ontology OBO Reference')
-  );
-
-  $form['obo_existing']['existing_instructions']= array(
-    '#value' => t('The Ontology OBO files listed in the drop down below have been automatically added upon
-                   installation of the Tripal CV module or were added from a previous upload.  Select
-                   an OBO, then click the submit button to load the vocabulary into the database.  If the
-                   vocabularies already exist then the ontology will be updated.'),
-    '#weight'        => -1
-  );
-
-  $form['obo_existing']['obo_id'] = array(
-    '#title' => t('Ontology OBO File Reference'),
-    '#type' => 'select',
-    '#options' => $obos,
-    '#weight'        => 0
-  );
-
-  $form['obo_new']['path_instructions']= array(
-    '#value' => t('Provide the name and path for the OBO file.  If the vocabulary OBO file
-                   is stored local to the server provide a file name. If the vocabulry is stored remotely,
-                   provide a URL.  Only provide a URL or a local file, not both.'),
-    '#weight'        => 0
-  );
-
-  $form['obo_new']['obo_name']= array(
-    '#type'          => 'textfield',
-    '#title'         => t('New Vocabulary Name'),
-    '#description'   => t('Please provide a name for this vocabulary.  After upload, this name will appear in the drop down
-                           list above for use again later.'),
-    '#weight'        => 1
-  );
-
-  $form['obo_new']['obo_url']= array(
-    '#type'          => 'textfield',
-    '#title'         => t('Remote URL'),
-    '#description'   => t('Please enter a URL for the online OBO file.  The file will be downloaded and parsed.
-                           (e.g. http://www.obofoundry.org/ro/ro.obo'),
-    '#default_value' => $default_desc,
-    '#weight'        => 2
-  );
-
-  $form['obo_new']['obo_file']= array(
-    '#type'          => 'textfield',
-    '#title'         => t('Local File'),
-    '#description'   => t('Please enter the full system path for an OBO definition file, or a path within the Drupal
-                           installation (e.g. /sites/default/files/xyz.obo).  The path must be accessible to the
-                           server on which this Drupal instance is running.'),
-    '#default_value' => $default_desc,
-    '#weight'        => 3
-  );
-
-  $form['submit'] = array(
-    '#type'         => 'submit',
-    '#value'        => t('Submit'),
-    '#weight'       => 5,
-    '#executes_submit_callback' => TRUE,
-  );
-
-  $form['#redirect'] = 'admin/tripal/tripal_cv/obo_loader';
-
-  return $form;
-}
-
-/**
- * Purpose: The submit function for the load ontology form. It registers a
- *   tripal job to run the obo_loader.php script
- *
-   * @ingroup tripal_obo_loader
- */
-function tripal_cv_obo_form_submit($form, &$form_state) {
-  global $user;
-
-  $obo_id =  $form_state['values']['obo_id'];
-  $obo_name =  $form_state['values']['obo_name'];
-  $obo_url =  $form_state['values']['obo_url'];
-  $obo_file  = $form_state['values']['obo_file'];
-
-  $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = %d";
-  $obo = db_fetch_object(db_query($sql, $obo_id));
-
-  if ($obo_id) {
-    $args = array($obo_id);
-    tripal_add_job("Load OBO $obo->name", 'tripal_cv',
-       "tripal_cv_load_obo_v1_2_id", $args, $user->uid);
-  }
-  else {
-    if ($obo_url) {
-      $args = array($obo_name, $obo_url);
-      tripal_add_job("Load OBO $obo_name", 'tripal_cv',
-        "tripal_cv_load_obo_v1_2_url", $args, $user->uid);
-    }
-    elseif ($obo_file) {
-      $args = array($obo_name, $obo_file);
-      tripal_add_job("Load OBO $obo_name", 'tripal_cv',
-        "tripal_cv_load_obo_v1_2_file", $args, $user->uid);
-    }
-  }
-
-}
-
-////////////////////////////////////
-// cvterm path management
-///////////////////////////////////
-
-/**
- * Form for re-doing the cvterm path
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cvtermpath_form() {
-
-  // get a list of db from chado for user to choose
-  $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
-  $results = chado_query($sql);
-
-  $cvs = array();
-  $cvs[] = '';
-  while ($cv = db_fetch_object($results)) {
-    $cvs[$cv->cv_id] = $cv->name;
-  }
-
-  $form['cvid'] = array(
-    '#title' => t('Controlled Vocabulary/Ontology Name'),
-    '#type' => 'select',
-    '#options' => $cvs,
-    '#description' => t('The Chado cvtermpath is a database table that provides lineage for ontology terms 
-      and is useful for quickly finding any ancestor parent of a term.  This table must be populated for each
-      ontology.  Select a controlled vocabulary for which you would like to upate the cvtermpath.'),
-  );
-
-  $form['description'] = array(
-    '#type' => 'item',
-    '#value' => t("Submit a job to update chado cvtermpath table."),
-    '#weight' => 1,
-  );
-
-  $form['button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Update cvtermpath'),
-    '#weight' => 2,
-  );
-
-  return $form;
-}
-
 /**
  * Cvterm path form submit
  *
@@ -835,82 +660,4 @@ function tripal_cv_cvtermpath_form_submit($form, &$form_state) {
     tripal_add_job("Update cvtermpath: $cv->name", 'tripal_cv',
        'tripal_cv_update_cvtermpath', $job_args, $user->uid);
   }
-}
-
-/**
- * Update the cvtermpath table
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_update_cvtermpath($cvid = NULL, $job_id = NULL) {
-
-  // first get the controlled vocabulary name:
-  $cv = db_fetch_object(chado_query("SELECT * FROM {cv} WHERE cv_id = %d", $cvid));
-  print "\nUpdating cvtermpath for $cv->name...\n";
-
-  // now fill the cvtermpath table
-  // @coder-ignore: using a function rather then tablename therefore table prefixing doesn't apply
-  $sql = "SELECT * FROM fill_cvtermpath('%s')";
-  chado_query($sql, $cv->name);
-
-  return;
-}
-
-//////////////////////////////////////
-// @section Miscellaneous
-// @todo check to see if these functions are still needed and/or if they
-//   should be moved to the api file
-//////////////////////////////////////
-
-/**
- * Get the CV ID based on name
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_get_cv_id($cv_name) {
-
-  $sql = "
-    SELECT cv_id FROM {cv} WHERE name = '%s'
-  ";
-  $cv = db_fetch_object(chado_query($sql, $cv_name));
-
-  return $cv->cv_id;
-}
-
-/**
- * Returns a themed cvterm definition table
- *
- * @ingroup tripal_cv
- */
-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
-  ";
-  $cvterm = db_fetch_object(chado_query($sql, $cvterm_id));
-
-  return theme('tripal_cv_cvterm_edit', $cvterm);
-}
-
-/**
- * Does the actual themeing of the cvterm definition table
- *
- * @ingroup tripal_cv
- */
-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;
-}
+}

+ 13 - 71
tripal_cv/tripal_cv.module

@@ -46,7 +46,7 @@ function tripal_cv_menu() {
     'description' => 'Basic Description of Tripal CV Module Functionality',
     'page callback' => 'tripal_cv_module_description_page',
     'page arguments' => array(''),
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_NORMAL_ITEM,
   );
   
@@ -54,7 +54,7 @@ function tripal_cv_menu() {
     'title' => 'Load Ontology',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_cv_obo_form'),
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_NORMAL_ITEM,
   );
   
@@ -63,7 +63,7 @@ function tripal_cv_menu() {
     'description' => 'The Chado cvtermpath table provides lineage for terms and is useful for quickly finding any ancestor parent of a term.  However, this table must be populated.  This page allows for populating of this table one vocabulary at a time',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_cv_cvtermpath_form'),
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_NORMAL_ITEM,
   );
 
@@ -74,7 +74,7 @@ function tripal_cv_menu() {
     'title' => 'Add a Vocabulary',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_cv_add_form'),
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_NORMAL_ITEM,
   );
   
@@ -82,13 +82,13 @@ function tripal_cv_menu() {
     'title' => 'Edit a Vocabulary',
     'description' => 'Edit a controlled vocabularies/ontolgoies in Chado ',
     'page callback' => 'tripal_cv_edit_page',
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_NORMAL_ITEM,
   );
       
   $items['admin/tripal/tripal_cv/cv/edit/js'] = array(
     'page callback' => 'tripal_ajax_cv_edit',
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_CALLBACK,
   );
 
@@ -100,19 +100,19 @@ function tripal_cv_menu() {
     'description' => 'Manage controlled vocabulary/ontology terms in Chado ',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_cv_cvterm_form', 'add'),
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_NORMAL_ITEM,
   );
   
   $items['admin/tripal/tripal_cv/cvterm/ahah'] = array(
     'page callback' => 'tripal_cv_cvterm_callback',
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_CALLBACK,
   );
   $items['admin/tripal/tripal_cv/cvterm/auto_name/%/%'] = array(
     'page callback' => 'tripal_cv_cvterm_name_autocomplete',
     'page arguments' => array(5, 6),
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_CALLBACK,
   );
   
@@ -121,10 +121,10 @@ function tripal_cv_menu() {
     'description' => 'Edit an existing controlled vocabulary/ontology terms in Chado ',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_cv_cvterm_form', 'edit'),
-    'access arguments' => array('administer site configuration'),
+    'access arguments' => array('administer controlled vocabularies'),
     'type' => MENU_NORMAL_ITEM,
   );
-
+  
   /*
    * Charts
    */  
@@ -142,7 +142,7 @@ function tripal_cv_menu() {
    */  
   $items['cv_browser'] = array(
     'page callback' => 'tripal_cv_show_browser',
-    'access arguments' => array('access chado_cv content'),
+    'access arguments' => array('access content'),
     'type' => MENU_CALLBACK
   );
     
@@ -181,49 +181,9 @@ function tripal_cv_menu() {
     'type' => MENU_CALLBACK
   );
 
-  $items['tripal_cv_cvterm_edit'] = array(
-    'path' => 'tripal_cv_edit',
-    'title' => '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
- *
- * @ingroup tripal_cv
- */
-function chado_cv_access($op, $node, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_cv content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'update') {
-    if (!user_access('edit chado_cv content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_cv content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_cv content', $account)) {
-      return FALSE;
-    }
-  }
-
-  return NULL;
-}
-
 /**
  *  Set the permission types that the chado module uses.  Essentially we
  *  want permissionis that protect creation, editing and deleting of chado
@@ -233,10 +193,7 @@ function chado_cv_access($op, $node, $account) {
  */
 function tripal_cv_perm() {
   return array(
-    'access chado_cv content',
-    'create chado_cv content',
-    'delete chado_cv content',
-    'edit chado_cv content',
+    'administer controlled vocabularies',
   );
 }
 
@@ -252,21 +209,6 @@ function tripal_cv_views_api() {
   return array('api' => 2.0);
 }
 
-/**
- *  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
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_theme() {
-  return array(
-    'tripal_cv_cvterm_edit' => array(
-      'arguments' => array('cvterm'),
-    ),
-  );
-}
-
 /**
  * Implements hook_coder_ignore().
  * Defines the path to the file (tripal_cv.coder_ignores.txt) where ignore rules for coder are stored

+ 1 - 1
tripal_db/includes/tripal_db.admin.inc

@@ -31,7 +31,7 @@ function tripal_db_module_description_page() {
                permissions.  Best practice is to create <a href="' . url('admin/user/roles') . '">a new role</a> 
                for administrative tasks, (such as a webmaster role),
                and then <a href="' . url('admin/user/user') . '">assign users to the role</a>. Finally,
-               <a href="' . url('admin/user/permissions') . '">assign the permission</a> titled "administer tripal db cross-reference".
+               <a href="' . url('admin/user/permissions') . '">assign the permission</a> titled "administer db cross-reference".
                to the new role.</li>';
   $text .= '<li><b>Adding or Editing an External Databases</b>. Many resources such as NCBI nr or ExPASy SwissProt (to name a few) 
             come pre-loaded with Chado.  However, you can add new entries or edit existing entries. Also, when loading 

+ 4 - 4
tripal_db/tripal_db.module

@@ -30,7 +30,7 @@ function tripal_db_menu() {
     'description' => 'Basic Description of Tripal DB Module Functionality',
     'page callback' => 'tripal_db_module_description_page',
     'access callback' => 'user_access',
-    'access arguments' => array('administer tripal db cross-references'),
+    'access arguments' => array('administer db cross-references'),
     'type' => MENU_NORMAL_ITEM,
   );
 
@@ -40,7 +40,7 @@ function tripal_db_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_db_form', 'Update'),
     'access callback' => 'user_access',
-    'access arguments' => array('administer tripal db cross-references'),
+    'access arguments' => array('administer db cross-references'),
     'type' => MENU_NORMAL_ITEM,
   );
 
@@ -49,7 +49,7 @@ function tripal_db_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_db_form', 'Add'),
     'access callback' => 'user_access',
-    'access arguments' => array('administer tripal db cross-references'),
+    'access arguments' => array('administer db cross-references'),
     'type' => MENU_NORMAL_ITEM,
   );
   $items['admin/tripal/tripal_db/edit/js'] = array(
@@ -71,7 +71,7 @@ function tripal_db_menu() {
  */
 function tripal_db_perm() {
   return array(
-    'administer tripal db cross-references',
+    'administer db cross-references',
   );
 }
 

+ 140 - 1
tripal_feature/api/tripal_feature.api.inc

@@ -888,4 +888,143 @@ function tripal_feature_get_custom_tables($table = NULL) {
     );
   }
   return $schema;
-}
+}
+
+/**
+ * Using the tripal_core_expand_chado_vars function to retrieve a set
+ * of relationships can be very slow, especialy if there are many relationships
+ * This function is intended to help speed up the retrieval of relationships
+ * by only retrieving the base information for the relationship and returning
+ * an array with  
+ *
+ * @param $feature
+ *   The feature object 
+ 
+ * @return
+ *   An array with two objects
+ *
+ * @ingroup tripal_feature_api
+ */
+function tripal_feature_get_feature_relationships($feature) {
+  // expand the feature object to include the feature relationships.
+  $options = array(
+    'return_array' => 1,
+    'order_by'     => array('rank' => 'ASC'),
+  );
+  $feature = tripal_core_expand_chado_vars($feature, 'table',
+    'feature_relationship', $options);
+
+  // get the subject relationships
+  $srelationships = $feature->feature_relationship->subject_id;
+  $orelationships = $feature->feature_relationship->object_id;
+  
+  // get alignment as child. The $feature->featureloc element
+  // is already populated from the alignment preprocess function
+  $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc');
+  $cfeaturelocs = $feature->featureloc->feature_id;
+  if (!$cfeaturelocs) {
+     $cfeaturelocs = array();
+  } 
+  elseif (!is_array($cfeaturelocs)) { 
+     $cfeaturelocs = array($cfeaturelocs); 
+  }
+  
+  // prepare the SQL statement to get the featureloc for the 
+  // feature in the relationships. 
+  $connection = tripal_db_persistent_chado();
+  $psql = " 
+    PREPARE sel_featureloc_preprocess_relationships (int, int) AS 
+    SELECT 
+      FL.featureloc_id, F.name as srcfeature_name, FL.srcfeature_id,
+      FL.feature_id, FL.fmin, FL.fmax, FL.strand, FL.phase
+    FROM featureloc FL 
+      INNER JOIN feature F ON F.feature_id = FL.srcfeature_id
+    WHERE FL.feature_id = $1 and FL.srcfeature_id = $2
+  ";
+  tripal_core_chado_prepare('sel_featureloc_preprocess_relationships', $psql, array('int', 'int'));
+
+  
+  // combine both object and subject relationshisp into a single array
+  $relationships = array();
+  $relationships['object'] = array();
+  $relationships['subject'] = array();
+  
+  // iterate through the object relationships
+  if ($orelationships) {
+    foreach ($orelationships as $relationship) {
+       $rel = new stdClass(); 
+       // get locations where the child feature and this feature overlap with the
+       // same landmark feature.
+       $rel->child_featurelocs = array();     
+       foreach ($cfeaturelocs as $featureloc) {
+          $res = chado_query("EXECUTE sel_featureloc_preprocess_relationships (%d, %d)", 
+            $relationship->subject_id->feature_id, 
+            $featureloc->srcfeature_id->feature_id);        
+          while ($loc = db_fetch_object($res)) {
+             // add in the node id of the src feature if it exists and save this location
+             $loc->nid = $featureloc->srcfeature_id->nid;
+             $rel->child_featurelocs[] = $loc;
+          }
+       }
+       $rel->record = $relationship;    
+       
+       // get the relationship and child types
+       $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
+       $child_type = $relationship->subject_id->type_id->name;
+       
+       // get the node id of the subject
+       $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
+       $n = db_fetch_object(db_query($sql, $relationship->subject_id->feature_id));
+       if ($n) {
+          $rel->record->nid = $n->nid;
+       }
+  
+       if (!array_key_exists($rel_type, $relationships['object'])) {
+         $relationships['object'][$rel_type] = array();   
+       }
+       if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
+         $relationships['object'][$rel_type][$child_type] = array();   
+       }
+       $relationships['object'][$rel_type][$child_type][] = $rel;     
+    }
+  }
+  
+  // now add in the subject relationships
+  if ($srelationships) {
+    foreach ($srelationships as $relationship) {
+       $rel = new stdClass(); 
+       // get locations where this feature overlaps with the parent
+       $rel->parent_featurelocs = array();     
+       foreach ($cfeaturelocs as $featureloc) {
+          $res = chado_query("EXECUTE sel_featureloc_preprocess_relationships (%d, %d)", 
+            $relationship->object_id->feature_id, 
+            $featureloc->srcfeature_id->feature_id);
+          while ($loc = db_fetch_object($res)) {
+             // add in the node id of the src feature if it exists and save this location
+             $loc->nid = $featureloc->srcfeature_id->nid;
+             $rel->parent_featurelocs[] = $loc;
+          }
+       }
+       $rel->record = $relationship;
+       $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
+       $parent_type = $relationship->object_id->type_id->name;
+       
+       // get the node id of the subject
+       $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
+       $n = db_fetch_object(db_query($sql, $relationship->object_id->feature_id));
+       if ($n) {
+          $rel->record->nid = $n->nid;
+       }
+       
+       if (!array_key_exists($rel_type, $relationships['subject'])) {
+         $relationships['subject'][$rel_type] = array();   
+       }
+       if (!array_key_exists($child_type, $relationships['subject'][$rel_type])) {
+         $relationships['subject'][$rel_type][$parent_type] = array();   
+       }
+       $relationships['subject'][$rel_type][$parent_type][] = $rel;
+    }
+  }
+  return $relationships;
+}
+} 

+ 2 - 120
tripal_feature/tripal_feature.module

@@ -1925,127 +1925,9 @@ function tripal_feature_preprocess_tripal_feature_relationships(&$variables) {
   // we want to provide a new variable that contains the matched features.
   $feature = $variables['node']->feature;
    
-  // expand the feature object to include the feature relationships.
-  $options = array(
-    'return_array' => 1,
-    'order_by'     => array('rank' => 'ASC'),
-  );
-  $feature = tripal_core_expand_chado_vars($feature, 'table',
-    'feature_relationship', $options);
-
-  // get the subject relationships
-  $srelationships = $feature->feature_relationship->subject_id;
-  $orelationships = $feature->feature_relationship->object_id;
-  
-  // get alignment as child. The $feature->featureloc element
-  // is already populated from the alignment preprocess function
-  $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc');
-  $cfeaturelocs = $feature->featureloc->feature_id;
-  if (!$cfeaturelocs) {
-     $cfeaturelocs = array();
+  if (!$feature->all_relationships) {
+    $feature->all_relationships = tripal_feature_get_feature_relationships($feature);  
   } 
-  elseif (!is_array($cfeaturelocs)) { 
-     $cfeaturelocs = array($cfeaturelocs); 
-  }
-  
-  // prepare the SQL statement to get the featureloc for the 
-  // feature in the relationships. 
-  $connection = tripal_db_persistent_chado();
-  $psql = " 
-    PREPARE sel_featureloc_preprocess_relationships (int, int) AS 
-    SELECT 
-      FL.featureloc_id, F.name as srcfeature_name, FL.srcfeature_id,
-      FL.feature_id, FL.fmin, FL.fmax, FL.strand, FL.phase
-    FROM featureloc FL 
-      INNER JOIN feature F ON F.feature_id = FL.srcfeature_id
-    WHERE FL.feature_id = $1 and FL.srcfeature_id = $2
-  ";
-  tripal_core_chado_prepare('sel_featureloc_preprocess_relationships', $psql, array('int', 'int'));
-
-  
-  // combine both object and subject relationshisp into a single array
-  $relationships = array();
-  $relationships['object'] = array();
-  $relationships['subject'] = array();
-  
-  // iterate through the object relationships
-  if ($orelationships) {
-    foreach ($orelationships as $relationship) {
-       $rel = new stdClass(); 
-       // get locations where the child feature and this feature overlap with the
-       // same landmark feature.
-       $rel->child_featurelocs = array();     
-       foreach ($cfeaturelocs as $featureloc) {
-          $res = chado_query("EXECUTE sel_featureloc_preprocess_relationships (%d, %d)", 
-            $relationship->subject_id->feature_id, 
-            $featureloc->srcfeature_id->feature_id);        
-          while ($loc = db_fetch_object($res)) {
-             // add in the node id of the src feature if it exists and save this location
-             $loc->nid = $featureloc->srcfeature_id->nid;
-             $rel->child_featurelocs[] = $loc;
-          }
-       }
-       $rel->record = $relationship;    
-       
-       // get the relationship and child types
-       $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
-       $child_type = $relationship->subject_id->type_id->name;
-       
-       // get the node id of the subject
-       $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
-       $n = db_fetch_object(db_query($sql, $relationship->subject_id->feature_id));
-       if ($n) {
-          $rel->record->nid = $n->nid;
-       }
-  
-       if (!array_key_exists($rel_type, $relationships['object'])) {
-         $relationships['object'][$rel_type] = array();   
-       }
-       if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
-         $relationships['object'][$rel_type][$child_type] = array();   
-       }
-       $relationships['object'][$rel_type][$child_type][] = $rel;     
-    }
-  }
-  
-  // now add in the subject relationships
-  if ($srelationships) {
-    foreach ($srelationships as $relationship) {
-       $rel = new stdClass(); 
-       // get locations where this feature overlaps with the parent
-       $rel->parent_featurelocs = array();     
-       foreach ($cfeaturelocs as $featureloc) {
-          $res = chado_query("EXECUTE sel_featureloc_preprocess_relationships (%d, %d)", 
-            $relationship->object_id->feature_id, 
-            $featureloc->srcfeature_id->feature_id);
-          while ($loc = db_fetch_object($res)) {
-             // add in the node id of the src feature if it exists and save this location
-             $loc->nid = $featureloc->srcfeature_id->nid;
-             $rel->parent_featurelocs[] = $loc;
-          }
-       }
-       $rel->record = $relationship;
-       $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
-       $parent_type = $relationship->object_id->type_id->name;
-       
-       // get the node id of the subject
-       $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
-       $n = db_fetch_object(db_query($sql, $relationship->object_id->feature_id));
-       if ($n) {
-          $rel->record->nid = $n->nid;
-       }
-       
-       if (!array_key_exists($rel_type, $relationships['subject'])) {
-         $relationships['subject'][$rel_type] = array();   
-       }
-       if (!array_key_exists($child_type, $relationships['subject'][$rel_type])) {
-         $relationships['subject'][$rel_type][$parent_type] = array();   
-       }
-       $relationships['subject'][$rel_type][$parent_type][] = $rel;
-    }
-  }
-  $feature->all_relationships = $relationships;
-
 }
 /**
  *

+ 6 - 1
tripal_stock/includes/tripal_stock-administration.inc

@@ -184,7 +184,12 @@ function tripal_stock_admin() {
           ." between stocks. Only cvs already loaded into chado can be selected here.")
     );
 
-    $cv_options = tripal_cv_get_cv_options();
+    // get the list of CVs for the next form element
+    $results = tripal_core_chado_select('cv', array('cv_id', 'name'), array());
+    $cv_options = array();
+    foreach ($results as $r) {
+      $cv_options[$r->cv_id] = $r->name;
+    }
 
     $form['set_cv']['stock_types_cv'] = array(
      '#type' => 'select',