Browse Source

API: finished feature api including creating chado_associate_dbxref/cvterm

Lacey Sanderson 11 years ago
parent
commit
e8d5ef6ddb

+ 116 - 0
tripal_cv/api/tripal_cv.api.inc

@@ -846,4 +846,120 @@ function chado_cvterm_autocomplete($cv_id, $string = '') {
      $items[$term->name] = $term->name;
   }
   drupal_json_output($items);
+}
+
+/**
+ * Add a record to a cvterm linking table (ie: feature_cvterm)
+ *
+ * @param $basetable
+ *   The base table to which the cvterm should be linked/associated. Thus to associate a
+ *   cvterm to a feature the basetable=feature and cvterm_id is added to the feature_cvterm table.
+ * @param $record_id
+ *   The primary key of the basetable to associate the cvterm with. This should be in integer.
+ * @param $cvterm
+ *   An associative array describing the cvterm. Valid keys include: 'name' => the
+ *   name for the cvterm, 'cv_name' => the name of the cv the cvterm belongs to;
+ *   'cv_id' => the primary key of the cv the cvterm belongs to.
+ * @param $options
+ *   An associative array of options. Valid keys include:
+ *    - insert_cvterm: Insert the cvterm if it doesn't already exist. FALSE is the default
+ *
+ * @ingroup tripal_db_api
+ */
+function chado_associate_cvterm($basetable, $record_id, $cvterm) {
+  $linking_table = $basetable . '_cvterm';
+  $foreignkey_name = $basetable . '_id';
+
+  // Default Values
+  $options['insert_cvterm'] = (isset($options['insert_cvterm'])) ? $options['insert_cvterm'] : FALSE;
+
+  // If the cvterm_id is set then we know it already exists
+  // Otherwise, select to check
+  if (!isset($cvterm['cvterm_id'])) {
+    $values = array(
+      'name' => $cvterm['name'],
+    );
+    if (isset($cvterm['cv_id'])) {
+      $values['cv_id'] = $cvterm['cv_id'];
+    } elseif (isset($cvterm['cv_name'])) {
+      $values['cv_id'] = array(
+        'name' => $cvterm['cv_name']
+      );
+    }
+    else {
+      tripal_report_error(
+        'tripal_cv_api',
+        TRIPAL_WARNING,
+        "chado_associate_cvterm: The cvterm needs to have either the cv_name or cv_id
+          supplied. You were trying to associate a cvterm with the %base %record_id
+          and supplied the cvterm values: %cvterm.",
+        array('%base' => $basetable, '%record_id' => $record_id, '%cvterm' => print_r($cvterm,TRUE))
+      );
+      return FALSE;
+    }
+    $select = chado_select_record('cvterm',array('*'), $values);
+    if ($select) {
+      $cvterm['cvterm_id'] = $select[0]->cvterm_id;
+    }
+    elseif ($options['insert_cvterm']) {
+      // Insert the cvterm
+      $insert = chado_insert_cvterm($values);
+      if (isset($insert->cvterm_id)) {
+        $cvterm['cvterm_id'] = $insert->cvterm_id;
+      }
+      else {
+        tripal_report_error(
+          'tripal_cv_api',
+          TRIPAL_WARNING,
+          "chado_associate_cvterm: Unable to insert the cvterm using the cvterm values: %cvterm.",
+          array('%cvterm' => print_r($cvterm,TRUE))
+        );
+        return FALSE;
+      }
+    }
+    else {
+      tripal_report_error(
+        'tripal_api',
+        TRIPAL_WARNING,
+        "chado_associate_cvterm: The cvterm doesn't already exist. You supplied the cvterm values: %cvterm.",
+        array('%cvterm' => print_r($cvterm,TRUE))
+      );
+      return FALSE;
+    }
+  }
+
+  // Now add the link between the record & cvterm
+  if ($cvterm['cvterm_id'] > 0) {
+    $values = array(
+      'cvterm_id' => $cvterm['cvterm_id'],
+      $foreignkey_name => $record_id,
+      'pub_id' => 1,
+    );
+
+    $result = chado_select_record($linking_table, array('*'), $values);
+
+    // if it doesn't already exist then add it
+    if (!$result) {
+      $success = chado_insert_record($linking_table, $values);
+      if (!$success) {
+        tripal_report_error(
+          'tripal_api',
+          TRIPAL_WARNING,
+          "Failed to insert the %base record %term",
+          array('%base' => $linking_table, '%term' => $cvterm['name'])
+        );
+        return FALSE;
+      }
+      $result = chado_select_record($linking_table, array('*'), $values);
+    }
+
+    if (isset($result[0])) {
+      return $result[0];
+    }
+    else {
+      return FALSE;
+    }
+  }
+
+  return FALSE;
 }

+ 8 - 6
tripal_db/api/tripal_db.DEPRECATED.inc

