Skip to content

Commit

Permalink
Merge pull request #7 from statonlab/master
Browse files Browse the repository at this point in the history
Fix issue with analysis table
  • Loading branch information
almasaeed2010 authored Mar 22, 2017
2 parents 351d8c8 + a8f3f4a commit 82d58a4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
58 changes: 41 additions & 17 deletions includes/feature_heatmap_form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,35 @@ function e($value) {
function feature_heatmap_form($form, &$form_state) {
$form['descriptions'] = array(
'#type' => 'item',
'#markup' => t('<b>Feature unique names need to be separated by comma(,).</b>')
'#markup' => t(
'<b>Feature unique names need to be separated by comma(,).</b>'
),
);

$form['example_button'] = array(
'#type' => 'button',
'#value' => 'Try an Example',
'#attributes' => array(
'class' => array('pull-right', 'btn-info'),
),
);

$form['heatmap_feature_uniquename'] = array(
'#type' => 'textarea',
'#title' => t('Enter feature unique names'),
'#description' => t('<b>Example feature unique names:</b> Juglans_nigra_120313_comp34229_c0_seq1 ,Quercus_rubra_120313_comp31392_c0_seq1, Acer_saccharum_022416_comp57075_c0_seq8, Liquidambar_styraciflua_01052015_comp34573_c0_seq2,Fraxinus_pennsylvanica_120313_comp50845_c0_seq2, Nyssa_sylvatica_10132014_comp27824_c0_seq1, Quercus_rubra_120313_comp13209_c0_seq1'),
'#description' => t(
'<b>Example feature unique names:</b> Fraxinus_pennsylvanica_120313_comp59663_c0_seq1, Fraxinus_pennsylvanica_120313_comp59663_c0_seq2, Fraxinus_pennsylvanica_120313_comp56723_c0_seq1, Fraxinus_pennsylvanica_120313_comp60325_c0_seq16, Fraxinus_pennsylvanica_120313_comp61194_c0_seq4, Fraxinus_pennsylvanica_120313_comp61194_c0_seq5, Fraxinus_pennsylvanica_120313_comp61194_c0_seq8, Fraxinus_pennsylvanica_120313_comp61194_c0_seq6'
),
'#attributes' => array(
'placeholder' => t('Nyssa_sylvatica_10132014_comp23154_c0_seq12_m.8255, Quercus_rubra_120313_comp172643_c0_seq1_m.37896, Liriodendron_tulipifera_10132014_comp16064_c0_seq1'),
'placeholder' => 'Example: Fraxinus_pennsylvanica_120313_comp59663_c0_seq1, Fraxinus_pennsylvanica_120313_comp59663_c0_seq2, Fraxinus_pennsylvanica_120313_comp56723_c0_seq1, Fraxinus_pennsylvanica_120313_comp60325_c0_seq16, Fraxinus_pennsylvanica_120313_comp61194_c0_seq4, Fraxinus_pennsylvanica_120313_comp61194_c0_seq5, Fraxinus_pennsylvanica_120313_comp61194_c0_seq8, Fraxinus_pennsylvanica_120313_comp61194_c0_seq6',
),
);

// Escaped get value if it exists
if (isset($_GET['heatmap_feature_uniquename']) && !empty($_GET['heatmap_feature_uniquename'])) {
$form['heatmap_feature_uniquename']['#value'] = e($_GET['heatmap_feature_uniquename']);
$form['heatmap_feature_uniquename']['#value'] = e(
$_GET['heatmap_feature_uniquename']
);
}


Expand All @@ -60,13 +74,12 @@ function feature_heatmap_form_submit($form, &$form_state) {
function generate_heatmap_values() {
// Escaped get value if it exists
if (!isset($_GET['heatmap_feature_uniquename']) || empty($_GET['heatmap_feature_uniquename'])) {
return null;
return NULL;
}

$heatmap_feature_uniquename = e($_GET['heatmap_feature_uniquename']);

$sql_feature_uniquename =
"SELECT ER.elementresult_id, ER.signal, F.feature_id, F.uniquename,
$sql_feature_uniquename = "SELECT ER.elementresult_id, ER.signal, F.feature_id, F.uniquename,
Q.name AS quantification_name, Q.analysis_id,
B.name, B.biomaterial_id, B.description FROM {chado.elementresult} ER
INNER JOIN {chado.element} E ON E.element_id = ER.element_id
Expand All @@ -86,7 +99,10 @@ function generate_heatmap_values() {
foreach ($feature_ids as $feature_id) {
// trim white space at the beginning and the end
$feature_id = trim($feature_id);
$expressions[$feature_id] = db_query($sql_feature_uniquename, array(":feature_uniquename" => $feature_id))->fetchAllAssoc('elementresult_id');
$expressions[$feature_id] = db_query(
$sql_feature_uniquename,
array(":feature_uniquename" => $feature_id)
)->fetchAllAssoc('elementresult_id');
}
}

Expand Down Expand Up @@ -118,14 +134,22 @@ function generate_heatmap_values() {
$analysis_id = $feature->analysis_id;
$sql_analysis = "SELECT * FROM chado.analysis WHERE analysis_id=:analysis_id";
if (!empty($analysis_id)) {
$analysis = db_query($sql_analysis, array(':analysis_id' => $analysis_id))->fetchAllAssoc('analysis_id');
$analysis = db_query(
$sql_analysis,
array(':analysis_id' => $analysis_id)
)->fetchAllAssoc('analysis_id');
// analysis page url consists of analysis name, sourcename, program and programversion
$analysis_url = $analysis[$analysis_id]->name . ', ' .
$analysis[$analysis_id]->sourcename . ' (' .
$analysis[$analysis_id]->program . ', ' .
$analysis[$analysis_id]->programversion . ')';
$analysis_url = preg_replace("/[^A-Za-z0-9 ]/", '', $analysis_url); // remove all non-alphanumeric charaters
$analysis_url = preg_replace("/\s/", '-', $analysis_url); // replace ' ' with '-'
$analysis_url = $analysis[$analysis_id]->name . ', ' . $analysis[$analysis_id]->sourcename . ' (' . $analysis[$analysis_id]->program . ', ' . $analysis[$analysis_id]->programversion . ')';
$analysis_url = preg_replace(
"/[^A-Za-z0-9 ]/",
'',
$analysis_url
); // remove all non-alphanumeric charaters
$analysis_url = preg_replace(
"/\s/",
'-',
$analysis_url
); // replace ' ' with '-'
$analysis_url = 'content/' . strtolower($analysis_url);
}
// get treatment
Expand All @@ -147,7 +171,7 @@ function generate_heatmap_values() {
'signal' => (float) $feature->signal,
'description' => $feature->description,
'quantification_name' => $treatment,
'analysis_url' => $analysis_url
'analysis_url' => $analysis_url,
);
}
}
Expand Down Expand Up @@ -208,7 +232,7 @@ function generate_heatmap_values() {
return array(
'heatmap_data' => $heatmap_data,
'bottom_margin' => $bottom_margin,
'left_margin' => $left_margin
'left_margin' => $left_margin,
);
}

Expand Down
2 changes: 1 addition & 1 deletion includes/tripal_analysis_expression.chado_node.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ function tripal_analysis_expression_node_insert($node) {
case 'chado_analysis_expression':

// Find the a analysis_expression and add details.
$analysis_expression_id = chado_get_id_from_nid('analysis', $node->nid, 'chado.analysis');
$analysis_expression_id = chado_get_id_from_nid('analysis', $node->nid);
$values = array('analysis_id' => $analysis_expression_id);
$analysis_expression = chado_generate_var('analysis', $values);
$node->analysis_expression = $analysis_expression;
Expand Down
13 changes: 13 additions & 0 deletions js/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function($) {
Drupal.behaviors.tripal_analysis_expression_example = {
attach: function (context, settings) {
var example = 'Fraxinus_pennsylvanica_120313_comp59663_c0_seq1, Fraxinus_pennsylvanica_120313_comp59663_c0_seq2, Fraxinus_pennsylvanica_120313_comp56723_c0_seq1, Fraxinus_pennsylvanica_120313_comp60325_c0_seq16, Fraxinus_pennsylvanica_120313_comp61194_c0_seq4, Fraxinus_pennsylvanica_120313_comp61194_c0_seq5, Fraxinus_pennsylvanica_120313_comp61194_c0_seq8, Fraxinus_pennsylvanica_120313_comp61194_c0_seq6';
$('#edit-example-button').click(function(e) {
e.preventDefault()
$(this).val('Creating example heat map. Please wait...')
$('#edit-heatmap-feature-uniquename').val(example)
$(this).parents('form').submit()
})
}
}
})(jQuery);
1 change: 1 addition & 0 deletions tripal_analysis_expression.module
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ function tripal_analysis_expression_block_view($delta = ''){
case 'input_features':
$block['subject'] = t('Feature Expression');
$block['content'] = drupal_get_form('feature_heatmap_form');
drupal_add_js(drupal_get_path('module', 'tripal_analysis_expression') . '/js/example.js');
break;
case 'heatmap_features':
$heatmap = generate_heatmap_values();
Expand Down

0 comments on commit 82d58a4

Please sign in to comment.