function tripal_feature_color_sequence
2.x tripal_feature.theme.inc | tripal_feature_color_sequence($sequence, $parts, $defline) |
3.x tripal_feature.theme.inc | tripal_feature_color_sequence($sequence, $parts, $defline) |
1.x tripal_feature.module | tripal_feature_color_sequence($sequence, $parts, $defline) |
Related topics
1 call to tripal_feature_color_sequence()
- tripal_feature_load_featureloc_sequences in tripal_feature/
tripal_feature.module
File
- tripal_feature/
tripal_feature.module, line 1718 - @todo Add file header description
Code
function tripal_feature_color_sequence($sequence, $parts, $defline) {
$types = array();
// first get the list of types so we can create a color legend
foreach ($parts as $index => $t) {
foreach ($t as $type_name => $details) {
$types[$type_name] = 1;
}
}
$newseq .= "<div id=\"tripal_feature-featureloc_sequence-legend\">Legend: ";
foreach ($types as $type_name => $present) {
$newseq .= "<span id=\"tripal_feature-legend-$type_name\" class=\"tripal_feature-legend-item tripal_feature-featureloc_sequence-$type_name\" script=\"\">$type_name</span>";
}
$newseq .= "</div>Hold the cursor over a type above to highlight its positions in the sequence below. The colors in the sequence below merge when types overlap.";
// set the background color of the rows based on the type
$pos = 0;
$newseq .= "<pre id=\"tripal_feature-featureloc_sequence\">";
$newseq .= ">$defline\n";
// iterate through the parts. They should be in order.
$ends = array();
foreach ($parts as $index => $types) {
// get the start for this part. All types in this part start at the
// same position so we only need the first record
foreach ($types as $type => $child) {
$start = $child['start'];
break;
}
// add in the sequence up to the start of this part
for ($i = $pos; $i < $start; $i++) {
$newseq .= $sequence{$pos};
$seqcount++;
if ($seqcount % 50 == 0) {
$newseq .= "\n";
}
if (array_key_exists($pos, $ends)) {
foreach ($ends[$pos] as $end) {
$newseq .= "</span>";
}
}
$pos++;
}
// we want to sort the parts by their end. We want the span tag to
// to be added in the order the parts end.
usort($types, 'tripal_feature_sort_rel_parts_by_end');
// now add the child span for all types that start at this position
foreach ($types as $type) {
$class = "tripal_feature-featureloc_sequence-" . $type['type'];
$newseq .= "<span class=\"$class\">";
// add the end position
$end = $type['end'];
$ends[$end][] = $end;
}
}
// add in rest of the sequence
for ($i = $pos; $i <= strlen($sequence); $i++) {
$newseq .= $sequence{$pos};
$seqcount++;
if ($seqcount % 50 == 0) {
$newseq .= "\n";
}
if (array_key_exists($pos, $ends)) {
foreach ($ends[$pos] as $end) {
$newseq .= "</span>";
}
}
$pos++;
}
$newseq .= "</pre>";
return $newseq;
}