@@ -222,10 +222,12 @@ function tripal_db_add_dbxref_link($linking_table, $dbxref_id, $foreignkey_name,
     )
   );
 
-  return chado_associate_dbxref(array(
-    'linking_table' => $linking_table,
-    'dbxref_id' => $dbxref_id,
-    'foreignkey_name' => $foreignkey_name,
-    'foreignkey_id' => $foreignkey_id
-  ));
+  if (preg_match('/(\w+)_dbxref/',$linking_table,$matches)) {
+    $basetable = $matches[1];
+
+    return chado_associate_dbxref($basetable, $foreignkey_id, array('dbxref_id' => $dbxref_id));
+  }
+  else {
+    return FALSE;
+  }
 }

+ 101 - 30
tripal_db/api/tripal_db.api.inc

@@ -382,43 +382,114 @@ function chado_insert_dbxref($values) {
 /**
  * Add a record to a database reference linking table (ie: feature_dbxref)
  *
- * @param: $values
- *   An associative array describing the link
- *    - linking_table:
- *    - dbxref_id:
- *    - foreignkey_name:
- *    - foreignkey_id:
+ * @param $basetable
+ *   The base table for which the dbxref should be associated. Thus to associate a dbxref
+ *   with a feature the basetable=feature and dbxref_id is added to the feature_dbxref table
+ * @param $record_id
+ *   The primary key of the basetable to associate the dbxref with. This should be in integer.
+ * @param $dbxref
+ *   An associative array describing the dbxref. Valid keys include: 'accession' => the
+ *   accession for the dbxref, 'db_name' => the name of the database the dbxref belongs to;
+ *   'db_id' => the primary key of the database the dbxref belongs to.
+ * @param $options
+ *   An associative array of options. Valid keys include:
+ *    - insert_dbxref: Insert the dbxref if it doesn't already exist. TRUE is the default
  *
  * @ingroup tripal_db_api
  */
-function chado_associate_dbxref($values) {
+function chado_associate_dbxref($basetable, $record_id, $dbxref, $options = array()) {
+  $linking_table = $basetable . '_dbxref';
+  $foreignkey_name = $basetable . '_id';
 
-  $linking_table = $values['linking_table'];
-  $dbxref_id = $values['dbxref_id'];
-  $foreignkey_name = $values['foreignkey_name'];
-  $foreignkey_id = $values['foreignkey_id'];
+  // Default Values
+  $options['insert_dbxref'] = (isset($options['insert_dbxref'])) ? $options['insert_dbxref'] : TRUE;
 
-  $values = array(
-    'dbxref_id' => $dbxref_id,
-    $foreignkey_name => $foreignkey_id
-  );
+  // If the dbxref_id is set then we know it already exists
+  // Otherwise, select to check
+  if (!isset($dbxref['dbxref_id'])) {
+    $values = array(
+      'accession' => $dbxref['accession'],
+    );
+    if (isset($dbxref['db_id'])) {
+      $values['db_id'] = $dbxref['db_id'];
+    } elseif (isset($dbxref['db_name'])) {
+      $values['db_id'] = array(
+        'name' => $dbxref['db_name']
+      );
+    }
+    else {
+      tripal_report_error(
+        'tripal_db_api',
+        TRIPAL_WARNING,
+        "chado_associate_dbxref: The dbxref needs to have either the db_name or db_id
+          supplied. You were trying to associate a dbxref with the %base %record_id
+          and supplied the dbxref values: %dbxref.",
+        array('%base' => $basetable, '%record_id' => $record_id, '%dbxref' => print_r($dbxref,TRUE))
+      );
+      return FALSE;
+    }
+    $select = chado_select_record('dbxref',array('*'), $values);
+    if ($select) {
+      $dbxref['dbxref_id'] = $select[0]->dbxref_id;
+    }
+    elseif ($options['insert_dbxref']) {
+      // Insert the dbxref
+      $insert = chado_insert_dbxref($values);
+      if (isset($insert->dbxref_id)) {
+        $dbxref['dbxref_id'] = $insert->dbxref_id;
+      }
+      else {
+        tripal_report_error(
+          'tripal_db_api',
+          TRIPAL_WARNING,
+          "chado_associate_dbxref: Unable to insert the dbxref using the dbxref values: %dbxref.",
+          array('%dbxref' => print_r($dbxref,TRUE))
+        );
+        return FALSE;
+      }
+    }
+    else {
+      tripal_report_error(
+        'tripal_api',
+        TRIPAL_WARNING,
+        "chado_associate_dbxref: The dbxref doesn't already exist. You supplied the dbxref values: %dbxref.",
+        array('%dbxref' => print_r($dbxref,TRUE))
+      );
+      return FALSE;
+    }
+  }
 
-  $result = chado_select_record($linking_table, array('*'), $values);
+  // Now add the link between the record & dbxref
+  if ($dbxref['dbxref_id'] > 0) {
+    $values = array(
+      'dbxref_id' => $dbxref['dbxref_id'],
+      $foreignkey_name => $record_id
+    );
 
-  // if it doesn't already exist then add it
-  if (!$result) {
-    $success = chado_insert_record($linking_table, $values);
-    if (!$success) {
-      tripal_report_error('tripal_db', TRIPAL_WARNING, "Failed to insert the $linking_table record $accession", NULL);
-      return 0;
-    }
     $result = chado_select_record($linking_table, array('*'), $values);
-  }
 
-  if (isset($result[0])) {
-    return $result[0];
-  }
-  else {
-    return FALSE;
+    // if it doesn't already exist then add it
+    if (!$result) {
+      $success = chado_insert_record($linking_table, $values);
+      if (!$success) {
+        tripal_report_error(
+          'tripal_api',
+          TRIPAL_WARNING,
+          "Failed to insert the %base record %accession",
+          array('%base' => $linking_table, '%accession' => $dbxref['accession'])
+        );
+        return FALSE;
+      }
+      $result = chado_select_record($linking_table, array('*'), $values);
+    }
+
+    if (isset($result[0])) {
+      return $result[0];
+    }
+    else {
+      return FALSE;
+    }
   }
-}
+
+  return FALSE;
+}

+ 37 - 5
tripal_feature/api/tripal_feature.DEPRECATED.inc

@@ -370,7 +370,7 @@ function tripal_feature_reverse_complement($sequence) {
     )
   );
 
-  return FALSE;
+  return feature_sequence_reverse_complement($sequence);
 }
 
 /**
@@ -392,7 +392,25 @@ function tripal_feature_get_formatted_sequence($feature_id, $feature_name, $num_
     )
   );
 
-  return FALSE;
+  return feature_sequence_get_formatted(
+    // Feature
+    array(
+      'feature_id' => $feature_id,
+      'name' => $feature_name
+    ),
+    // Options
+    array(
+      'width' => $num_bases_per_line,
+      'derive_from_parent' => $derive_from_parent,
+      'aggregate' => $aggregate,
+      'output_format' => $output_format,
+      'num_upstream' => $upstream,
+      'num_downstream' => $downstream,
+      'sub_feature_types' => $sub_features,
+      'relationship_type' => $relationship,
+      'relationship_part' => $rel_part
+    )
+  );
 }
 
 /**
@@ -414,7 +432,14 @@ function tripal_feature_add_dbxref($feature_id, $dbname, $accession) {
     )
   );
 
-  return FALSE;
+  return chado_associate_dbxref(
+    'feature',
+    $feature_id,
+    array(
+      'accession' => $accession,
+      'db_name' => $dbname
+    )
+  );
 }
 
 /**
@@ -436,7 +461,14 @@ function tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) {
     )
   );
 
-  return FALSE;
+  return chado_associate_cvterm(
+    'feature',
+    $feature_id,
+    array(
+      'name' => $cvterm,
+      'cv_name' => $cvname
+    )
+  );
 }
 
 /**
@@ -458,5 +490,5 @@ function tripal_feature_return_fasta($feature, $desc) {
     )
   );
 
-  return FALSE;
+  return feature_sequence_get_fasta($feature, $desc);
 }

+ 49 - 573
tripal_feature/api/tripal_feature.api.inc

@@ -12,422 +12,6 @@
  * @}
  */
 
