Browse Source

Tripal: Cleaned-up Bulk Loader for release

laceysanderson 13 years ago
parent
commit
ee00625974

+ 35 - 10
tripal_bulk_loader/tripal_bulk_loader.admin.inc

@@ -6,14 +6,30 @@
  */
  
 /**
- * tripal_bulk_loader_admin_template
+ * Provides a description page and quick links for the bulk loader
  */
 function tripal_bulk_loader_admin_template () {
-	$add_url = url("admin/tripal/tripal_bulk_loader_template/add");
-   $output = "<a href=\"$add_url\">Create a new bulk loader template</a><br>"; 
-   $del_url = url("admin/tripal/tripal_bulk_loader_template/delete");
-   $output .= "<a href=\"$del_url\">Delete a bulk loader template</a>";
-   return $output;
+	$output = '';
+	
+	$output .= '<br><h3>Quick Links:</h3>';
+  $output .= l('Create a new bulk loader template', 'admin/tripal/tripal_bulk_loader_template/create')."<br>"; 
+  $output .= l('Edit a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/edit')."<br>"; 
+  $output .= l('Delete a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/delete')."<br>"; 
+  $output .= l('Export a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/export')."<br>";
+  $output .= l('Import a bulk loader template', 'admin/tripal/tripal_bulk_loader_template/import')."<br>";
+  $output .= '<br>';
+  
+  $output .= '<h3>Module Description:</h3>';
+  $output .= '<p>This module provides the ability to create loading templates for any tab-delimited '
+    .'data file allowing it to be loaded into chado. The Loading Templates are a direct mapping '
+    .'between the columns in your file and the columns in chado tables. As such to use this tool '
+    .'you need to be very familar with the chado schema -See '
+    .l('Chado -Getting Started', 'http://gmod.org/wiki/Chado_-_Getting_Started')
+    .'. The ability to add constants and specify foreign key contraints is also provided '
+    .'in order for the loader to fill chado columns which may be required but are not specified '
+    .'in your input file.</p>';
+  
+  return $output;
 }
 
 
