Browse Source

Tripal chado select: fixed bug -allows select of int 0's | Tripal bulk loader: Basic functionalty -allows spreadsheet columns and constants; relationships between tables honoured; update to various schema hooks

laceysanderson 14 years ago
parent
commit
1832451b86

+ 1 - 1
theme_tripal/tripal_bulk_loader/tripal_bulk_loader_edit_template_base_form.tpl.php

@@ -4,8 +4,8 @@
 <?php print drupal_render($form['template_name']); ?>
 
 <!-- For each field display details plus edit/delete buttons-->
-<fieldset><legend>Current Fields</legend>
 <?php if ($form['fields']['total_fields']['#value'] > 0) {?>
+<fieldset><legend>Current Fields</legend>
   <table>
     <tr>
       <th>Field Name</th>

+ 25 - 0
tripal_analysis/tripal_analysis.api.inc

@@ -3,7 +3,32 @@
 /****************************************************************************
  * @section Chado Table Descriptions
  ****************************************************************************/
+/**
+ * Implements hook_chado_analysis_schema()
+ * Purpose: To add descriptions and foreign keys to default table description
+ * Note: This array will be merged with the array from all other implementations
+ *
+ * @return
+ *    Array describing the analysis table
+ *
+ * @ingroup tripal_analysis
+ */
+function tripal_analysis_chado_analysis_schema() {
+  $description = array();
+  
+  // Default table description in tripal_core.schema.api.inc: tripal_core_chado_analysis_schema()
+  
+  $referring_tables = array(
+      'analysisfeature',
+      'analysisprop',
+      'phylotree',
+      'quantification'
+  );
+  $description['referring_tables'] = $referring_tables;
   
+  return $description;
+}
+
  /****************************************************************************
  * Implements hook_chado_analysisfeature_schema()
  * Purpose: To add descriptions and foreign keys to default table description

+ 55 - 49
tripal_bulk_loader/tripal_bulk_loader.admin.inc

@@ -16,42 +16,6 @@ function tripal_bulk_loader_admin_template () {
    return $output;
 }
 
-/**
- * Implements hook_tripal_bulk_loader_supported_modules
- * 
- * @return 
- *   An array of <chado table> => <Human-readable Name> describing the modules supported
- */
-function tripal_bulk_loader_tripal_bulk_loader_supported_modules() {
-  return array(
-    'feature' => 'Feature',
-    'organism' => 'Organism',
-    'library' => 'Library',
-    'analysis' => 'Analysis',
-  );
-}
-
-function tripal_bulk_loader_tripal_bulk_loader_feature_related_tables () {
-  return array(
-    'feature' => 'Feature',
-    'analysis' => 'Analysis',
-    'element' => 'Element',
-    'cvterm' => 'CV Terms',
-    'dbxref' => 'External Database References',
-    'genotype' => 'Genotypes',
-    'phenotype' => 'Phenotypes',
-    'pub' => 'Publications',
-    'feature_relationship' => 'Relationships between Features',
-    'synonym' => 'Synonyms',
-    'featureloc' => 'Feature Locations',
-    'featurepos' => 'Feature Positions',
-    'featureprop' => 'Feature Properties',
-    'featurerange' => 'Feature Ranges',
-    'library' => 'Library',
-    'phylonode' => 'Polynode'
-  );
-}
-
 //////////////////////////////////////////////////////////////////////////////////////
 // Create Template
 //////////////////////////////////////////////////////////////////////////////////////
@@ -177,7 +141,7 @@ function tripal_bulk_loader_create_template_base_form_submit($form, &$form_state
       
       // Add Field to Template----------------------------------------------
     } elseif ($form_state['values']['op'] ==  'Add Field') {
-      
+      $form_state = tripal_bulk_loader_add_template_field_form_submit($form_state);
       
       // Save Template ----------------------------------------------------
     } 
@@ -196,6 +160,9 @@ function tripal_bulk_loader_create_template_base_form_submit($form, &$form_state
 			drupal_write_record('tripal_bulk_loader_template', $record);
 		}
   } //end of if not ahah submission