-/**
- * Retrieve properties from the analysisfeatureprop table for a feature.
- *
- * @param $analysis_id
- *    The analysis ID for the analysis feature. This argument is optional but
- *    if specified it must also be accompanied with a feature ID.
- * @param $feature_id
- *    The feature ID for the analysis feature. This argument is optional but
- *    if specified it must also be accompanied with an analysis ID.
- * @param $analysisfeature_id
- *    The analysis feature ID for the analysis feature. This argument is
- *    optional and can be used rather than specifying the $analysis_id and
- *    $feature_id arguments.  If all three arguments are specified (e.g.
- *    an $analysis_id, $feature_id and $analysisfeature_id, then the
- *    $analysisfeature_id is used and the other two arguments are ignored.
- * @param $property
- *    The cvterm name of the properties to retrieve
- * @param $cv_name
- *    Optional.  The name of the cv to which the property belongs.  By
- *    default this is the 'tripal' cv.
- *
- * @return
- *    An analysisfeature chado variable with the specified properties expanded
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_analysis_get_property($analysis_id = NULL, $feature_id = NUll,
-  $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
-
-  // check that the incoming arguments are correct
-  if (($analysis_id and !$feature_id) or
-    (!$analysis_id and $feature_id)) {
-      tripal_report_error('tripal_feature', TRIPAL_WARNING,
-      'tripal_feature_analysis_get_property: Both an analysis ID and feature ID should be specified',
-      array());
-  }
-
-  // get the analysisfeature_id if one is not provided
-  if (!$analysisfeature_id) {
-    $columns = array('analysisfeature_id');
-    $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-    $result = chado_select_record('analysisfeature', $columns, $values);
-    $analysisfeature_id = $result[0]->analysisfeature_id;
-  }
-
-  // get the property.
-  return chado_get_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
-}
-
-/**
- * Insert a property for an analysis feature
- *
- * @param $analysis_id
- *    The analysis ID for the analysis feature. This argument is optional but
- *    if specified it must also be accompanied with a feature ID.
- * @param $feature_id
- *    The feature ID for the analysis feature. This argument is optional but
- *    if specified it must also be accompanied with an analysis ID.
- * @param $analysisfeature_id
- *    The analysis feature ID for the analysis feature. This argument is
- *    optional and can be used rather than specifying the $analysis_id and
- *    $feature_id arguments.  If all three arguments are specified (e.g.
- *    an $analysis_id, $feature_id and $analysisfeature_id, then the
- *    $analysisfeature_id is used and the other two arguments are ignored.
- * @param $property
- *   The cvterm name of the property to insert
- * @param $value
- *   The value of the property to insert
- * @param $update_if_present
- *   A boolean indicated whether to update the record if it's already present
- * @param $cv_name
- *    Optional.  The name of the cv to which the property belongs.  By
- *    default this is the 'tripal' cv.
- *
- * @return
- *   True of success, False otherwise
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_analysis_insert_property($analysis_id = NULL, $feature_id = NUll,
-  $analysisfeature_id = NULL, $property, $value, $update_if_present = 0, $cv_name = 'tripal') {
-
-  // check that the incoming arguments are correct
-  if (($analysis_id and !$feature_id) or
-      (!$analysis_id and $feature_id)) {
-    tripal_report_error('tripal_feature', TRIPAL_WARNING,
-      'tripal_feature_analysis_insert_property: Both an analysis ID and feature ID should be specified',
-      array());
-  }
-
-  // get the analysisfeature_id if one is not provided
-  if (!$analysisfeature_id) {
-    $columns = array('analysisfeature_id');
-    $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-    $result = chado_select_record('analysisfeature', $columns, $values);
-    $analysisfeature_id = $result[0]->analysisfeature_id;
-  }
-
-  // insert the property.
-  $success = chado_insert_property('analysisfeature', $analysisfeature_id,
-    $property, $cv_name, $value, $update_if_present);
-  if (!$success) {
-     tripal_report_error('tripal_feature', TRIPAL_WARNING,
-      'tripal_feature_analysis_insert_property: Failed to insert analysis feature property',
-       array());
-     return FALSE;
-  }
-  return $success;
-}
-
-/**
- * Update an analysis feature property using the property name. Use this
- * when a property only exists once for a given analysis feature.  When more
- * than one value can exist for the same property use the
- * tripal_feature_analysis_update_property_by_id() function.
- *
- * @param $analysis_id
- *    The analysis ID for the analysis feature. This argument is optional but
- *    if specified it must also be accompanied with a feature ID.
- * @param $feature_id
- *    The feature ID for the analysis feature. This argument is optional but
- *    if specified it must also be accompanied with an analysis ID.
- * @param $analysisfeature_id
- *    The analysis feature ID for the analysis feature. This argument is
- *    optional and can be used rather than specifying the $analysis_id and
- *    $feature_id arguments.  If all three arguments are specified (e.g.
- *    an $analysis_id, $feature_id and $analysisfeature_id, then the
- *    $analysisfeature_id is used and the other two arguments are ignored.
- * @param $property
- *   The cvterm name of the property to update
- * @param $value
- *   The value of the property to update
- * @param $insert_if_missing
- *   A boolean indicated whether to insert the record if it's absent
- * @param $cv_name
- *    Optional.  The name of the cv to which the property belongs.  By
- *    default this is the 'tripal' cv.
- *
- * Note: The property will be identified using the unique combination of the $analysis_id and $property
- * and then it will be updated with the supplied value
- *
- * @return
- *   True of success, False otherwise
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_analysis_update_property($analysis_id = NULL, $feature_id = NUll,
-  $analysisfeature_id = NULL, $property, $value, $insert_if_missing = 0,
-  $cv_name = 'tripal') {
-
-  // check that the incoming arguments are correct
-  if (($analysis_id and !$feature_id) or
-    (!$analysis_id and $feature_id)) {
-      tripal_report_error('tripal_feature', TRIPAL_WARNING,
-      'tripal_feature_analysis_update_property: Both an analysis ID and feature ID should be specified',
-      array());
-  }
-
-  // get the analysisfeature_id if one is not provided
-  if (!$analysisfeature_id) {
-    $columns = array('analysisfeature_id');
-    $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-    $result = chado_select_record('analysisfeature', $columns, $values);
-    $analysisfeature_id = $result[0]->analysisfeature_id;
-  }
-
-  // update the property.
-  return chado_update_property('analysisfeature', $analysisfeature_id, $property, $cv_name, $value, $insert_if_missing);
-}
-
-/**
- * Update a property for an analysis feature using the analysisfeatureprop_id.
- *
- * @param $analysisfeatureprop_id
- *    The analysis feature property ID for the analysis feature.
- * @param $property
- *   The cvterm name of the property
- * @param $value
- *   The value of the property
- * @param $cv_name
- *    Optional.  The name of the cv to which the property belongs.  By
- *    default this is the 'tripal' cv.
- * *
- * @return
- *   True of success, False otherwise
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_analysis_update_property_by_id($analysisfeatureprop_id,
-  $property, $value, $cv_name = 'tripal') {
-
-    // update the property.
-    return chado_update_property('analysisfeature',
-      NULL, $property, $cv_name, $value, FALSE, $analysisfeatureprop_id);
-}
-
-/**
- * Delete an analysis feature property using the property name.  Use this
- * when a property only exists once for a given analysis feature.  When more
- * than one value can exist for the same property use the
- * tripal_feature_analysis_delete_property_by_id() function.
- *
- * @param $analysis_id
- *    The analysis ID for the analysis feature. This argument is optional but
- *    if specified it must also be accompanied with a feature ID.
- * @param $feature_id
- *    The feature ID for the analysis feature. This argument is optional but
- *    if specified it must also be accompanied with an analysis ID.
- * @param $analysisfeature_id
- *    The analysis feature ID for the analysis feature. This argument is
- *    optional and can be used rather than specifying the $analysis_id and
- *    $feature_id arguments.  If all three arguments are specified (e.g.
- *    an $analysis_id, $feature_id and $analysisfeature_id, then the
- *    $analysisfeature_id is used and the other two arguments are ignored.
- * @param $property
- *    The cvterm name of the property to delete
- * @param $cv_name
- *    Optional.  The name of the cv to which the property belongs.  By
- *    default this is the 'tripal' cv.
- *
- * Note: The property will be identified using the unique combination of the $analysis_id and $property
- * and then it will be deleted
- *
- * @return
- *   True of success, False otherwise
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_analysis_delete_property($analysis_id = NULL, $feature_id = NUll,
-  $analysisfeature_id = NULL, $property, $cv_name = 'tripal') {
-  // check that the incoming arguments are correct
-  if (($analysis_id and !$feature_id) or
-    (!$analysis_id and $feature_id)) {
-      tripal_report_error('tripal_feature', TRIPAL_WARNING,
-      'tripal_feature_analysis_delete_property: Both an analysis ID and feature ID should be specified',
-        array());
-  }
-
-  // get the analysisfeature_id if one is not provided
-  if (!$analysisfeature_id) {
-    $columns = array('analysisfeature_id');
-    $values = array('analysis_id' => $analysis_id, 'feature_id' => $feature_id);
-    $result = chado_select_record('analysisfeature', $columns, $values);
-    $analysisfeature_id = $result[0]->analysisfeature_id;
-  }
-
-  // get the property.
-  return chado_delete_property('analysisfeature', $analysisfeature_id, $property, $cv_name);
-}
-
-/**
- * Delete a property using the analysisfeatureprop_id
- *
- * @param $analysisfeatureprop_id
- *    The analysis feature property ID for the analysis feature.
- *
- * @return
- *   True of success, False otherwise
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_analysis_delete_property_by_id($analysisfeatureprop_id) {
-
-  // construct the array that will match the exact record to update
-  $match = array(
-    'analysisfeatureprop_id' => $analysisfeatureprop_id,
-  );
-
-  return chado_delete_record('analysisfeatureprop', $match);
-
-}
-
-/**
- * Retrieve properties of a given type for a given feature
- *
- * @param $feature_id
- *    The feature_id of the properties you would like to retrieve
- * @param $property
- *    The cvterm name of the properties to retrieve
- * @param $cv_name
- *    Optional.  The name of the cv to which the property belongs.  By
- *    default this is the 'tripal' cv.
- *
- * @return
- *    A feature chado variable with the specified properties expanded
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_get_property($feature_id, $property, $cv_name='tripal') {
-  return chado_get_property('feature', $feature_id, $property, $cv_name);
-}
-
-/**
- * Insert a given property
- *
- * @param $feature_id
- *   The feature_id of the property to insert
- * @param $property
- *   The cvterm name of the property to insert
- * @param $value
- *   The value of the property to insert
- * @param $update_if_present
- *   A boolean indicated whether to update the record if it's already present
- * @param $cv_name
- *    Optional.  The name of the cv to which the property belongs.  By
- *    default this is the 'tripal' cv.
- *
- * @return
- *   True of success, False otherwise
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_insert_property($feature_id, $property, $value,
-  $update_if_present = 0, $cv_name = 'tripal') {
-  return chado_insert_property('feature', $feature_id, $property,
-    $cv_name, $value, $update_if_present);
-}
-
-/**
- * Update a feature property using the property name. Only use this
- * if the property is unique and only exist once for the feature.
- *
- * @param $feature_id
- *   The feature_id of the property to update
- * @param $property
- *   The cvterm name of the property to update
- * @param $value
- *   The value of the property to update
- * @param $insert_if_missing
- *   A boolean indicated whether to insert the record if it's absent
- * @param $cv_name
- *   Optional.  The name of the cv to which the property belongs.  By
- *   default this is the 'tripal' cv.
- *
- * Note: The property will be identified using the unique combination of the $feature_id and $property
- * and then it will be updated with the supplied value
- *
- * @return
- *   True of success, False otherwise
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_update_property($feature_id, $property,
-  $value, $insert_if_missing = 0, $cv_name = 'tripal') {
-    return chado_update_property('feature', $feature_id, $property, $cv_name, $value, $insert_if_missing);
-}
-
-/**
- * Update a given feature property using the featureprop_id
- *
- * @param $featureprop_id
- *   The featureprop_id of the property to update
- * @param $property
- *   The cvterm name of the property
- * @param $value
- *   The value of the property
- * @param $cv_name
- *   Optional.  The name of the cv to which the property belongs.  By
- *   default this is the 'tripal' cv.
- *
- * @return
- *   True of success, False otherwise
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_update_property_by_id($featureprop_id, $property,
-  $value, $cv_name = 'tripal') {
-    return chado_update_property('feature', NULL, $property, $cv_name, $value, FALSE, $featureprop_id);
-}
-
-/**
- * Delete a given feature property using the property name.  Only use this
- * if the property is unique and only exists once for the feature.
- *
- * @param $feature_id
- *   The feature_id of the property to delete
- * @param $property
- *   The cvterm name of the property to delete
- * @param $cv_name
- *   Optional.  The name of the cv to which the property belongs.  By
- *   default this is the 'tripal' cv.
- *
- * Note: The property will be identified using the unique combination of the $feature_id and $property
- * and then it will be deleted
- *
- * @return
- *   True of success, False otherwise
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_delete_property($feature_id, $property, $cv_name='tripal') {
-  return chado_delete_property('feature', $feature_id, $property, $cv_name);
-}
-
-/**
- * Delete a given feature property using the featureprop_id
- *
- * @param $featureprop_id
- *   The feature_id of the property to delete
- *
- * @return
- *   True of success, False otherwise
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_delete_property_by_id($featureprop_id) {
-
-  // construct the array that will match the exact record to update
-  $match = array(
-    'featureprop_id' => $featureprop_id,
-  );
-
-  return chado_delete_record('featureprop', $match);
-
-}
-
 /**
  * Performs a reverse compliment of a nucleotide sequence
  *
@@ -439,7 +23,7 @@ function tripal_feature_delete_property_by_id($featureprop_id) {
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_reverse_complement($sequence) {
+function feature_sequence_reverse_complement($sequence) {
 
   $seq = strtoupper($sequence);
   $seq = strrev($seq);
@@ -463,51 +47,56 @@ function tripal_feature_reverse_complement($sequence) {
 /**
  * Retrieves the sequence for a feature.
  *
- * @param $feature_id
- *   The feature_id of the feature for which the sequence will be retrieved
- * @param $feature_name
- *   The feature name. This will appear on the FASTA definition line
- * @param $num_bases_per_line
- *   Indicate the number of bases to use per line.  A new line will be added
- *   after the specified number of bases on each line.
- * @param $derive_from_parent
- *   Set to '1' if the sequence should be obtained from the parent to which
- *   this feature is aligned.
- * @param $aggregate
- *   Set to '1' if the sequence should only contain sub features, excluding
- *   intra sub feature sequence.  For example, set this option to obtain just
- *   the coding sequence of an mRNA.
- * @param $output_format
- *   The type of format.  Valid formats include 'fasta_html', 'fasta_txt' and
- *   'raw'.  The format 'fasta_txt' outputs line
- *   breaks as <br> tags and the entire return value is in a <span> tag
- *   with a fixed-width font definition.  'fasta_txt' outputs line breaks with
- *   windows format carriage returns (e.g. \r\n) with no other formatting. The
- *   raw format is simply the sequence with now FASTA formatting and no
- *   line breaks.
- * @param $upstream
- *   An integer specifing the number of upstream bases to include in the output
- * @param $downstream
- *   An integer specifying the number of downstream bases to include in the
- *   output.
- * @param $sub_features
- *   Only include sub features (or child features) of the types provided in the array
- * @param $relationship
- *   If a relationship name is provided (e.g. sequence_of) then any sequences that
- *   are in relationships of this type with matched sequences are also included
- * @param $rel_part
- *   If a relationship is provided in the preceeding argument then the rel_part
- *   must be either 'object' or 'subject' to indicate which side of the
- *   relationship the matched features belong
+ * @param $feature
+ *   An associative array describing the feature. Valid keys include:
+ *    - feature_id: The feature_id of the feature for which the sequence will be retrieved
+ *    - name: The feature name. This will appear on the FASTA definition line
+ * @param $options
+ *   An associative array of options. Valid keys include:
+ *    - width: Indicate the number of bases to use per line.  A new line will be added
+ *      after the specified number of bases on each line.
+ *    - derive_from_parent: Set to '1' if the sequence should be obtained from the parent
+ *      to which this feature is aligned.
+ *    - aggregate: Set to '1' if the sequence should only contain sub features, excluding
+ *      intro sub feature sequence.  For example, set this option to obtain just
+ *      the coding sequence of an mRNA.
+ *    - output_format: The type of format.  Valid formats include 'fasta_html', 'fasta_txt' and
+ *      'raw'.  The format 'fasta_txt' outputs line breaks as <br> tags and the entire
+ *      return value is in a <span> tag with a fixed-width font definition.  'fasta_txt'
+ *      outputs line breaks with windows format carriage returns (e.g. \r\n) with no other
+ *      formatting. The raw format is simply the sequence with now FASTA formatting and no
+ *      line breaks.
+ *    - num_upstream: An integer specifing the number of upstream bases to include in the output
+ *    - num_downstream: An integer specifying the number of downstream bases to include in the
+ *      output.
+ *    - sub_feature_types: Only include sub features (or child features) of the types
+ *      provided in the array
+ *    - relationship_type: If a relationship name is provided (e.g. sequence_of) then any
+ *      sequences that are in relationships of this type with matched sequences are also included
+ *    - relationship_part: If a relationship is provided in the preceeding argument then
+ *      the rel_part must be either 'object' or 'subject' to indicate which side of the
+ *      relationship the matched features belong
  *
  * @return
  *   The DNA/protein sequence formated as requested.
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_get_formatted_sequence($feature_id, $feature_name,
-  $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
-  $upstream, $downstream, $sub_features = array(), $relationship = '', $rel_part = '') {
+function feature_sequence_get_formatted($feature, $options) {
+
+  // Default Values
+  $feature_id = $feature['feature_id'];
+  $feature_name = $feature['name'];
+
+  $num_bases_per_line = $options['width'];
+  $derive_from_parent = $options['derive_from_parent'];
+  $aggregate = $options['aggregate'];
+  $output_format = $options['output_format'];
+  $upstream = $options['num_upstream'];
+  $downstream = $options['num_downstream'];
+  $sub_features = $options['sub_feature_types'];
+  $relationship = $options['relationship_type'];
+  $rel_part = $options['relationship_part'];
 
   // to speed things up we need to make sure we have a persistent connection
   $connection = tripal_db_persistent_chado();
@@ -855,122 +444,6 @@ function tripal_feature_get_formatted_sequence($feature_id, $feature_name,
   return $residues;
 }
 
-/**
- * This function adds an entry to the feature_dbxref table.
- *
- * @param $feature_id
- *   The numeric feature_if of the feature
- * @param $dbname
- *   The name of the database to which the term belongs
- * @param accession
- *   The accession of the term
- *
- * @return
- *   TRUE on success. FALSE on failure.
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_add_dbxref($feature_id, $dbname, $accession) {
-
-  // make sure the db exists. If it doesn't, then add it
-  $values = array('name' => $dbname);
-  $options = array('statement_name' => 'sel_db_na');
-  $db = chado_select_record('db', array('db_id'), $values, $options);
-  if (!$db or count($db) == 0) {
-    $options = array('statement_name' => 'ins_db_na');
-    $success = chado_insert_record('db', $values, $options);
-      if (!$success) {
-      tripal_report_error('tripal_feature', TRIPAL_WARNING, 'tripal_feature_add_dbxref: The feature dbxref entry for feature, %feature_id, " .
-        "could not be added because the database, %dbname, does not exist and cannot be added.',
-        array('%feature_id' => $feature_id, '%dbname' => $dbname));
-      return FALSE;
-    }
-  }
-
-  // first make sure that the record doesn't already exist
-  $values = array(
-    'dbxref_id' => array(
-      'accession' => $accession,
-      'db_id' => array(
-        'name' => $dbname
-      ),
-    ),
-    'feature_id' => $feature_id,
-  );
-  $options = array('statement_name' => 'sel_featuredbxref_dbfe');
-  $xref = chado_select_record('feature_dbxref', array('feature_dbxref_id'), $values, $options);
-  if (count($xref) == 0) {
-    // if the record doesn't exist then add it.
-    $options = array('statement_name' => 'ins_featuredbxref_dbfe');
-    $success = chado_insert_record('feature_dbxref', $values, $options);
-    if (!$success) {
-      tripal_report_error('tripal_feature', TRIPAL_WARNING, 'tripal_feature_add_dbxref: The feature dbxref entry for feature, %feature_id, ' .
-        'could not be added: %db:%accession.', array('%feature_id' => $feature_id, '%db' => $dbname,
-        '%accession' => $accession));
-      return FALSE;
-    }
-  }
-  return TRUE;
-}
-
-/**
- * This function adds an entry to the feature_cvterm table.
- *
- * @param $feature_id
- *   The numeric feature_if of the feature
- * @param $cvname
- *   The name of the controlled vocabulary to which the term belongs
- * @param cvterm
- *   The name of the cvterm
- *
- * @return
- *   TRUE on success. FALSE on failure.
- *
- * @ingroup tripal_feature_api
- */
-function tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) {
-
-  // make sure the cv exists. If it doesn't, then add it
-  $values = array('name' => $cvname);
-  $options = array('statement_name' => 'sel_cv_na');
-  $cv = chado_select_record('cv', array('cv_id'), $values, $options);
-  if (!$cv or count($cv) == 0) {
-    $options = array('statement_name' => 'ins_cv_na');
-    $success = chado_insert_record('cv', $values, $options);
-      if (!$success) {
-      tripal_report_error('tripal_feature', TRIPAL_WARNING, 'tripal_feature_add_cvterm: The feature cvterm entry for feature, %feature_id, " .
-        "could not be added because the CV, %cvname, does not exist and cannot be added.',
-        array('%feature_id' => $feature_id, '%cvname' => $cvname));
-      return FALSE;
-    }
-  }
-
-  // first make sure that the record doesn't already exist
-  $values = array(
-    'cvterm_id' => array(
-      'name' => $cvterm,
-      'cv_id' => array(
-        'name' => $cvname
-      ),
-    ),
-    'feature_id' => $feature_id,
-    'pub_id' => 1,
-  );
-  $options = array('statement_name' => 'sel_featuredcvterm_cvfepu');
-  $xref = chado_select_record('feature_cvterm', array('feature_cvterm_id'), $values, $options);
-  if (count($xref) == 0) {
-    // if the record doesn't exist then add it.
-    $options = array('statement_name' => 'ins_featurecvterm_cvfepu');
-    $success = chado_insert_record('feature_cvterm', $values, $options);
-    if (!$success) {
-      tripal_report_error('tripal_feature', TRIPAL_WARNING, 'tripal_feature_add_cvterm: The feature cvterm entry for feature, %feature_id, ' .
-        'could not be added: %cvterm.', array('%feature_id' => $feature_id, '%cvterm' => $cvterm));
-      return FALSE;
-    }
-  }
-  return TRUE;
-}
-
 /**
  * Returns a fasta record for the passed in feature
  *
@@ -985,10 +458,13 @@ function tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) {
  *
  * @ingroup tripal_feature_api
  */