@@ -23,7 +39,7 @@ function tripal_bulk_loader_admin_template () {
 
 
 /**
- * 
+ * The main form reached at admin/tripal/tripal_bulk_loader/create and /edit
  */
 function tripal_bulk_loader_modify_template_base_form ($form_state = NULL, $mode){
 	$form = array();
@@ -276,7 +292,7 @@ function tripal_bulk_loader_modify_template_base_form ($form_state = NULL, $mode
 }
 
 /**
- * 
+ * Submit for tripal_bulk_loader_modify_template_base_form
  */
 function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state){
 
@@ -450,6 +466,10 @@ function tripal_bulk_loader_delete_template_base_form_submit ($form, &$form_stat
 	db_query($sql, $form_state['values']['template_name']);
 }
 
+//////////////////////////////////////////////////////////////////////////////////////
+// Import/Export Template
+//////////////////////////////////////////////////////////////////////////////////////
+
 /**
  * Import/Export Template Form
  *
@@ -546,7 +566,7 @@ function tripal_bulk_loader_import_export_template_form_submit ($form, &$form_st
 }
 
 //////////////////////////////////////////////////////////////////////////////////////
-// Add/Edit Field/Record Forms
+// Edit Record Form
 //////////////////////////////////////////////////////////////////////////////////////
 
 /**
@@ -744,6 +764,10 @@ function tripal_bulk_loader_edit_template_record_form_submit ($form, &$form_stat
   
 }
 
+//////////////////////////////////////////////////////////////////////////////////////
+// Add/Edit Field Forms
+//////////////////////////////////////////////////////////////////////////////////////
+
 /**
  * Add Field Form
  *
@@ -823,6 +847,7 @@ function tripal_bulk_loader_add_template_field_form (&$form_state = NULL) {
   $fk_options = array();
   $fk_options['NULL'] = 'None';
   $table_description = module_invoke_all('chado_'.$table.'_schema');
+  //dpm($table_description, 'table description for |'.$table.'|');
   if ($field_type == 'foreign key') {
     $foreign_field2table = array();
     foreach ($table_description['foreign keys'] as $key_table => $key_array) {
@@ -1410,7 +1435,7 @@ function tripal_bulk_loader_edit_template_field_form (&$form_state = NULL) {
     } else {
       $field = current($chado_fields);
     }
-    dpm($field, 'field');
+    //dpm($field, 'field');
     
     // Foreign key options
     $foreign_table = $foreign_field2table[$field];

+ 1 - 1
tripal_bulk_loader/tripal_bulk_loader.info

@@ -4,4 +4,4 @@ core = 6.x
 project = tripal_bulk_loader
 package = Tripal
 dependencies[] = tripal_core
-version = 6.x-0.3.1b
+version = 6.x-0.3.1b-1.0

+ 0 - 229
tripal_bulk_loader/tripal_bulk_loader.info_hooks.inc

@@ -1,229 +0,0 @@
-<?php
-
-/**
- * Implements hook_tripal_bulk_loader_supported_modules()
- * This is used to supply the base tables or modules supported by the bulk loader.
- * If a base table is included in this list there must also be a corresponding 
- * implementation of hook_tripal_bulk_loader_<base table>_related_tables()
- * 
- * @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',
-    'stock' => 'Stocks',
-    'genotype' => 'Genotypes',
-  );
-}
-
-/**
- * Implements hook_tripal_bulk_loader_<base table>_related_tables()
- * This is used to supply the bulk loader with a list of tables and their 
- * relationship to the base table.
- *
- * @return
- * An array of relationships (any combination of 'Base Table', 'Foreign Key Relations', 
- * 'Direct Relations', 'Indirect Relations') where each relationship is keyed by the type
- * of relationship and the value is an array of tables with that relationship to the base table.
- * Each table in the array of tables with that relationship should be of the form
- * <chado table> => <Human-readable Name>.
- */
-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',
-    ),
-  );
-
-}
-
-/**
- * Implements hook_tripal_bulk_loader_<base table>_related_tables()
- * This is used to supply the bulk loader with a list of tables and their 
- * relationship to the base table.
- *
- * @return
- * An array of relationships (any combination of 'Base Table', 'Foreign Key Relations', 
- * 'Direct Relations', 'Indirect Relations') where each relationship is keyed by the type
- * of relationship and the value is an array of tables with that relationship to the base table.
- * Each table in the array of tables with that relationship should be of the form
- * <chado table> => <Human-readable Name>.
- */
-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',
-    ),
-  );
-}
-
-/**
- * Implements hook_tripal_bulk_loader_<base table>_related_tables()
- * This is used to supply the bulk loader with a list of tables and their 
- * relationship to the base table.
- *
- * @return
- * An array of relationships (any combination of 'Base Table', 'Foreign Key Relations', 
- * 'Direct Relations', 'Indirect Relations') where each relationship is keyed by the type
- * of relationship and the value is an array of tables with that relationship to the base table.
- * Each table in the array of tables with that relationship should be of the form
- * <chado table> => <Human-readable Name>.
- */
-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',
-    ),
-  );
-}
-
-/**
- * Implements hook_tripal_bulk_loader_<base table>_related_tables()
- * This is used to supply the bulk loader with a list of tables and their 
- * relationship to the base table.
- *
- * @return
- * An array of relationships (any combination of 'Base Table', 'Foreign Key Relations', 
- * 'Direct Relations', 'Indirect Relations') where each relationship is keyed by the type
- * of relationship and the value is an array of tables with that relationship to the base table.
- * Each table in the array of tables with that relationship should be of the form
- * <chado table> => <Human-readable Name>.
- */
-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',
-    ),
-  );
-}
-
-/**
- * Implements hook_tripal_bulk_loader_<base table>_related_tables()
- * This is used to supply the bulk loader with a list of tables and their 
- * relationship to the base table.
- *
- * @return
- * An array of relationships (any combination of 'Base Table', 'Foreign Key Relations', 
- * 'Direct Relations', 'Indirect Relations') where each relationship is keyed by the type
- * of relationship and the value is an array of tables with that relationship to the base table.
- * Each table in the array of tables with that relationship should be of the form
- * <chado table> => <Human-readable Name>.
- */
-function tripal_bulk_loader_tripal_bulk_loader_stock_related_tables () {
-
-  return array(
-    'Base Table' => array(
-      'stock' => 'Stock'
-    ),
-    'Foreign Key Relations' => array(
-      'organism' => 'Organism',
-      'cvterm' => 'Type: Cv Term',
-      'dbxref' => 'Database Reference',
-    ),
-    'Direct Relations' => array(
-      'stockprop' => 'Stock Properties',
-      'stock_relationship' => 'Stock Relationships',
-    ),
-    'Indirect Relations' => array(
-      'stock_cvterm' => 'Additional Cv Terms',
-      'stock_dbxref' => 'Additional Database References',
-      'stock_genotype' => 'Genotypes',
-      'stock_pub' => 'Publications',
-      'stockcollection_stock' => 'Stock Collections'
-    ),
-  );
-
-}
-
-/**
- * Implements hook_tripal_bulk_loader_<base table>_related_tables()
- * This is used to supply the bulk loader with a list of tables and their 
- * relationship to the base table.
- *
- * @return
- * An array of relationships (any combination of 'Base Table', 'Foreign Key Relations', 
- * 'Direct Relations', 'Indirect Relations') where each relationship is keyed by the type
- * of relationship and the value is an array of tables with that relationship to the base table.
- * Each table in the array of tables with that relationship should be of the form
- * <chado table> => <Human-readable Name>.
- */
-function tripal_bulk_loader_tripal_bulk_loader_genotype_related_tables () {
-
-  return array(
-    'Base Table' => array(
-      'genotype' => 'Genotype'
-    ),
-    'Indirect Relations' => array(
-      'feature_genotype' => 'Features',
-      'nd_experiment_genotype' => 'ND Experiments',
-      'phendesc' => 'Phenotypic Statements',
-      'phenotype_comparison' => 'Phenotype Comparisons',
-      'phenstatement' => 'Phenotypic Statements',
-      'stock_genotype' => 'Stocks',
-    ),
-  );
-
-}
-

