class TripalNucFASTADownloader

Hierarchy

Expanded class hierarchy of TripalNucFASTADownloader

1 string reference to 'TripalNucFASTADownloader'
data__sequence.inc in tripal_chado/includes/TripalFields/data__sequence/data__sequence.inc

File

tripal/includes/TripalFieldDownloaders/TripalNucFASTADownloader.inc, line 3

View source
class TripalNucFASTADownloader extends TripalFieldDownloader {

  /**
   * Sets the label shown to the user describing this formatter.  It
   * should be a short identifier. Use the $full_label for a more
   * descriptive label.
   */
  static public $label = 'FASTA';

  /**
   * A more verbose label that better describes the formatter.
   */
  static public $full_label = 'Nucleotide FASTA';

  /**
   * Indicates the default extension for the outputfile.
   */
  static public $default_extension = 'fna';

  /**
   * @see TripalFieldDownloader::format()
   */
  protected function formatEntity($entity) {
    $lines = array();
    $site = !property_exists($entity, 'site_id') ? 'local' : $entity->site_id;
    $bundle_name = $entity->bundle;

    // Holds the list of sequence identifiers that will be used to build the
    // definition line.
    $identifiers = array(
      'identifier' => '',
      'name' => '',
      'accession' => '',
    );
    // Holds the list of non identifiers that will be used in the definitino
    // line.
    $others = array();
    // Holds the sequence string for the FASTA item.
    $residues = '';

    // Iterate through all of the fields and build the definition line and
    // the sequence string.
    foreach ($this->fields[$site][$bundle_name] as $field_id => $info) {
      $field = $info['field'];
      $instance = $info['instance'];
      $field_name = $field['field_name'];
      $accession = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];

      // If this field really is not attched to the entity then skip it.
      if (!property_exists($entity, $field_name)) {
        continue;
      }

      // If we only have one element then this is good.
      if (count($entity->{$field_name}['und']) == 1) {

        $value = $entity->{$field_name}['und'][0]['value'];

        // Add in the unique identifier for this sequence to the defline.
        if ($accession == 'data:0842') {
          $identifiers['identifier'] = $value;
        }
        // Add in the non-unique name for this sequence to the defline.
        else if ($accession == 'schema:name') {
          $identifiers['name'] = $value;
        }
        // Add in the local site accession for this sequence to the defline.
        else if ($accession == 'data:2091') {
          $identifiers['accession'] = $value;
        }
        // Add in the sequence coordinataes to the defline.
        else if ($accession == 'data:2012') {
          $others[$instance['label']] = $value["data:3002"] . ':' . $value["local:fmin"] . '-' . $value["local:fmax"] . $value["data:0853"];
        }
        // Get the nuclotide sequence.
        else if ($accession == 'data:2044') {
          $residues = $entity->{$field_name}['und'][0]['value'];
        }
        // Skip the protein sequence if it exists.
        else if ($accession == 'data:2976') {
          // do nothing.
        }
        // Add in the organism.
        else if ($accession == 'OBI:0100026') {
          //$others[$instance['label']] = strip_tags($value['rdfs:label']);
        }
        // All other fields add them to the others list.
        else {
          if (!is_array($value)) {
            $others[$instance['label']] = $value;
          }
          else {
            // TODO: What to do with fields that are arrays?
          }
        }
      }
      else {
        // TODO: What to do with fields that have multiple values?
      }
    }

    // First add the definition line.
    if (count(array_keys($identifiers)) == 0) {
      $defline = ">Unknown feature identifier. The data collection must have a name or accession field";
      $lines[] = $defline;
    }
    else {
      $defline = ">";
      $defline .= $identifiers['identifier'] ? $identifiers['identifier'] . ' ' : '';
      $defline .= $identifiers['name'] ? $identifiers['name'] . ' ' : '';
      $defline .= $identifiers['accession'] ? $identifiers['accession'] . ' ' : '';

      foreach ($others as $k => $v) {
        if ($v) {
          // If the value has non alpha-numeric characters then wrap it in
          // quotes.
          if (preg_match('/[^\w]/', $v)) {
            $defline .= $k . ':"' . $v . '"; ';
          }
          else {
            $defline .= $k . ':' . $v . '; ';
          }
        }
      }
      $lines[] = $defline;
    }

    // Now add the residues.
    if ($residues) {
      $sequence = explode('|', wordwrap($residues, 50, "|", TRUE));
      foreach ($sequence as $line) {
        $lines[] = $line;
      }
    }
    return $lines;
  }

  /**
   * @see TripalFieldDownloader::getHeader()
   */
  protected function getHeader() {

  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
TripalFieldDownloader::$collection protected property The data collection assigned to this downloader.
TripalFieldDownloader::$collection_bundles protected property An array of collection_bundle records for the content types that belong to this data collection.
TripalFieldDownloader::$collection_id protected property The collection ID
TripalFieldDownloader::$fh protected property The file handle for an opeend file using during writing.
TripalFieldDownloader::$fields protected property A list of field and instance items, indexed first by site_id with 'local' being the key for local fields and the numeric site_id for remote fields. The second-levle key is the bundle_name and the the field_id. Below the field_id are the…
TripalFieldDownloader::$fields2terms protected property An array that associates a field ID with a term.
TripalFieldDownloader::$outfile protected property The output file URI.
TripalFieldDownloader::$printable_fields protected property An array of printable fields. Because fields can come from multiple bundles and those bundles can be from multiple sites, it is possible that 1) two bundles use the same field and we want to conslidate to a single printable field; and 2) that a…
TripalFieldDownloader::$remote_entity protected property The remote site json data returned for the entity
TripalFieldDownloader::delete public function Removes the downloadable file.
TripalFieldDownloader::download public function Setups a download stream for the file.
TripalFieldDownloader::getURL public function Retrieves the URL for the downloadable file.
TripalFieldDownloader::isFieldSupported public function Inidcates if a given field is supported by this Downloader class.
TripalFieldDownloader::setFields protected function Sets the fields array
TripalFieldDownloader::setFields2Terms protected function Sets the fields2term array.
TripalFieldDownloader::setLocalFields private function A helper function for the setFields() function.
TripalFieldDownloader::setPrintableFields protected function Conslidates all the fields into a single list of accession numbers.
TripalFieldDownloader::setRemoteFields private function A helper function for the setFields() function.
TripalFieldDownloader::write public function Creates the downloadable file.
TripalFieldDownloader::writeDone public function Closes the output file once writing of all entities is completed.
TripalFieldDownloader::writeEntity public function Write a single entity to the file.
TripalFieldDownloader::writeInit public function
TripalFieldDownloader::__construct public function Constructs a new instance of the TripalFieldDownloader class.
TripalNucFASTADownloader::$default_extension static public property Indicates the default extension for the outputfile. Overrides TripalFieldDownloader::$default_extension
TripalNucFASTADownloader::$full_label static public property A more verbose label that better describes the formatter. Overrides TripalFieldDownloader::$full_label
TripalNucFASTADownloader::$label static public property Sets the label shown to the user describing this formatter. It should be a short identifier. Use the $full_label for a more descriptive label. Overrides TripalFieldDownloader::$label
TripalNucFASTADownloader::formatEntity protected function Overrides TripalFieldDownloader::formatEntity
TripalNucFASTADownloader::getHeader protected function Overrides TripalFieldDownloader::getHeader