浏览代码

Merge branch '7.x-2.x' of git.drupal.org:project/tripal into 7.x-2.x

Stephen Ficklin 9 年之前
父节点
当前提交
b3c3201ee6

+ 7 - 4
tripal_bulk_loader/includes/tripal_bulk_loader.loader.inc

@@ -150,7 +150,10 @@ function tripal_bulk_loader_load_data($nid, $job_id) {
   $node = node_load($nid);
   print "Template: " . $node->template->name . " (" . $node->template_id . ")\n";
 
+  // Determine the total number of lines in the file.
   $total_lines = trim(`wc --lines < $node->file`);
+  // Correct for files with a single line and no enter character.
+  $total_lines = ($total_lines == 0) ? 1 : $total_lines;
   print "File: " . $node->file . " (" . $total_lines . " lines)\n";
 
   //print "\nClearing all prepared statements from previous runs of this loader...\n";
@@ -577,7 +580,7 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
   // skip optional fields
   if ($skip_optional) {
     // SPF -- Commented out the following line.  This state is intentional due
-    // to the loader setup and and is not an error.  If informational it 
+    // to the loader setup and and is not an error.  If informational it
     // prints too much to the terminal.
     // tripal_bulk_loader_throw_error('Skipping an optional record (%record)',array('%record'=>$table_data['record_id']),TRIPAL_NOTICE);
     return $no_errors;
@@ -586,7 +589,7 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
   // check if it is already inserted
   if (array_key_exists('inserted', $table_data) and $table_data['inserted']) {
     // SPF -- Commented out the following line.  This state is intentional due
-    // to the loader setup and and is not an error.  If informational it 
+    // to the loader setup and and is not an error.  If informational it
     // prints too much to the terminal.
     // tripal_bulk_loader_throw_error('Skipping %record since it is already inserted',array('%record'=>$table_data['record_id']),TRIPAL_NOTICE);
     return $no_errors;
@@ -597,7 +600,7 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
   if (array_key_exists('selected', $table_data) and $table_data['selected']) {
     $data[$priority]['values_array'] = $default_data[$priority]['values_array'];
     // SPF -- Commented out the following line.  This state is intentional due
-    // to the loader setup and and is not an error.  If informational it 
+    // to the loader setup and and is not an error.  If informational it
     // prints too much to the terminal.
     // tripal_bulk_loader_throw_error('%record was already selected thus we are just returning the values previously selected.',array('%record'=>$table_data['record_id']),TRIPAL_NOTICE);
     return $no_errors;
@@ -651,7 +654,7 @@ function process_data_array_for_line($priority, &$data, &$default_data, $addt) {
       // return if this is a select_if_duplicate
       if ($table_data['select_if_duplicate'] == 1) {
         // SPF -- Commented out the following line.  This state is intentional due
-        // to the loader setup and and is not an error.  If informational it 
+        // to the loader setup and and is not an error.  If informational it
         // prints too much to the terminal.
         // tripal_bulk_loader_throw_error('Simply returning values for %record since it was already inserted',array('%record'=>$table_data['record_id']),TRIPAL_NOTICE);
         return $no_errors;

+ 7 - 103
tripal_feature/includes/tripal_feature.admin.inc

@@ -38,109 +38,13 @@ function tripal_feature_admin_feature_view() {
 
   // Add a summary chart.
   //-----------------------------------
-  // We are using the organism_feature_count materialized view as the source for our data.
-  // Thus grab all the records from this materialized view.
-  $organism_feature_count = chado_select_record(
-    'organism_feature_count',
-    array('*'),
-    array(),
-    array('order_by' => array('genus' => 'ASC', 'species' => 'ASC', 'feature_type' => 'ASC', 'num_features' => 'DESC'))
-  );
-
-  // Initialize variables.
-  $chart = array();
-  $type_names = array();
-  $organism_names = array();
-  $max_bar_height = 0;
-
-  // Process each row of the materialzied view into the chart array.
-  // Note: it's first keyed by type since each type will be a bar. Each type will have
-  // a "bars" array with the start (y0) and end (y1) height on the bar for a given
-  // organism. Finally we keep a record of the names of the types & organisms
-  // for axis' and legend generation respectively.
-  foreach ($organism_feature_count as $row) {
-
-    // Build up the easy details for the current row's type. These will be overridden
-    // multiple times but that's more efficient than checking each time.
-    $chart[$row->cvterm_id]['cvterm_id'] = $row->cvterm_id;
-    $chart[$row->cvterm_id]['name'] = str_replace('_', ' ', $row->feature_type);
-
-    // Save the name of the type and organism into their respective arrays
-    // for generation of axis' and legends for the chart.
-    $type_names[$row->cvterm_id] = $row->feature_type;
-    $organism_names[$row->organism_id] = $row->genus . ' ' . $row->species;
-
-    // Save information about the current organism. This isn't actually used by the
-    // chart but can be used to debug the bar generation to follow.
-    $chart[$row->cvterm_id]['organisms'][] = array(
-      'name' => $row->genus . ' ' . $row->species,
-      'value' => (int) $row->num_features
-    );
-
-    // Now to build the bar array with the start (y0) and end (y1) height on the
-    // bar for a given organism.
-    // NOTE: we cannot assume the types are all in order so store y0 & y1 in the
-    // $chart[type] array.
-    // If y0 has not yet been set for this type then we're starting with the first
-    // chunk (organism) on the bar.
-    if (!isset($chart[$row->cvterm_id]['y0'])) {
-      $chart[$row->cvterm_id]['y0'] = 0;
-      $chart[$row->cvterm_id]['y1'] = $row->num_features;
-    }
-    // Otherwise, add the next chunk (organism) on top of the pre-existing bar.
-    else {
-      $chart[$row->cvterm_id]['y0'] = $chart[$row->cvterm_id]['y1'];
-      $chart[$row->cvterm_id]['y1'] = $chart[$row->cvterm_id]['y0'] + $row->num_features;
-    }
-    // Now save the bar chunk we just determined.
-    $chart[$row->cvterm_id]['bars'][] = array(
-      'name' => $row->genus . ' ' . $row->species,
-      'y0' => $chart[$row->cvterm_id]['y0'],
-      'y1' => $chart[$row->cvterm_id]['y1'],
-    );
-
-    // We also need to keep track of the total number of features for a single bar (Type).
-    $chart[$row->cvterm_id]['total_features'] = (int) $chart[$row->cvterm_id]['y1'];
-    // And the maximum "height" for all bars.
-    if ($max_bar_height < $chart[$row->cvterm_id]['total_features']) {
-      $max_bar_height = (int) $chart[$row->cvterm_id]['total_features'];
-    }
-  }
-
-  // Sort based on the total number of features.
-  // NOTE: This changes the keys so it's no longer the organism/type_id.
-  usort($chart, 'tripal_feature_admin_summary_sort');
-  sort($type_names);
-  sort($organism_names);
-
-  // We also need to add information about the materialized views
-  // so that admin can update it and know how recent the data is.
-  $mview = db_query('
-    SELECT mview_id, name, last_update
-    FROM tripal_mviews
-    WHERE mv_table=:mv_table',
-    array(':mv_table' => 'organism_feature_count')
-  )->fetchObject();
-
-  // Save everything we just determined as a Drupal JS settings so that we have access to
-  // it in our js script.
-  $last_updated = $mview->last_update ? format_date($mview->last_update) : '';
-  drupal_add_js(array('tripalFeature' => array('admin' => array(
-    'summary' => $chart,
-    'types' => $type_names,
-    'organisms' => $organism_names,
-    'legendPosition' => 'top',
-    'maxBarHeight' => $max_bar_height,
-    'mviewUrl' => url('admin/tripal/schema/mviews/update/' . $mview->mview_id),
-    'mviewUable' => $mview->name,
-    'mviewLastUpdate' => $last_updated,
-    'figureDesc' => '<span class="figure-title">Feature Composition</span>: This figure depicts the type and source organism of features in your Tripal site. It is populated from the <em>'.$mview->name.'</em> materialized view which was last updated on <em>'.$last_updated.'</em>. <strong><em>To update this chart, <a href="'.url('admin/tripal/schema/mviews/update/' . $mview->mview_id).'">submit a job to update the materialized view</a></em></strong>.'
-  ))), 'setting');
-
-  // Finally add all the javascript and css needed to render the chart.
-  tripal_add_d3js();
-  drupal_add_css(drupal_get_path('module','tripal_feature') . '/theme/css/tripal_feature.css');
-  drupal_add_js(drupal_get_path('module','tripal_feature') . '/theme/js/tripalFeature.adminChart.js');
+  $output .= theme('tripal_feature_bar_chart_type_organism_summary');
+  drupal_add_js('
+    Drupal.behaviors.tripalFeature_moveAdminSummaryChart = {
+      attach: function (context, settings) {
+        jQuery("#tripal-feature-admin-summary").insertBefore( jQuery(".view-filters") );
+    }};
+  ', 'inline');
 
   return $output;
 }

+ 0 - 22
tripal_feature/theme/js/tripalFeature.adminChart.js

@@ -1,22 +1,6 @@
 Drupal.behaviors.tripalFeature_adminSummaryChart = {
   attach: function (context, settings) {
 
-    // First add the container after the view header.
-    var container = d3.select('#tripal-feature-admin-summary');
-    if (container.empty) {
-      container = d3.select('.view-header').append('div')
-        .attr('id', 'tripal-feature-admin-summary')
-        .classed('tripal-admin-summary',true);
-
-      container.append('div')
-        .attr('id', 'tripal-feature-admin-summary-chart')
-        .classed('tripal-admin-chart',true);
-
-      container.append('div')
-        .attr('id', 'tripal-feature-admin-summary-figure-desc')
-        .classed('tripal-admin-figure-desc',true);
-    }
-
     // Set-up the dimensions for our chart canvas.
     // Note: these are adjusted below so think of these are your minimum size.
     var margin = {top: 20, right: 50, bottom: 20, left: 100},
@@ -254,12 +238,6 @@ Drupal.behaviors.tripalFeature_adminSummaryChart = {
             .attr('font-style','italic')
             .text(function(d) { return d; });
       }
-
-
-      // Add a small blurb mentioning this is from an mview and you should update ;).
-      d3.selectAll('#tripal-feature-admin-summary-figure-desc')
-        .html(Drupal.settings.tripalFeature.admin.figureDesc);
-
     }
   }
 };

+ 28 - 0
tripal_feature/theme/templates/tripal_feature_bar_chart_type_organism_summary.tpl.php

@@ -0,0 +1,28 @@
+<?php
+/**
+ * Feature Summary Bar Chart (broken down by type & organism).
+ *
+ * This template displays a feature summary stacked bar chart
+ * where each bar depicts the total number of features per
+ * feature type and the stacked portions of a given bar
+ * respresent the organism breakdown of those featurs.
+ *
+ * Most of the functionality is in the preprocess for this template and
+ * the acompanying javascript file.
+ * @see tripal_feature/theme/js/tripalFeature.adminChart.js
+ * @see tripal_feature/theme/tripal_feature.theme.inc:tripal_feature_preprocess_tripal_feature_bar_chart_type_organism_summary()
+ */
+?>
+
+<div id="tripal-feature-admin-summary" class="tripal-admin-summary">
+  <div id="tripal-feature-admin-summary-chart" "tripal-admin-chart"></div>
+  <div id="tripal-feature-admin-summary-figure-desc" "tripal-admin-figure-desc">
+    <span class="figure-title">Feature Composition</span>:
+    This figure depicts the type and source organism of features in your Tripal
+    site. It is populated from the <em><?php print $chart_details['mviewTable']; ?></em>
+    materialized view which was last updated on <em><?php print $chart_details['mviewLastUpdate']; ?></em>.
+    <strong><em>To update this chart, <a href="<?php print $chart_details['mviewUrl'];?>">
+    submit a job to update the materialized view</a></em></strong>.
+  </div>
+</div>
+

+ 121 - 8
tripal_feature/theme/tripal_feature.theme.inc

@@ -1,4 +1,4 @@
-<?php 
+<?php
 
 
 /**
@@ -27,9 +27,9 @@ function tripal_feature_preprocess_tripal_feature_sequence(&$variables) {
   // now extract the sequences
   $featureloc_sequences = tripal_feature_load_featureloc_sequences($feature->feature_id, $ffeaturelocs);
   $feature->featureloc_sequences = $featureloc_sequences;
-  
+
   // if this feature has associated protein sequences (or others via relationships
-  // then we want to make sure the relationships are added so that we can 
+  // then we want to make sure the relationships are added so that we can
   // show the protein sequences
   if (!$feature->all_relationships) {
     $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
@@ -145,7 +145,7 @@ function tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) {
       $args = array(':feature_id' => $featureloc->srcfeature_id->feature_id);
       $start = $featureloc->fmin + 1;
       $size = $featureloc->fmax - $featureloc->fmin;
-      
+
       // TODO: fix the hard coded $start and $size
       // the $start and $size variables are hard-coded in the SQL statement
       // because the db_query function places quotes around all placeholders
@@ -852,11 +852,11 @@ function tripal_feature_get_feature_relationships($feature) {
         }
       }
       $rel->record = $relationship;
-       
+
       // get the relationship and child types
       $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
       $child_type = $relationship->subject_id->type_id->name;
-       
+
       // get the node id of the subject
       $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
       $n = db_query($sql, array(':feature_id' => $relationship->subject_id->feature_id))->fetchObject();
@@ -893,14 +893,14 @@ function tripal_feature_get_feature_relationships($feature) {
       $rel->record = $relationship;
       $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
       $parent_type = $relationship->object_id->type_id->name;
-       
+
       // get the node id of the subject
       $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
       $n = db_query($sql, array(':feature_id' => $relationship->object_id->feature_id))->fetchObject();
       if ($n) {
         $rel->record->nid = $n->nid;
       }
-       
+
       if (!array_key_exists($rel_type, $relationships['subject'])) {
         $relationships['subject'][$rel_type] = array();
       }
@@ -912,3 +912,116 @@ function tripal_feature_get_feature_relationships($feature) {
   }
   return $relationships;
 }
+
+/**
+ *
+ */
+function tripal_feature_preprocess_tripal_feature_bar_chart_type_organism_summary(&$vars) {
+
+  // Add in all the javascript/css files.
+  tripal_add_d3js();
+  drupal_add_css(drupal_get_path('module','tripal_feature') . '/theme/css/tripal_feature.css');
+  drupal_add_js(drupal_get_path('module','tripal_feature') . '/theme/js/tripalFeature.adminChart.js');
+
+  // Retrieve and process all the data and save it as javascript settings.
+  //'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+  // We are using the organism_feature_count materialized view as the source for our data.
+  // Thus grab all the records from this materialized view.
+  $organism_feature_count = chado_select_record(
+    'organism_feature_count',
+    array('*'),
+    array(),
+    array('order_by' => array('genus' => 'ASC', 'species' => 'ASC', 'feature_type' => 'ASC', 'num_features' => 'DESC'))
+  );
+
+  // Initialize variables.
+  $chart = array();
+  $type_names = array();
+  $organism_names = array();
+  $max_bar_height = 0;
+
+  // Process each row of the materialzied view into the chart array.
+  // Note: it's first keyed by type since each type will be a bar. Each type will have
+  // a "bars" array with the start (y0) and end (y1) height on the bar for a given
+  // organism. Finally we keep a record of the names of the types & organisms
+  // for axis' and legend generation respectively.
+  foreach ($organism_feature_count as $row) {
+
+    // Build up the easy details for the current row's type. These will be overridden
+    // multiple times but that's more efficient than checking each time.
+    $chart[$row->cvterm_id]['cvterm_id'] = $row->cvterm_id;
+    $chart[$row->cvterm_id]['name'] = str_replace('_', ' ', $row->feature_type);
+
+    // Save the name of the type and organism into their respective arrays
+    // for generation of axis' and legends for the chart.
+    $type_names[$row->cvterm_id] = $row->feature_type;
+    $organism_names[$row->organism_id] = $row->genus . ' ' . $row->species;
+
+    // Save information about the current organism. This isn't actually used by the
+    // chart but can be used to debug the bar generation to follow.
+    $chart[$row->cvterm_id]['organisms'][] = array(
+      'name' => $row->genus . ' ' . $row->species,
+      'value' => (int) $row->num_features
+    );
+
+    // Now to build the bar array with the start (y0) and end (y1) height on the
+    // bar for a given organism.
+    // NOTE: we cannot assume the types are all in order so store y0 & y1 in the
+    // $chart[type] array.
+    // If y0 has not yet been set for this type then we're starting with the first
+    // chunk (organism) on the bar.
+    if (!isset($chart[$row->cvterm_id]['y0'])) {
+      $chart[$row->cvterm_id]['y0'] = 0;
+      $chart[$row->cvterm_id]['y1'] = $row->num_features;
+    }
+    // Otherwise, add the next chunk (organism) on top of the pre-existing bar.
+    else {
+      $chart[$row->cvterm_id]['y0'] = $chart[$row->cvterm_id]['y1'];
+      $chart[$row->cvterm_id]['y1'] = $chart[$row->cvterm_id]['y0'] + $row->num_features;
+    }
+    // Now save the bar chunk we just determined.
+    $chart[$row->cvterm_id]['bars'][] = array(
+      'name' => $row->genus . ' ' . $row->species,
+      'y0' => $chart[$row->cvterm_id]['y0'],
+      'y1' => $chart[$row->cvterm_id]['y1'],
+    );
+
+    // We also need to keep track of the total number of features for a single bar (Type).
+    $chart[$row->cvterm_id]['total_features'] = (int) $chart[$row->cvterm_id]['y1'];
+    // And the maximum "height" for all bars.
+    if ($max_bar_height < $chart[$row->cvterm_id]['total_features']) {
+      $max_bar_height = (int) $chart[$row->cvterm_id]['total_features'];
+    }
+  }
+
+  // Sort based on the total number of features.
+  // NOTE: This changes the keys so it's no longer the organism/type_id.
+  usort($chart, 'tripal_feature_admin_summary_sort');
+  sort($type_names);
+  sort($organism_names);
+
+  // We also need to add information about the materialized views
+  // so that admin can update it and know how recent the data is.
+  $mview = db_query('
+    SELECT mview_id, name, last_update
+    FROM tripal_mviews
+    WHERE mv_table=:mv_table',
+    array(':mv_table' => 'organism_feature_count')
+  )->fetchObject();
+
+  $vars['chart_details'] = array(
+    'summary' => $chart,
+    'types' => $type_names,
+    'organisms' => $organism_names,
+    'legendPosition' => 'top',
+    'maxBarHeight' => $max_bar_height,
+    'mviewUrl' => url('admin/tripal/schema/mviews/update/' . $mview->mview_id),
+    'mviewTable' => $mview->name,
+    'mviewLastUpdate' => $mview->last_update ? format_date($mview->last_update) : '',
+  );
+
+  // Save everything we just determined as a Drupal JS settings so that we have access to
+  // it in our js script.
+  drupal_add_js(array('tripalFeature' => array('admin' => $vars['chart_details'])), 'setting');
+}

+ 38 - 27
tripal_feature/tripal_feature.module

@@ -249,6 +249,7 @@ function tripal_feature_search_biological_data_views() {
 function tripal_feature_theme($existing, $type, $theme, $path) {
   $core_path = drupal_get_path('module', 'tripal_core');
 
+  // Feature Node Page Templates.
   $items = array(
     'node__chado_feature' => array(
       'template' => 'node--chado-generic',
@@ -311,36 +312,46 @@ function tripal_feature_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_feature_relationships',
       'path' => "$path/theme/templates",
     ),
-    // help template
-    'tripal_feature_help' => array(
-      'template' => 'tripal_feature_help',
-      'variables' =>  array(NULL),
-      'path' => "$path/theme/templates"
-    ),
+  );
 
-    // template for the organism page
-    'tripal_organism_feature_browser' => array(
-      'variables' => array('node' => NULL),
-      'template' => 'tripal_organism_feature_browser',
-      'path' => "$path/theme/templates",
-    ),
-    'tripal_organism_feature_counts' => array(
-      'variables' => array('node' => NULL),
-      'template' => 'tripal_organism_feature_counts',
-      'path' => "$path/theme/templates",
-    ),
+  // Feature Node Teaser
+  $items['tripal_feature_teaser'] = array(
+    'variables' => array('node' => NULL),
+    'template' => 'tripal_feature_teaser',
+    'path' => "$path/theme/templates",
+  );
 
-    // themed forms
-    'tripal_feature_seq_extract_form' => array(
-       'arguments' => array('form'),
-    ),
+  // Templates for other node pages.
+  // Organism Feature Browser.
+  $items['tripal_organism_feature_browser'] = array(
+    'variables' => array('node' => NULL),
+    'template' => 'tripal_organism_feature_browser',
+    'path' => "$path/theme/templates",
+  );
+  $items['tripal_organism_feature_counts'] = array(
+    'variables' => array('node' => NULL),
+    'template' => 'tripal_organism_feature_counts',
+    'path' => "$path/theme/templates",
+  );
 
-    // themed teaser
-    'tripal_feature_teaser' => array(
-      'variables' => array('node' => NULL),
-      'template' => 'tripal_feature_teaser',
-      'path' => "$path/theme/templates",
-    ),
+  // Administrative Help Template.
+  $items['tripal_feature_help'] = array(
+    'template' => 'tripal_feature_help',
+    'variables' =>  array(NULL),
+    'path' => "$path/theme/templates"
+  );
+
+  // Themed Forms
+  $items['tripal_feature_seq_extract_form'] = array(
+     'arguments' => array('form'),
+  );
+
+  // D3 Charts.
+  // Feature Type/Organism Stacked Bar Chart.
+  $items['tripal_feature_bar_chart_type_organism_summary'] = array(
+    'template' => 'tripal_feature_bar_chart_type_organism_summary',
+    'variables' =>  array(NULL),
+    'path' => "$path/theme/templates"
   );
 
   return $items;