+ 14 - 9
tripal_bulk_loader/tripal_bulk_loader.install

@@ -1,22 +1,27 @@
 <?php
 
-/*******************************************************************************
-* tripal_bulk_loader_install
-*/
+/**
+ * Implements hook_install
+ */
 function tripal_bulk_loader_install(){
    drupal_install_schema('tripal_bulk_loader');
 }
 
-/*******************************************************************************
-* tripal_bulk_loader_uninstall
-*/
+/**
+ * Implements hook_uninstall
+ */
 function tripal_bulk_loader_uninstall(){
    drupal_uninstall_schema('tripal_bulk_loader');
 }
 
-/*******************************************************************************
-* tripal_bulk_loader_schema
-*/
+/**
+ * Implements hook_schema
+ *
+ * Creates the following tables in the Drupal database:
+ *  - tripal_bulk_loader: Stores extra details for bulk loading jobs (nodes)
+ *  - tripal_bulk_loader_template: Stores all loading templates
+ *  - tripal_bulk_loader_inserted: Keeps track of all records inserted for a given bulk loading job
+ */
 function tripal_bulk_loader_schema() {
 	$schema = array();
 	$schema['tripal_bulk_loader'] = array(

+ 3 - 2
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -89,12 +89,13 @@ function tripal_bulk_loader_add_loader_job_form_submit ($form, $form_state) {
  * Tripal Bulk Loader
  *
  * This is the function that's run by tripal_launch_jobs to bulk load chado data.
+ *
  * @param $nid
  *   The Node ID of the bulk loading job node to be loaded. All other needed data is expected to be 
  *   in the node (ie: template ID and file)
  *
- * Note: Instead of returning a value this function updates the tripal_bulk_loader.status and
- *   Enters errors into tripal_bulk_loader_errors if they are encountered.
+ * Note: Instead of returning a value this function updates the tripal_bulk_loader.status.
+ *   Errors are thrown through watchdog and can be viewed at admin/reports/dblog.
  */
 function tripal_bulk_loader_load_data($nid) {
   

+ 71 - 54
tripal_bulk_loader/tripal_bulk_loader.module

@@ -1,23 +1,24 @@
 <?php
 
 include('tripal_bulk_loader.loader.inc');
-include('tripal_bulk_loader.info_hooks.inc');
 
 /**
- * tripal_bulk_loader_init
+ * Implements hook_init
+ * Used to add stylesheets and javascript files to the header
  */
 function tripal_bulk_loader_init(){
 	// Add javascript and style sheet
 	drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_bulk_loader.css');
 	drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_bulk_loader.js');
 }
+
 /**
- * tripal_bulk_loader_menu
+ * Implements hook_menu
  */
 function tripal_bulk_loader_menu() {
   $items = array();
    // Show all loaders
-   $items['/tripal_bulk_loaders'] = array(
+   $items['tripal_bulk_loaders'] = array(
      'title' => 'Tripal Bulk Loaders',
      'description' => 'Tripal bulk loaders for loading tab-delimited file into chado database',
      'page callback' => 'tripal_bulk_loader_list',
@@ -126,14 +127,31 @@ function tripal_bulk_loader_menu() {
 }
 
 /**
- * tripal_bulk_loader_list
+ * Implements hook_theme
  */
-function tripal_bulk_loader_list () {
-	return "Loaders";
+function tripal_bulk_loader_theme() {
+  return array(
+    'tripal_bulk_loader_template' => array(
+    	'arguments'=> array('template_id' => NULL),
+    	'template' => 'tripal_bulk_loader_template'
+    ),
+    'tripal_bulk_loader_modify_template_base_form' => array(
+    	'arguments' => array('form' => NULL),
+    	'template' => 'tripal_bulk_loader_modify_template_base_form',
+    ),
+    'tripal_bulk_loader_edit_template_field_form' => array(
+      'arguments' => array('form' => NULL),
+      'template' => 'tripal_bulk_loader_edit_template_field_form',
+    ),
+    'tripal_bulk_loader_add_template_field_form' => array(
+      'arguments' => array('form' => NULL),
+      'template' => 'tripal_bulk_loader_add_template_field_form',
+    ),
+  );
 }
 
 /**
- *  tripal_bulk_loader_access
+ *  Implements hook_access
  */
 function tripal_bulk_loader_access($op, $node, $account){
 	if ($op == 'create') {
@@ -160,7 +178,7 @@ function tripal_bulk_loader_access($op, $node, $account){
 }
 
 /**
- * tripal_bulk_loader_perm
+ * Implements hook_perm
  */
 function tripal_bulk_loader_perm(){
 	return array(
@@ -172,7 +190,40 @@ function tripal_bulk_loader_perm(){
 }
 
 /**
- * tripal_bulk_loader_node_info
+ * Creates a listing page for all bulk loading jobs
+ */
+function tripal_bulk_loader_list () {
+  $num_results_per_page = 50;
+  $output = '';
+  
+  $header = array('','Status','Loader','File');
+  $rows = array();
+  
+  $query = 'SELECT * FROM {tripal_bulk_loader} l '
+    .'LEFT JOIN {node} n ON n.nid = l.nid '
+    .'LEFT JOIN {tripal_bulk_loader_template} t ON t.template_id = cast(l.template_id as integer)';
+  $resource = pager_query($query, $num_results_per_page, 0, NULL);
+  while ($r = db_fetch_object($resource)) {
+    $row = array(
+      l($r->title, 'node/'.$r->nid),
+      $r->job_status,
+      $r->name,
+      $r->file
+    );
+    $rows[] = $row;
+  }
+  
+  $output .= theme('table', $header, $rows);
+  return $output;
+  
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+// Node Functions
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Implements hook_node_info
  */
 function tripal_bulk_loader_node_info() {
 	$nodes = array();
@@ -188,7 +239,8 @@ function tripal_bulk_loader_node_info() {
 }
 
 /**
- * tripal_bulk_loader_form
+ * Implements node_form
+ * Used to gather the extra details stored with a Bulk Loading Job Node
  */
 function tripal_bulk_loader_form ($node){
    $form = array();
@@ -247,46 +299,7 @@ function tripal_bulk_loader_form ($node){
 }
 
 /**
- * tripal_bulk_loader_theme
- */
-function tripal_bulk_loader_theme() {
-  return array(
-    'tripal_bulk_loader_node_form' => array(
-      'arguments' => array('form' => NULL),
-    ),
-    'tripal_bulk_loader_template' => array(
-    	'arguments'=> array('template_id' => NULL),
-    	'template' => 'tripal_bulk_loader_template'
-    ),
-    'tripal_bulk_loader_modify_template_base_form' => array(
-    	'arguments' => array('form' => NULL),
-    	'template' => 'tripal_bulk_loader_modify_template_base_form',
-    ),
-    'tripal_bulk_loader_edit_template_field_form' => array(
-      'arguments' => array('form' => NULL),
-      'template' => 'tripal_bulk_loader_edit_template_field_form',
-    ),
-    'tripal_bulk_loader_add_template_field_form' => array(
-      'arguments' => array('form' => NULL),
-      'template' => 'tripal_bulk_loader_add_template_field_form',
-    ),
-  );
-}
-
-/**
- * theme_tripal_bulk_loader_node_form
- */
-function theme_tripal_bulk_loader_node_form($form) {
-	// Do not show [Save] and [Preview] buttons if loader template is not available
-	if($form['label']['#type'] == "item") {
-		unset($form['buttons']);
-	}
-
-	return drupal_render($form);
-}
-
-/**
- * tripal_bulk_loader_load
+ * Implements node_load
  */
 function tripal_bulk_loader_load($node){
 	$sql = "SELECT * FROM {tripal_bulk_loader} WHERE nid = %d";
@@ -308,11 +321,13 @@ function tripal_bulk_loader_load($node){
     $r->num_inserted = sizeof(preg_split('/,/',$r->ids_inserted)); 
     $node->inserted_records->{$r->table_inserted_into} = $r;
   }
+  
 	return $node;
 }
 
 /**
- * tripal_bulk_loader_insert
+ * Implements node_insert
+ * Insert the data from the node form on Create content
  */
 function tripal_bulk_loader_insert ($node) {
   
@@ -327,7 +342,8 @@ function tripal_bulk_loader_insert ($node) {
 }
 
 /**
- * tripal_bulk_loader_delete
+ * Implements node_delete
+ * Deletes the data when the delete button on the node form is clicked
  */
 function tripal_bulk_loader_delete ($node) {
 	$sql = "DELETE FROM {tripal_bulk_loader} WHERE nid = %d";
@@ -335,7 +351,8 @@ function tripal_bulk_loader_delete ($node) {
 }
 
 /**
- * tripal_bulk_loader_update
+ * Implements node_update
+ * Updates the data submitted by the node form on edit
  */
 function tripal_bulk_loader_update ($node) {
 	$sql = "UPDATE {tripal_bulk_loader} SET nid = %d, loader_name = '%s', template_id = %d, file = '%s', file_has_header = '%s' WHERE nid = %d";