function tripal_feature_seq_extract_download

2.x tripal_feature.seq_extract.inc tripal_feature_seq_extract_download()

The page allowing users to download feature sequences

Related topics

1 string reference to 'tripal_feature_seq_extract_download'
tripal_feature_menu in tripal_feature/tripal_feature.module
Implements hook_menu().

File

tripal_feature/includes/tripal_feature.seq_extract.inc, line 12
Interface for downloading feature sequences

Code

function tripal_feature_seq_extract_download() {

  if (!array_key_exists('tripal_feature_seq_extract', $_SESSION)) {
    drupal_goto('find/sequences');
  }

  $genus = $_SESSION['tripal_feature_seq_extract']['genus'];
  $species = $_SESSION['tripal_feature_seq_extract']['species'];
  $analysis = $_SESSION['tripal_feature_seq_extract']['analysis'];
  $ftype = $_SESSION['tripal_feature_seq_extract']['ftype'];
  $fnames = $_SESSION['tripal_feature_seq_extract']['fnames'];
  $upstream = $_SESSION['tripal_feature_seq_extract']['upstream'];
  $downstream = $_SESSION['tripal_feature_seq_extract']['downstream'];
  $format = $_SESSION['tripal_feature_seq_extract']['format'];
  $use_parent = $_SESSION['tripal_feature_seq_extract']['use_parent'];
  $aggregate = $_SESSION['tripal_feature_seq_extract']['aggregate'];
  $agg_types = $_SESSION['tripal_feature_seq_extract']['agg_types'];

  // Split the sub features and remove any surrounding white space
  $agg_types = preg_split("/[\n|,]/", $agg_types);
  for ($i = 0; $i < count($agg_types); $i++) {
    $agg_types[$i] = trim($agg_types[$i]);
  }



  header('Content-Type: text; utf-8');
  if ($ftype == 'polypeptide') {
    header('Content-Disposition: attachment; filename="sequences.fna"');
  }
  else {
    header('Content-Disposition: attachment; filename="sequences.fnn"');
  }

  $seqs = tripal_get_bulk_feature_sequences(array(
    'genus' => $genus,
    'species' => $species,
    'analysis_name' => $analysis,
    'type' => $ftype,
    'feature_name' => $fnames['items_array'],
    'upstream' => $upstream,
    'downstream' => $downstream,
    'output_format' => $format,
    'derive_from_parent' => $use_parent,
    'aggregate' => $aggregate,
    'sub_feature_types' => $agg_types,
    'width' => 60
  ));

  if (count($seqs) == 0) {
    print ">No sequences found that match the criteria.";
  }

  foreach ($seqs as $seq) {
    print ">" . $seq['defline'] . "\r\n";
    print $seq['residues'] . "\r\n";
  }
}