-function tripal_feature_return_fasta($feature, $desc) {
+function feature_sequence_get_fasta($feature, $desc) {
+
   $fasta  = ">" . variable_get('chado_feature_accession_prefix', 'FID') . "$feature->feature_id|$feature->name";
   $fasta .= " $desc\n";
   $fasta .= wordwrap($feature->residues, 50, "\n", TRUE);
   $fasta .= "\n\n";
+
   return $fasta;
+
 }

+ 6 - 5
tripal_feature/tripal_feature.module

@@ -14,7 +14,7 @@
 
 require_once 'api/tripal_feature.api.inc';
 require_once 'api/tripal_feature.schema.api.inc';
-//require_once 'api/tripal_feature.DEPRECATED.inc';
+require_once 'api/tripal_feature.DEPRECATED.inc';
 
 require_once 'theme/tripal_feature.theme.inc';
 
@@ -246,6 +246,11 @@ function tripal_feature_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_feature_base',
       'path' => "$path/theme/tripal_feature",
     ),
+    'tripal_feature_featurepos' => array(
+      'arguments' => array('node' => NULL),
+      'template' => 'tripal_feature_featurepos',
+      'path' => "$path/theme/tripal_feature",
+    ),
     'tripal_feature_sequence' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_feature_sequence',
@@ -1202,10 +1207,6 @@ function tripal_feature_form_alter(&$form, &$form_state, $form_id) {
   }
   // turn off preview button for insert/updates
   if ($form_id == "chado_feature_node_form") {
-    // turn of preview button for insert/updates
     $form['actions']['preview']['#access'] = FALSE;
-    
-    //remove the body field
-    unset($form['body']);
   }
 }