Skip to content

Commit

Permalink
Fix HTML issue
Browse files Browse the repository at this point in the history
  • Loading branch information
almasaeed2010 committed Apr 26, 2019
1 parent dcd252a commit 7110b49
Showing 1 changed file with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ class format__blast_results_formatter extends ChadoFieldFormatter {
public static $default_label = 'BLAST Results';

// The list of field types for which this formatter is appropriate.
public static $field_types = array('format__blast_results');
public static $field_types = ['format__blast_results'];

/**
* @see TripalFieldFormatter::view()
*/
public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {

if (count($items) == 0 or (count($items) == 1 and empty($items[0]['value']))) {
$element[0] = array(
$element[0] = [
'#type' => 'markup',
'#markup' => 'There are no blast results.',
);
];
return;
}

$element[0]['preamble'] = ['#markup' => "<p>Click a tab below to view blast alignments.</p>"];
$element[0]['preamble'] = ['#markup' => "<p>Click a tab below to view blast alignments.</p>"];

drupal_add_js("https://cdn.rawgit.com/calipho-sib/feature-viewer/v1.0.4/dist/feature-viewer.bundle.js", [
'type' => 'external',
Expand All @@ -40,7 +40,7 @@ class format__blast_results_formatter extends ChadoFieldFormatter {
$num_results_per_page = 10000;
$feature_pager_id = 15; // increment by 1 for each database
$i = 0;
$list_items = array();
$list_items = [];
$total = count($items);

foreach ($items as $delta => $item) {
Expand All @@ -49,21 +49,21 @@ class format__blast_results_formatter extends ChadoFieldFormatter {
}
$blast_result = $item['parsed'];

$hits_array = $blast_result->hits_array;
$db = $blast_result->db;
$analysis = $blast_result->analysis;
$pager_id = $feature_pager_id + $i;
$hits_array = $blast_result->hits_array;
$db = $blast_result->db;
$analysis = $blast_result->analysis;
$pager_id = $feature_pager_id + $i;
$total_records = count($hits_array);

if(empty($db->name)) {
if (empty($db->name)) {
$db->name = "Database not found";
}

$current_page_num = pager_default_initialize($total_records, $num_results_per_page, $pager_id);
$offset = $num_results_per_page * $current_page_num;

// add this blast report to the list of available reports
$result_name = "BLAST of " . $feature->name . " vs. " . $db->name . ' (' . preg_replace('/(.*)\s.*/','\1', $analysis->timeexecuted) . ')';
$result_name = "BLAST of " . $feature->name . " vs. " . $db->name . ' (' . preg_replace('/(.*)\s.*/', '\1', $analysis->timeexecuted) . ')';
$list_items[] = "<a href=\"#analysis-" . $analysis->analysis_id . "\">$result_name</a>";

$analysis_link = $analysis->name;
Expand Down Expand Up @@ -91,20 +91,22 @@ class format__blast_results_formatter extends ChadoFieldFormatter {

$content = '
<p>
Performed on: ' . preg_replace("/^(\d+-\d+-\d+) .*/", "$1", $analysis->timeexecuted) . '
Performed on: ' . preg_replace("/^(\d+-\d+-\d+) .*/", "$1", $analysis->timeexecuted) . '
<br>Details: ' . $analysis_link . '
<br>Display provided by the ' . l('neXtProt Feature Viewer' , 'https://github.com/calipho-sib/feature-viewer') . '
<br>Display provided by the ' . l('neXtProt Feature Viewer', 'https://github.com/calipho-sib/feature-viewer') . '
<div
id="features_vis-' . $analysis->analysis_id . '"
class="blast-alignment-viewer"
analysis_id="' . $analysis->analysis_id . '" residues="' . $feature->residues . '"
analysis_id="' . $analysis->analysis_id . '"
residues="' . $feature->residues . '"
width="' . variable_get('tripal_blast_results_viewer_size', 500) . 'px"></div>
<br><a id="tripal-analysis-blast-table-link-' . $analysis->analysis_id . '" class="tripal-analysis-blast-table-link" href="javascript:void(0)">Show Results Table</a>
</p>
';

$element[0][$i]['content'] = ['#markup' => $content];
$headers = array('Match Name', 'Summary');
$rows = array();
$headers = ['Match Name', 'Summary'];
$rows = [];

$content = '';

Expand All @@ -114,7 +116,7 @@ class format__blast_results_formatter extends ChadoFieldFormatter {
$hit = $hits_array[$j];
$hit_name = $hit['hit_name'];
if (array_key_exists('hit_url', $hit)) {
$hit_name = l($hit_name, $hit['hit_url'], array('attributes' => array('target' => '_blank')));
$hit_name = l($hit_name, $hit['hit_url'], ['attributes' => ['target' => '_blank']]);
}

$description = substr($hit['description'], 0, 150);
Expand All @@ -133,33 +135,33 @@ class format__blast_results_formatter extends ChadoFieldFormatter {
$hsps_array = $hit['hsp'];

$content .= '
<div class="tripal-analysis-blast-info-hsp-desc" id="hsp-desc-' . $analysis->analysis_id . '-' . $j . '">
<div class="hsp-desc-close"><a href="javascript:void(0)" onclick="this.hide()">[Close]</a></div>
<div class="tripal-analysis-blast-info-hsp-desc" id="hsp-desc-' . $analysis->analysis_id . '-' . $j . '">
<div class="hsp-desc-close"><a href="javascript:void(0)">[Close]</a></div>
<strong>BLAST of ' . $feature->name . ' vs. ' . $db->name . '</strong>
<br>Match Name: ' . $hit_name . '
<br>Description: ' . $hit['description'] . '<br>';
foreach ($hsps_array AS $hsp) {
$content .= '
<br><b>HSP ' . $hsp['hsp_num'] . '</b> Score: ' . $hsp['bit_score'] . ' bits (' . $hsp['score'] . '), Expect = ' . sprintf('%.3e', floatval($hsp['evalue'])) . '<br>Identity = ' . sprintf("%d/%d (%.2f%%)", $hsp['identity'], $hsp['align_len'], $hsp['identity']/$hsp['align_len']*100) . ', Postives = ' . sprintf("%d/%d (%.2f%%)", $hsp['positive'], $hsp['align_len'], $hsp['positive']/$hsp['align_len']*100) . ', Query Frame = ' . $hsp['query_frame'] . '
<br><b>HSP ' . $hsp['hsp_num'] . '</b> Score: ' . $hsp['bit_score'] . ' bits (' . $hsp['score'] . '), Expect = ' . sprintf('%.3e', floatval($hsp['evalue'])) . '<br>Identity = ' . sprintf("%d/%d (%.2f%%)", $hsp['identity'], $hsp['align_len'], $hsp['identity'] / $hsp['align_len'] * 100) . ', Postives = ' . sprintf("%d/%d (%.2f%%)", $hsp['positive'], $hsp['align_len'], $hsp['positive'] / $hsp['align_len'] * 100) . ', Query Frame = ' . $hsp['query_frame'] . '
<pre class="blast_align">' . "\n" .
'Query: ' . sprintf("%8d", $hsp['query_from']) . ' ' . $hsp['qseq'] . ' ' . sprintf("%d", $hsp['query_to']) . "\n" .
' ' . $hsp['midline'] . "\n" .
'Sbjct: ' . sprintf("%8d", $hsp['hit_from']) . ' ' . $hsp['hseq'] . ' ' . sprintf("%d",$hsp['hit_to']) . '
'Query: ' . sprintf("%8d", $hsp['query_from']) . ' ' . $hsp['qseq'] . ' ' . sprintf("%d", $hsp['query_to']) . "\n" .
' ' . $hsp['midline'] . "\n" .
'Sbjct: ' . sprintf("%8d", $hsp['hit_from']) . ' ' . $hsp['hseq'] . ' ' . sprintf("%d", $hsp['hit_to']) . '
</pre>';


// Get the start/stop and description info for the feature viewer.
$feature_viewer_data[] = array(
$feature_viewer_data[] = [
'x' => intval($hsp['query_from']),
'y' => intval($hsp['query_to']),
'id' => 'tripal-analysis-blast-hsp-' . $analysis->analysis_id . '-' . $j,
'description' => 'E-value: ' . sprintf('%.2e', floatval($hsp['evalue'])) . ', PID: ' . $hit['percent_identity']
);
'id' => 'tripal-analysis-blast-hsp-' . $analysis->analysis_id . '-' . $j,
'description' => 'E-value: ' . sprintf('%.2e', floatval($hsp['evalue'])) . ', PID: ' . $hit['percent_identity'],
];
}
// End the HSP div.
$content .= '</div>';

$element[0][$i]['Blast_description'] = ['#markup'=> $content];
$element[0][$i]['Blast_description'] = ['#markup' => $content];

$rows[] = [
'data' => [
Expand All @@ -169,7 +171,7 @@ class format__blast_results_formatter extends ChadoFieldFormatter {
'<strong>Description</strong>: <span title="' . $hit['description'] . '">' . $description . '</span> ' .
// add the [more] link at the end of the row. Javascript is used
// to display this record
'<a href="javascript:void(0);" id="hsp-link-' . $analysis->analysis_id . '-' . $j . '" class="tripal-analysis-blast-info-hsp-link">[more]</a>',
'<a href="javascript:void(0);" id="hsp-link-' . $analysis->analysis_id . '-' . $j . '" class="tripal-analysis-blast-info-hsp-link">[more]</a>',
],
// Add data as attributes. These will be used for adding the hit
// to the feature viewer.
Expand Down Expand Up @@ -213,12 +215,8 @@ class format__blast_results_formatter extends ChadoFieldFormatter {
]);

$themed_table .= $this->ajaxifyPager($pager, $entity);
// End the paragraph for this item in the accordion.
$themed_table .= '</p>';
// End the div for this item in the accordion.
$themed_table .= '</div>';

$element[0][$i]['table'] = ['#markup'=> $themed_table];
$element[0][$i]['table'] = ['#markup' => $themed_table];

$i++;
}
Expand Down

0 comments on commit 7110b49

Please sign in to comment.