function tripal_get_bulk_feature_sequences

2.x tripal_feature.api.inc tripal_get_bulk_feature_sequences($options)

Parameters

$options: An associative array of options for selecting a feature. Valid keys include:

  • org_commonname: The common name of the organism for which sequences should be retrieved
  • genus: The genus of the organism for which sequences should be retrieved
  • species: The species of the organism for which sequences should be retrieved
  • analysis_name: The name of an analysis to which sequences belong. Only those that are associated with the analysis will be retrieved.
  • type: The type of feature (a sequence ontology term).
  • feature_name: the name of the feature. Can be an array of feature names.
  • feature_uname: the uniquename of the feature. Can be an array of feature unique names.
  • upstream: An integer specifing the number of upstream bases to include in the output
  • downstream: An integer specifying the number of downstream bases to include in the output.
  • derive_from_parent: Set to '1' if the sequence should be obtained from the parent to which this feature is aligned.
  • aggregate: Set to '1' if the sequence should only contain sub features, excluding intro sub feature sequence. For example, set this option to obtain just the coding sequence of an mRNA.
  • sub_feature_types: Only include sub features (or child features) of the types provided in the array
  • relationship_type: If a relationship name is provided (e.g. sequence_of) then any sequences that are in relationships of this type with matched sequences are also included
  • relationship_part: If a relationship is provided in the preceeding argument then the rel_part must be either 'object' or 'subject' to indicate which side of the relationship the matched features belong
  • width: Indicate the number of bases to use per line. A new line will be added after the specified number of bases on each line.
  • is_html: Set to '1' if the sequence is meant to be displayed on a web page. This will cause a <br> tag to separate lines of the FASTA sequence.

Return value

Returns an array of sequences. The sequences will be in an array with the following keys for each sequence: 'types' => an array of feature types that were used to derive the sequence (e.g. from an aggregated sequence) 'upstream' => the number of upstream bases in the sequence 'downstream' => the number of downstream bases in the sequence 'defline' => the definintion line used to create a FASTA sequence 'residues' => the residues 'featureloc_id' => the featureloc_id if from an alignment

Related topics

2 calls to tripal_get_bulk_feature_sequences()
drush_tripal_feature_tripal_get_sequence in tripal_feature/tripal_feature.drush.inc
Retrieves the sequence of the indicated features
tripal_feature_seq_extract_download in tripal_feature/includes/tripal_feature.seq_extract.inc
The page allowing users to download feature sequences

File

tripal_feature/api/tripal_feature.api.inc, line 536
Provides an application programming interface (API) for working with features

Code

function tripal_get_bulk_feature_sequences($options) {

  // default values for building the sequence
  $org_commonname = array_key_exists('org_commonname', $options) ? $options['org_commonname'] : '';
  $genus = array_key_exists('genus', $options) ? $options['genus'] : '';
  $species = array_key_exists('species', $options) ? $options['species'] : '';
  $analysis_name = array_key_exists('analysis_name', $options) ? $options['analysis_name'] : '';
  $type = array_key_exists('type', $options) ? $options['type'] : '';
  $feature_name = array_key_exists('feature_name', $options) ? $options['feature_name'] : '';
  $feature_uname = array_key_exists('feature_uname', $options) ? $options['feature_uname'] : '';
  $derive_from_parent = array_key_exists('derive_from_parent', $options) ? $options['derive_from_parent'] : 0;
  $aggregate = array_key_exists('aggregate', $options) ? $options['aggregate'] : 0;
  $sub_features = array_key_exists('sub_feature_types', $options) ? $options['sub_feature_types'] : array();
  $relationship = array_key_exists('relationship_type', $options) ? $options['relationship_type'] : '';
  $rel_part = array_key_exists('relationship_part', $options) ? $options['relationship_part'] : '';
  $num_bases_per_line = array_key_exists('width', $options) ? $options['width'] : 50;
  $upstream = array_key_exists('upstream', $options) ? $options['upstream'] : 0;
  $downstream = array_key_exists('downstream', $options) ? $options['downstream'] : 0;

  if (!$type and !$feature_name and !$genus) {
    print "Please provide a type, feature name or genus\n";
    return;
  }

  // get the list of features
  $vars = array();
  $sql = "
    SELECT DISTINCT F.feature_id, F.name, F.uniquename,
      O.genus, O.species, CVT.name as feature_type
    FROM {feature} F
      INNER JOIN {organism} O on O.organism_id = F.organism_id
      INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
  ";
  if ($analysis_name) {
    $sql .= "
      INNER JOIN {analysisfeature} AF on AF.feature_id = F.feature_id
      INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id
    ";
  }
  $sql .= "WHERE (1=1) ";
  if ($org_commonname) {
    $sql .= "AND O.common_name = :common_name ";
    $vars[':common_name'] = $org_commonname;
  }
  if ($genus) {
    $sql .= "AND O.genus = :genus ";
    $vars[':genus'] = $genus;
  }
  if ($species) {
    $sql .= "AND O.species = :species ";
    $vars[':species'] = $species;
  }
  if ($type) {
    $sql .= "AND CVT.name = :cvtname ";
    $vars[':cvtname'] = $type;
  }
  if ($feature_name) {
    if (is_array($feature_name)) {
      $sql .= "AND F.name IN (";
      foreach ($feature_name as $i => $fname) {
        $sql .= ":fname$i, ";
        $vars[":fname$i"] = $fname;
      }
      // remove the trailing comma and close the paren
      $sql = substr($sql, 0, -2) . ")";
    }
    else {
      $sql .= "AND F.name = :fname";
      $vars[':fname'] = $feature_name;
    }
  }
  if ($feature_uname) {
    if (is_array($feature_uname)) {
      $sql .= "AND F.uniquename IN (";
      foreach ($feature_uname as $i => $funame) {
        $sql .= ":funame$i, ";
        $vars[":funame$i"] = $funame;
      }
      // remove the trailing comma and close the paren
      $sql = substr($sql, 0, -2) . ")";
    }
    else {
      $sql .= "AND F.uniquename = :funame";
      $vars[':funame'] = $feature_uname;
    }
  }
  if ($analysis_name) {
    $sql .= "AND A.name = :aname";
    $vars[':aname'] = $analysis_name;
  }
  $num_bases_per_line = 50;
  $num_seqs = 0;
  $q = chado_query($sql, $vars);

  $sequences = array();
  while ($feature = $q->fetchObject()) {
    // get the sequences
    $seqs = tripal_get_feature_sequences(array('feature_id' => $feature->feature_id), $options);
    $sequences = array_merge($sequences, $seqs);
    $num_seqs++;
  }

  return $sequences;
}