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)

Returns the marked up fasta sequence for the described feature

Parameters

$sequence:

$parts:

$defline:

1 call to tripal_feature_color_sequence()
tripal_feature_load_featureloc_sequences in legacy/tripal_feature/theme/tripal_feature.theme.inc
Get the sequence this feature is located on

File

legacy/tripal_feature/theme/tripal_feature.theme.inc, line 286

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.";


  // set the background color of the rows based on the type
  $pos = 0;
  $newseq .= "<pre class=\"tripal_feature-sequence\">";
  $newseq .= ">$defline<br>";

  // iterate through the parts. They should be in order.
  $starts = array(); // an array holding all of the children starting locations
  $ends = array(); // an array holding all of the children's ending locations
  $seqcount = 0;
  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'];
      $starts[$start][] = $type;
    }

    // next, 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');

    // iterate through the types in order that then end and create a
    // span for it.
    foreach ($types as $type) {
      $end = $type['end'];
      $ends[$end][] = $type;
    }
  }

  // iterate through each nucleotide in the sequence, add a new line very
  // 50 characters and add the spans as we encounter them
  for ($i = 0; $i < strlen($sequence); $i++) {

    // if we are at and end of a span then close it
    if (array_key_exists($i, $ends)) {
      foreach ($ends[$i] as $index => $type) {
        $newseq .= "</span>";
      }
    }

    // if we are at and end of a span then close it
    if (array_key_exists($i, $starts)) {
      foreach ($starts[$i] as $index => $type) {
        $class = "tripal_feature-featureloc_sequence-" . $type;
        $newseq .= "<span class=\"$class\">";
      }
    }

    $newseq .= $sequence{$i};
    $seqcount++;
    if ($seqcount % 50 == 0) {
      $newseq .= "\n";
    }
  }

  $newseq .= "</pre>";
  return $newseq;
}