Browse Source

Analysis module is now functional for inserts/updates/syncs and propely handles properties

Stephen Ficklin 11 years ago
parent
commit
e08eb3eb16

+ 23 - 12
tripal_analysis/includes/tripal_analysis.form.inc

@@ -87,7 +87,16 @@ function chado_analysis_form($node, &$form_state) {
   $form['title']= array(
     '#type' => 'value',
     '#default_value' => $node->title,
-  );  
+  );
+  $form['instructions'] = array(
+    '#markup' => t('<b>Note</b>: When adding any type of data it is good to associate it with
+        an analysis so that site visitors can identify the source of the data including
+        necessary materials and methods.  The fields below imply that all analyses 
+        are derived from some software package. But, data can also be derived via retreival
+        from an external source or an analysis pipeline with multipel software components.
+        In these cases, provide values for the fields below that best makes sense
+        '),
+  );
   $form['analysisname']= array(
     '#type' => 'textfield',
     '#title' => t('Analysis Name'),
@@ -98,17 +107,17 @@ function chado_analysis_form($node, &$form_state) {
   );
   $form['program']= array(
     '#type' => 'textfield',
-    '#title' => t('Program'),
+    '#title' => t('Program, Pipeline Name or Method Name'),
     '#required' => TRUE,
     '#default_value' => $program,
-    '#description' => t("Program name, e.g. blastx, blastp, sim4, genscan."),
+    '#description' => t("Program name, e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package, provide a very brief description of the pipeline or method."),
   );
   $form['programversion']= array(
     '#type' => 'textfield',
-    '#title' => t('Program Version'),
+    '#title' => t('Program, Pipeline  or Method version'),
     '#required' => TRUE,
     '#default_value' => $programversion,
-    '#description' => t("Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter 'n/a' if no version is available."),
+    '#description' => t("Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter 'n/a' if no version is available or applicable."),
   );
   $form['algorithm']= array(
     '#type' => 'textfield',
@@ -258,7 +267,7 @@ function chado_analysis_node_form_add_new_empty_props(&$form, &$form_state, $pro
   $form['properties']['table']['new']["new_id"] = array(
     '#type'          => 'select',
     '#options'       => $properties_select,
-    '#value'         => $id,
+    '#default_value' => $id,
     '#ajax' => array(
       'callback' => "tripal_analysis_property_get_description",
       'wrapper'  => 'tripal-analysis-new_value',
@@ -268,7 +277,7 @@ function chado_analysis_node_form_add_new_empty_props(&$form, &$form_state, $pro
   );
   $form['properties']['table']['new']["new_value"] = array(
     '#type'           => 'textarea',
-    '#value'          => $text,
+    '#default_value'  => $text,
     '#cols'           => 50,
     '#rows'           => $rows,
     '#prefix'         => '<div id="tripal-analysis-new_value">',
@@ -492,7 +501,10 @@ function chado_analysis_node_form_add_analysisprop_table_props(&$form, $form_sta
   while ($prop = $analysis_props->fetchObject()) {
 
     $type_id = $prop->cvterm_id;
-    $rank = count($ranks[$type_id]);
+    $rank = 0;
+    if(array_key_exists($type_id, $ranks)) {
+      $rank = count($ranks[$type_id]);
+    }
 
     // skip any properties that the user requested to delete through a previous
     // AHAH callback or through the current AHAH callback
@@ -510,10 +522,10 @@ function chado_analysis_node_form_add_analysisprop_table_props(&$form, $form_sta
     $ranks[$type_id][$rank]['value'] = $prop->value;
     $ranks[$type_id][$rank]['definition']  = $prop->definition;
     $num_properties++;
+    $rows = 1;
 
     $form['properties']['table'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
-      '#type'          => 'item',
-      '#value'         => $prop->name,
+      '#markup'        => $prop->name,
     );
     $form['properties']['table'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
       '#type'          => 'textarea',
@@ -569,7 +581,6 @@ function chado_analysis_validate($node, &$form_state) {
  * @ingroup tripal_analysis
  */
 function tripal_analysis_validate($node, &$form_state) {
-  
   $node->analysisname = trim($node->analysisname);
   $node->description = trim($node->description);
   $node->program = trim($node->program);
@@ -627,7 +638,7 @@ function tripal_analysis_validate($node, &$form_state) {
   else {
     // To differentiate if we are syncing or creating a new analysis altogther, see if an
     // analysis_id already exists
-    if ($node->analysis_id and $node->analysis_id != 0) {
+    if (property_exists($node, 'analysis_id') and $node->analysis_id != 0) {
       // CASE B: Synchronizing a node from chado to drupal
       // we don't need to do anything.
     }

+ 1 - 1
tripal_analysis/theme/tripal_analysis/tripal_analysis_base.tpl.php

@@ -8,7 +8,7 @@ $analysis = tripal_core_expand_chado_vars($analysis,'field','analysis.descriptio
   // the $headers array is an array of fields to use as the colum headers. 
   // additional documentation can be found here 
   // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-  // This table for the organism has a vertical header (down the first column)
+  // This table for the analysis has a vertical header (down the first column)
   // so we do not provide headers here, but specify them in the $rows array below.
   $headers = array();
   

+ 44 - 27
tripal_analysis/theme/tripal_analysis/tripal_analysis_properties.tpl.php

@@ -1,39 +1,56 @@
 <?php
-$analysis = $node->analysis;
 
-// expand the analysis to include the properties.
+// get the analysis object and expand it to include the records from the analysisprop table
+$analysis = $variables['node']->analysis;
 $analysis = tripal_core_expand_chado_vars($analysis,'table', 'analysisprop', array('return_array' => 1));
 $analysisprops = $analysis->analysisprop;
+
+// put the properties in an array for easier access
 $properties = array();
-if (is_array($analysisprops)) {
-  foreach ($analysisprops as $property) {
-    $property = tripal_core_expand_chado_vars($property,'field','analysisprop.value');
-    $properties[] = $property;
-  }
+foreach ($analysisprops as $property) {
+  $property = tripal_core_expand_chado_vars($property,'field','analysisprop.value');
+  $properties[] = $property;
 }
 
 if (count($properties) > 0) { ?>
   <div id="tripal_analysis-properties-box" class="tripal_analysis-info-box tripal-info-box">
     <div class="tripal_analysis-info-box-title tripal-info-box-title">More Details</div>
-    <div class="tripal_analysis-info-box-desc tripal-info-box-desc">Additional information about this analysis:</div>
-    <table class="tripal_analysis-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Property Name</th>
-        <th>Value</th>
-      </tr> <?php
-      $i = 0;
-      foreach ($properties as $property) {
-        $class = 'tripal_analysis-table-odd-row tripal-table-odd-row';
-        if ($i % 2 == 0 ) {
-           $class = 'tripal_analysis-table-odd-row tripal-table-even-row';
-        }
-        $i++; 
-        ?>
-        <tr class="<?php print $class ?>">
-          <td><?php print ucfirst(preg_replace('/_/', ' ', $property->type_id->name)) ?></td>
-          <td><?php print $property->value ?></td>
-        </tr><?php 
-      } ?>
-    </table>
+    <div class="tripal_analysis-info-box-desc tripal-info-box-desc">Additional information about this analysis:</div><?php
+    
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Property Name', 'Value');
+    
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();      
+    foreach ($properties as $property) {
+      $rows[] = array(
+        ucfirst(preg_replace('/_/', ' ', $property->type_id->name)),
+        $property->value
+      );
+    } 
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_analysis-table-properties',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?>
   </div> <?php
 }

+ 20 - 41
tripal_analysis/tripal_analysis.module

@@ -164,13 +164,9 @@ function tripal_analysis_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_analysis_base',
       'path' => "$path/theme/tripal_analysis",
     ),
-    'tripal_feature_analyses' => array(
-      'template' => 'tripal_feature_analyses',
-      'variables' =>  array('node' => NULL),
-      'path' => "$path/theme/tripal_analysis",
-    ),
     'tripal_analysis_properties' => array(
       'variables' => array('node' => NULL),
+      'template' => 'tripal_analysis_properties',
       'path' => "$path/theme/tripal_analysis",
     ),
     'tripal_analysis_help' => array(
@@ -178,6 +174,15 @@ function tripal_analysis_theme($existing, $type, $theme, $path) {
       'variables' =>  array(NULL),
       'path' => "$path/theme",
     ),
+    
+    // tripal_feature theme
+    'tripal_feature_analyses' => array(
+      'template' => 'tripal_feature_analyses',
+      'variables' =>  array('node' => NULL),
+      'path' => "$path/theme/tripal_analysis",
+    ),
+    
+    // form theme
     'chado_analysis_form' => array(
       'render element' => 'form',
     )
@@ -396,7 +401,10 @@ function chado_analysis_insert($node) {
   if ($node->new_id and $node->new_value) {
     $type_id = $node->new_id;
     $name = $properties_list[$type_id];
-    $index = count($properties[$name]);
+    $index = 0;
+    if (array_key_exists($name, $properties)) {
+      $index = count($properties[$name]);
+    }
     $properties[$name][$index] = trim($node->new_value);
   }
   // now add in the properties
@@ -494,17 +502,16 @@ function chado_analysis_update($node) {
 
   // now update the properties
   $properties = array(); // stores all of the properties we need to add
+  
   // get the list of properties for easy lookup (without doing lots of database queries
   $properties_list = array();
   $sql = "
-      SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
-      FROM  {cvterm} CVT
+    SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
+    FROM  {cvterm} CVT
       INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
-      WHERE
-      CV.name = 'analysis_property' AND
-      NOT CVT.is_obsolete = 1
-      ORDER BY CVT.name ASC
-      ";
+    WHERE CV.name = 'analysis_property' AND NOT CVT.is_obsolete = 1
+    ORDER BY CVT.name ASC
+  ";
   $prop_types = chado_query($sql);
   while ($prop = $prop_types->fetchObject()) {
     $properties_list[$prop->cvterm_id] = $prop->name;
@@ -560,10 +567,6 @@ function chado_analysis_update($node) {
       }
     }
   }
-}
-
-function chado_analysis_presave($node) {
-  
 }
  /**
   *  When a node is requested by the user this function is called to allow us
@@ -588,30 +591,6 @@ function chado_analysis_load($nodes) {
   }
 }
 
-/**
- *  This function customizes the view of the chado_analysis node.  It allows
- *  us to generate the markup.
- *
- * @ingroup tripal_analysis
- */
-function chado_analysis_view($node, $teaser = FALSE, $page = FALSE) {
-  // use drupal's default node view:
-  if (!$teaser) {
-    $node = node_prepare($node, $teaser);
-    // When previewing a node submitting form, it shows 'Array' instead of
-    // correct date format. We need to format the date here
-    $time = $node->timeexecuted;
-    if (is_array($time)) {
-      $month = $time['month'];
-      $day = $time['day'];
-      $year = $time['year'];
-      $timestamp = $year . '-' . $month . '-' . $day;
-      $node->timeexecuted = $timestamp;
-    }
-  }
-  return $node;
-}
-
 /**
  * Implement hook_access().
  *

+ 2 - 2
tripal_core/api/tripal_core_chado.api.inc

@@ -250,7 +250,7 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
 
     if (is_array($value)) {
       // select the value from the foreign key relationship for this value
-      $results = tripal_core_chado_get_foreign_key($table_desc, $field, $value, $foreign_options);
+      $results = tripal_core_chado_get_foreign_key($table_desc, $field, $value);
 
       if (sizeof($results) > 1) {
         tripal_core_report_error(
@@ -1867,7 +1867,7 @@ function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_option
               $object->expanded = $to_expand;
             }
             else {
-              if (!is_object($object->{$foreign_table})) {
+              if (!property_exists($object, $foreign_table) or !is_object($object->{$foreign_table})) {
                 $object->{$foreign_table} = new stdClass();
               }
               $object->{$foreign_table} = $foreign_object;

+ 20 - 22
tripal_organism/tripal_organism.module

@@ -199,20 +199,32 @@ function tripal_organism_theme($existing, $type, $theme, $path) {
   );
   return $items;
 }
+/**
+ * 
+ * @param $node
+ */
+function tripal_organism_node_presave($node) {
+  switch ($node->type) {
+    case 'chado_organism':
+      // set the title for the node
+      $node->title = "$node->genus $node->species";
+      break;
+  }
+}
 /**
  *
  * @ingroup tripal_feature
  */
 function tripal_organism_node_view($node, $view_mode, $langcode) {
   switch ($node->type) {
-  	case 'chado_organism':
-  	  // Show feature browser and counts
-  	  if ($view_mode == 'full') {
-  	    $node->content['tripal_organism_base'] = array(
-  	      '#value' => theme('tripal_organism_base', array('node' => $node)),
-  	    );
-  	  }
-  	  break;
+    case 'chado_organism':
+      // Show feature browser and counts
+      if ($view_mode == 'full') {
+        $node->content['tripal_organism_base'] = array(
+          '#value' => theme('tripal_organism_base', array('node' => $node)),
+        );
+      }
+      break;
   }
 }
 /**
@@ -428,13 +440,6 @@ function chado_organism_insert($node) {
     drupal_write_record('chado_organism', $record);
   }
 
-  // set the title for the node
-  $record = new stdClass();
-  $record->title = "$node->genus $node->species";
-  $record->nid = $node->nid;
-  drupal_write_record('node', $record, 'nid');
-  drupal_write_record('node_revisions', $record, 'nid');
-
   // add the image
   chado_organism_add_image($node);
 }
@@ -467,13 +472,6 @@ function chado_organism_update($node) {
   );
   $org_status = tripal_core_chado_update('organism', $match, $values);
 
-  // set the title for the node
-  $record = new stdClass();
-  $record->title = "$node->genus $node->species";
-  $record->nid = $node->nid;
-  drupal_write_record('node', $record, 'nid');
-  drupal_write_record('node_revisions', $record, 'nid');
-
   // add the image
   chado_organism_add_image($node);
 }