+  else {
+    $form_state = tripal_bulk_loader_add_template_field_form_submit($form_state);
+  }
 }
 
 //////////////////////////////////////////////////////////////////////////////////////
@@ -342,9 +309,9 @@ function tripal_bulk_loader_edit_template_base_form_submit($form, &$form_state){
       $table = $form_state['values']["chado_table_hidden-".$matches[1]];
       $field_key = $form_state['values']["field_index-".$matches[1]];
       unset($form_state['storage']['template'][$table]['field'][$field_key]);
-      
-      $set_default = TRUE;
-      $field_template = $form_state['storage']['edit_field'];      
+      if (!$form_state['storage']['template'][$table]['field']) {
+        unset($form_state['storage']['template'][$table]);
+      }   
     }
     
     // Save Template ----------------------------------------------------
@@ -398,7 +365,7 @@ function tripal_bulk_loader_delete_template_base_form_submit ($form, &$form_stat
 }
 
 //////////////////////////////////////////////////////////////////////////////////////
-// Add/Edit Field Forms (meant to be returned as part of a larger form
+// Add/Edit Field Forms (meant to be returned as part of a larger form)
 //////////////////////////////////////////////////////////////////////////////////////
 
 /**
@@ -509,10 +476,26 @@ function tripal_bulk_loader_add_template_field_form ($form_state) {
 			),
 	);
 
-	$table_description = module_invoke_all('chado_'.$table.'_schema');
-	$chado_fields = array();
-	foreach($table_description['fields'] as $field_name => $field_array) {
-		$chado_fields[$field_name] = $field_name;
+  if ($related_tables['Indirect Relations'][$table]) {
+    //Display fields for current table plus related tables
+    $table_description = module_invoke_all('chado_'.$table.'_schema');
+    $tables2list = array_keys($table_description['foreign keys']);
+    unset($tables2list[array_search($base_table, $tables2list)]);
+    $tables2list[] = $table;
+
+    $form['field_is_indirect'] = array(
+      '#type' => 'hidden',
+      '#value' => implode('#',$tables2list),
+    );
+  } else {
+    $tables2list = array($table);
+  }
+  $chado_fields = array();
+  foreach ($tables2list as $table) {
+  	$table_description = module_invoke_all('chado_'.$table.'_schema');
+	  foreach($table_description['fields'] as $field_name => $field_array) {
+		  $chado_fields[$field_name] = $field_name;
+	  }
 	}
 	$form['add_fields']['chado']['add-chado_field'] = array(
 		'#type' => 'select',
@@ -546,6 +529,8 @@ function tripal_bulk_loader_add_template_field_form ($form_state) {
  * @endcode
  */
 function tripal_bulk_loader_add_template_field_form_submit ($form_state) {
+  dpm($form_state, 'form state in add submit');
+  
   $form_state['storage']['add']['field_title'] = $form_state['values']['add-field_title'];
   $form_state['storage']['add']['field_type'] = $form_state['values']['add-type'];
   $form_state['storage']['add']['sheet_name'] = $form_state['values']['add-sheet'];
@@ -560,6 +545,27 @@ function tripal_bulk_loader_add_template_field_form_submit ($form_state) {
       
       $template['module'] = $form_state['storage']['base_table'];
       
+      //if table relationship to base is indirect, fields from 2+ tables are listed in the fields select
+      if ($form_state['values']['field_is_indirect']) {
+        $listed_tables = preg_split('/#/', $form_state['values']['field_is_indirect']);
+        $field = $form_state['storage']['add']['chado_field'];
+        foreach ($listed_tables as $table) {
+          $table_desc = module_invoke_all('chado_'.$table.'_schema');
+          if ($table_desc['fields'][$field]) {
+              if (preg_match('/'.$table.'/', $form_state['storage']['add']['chado_table'])) {
+                //ensure linking table is added
+                if (!$template[$form_state['storage']['add']['chado_table']]) {
+                  $template[$form_state['storage']['add']['chado_table']]['field'] = array();
+                }
+              }
+        
+             $form_state['storage']['add']['chado_table'] = $table;
+             break;
+          }
+        }
+        
+      }
+      
       if ($form_state['storage']['add']['field_type'] == 'table field') {
         $template[$form_state['storage']['add']['chado_table']]['field'][] = array(
           'type' => 'table field',
@@ -591,7 +597,8 @@ function tripal_bulk_loader_add_template_field_form_submit ($form_state) {
       $form_state['storage']['template'] = $template;
     }
   }  
-
+  
+  dpm($form_state['storage']['template'], 'template array from add submit');
   return $form_state;
 }
 
@@ -617,7 +624,7 @@ function tripal_bulk_loader_edit_template_field_form($form_state) {
  	$base_table = $form_state['storage']['base_table'];
  	
 	$form['edit_fields'] = array(
-		'#type' => 'fieldset',
+		'#type' => ($form_state['storage']['edit_field']) ? 'fieldset' : 'hidden',
 		'#title' => t('Edit Fields'),
 		'#prefix' => '<div id="tripal_bulk_loader-edit_field">',
 		'#suffix' => '</div>',
@@ -774,7 +781,6 @@ function tripal_bulk_loader_edit_template_field_form_submit ($form_state) {
   
   if (!$form_state['ahah_submission']) {
     if ($form_state['values']['op'] ==  'Edit Field') {
-      dpm($form_state, 'form_state before');
       if ($form_state['storage']['edit']['field_type'] == 'table field') {
         $field = array(
           'type' => 'table field',
@@ -955,7 +961,7 @@ function tripal_bulk_loader_edit_field_type_ahah () {
  *  JSON Data printed to the screen
  */
 function tripal_bulk_loader_edit_chado_column_ahah () {
-
+  
   $form_state = array('storage' => NULL, 'submitted' => FALSE);
   $form_build_id = $_POST['form_build_id'];
   $form = form_get_cache($form_build_id, $form_state);

+ 107 - 0
tripal_bulk_loader/tripal_bulk_loader.info_hooks.inc

@@ -0,0 +1,107 @@
+<?php
+
+/**
+ * Implements hook_tripal_bulk_loader_supported_modules
+ * 
+ * @return 
+ *   An array of <chado table> => <Human-readable Name> describing the modules supported
+ */
+function tripal_bulk_loader_tripal_bulk_loader_supported_modules() {
+  return array(
+    'feature' => 'Feature',
+    'organism' => 'Organism',
+    'library' => 'Library',
+    'analysis' => 'Analysis',
+  );
+}
+
+function tripal_bulk_loader_tripal_bulk_loader_feature_related_tables () {
+
+  return array(
+    'Base Table' => array(
+      'feature' => 'Feature'
+    ),
+    'Foreign Key Relations' => array(
+      'organism' => 'Organism',
+      'cvterm' => 'Type: Cv Term',
+      'dbxref' => 'Database Reference',
+    ),
+    'Direct Relations' => array(
+      'element' => 'Element',
+      'featureloc' => 'Feature Locations',
+      'featurepos' => 'Feature Positions on Map',
+      'featureprop' => 'Feature Properties',
+      'featurerange' => 'Feature Range',
+      'feature_relationship' => 'Feature Relationships',
+      'polynode' => 'Polynode'
+    ),
+    'Indirect Relations' => array(
+      'analysisfeature' => 'Analysis',
+      'feature_cvterm' => 'Additional Cv Terms',
+      'feature_dbxref' => 'Additional Database References',
+      'feature_expression' => 'Feature Expressions',
+      'feature_genotype' => 'Genotypes',
+      'library_feature' => 'Libraries',
+      'feature_phenotype' => 'Phenotypes',
+      'feature_pub' => 'Publications',
+      'feature_synonym' => 'Synonyms',
+    ),
+  );
+
+}
+
+function tripal_bulk_loader_tripal_bulk_loader_organism_related_tables () {
+  return array(
+    'Base Table' => array(
+      'feature' => 'Organism'
+    ),
+    'Direct Relations' => array(
+      'biomaterial' => 'Biological Material',
+      'feature' => 'Features',
+      'library' => 'Libraries',
+      'organismprop' => 'Organism Properties',
+      'stock' => 'Stocks'
+    ),
+    'Indirect Relations' => array(
+      'organism_dbxref' => 'Additional Database References',
+      'polynode_organism' => 'Polynodes',
+    ),
+  );
+}
+
+function tripal_bulk_loader_tripal_bulk_loader_library_related_tables () {
+  return array(
+    'Base Table' => array(
+      'library' => 'Library'
+    ),
+    'Foreign Key Relations' => array(
+      'organism' => 'Organism',
+      'cvterm' => 'Type: Cv Term',
+    ),
+    'Direct Relations' => array(
+      'libraryprop' => 'Library Properties',
+    ),
+    'Indirect Relations' => array(
+      'library_cvterm' => 'Additional Cv Terms',
+      'library_feature' => 'Features',
+      'library_pub' => 'Publications',
+      'library_synonym' => 'Synonyms',
+    ),
+  );
+}
+
+function tripal_bulk_loader_tripal_bulk_loader_analysis_related_tables () {
+  return array(
+    'Base Table' => array(
+      'analysis' => 'Analysis'
+    ),
+    'Direct Relations' => array(
+      'analysisprop' => 'Analysis Properties',
+      'phylotree' => 'Phylogeny Tree',
+      'quantification' => 'Quantification'
+    ),
+    'Indirect Relations' => array(
+      'analysis_feature' => 'Features',
+    ),
+  );
+}

+ 210 - 20
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -63,12 +63,24 @@ function tripal_bulk_loader_load_data($nid) {
   print "Template: ".$node->template->name." (".$node->template_id.")\n";
   print "File: ".$node->file."\n";
   
+  // Prep Work ==================================================================================
+  // get base table and it's table_description array
+  $base_table = $node->template->template_array['module'];
+  $base_table_desc = module_invoke_all('chado_'.$base_table.'_schema');
+  $related_tables = module_invoke_all('tripal_bulk_loader_'.$base_table.'_related_tables');
+  //print "Base Table: ".print_r($base_table,TRUE)."\nTable DEscription: ".print_r($base_table_desc, TRUE)."\nTemplate array: ".print_r($node->template->template_array,TRUE)."\n";
+
   // get a default values array to be passed into tripal_core_chado_insert
   // and get a mapping between table.field and spreadsheet column
+  // also determine relationship between each table and base table
   $default_values_array = array();
   $field2column = array();
+  $relationships2base = array();
+  $all_tables = array();
   foreach ($node->template->template_array as $table => $table_array) {
     if (is_array($table_array)) {
+      $all_tables[$table] = $table;
+    
       foreach ($table_array['field'] as $field_array) {
         if (preg_match('/table field/', $field_array['type'])) {
           $default_values_array[$table][$field_array['field']] = '';
@@ -79,43 +91,221 @@ function tripal_bulk_loader_load_data($nid) {
           print 'WARNING: Unsupported type: '. $field_array['type'] . ' for ' . $table . '.' . $field_array['field']."!\n";
         }
       }
+      
+      // Determine what relation is between this table and the base table-----------------------
+      // This is used later to link the various records
+      //print "===\n";
+      // Is there a foreign key to this table in the base table? 
+      // ie: feature.type_id (base) for cvterm (current)
+      //print "A) Is there fkey to ".$table." table in ".$base_table."?\n";
+      if ($related_tables['Foreign Key Relations'][$table]) {
+          //print "YES!\n";
+          $relationships2base['foreign key'][$table] = $base_table_desc['foreign keys'][$table];
+      }
+      
+      // Is there a foreign key in this table to the base table? 
+      // ie: featureloc.feature_id (current) for feature (base)
+      
+      //print "B) Does ".$table." contain a fkey to ".$base_table."?\n";
+      if ($related_tables['Direct Relations'][$table]) {
+          $table_desc = module_invoke_all('chado_'.$table.'_schema');
+          //print "YES!\n";
+          $relationships2base['direct'][$table] = $table_desc['foreign keys'][$base_table];
+      }
+      
+      // Is there a linking table which links this table with the base table
+      // ie: analysisfeature (current) links analysis and feature (base)
+      //print "C) Is ".$table." a linking table?\n";
+      if ($related_tables['Indirect Relations'][$table]) {
+        //print "YES!\n";
+        $table_desc = module_invoke_all('chado_'.$table.'_schema');
+        $relationships2base['indirect'][$table] = $table_desc['foreign keys'];
+      }
+
     }
   }
   
   //print "\nDefault Values Array: ".print_r($default_values_array, TRUE)."\n";
   //print "\nField to Column Mapping: ".print_r($field2column, TRUE)."\n";
+  //print "\nRelationships to Base Table: ".print_r($relationships2base, TRUE)."\n";
   
+  // Parse File adding records as we go ========================================================
   $file_handle = fopen($node->file, 'r');
   if (preg_match('/(t|true|1)/', $node->file_has_header)) { fgets($file_handle, 4096); }
+  $num_records = 0;
+  $num_lines;
   while (!feof($file_handle)) {
     $line = array();
     $raw_line = fgets($file_handle, 4096);
     $line = preg_split("/\t/", $raw_line);
+    $num_lines++;
     
+    // Contains constants set above
+    $tables = $all_tables;
     $values = $default_values_array;
-    foreach ($values as $table => $table_array) {
-      foreach ($table_array as $field => $value) {
-        $column = $field2column[$table][$field] - 1;
-        if ($line[$column]) {
-        	$values[$table][$field] = $line[$column];
-				}
+    
+    // Insert base record-----------------------------------------------------------------------
+    foreach ($relationships2base['foreign key'] as $table => $desc) {
+      // Ensure foreign key is present
+      $values[$table] = tripal_bulk_loader_supplement_values_array ($values[$table], $line, $field2column[$table]);
+      $success = tripal_bulk_loader_ensure_record ($table, $values[$table]);   
+      if ($success) {
+        $num_records++;
       }
-			$has_record = tripal_core_chado_select($table, array_keys($values[$table]), $values[$table], array('has_record' => TRUE));
-			if ($has_record) {
-				$values_string = array();
-				foreach ($values[$table] as $k => $v) { 
-					if (strlen($v) > 20) { $v = substr($v,0,20) . '...'; }
-					$values_string[] = $k.' => '.$v; 
-				}
-				print "\tWARNING: Record already exists in $table where ".implode(', ',$values_string).".\n";
-			} else {
-	      $success = tripal_core_chado_insert($table, $values[$table]);
-  	    if (!$success) {
-    	  	print "ERROR: Unable to insert the following record into $table: ".print_r($values[$table], TRUE)."\n";
-      	}
+      
+      //Add to base values array
+      foreach ($desc['columns'] as $foreign_key => $primary_key) {
+        $values[$base_table][$foreign_key] = $values[$table];
+      }
+      
+      unset($tables[$table]);
+    }
+    
+    // base table
+    $values[$base_table] = tripal_bulk_loader_supplement_values_array ($values[$base_table], $line, $field2column[$base_table]);
+    $success = tripal_bulk_loader_ensure_record ($base_table, $values[$base_table]);     
+    //print 'Base Table values array: '.print_r($values[$base_table], TRUE)."\n";
+    if (!$success) {
+      print "ERROR: Unable to insert base record where base table: ".$base_table.
+        " and values array: ".tripal_bulk_loader_flatten_array($values[$base_table])."\n";
+    } else {
+      $num_records++;
+    }
+    unset($tables[$base_table]);
+    
+    // Insert all tables with direct relationship to base ----------------------------------------
+    foreach ($relationships2base['direct'] as $table => $desc) {
+      //Add base to values array
+      foreach ($desc['columns'] as $foreign_key => $primary_key) {
+        $values[$table][$foreign_key] = $values[$base_table];
       }
-    } //end of tables in $values
 
+      // Supplement and Add record
+      $values[$table] = tripal_bulk_loader_supplement_values_array ($values[$table], $line, $field2column[$table]);
+      $success = tripal_bulk_loader_ensure_record ($table, $values[$table]);
+      if ($success) {
+        $num_records++;
+      }
+      unset($tables[$table]);
+    } 
+    
+    // Add in all other tables -----------------------------------------------------------------
+    foreach ($tables as $table) {
+      // Don't insert if its an indirect relationship linking table
+      if (!$relationships2base['indirect'][$table]) {
+        // Supplement and Add record
+        $values[$table] = tripal_bulk_loader_supplement_values_array ($values[$table], $line, $field2column[$table]);
+        $success = tripal_bulk_loader_ensure_record ($table, $values[$table]);    
+        if ($success) {
+          $num_records++;
+        }
+      }
+    }
+    
+    // Add in indirect relationships -----------------------------------------------------------
+    foreach ($relationships2base['indirect'] as $table => $desc) {
+      // Add foreign keys to values array
+      foreach ($desc as $subtable => $subdesc) {
+        foreach ($subdesc['columns'] as $foreign_key => $primary_key) {
+          $values[$table][$foreign_key] = $values[$subtable];
+        }
+      }
+      
+      // Supplement and Add record
+      $values[$table] = tripal_bulk_loader_supplement_values_array ($values[$table], $line, $field2column[$table]);
+      $success = tripal_bulk_loader_ensure_record ($table, $values[$table]);      
+      if ($success) {
+        $num_records++;
+      }
+    }
+    
   } //end of file
   
+  print "\nNumber of Records Inserted:".$num_records."\n";
+  print "Number of Lines in File:".$num_lines."\n\n";
+  
+}
+
+/**
+ * This function adds the file data to the values array
+ *
+ * @param $values
+ *   The default values array -contains all constants
+ * @param $line
+ *   An array of values for the current line
+ * @param $field2column
+ *   An array mapping values fields to line columns
+ * @return 
+ *   Supplemented values array
+ */
+function tripal_bulk_loader_supplement_values_array ($values, $line, $field2column) {
+
+  foreach ($values as $field => $value) {
+    $column = $field2column[$field] - 1;
+    if ($line[$column] OR (!$values[$field])) {
+      $values[$field] = $line[$column];
+    }
+  }
+  
+  return $values;
+}
+
+/**
+ * This function first ensures the record doesn't already exist and then inserts it
+ *
+ * @param $table
+ *   The table the record should be present in
+ * @param $values
+ *   The values array used for selecting and/or inserting the record
+ * @return
+ *   TRUE or FALSE based on presence or absence of record
+ */
+function tripal_bulk_loader_ensure_record ($table, $values) {
+  
+  // get flattened values array for printing errors
+  $flattened_values = tripal_bulk_loader_flatten_array($values);
+  
+  // check if record exists
+  $has_record = tripal_core_chado_select($table, array_keys($values), $values, array('has_record' => TRUE));
+  if ($has_record) {
+    print "\tWARNING: Record already exists in $table where ".implode(',',$flattened_values).".\n";
+    return true;
+  } else {
+    // if record doesn't exist then insert it
+    $success = tripal_core_chado_insert($table, $values);
+    if (!$success) {
+      print "ERROR: Unable to insert the following record into $table: ".implode(',',$flattened_values)."\n";
+      return false;
+    } else {
+      return true;
+    }
+  }
+      
+}
+
+/**
+ * Flattens an array up to two levels
+ * Used for printing of arrays without taking up much space
+ */
+function tripal_bulk_loader_flatten_array ($values) {
+  $flattened_values = array();
+  
+  foreach ($values as $k => $v) {
+    if (is_array($v)) {
+      $vstr = array();
+      foreach ($v as $vk => $vv) {
+        if (strlen($vv) > 20) {
+          $vstr[] = $vk .'=>'. substr($vv, 0, 20) . '...';
+        } else {
+          $vstr[] = $vk .'=>'. $vv;
+        }
+      }
+      $v = '{'. implode(',',$vstr) .'}';
+    } elseif (strlen($v) > 20) {
+      $v = substr($v, 0, 20) . '...';
+    }
+    $flattened_values[] = $k .'=>'. $v;
+  }
+  
+  return $flattened_values;
 }

+ 1 - 0
tripal_bulk_loader/tripal_bulk_loader.module

@@ -1,6 +1,7 @@
 <?php
 
 include('tripal_bulk_loader.loader.inc');
+include('tripal_bulk_loader.info_hooks.inc');
 
 /**
  * tripal_bulk_loader_init

+ 6 - 1
tripal_core/tripal_core.api.inc

@@ -525,7 +525,12 @@ function tripal_core_chado_select($table,$columns,$values,$options = null){
          }
       } 
       else {
-         $where[$field][] = $value;
+        //need to catch a 0 and make int if integer field
+        if ($table_desc['fields'][$field]['type'] == 'int') {
+          $where[$field][] = (int) $value;
+        } else {
+          $where[$field][] = $value;
+        }
       }
    }
 

+ 38 - 0
tripal_feature/tripal_feature.api.inc

@@ -13,6 +13,8 @@
 function tripal_feature_chado_feature_schema() {
   $description = array();
 
+  // Default table description in tripal_core.schema.api.inc: tripal_core_chado_feature_schema()
+
   $description['foreign keys']['organism'] = array(
         'table' => 'organism',
         'columns' => array(
@@ -57,3 +59,39 @@ function tripal_feature_chado_feature_schema() {
   return $description;
 }
 
+/**
+ * Implements hook_chado_featureprop_schema()
+ * Purpose: To add descriptions and foreign keys to default table description
+ * Note: This array will be merged with the array from all other implementations
+ *
+ * @return
+ *    Array describing the featureprop table
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_chado_featureprop_schema() {
+  $description = array();
+
+  // Default table description in tripal_core.schema.api.inc: tripal_core_chado_featureprop_schema()
+
+  $description['foreign keys']['feature'] = array(
+        'table' => 'feature',
+        'columns' => array(
+          'feature_id' => 'feature_id',
+        ),
+  );
+  
+  $description['foreign keys']['cvterm'] = array(
+        'table' => 'cvterm',
+        'columns' => array(
+          'type_id' => 'cvterm_id',
+        ),
+  );
+  
+  $referring_tables = array('analysisfeature',
+    'featureprop_pub',
+  );
+  $description['referring_tables'] = $referring_tables;
+
+  return $description;
+}

+ 74 - 0
tripal_library/tripal_library.api.inc

@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * Implements hook_chado_library_schema()
+ * Purpose: To add descriptions and foreign keys to default table description
+ * Note: This array will be merged with the array from all other implementations
+ *
+ * @return
+ *    Array describing the library table
+ *
+ * @ingroup tripal_library
+ */
+function tripal_library_chado_library_schema() {
+  $description = array();
+  
+  // Default table description in tripal_core.schema.api.inc: tripal_core_chado_feature_schema()
+
+  $description['foreign keys']['organism'] = array(
+        'table' => 'organism',
+        'columns' => array(
+          'organism_id' => 'organism_id',
+        ),
+  );  
+  
+  $description['foreign keys']['cvterm'] = array(
+        'table' => 'cvterm',
+        'columns' => array(
+          'type_id' => 'cvterm_id',
+        ),
+  );
+  
+  $referring_tables = array(
+      'library_cvterm',
+      'library_feature',
+      'library_pub',
+      'library_synonym',
+      'libraryprop' 
+  );
+  $description['referring_tables'] = $referring_tables;
+  
+  return $description;
+}
+
+/**
+ * Implements hook_chado_library_feature_schema()
+ * Purpose: To add descriptions and foreign keys to default table description
+ * Note: This array will be merged with the array from all other implementations
+ *
+ * @return
+ *    Array describing the library_feature table
+ *
+ * @ingroup tripal_library
+ */
+function tripal_library_chado_library_feature_schema() {
+  $description = array();
+  
+  // Default table description in tripal_core.schema.api.inc: tripal_core_chado_library_feature_schema()
+
+  $description['foreign keys']['library'] = array(
+        'table' => 'library',
+        'columns' => array(
+          'library_id' => 'library_id',
+        ),
+  );  
+  
+  $description['foreign keys']['feature'] = array(
+        'table' => 'feature',
+        'columns' => array(
+          'feature_id' => 'feature_id',
+        ),
+  );
+  
+  return $description;
+}

+ 1 - 0
tripal_library/tripal_library.module

@@ -1,5 +1,6 @@
 <?php
 
+require('tripal_library.api.inc');
 
 /*******************************************************************************
  * Display help and module information