feature;
// number of bases per line in FASTA format
$num_bases = 50; 
// we don't want to get the sequence for traditionally large types. They are
// too big,  bog down the web browser, take longer to load and it's not
// reasonable to print them on a page.
$residues ='';
if(strcmp($feature->type_id->name,'scaffold') !=0 and
   strcmp($feature->type_id->name,'chromosome') !=0 and
   strcmp($feature->type_id->name,'supercontig') !=0 and
   strcmp($feature->type_id->name,'pseudomolecule') !=0) {
  $feature = chado_expand_var($feature,'field','feature.residues');
  $residues = $feature->residues;
} 
// get the sequence derived from alignments
$feature = $variables['node']->feature;
$featureloc_sequences = $feature->featureloc_sequences;
if ($residues or count($featureloc_sequences) > 0) { 
  $sequences_html = '';  // a variable for holding all sequences HTML text
  $list_items = array(); // a list to be used for theming of content on this page
  
  // ADD IN RESIDUES FOR THIS FEATURE
  // add in the residues if they are present
  if ($residues) {
    $list_items[] = '' . $feature->type_id->name . ' sequence';
     
    // format the sequence to break every 50 residues
    $sequences_html .= '';
    $sequences_html .= '
';
    $sequences_html .= '
' . $feature->type_id->name . ' sequence
';
    $sequences_html .= '
';
    $sequences_html .= '>' . tripal_get_fasta_defline($feature, '', NULL, '', strlen($feature->residues)) . "\n";
    $sequences_html .= wordwrap($feature->residues, $num_bases, "
", TRUE);
    $sequences_html .= '';
    $sequences_html .= '
back to top';
    $sequences_html .= '
';
            $sequences_html .= '
protein sequence of ' . $protein->name . '
';
            $sequences_html .= '
';
            $sequences_html .= '>' . tripal_get_fasta_defline($protein, '', NULL, '', strlen($protein->residues)) . "\n";
            $sequences_html .= wordwrap($protein->residues, $num_bases, "
", TRUE);
            $sequences_html .= '';
            $sequences_html .= '
back to top';
            $sequences_html .= '
';
    $sequences_html .= '
coding sequence
';
    $sequences_html .= '
';
    $sequences_html .= wordwrap($coding_seq, $num_bases, "
", TRUE);
    $sequences_html .= '';
    $sequences_html .= '
back to top';
    $sequences_html .= '
';
      $sequences_html .= '
'. $feature->type_id->name . ' from alignment at  ' . $attrs['location'] .'
';
      $sequences_html .= $attrs['formatted_seq'];
      $sequences_html .= '
back to top';
      $sequences_html .= '
';
        $sequences_html .= '
Coding sequence (CDS) from alignment at  ' . $attrs['location'] . '
';
        $sequences_html .= '
';
        $sequences_html .= '>' . tripal_get_fasta_defline($feature, '', $attrs['featureloc'], 'CDS', $cds_sequence[0]['length']) . "
";
        $sequences_html .= $cds_sequence[0]['residues'];
        $sequences_html .= '';
        $sequences_html .= '
back to top';
        $sequences_html .= '
The following sequences are available for this feature:
 
  ';
  print theme_item_list(array(
    'items' => $list_items,
    'title' => '',
    'type' => 'ul',
    'attributes' => array(),
  ));
  $message = 'Administrators, sequences will appear on this page if:
    
For any feature type:
    
      - This feature has residues stored in the "residues" field of the feature table of Chado.
- This feature is aligned to another feature (e.g. scaffold, or chromosome). In this case, the
          sequence underlying the alignment will be shown.
For gene models:
    
      - This feature has a "polypeptide" (protein) feature associated via the "feature_relationship" table of Chado with a
          relationship of type "derives from" and the protein feature has residues. Typically, a protein
          is associated with an mRNA feature and protein sequences will appear on the mRNA page.
- This feature has one or more CDS features associated via the "feature_relationship" table of Chado with a
          relationship of type "part of". If the CDS features have residues then those will be concatenated
          and presented as a sequence. Typically, CDSs are associated with an mRNA feature and CDS sequences 
          will appear on the mRNA page.
- This feature is aligned to another feature (e.g. scaffold, or chromosome) and this feature has
          one or more CDS features associated.  The CDS sequenes underlying the alignment will be
          shown.
';
  print tripal_set_message($message, TRIPAL_INFO, array('return_html' => 1));
  
  // now print the sequences
  print $sequences_html;
}