Skip to content

Commit

Permalink
Merge pull request #302 from tripal/fix-301
Browse files Browse the repository at this point in the history
Fix issue #301
  • Loading branch information
almasaeed2010 authored Jun 12, 2019
2 parents ba4be2f + d1aa522 commit 4741e76
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions tripal_analysis_expression/includes/HeatMapGenerator.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class HeatMapGenerator {
class HeatMapGenerator{

/**
* GET feature names.
Expand All @@ -22,14 +22,15 @@ class HeatMapGenerator {
}

// Obtain unique names
$this->featureNames = array_map('trim', explode(',', $_GET['heatmap_feature_uniquename']));
$this->featureNames = array_map('trim',
explode(',', $_GET['heatmap_feature_uniquename']));
}

/**
* Generate heat map data.
*
* @throws \Exception
* @return object|bool
* @throws \Exception
*/
public function generate() {
if (count($this->featureNames) < 2) {
Expand All @@ -41,21 +42,31 @@ class HeatMapGenerator {
// Eager load biomaterial props
foreach ($expression->biomaterials as $analysis_id => $biomaterial) {
$this->biomaterialProps[$analysis_id] = [];
$this->loadBiomaterialProps($expression->biomaterials[$analysis_id], $analysis_id);
$this->loadBiomaterialProps($expression->biomaterials[$analysis_id],
$analysis_id);
}

// Set URLs
// The number of features is usually very small so looping directly here
// is not a big deal
foreach ($expression->features as $analysis_id => $features) {
foreach ($features as $feature_id => $feature) {
$expression->features[$analysis_id][$feature_id] = l($feature, 'bio_data/' . chado_get_record_entity_by_table('feature', $feature_id));
$expression->features[$analysis_id][$feature_id] = l($feature,
'bio_data/' . chado_get_record_entity_by_table('feature',
$feature_id));
}
}

foreach ($expression->biomaterials as $analysis_id => $biomaterials) {
foreach ($biomaterials as $biomaterial_id => $biomaterial) {
$expression->biomaterials[$analysis_id][$biomaterial_id]['name'] = l($biomaterial['name'], 'bio_data/' . chado_get_record_entity_by_table('biomaterial', $biomaterial_id));
$name = $this->trim($biomaterial['name']);
$expression->biomaterials[$analysis_id][$biomaterial_id]['name'] = l($name,
'bio_data/' . chado_get_record_entity_by_table('biomaterial',
$biomaterial_id), [
'attributes' => [
'title' => $biomaterial['name'],
],
]);
}
}

Expand All @@ -65,11 +76,25 @@ class HeatMapGenerator {
return $expression;
}

/**
* @param $str
* @param int $length
*
* @return string
*/
public function trim($str, $length = 10) {
if (strlen($str) > $length) {
return substr($str, 0, $length) . '...';
}

return $str;
}

/**
* Get features from the DB.
*
* @throws \Exception
* @return object
* @throws \Exception
*/
protected function getExpressionData() {
$sql = "SELECT ER.signal,
Expand Down Expand Up @@ -109,7 +134,8 @@ class HeatMapGenerator {
$biomaterials[$expression->analysis_id][$expression->biomaterial_id] = [
'name' => $expression->biomaterial_name,
'contact' => $expression->contact_name ?: 'Not Set',
'description' => wordwrap($expression->biomaterial_description, 75, '<br />'),
'description' => wordwrap($expression->biomaterial_description, 75,
'<br />'),
'props' => [],
];
$features[$expression->analysis_id][$expression->feature_id] = $expression->feature_uniquename;
Expand Down Expand Up @@ -156,7 +182,8 @@ class HeatMapGenerator {
INNER JOIN {biomaterialprop} BP ON B.biomaterial_id = BP.biomaterial_id
INNER JOIN {cvterm} CVT ON BP.type_id = CVT.cvterm_id
WHERE B.biomaterial_id IN (:ids)";
$props = chado_query($sql, [':ids' => array_keys($biomaterials)])->fetchAll();
$props = chado_query($sql,
[':ids' => array_keys($biomaterials)])->fetchAll();

foreach ($props as $prop) {
$biomaterials[$prop->biomaterial_id]['props'][$prop->name] = [
Expand Down

0 comments on commit 4741e76

Please sign in to comment.