Browse Source

Fixed leftover bugs from yesterdays changes. Fixed FASTA downloaders

Stephen Ficklin 7 years ago
parent
commit
76c58b2330

+ 3 - 3
tripal/api/tripal.fields.api.inc

@@ -237,7 +237,7 @@ function tripal_get_field_field_formatters($field, $instance) {
     foreach ($formatters as $class_name) {
       if (!array_key_exists($class_name, $downloaders)) {
         tripal_load_include_downloader_class($class_name);
-        $downloaders[$class_name] = $class_name::$label;
+        $downloaders[$class_name] = $class_name::$full_label;
       }
     }
   }
@@ -245,8 +245,8 @@ function tripal_get_field_field_formatters($field, $instance) {
     // For non TripalFields we'll assume TAB and CSV.
     tripal_load_include_downloader_class('TripalTabDownloader');
     tripal_load_include_downloader_class('TripalCSVDownloader');
-    $downloaders['TripalTabDownloader'] = TripalTabDownloader::$label;
-    $downloaders['TripalCSVDownloader'] = TripalCSVDownloader::$label;
+    $downloaders['TripalTabDownloader'] = TripalTabDownloader::$full_label;
+    $downloaders['TripalCSVDownloader'] = TripalCSVDownloader::$full_label;
   }
   return $downloaders;
 }

+ 1 - 0
tripal/includes/TripalEntityCollection.inc

@@ -365,6 +365,7 @@ class TripalEntityCollection {
         }
       }
     }
+    $this->downloaders = array_unique($this->downloaders);
     return $this->downloaders;
   }
 

+ 5 - 4
tripal/includes/TripalFieldDownloaders/TripalCSVDownloader.inc

@@ -33,6 +33,7 @@ class TripalCSVDownloader extends TripalFieldDownloader {
    */
   protected function formatEntity($entity) {
     $bundle_name = $entity->bundle;
+    $site = !property_exists($entity, 'site_id') ? 'local' : $entity->site_id;
     $row = array();
 
     // Iterate through all of the printable fields and add the value to
@@ -41,15 +42,15 @@ class TripalCSVDownloader extends TripalFieldDownloader {
 
       // If this field is not present for this entity then add an empty
       // element and move on.
-      if (!array_key_exists($accession, $this->fields2terms[$bundle_name]['by_accession'])) {
+      if (!array_key_exists($accession, $this->fields2terms[$site][$bundle_name]['by_accession'])) {
         $row[] = '';
         continue;
       }
 
       // Get the field from the class variables.
-      $field_id = $this->fields2terms[$bundle_name]['by_accession'][$accession];
-      $field = $this->fields[$bundle_name][$field_id]['field'];
-      $instance = $this->fields[$bundle_name][$field_id]['instance'];
+      $field_id = $this->fields2terms[$site][$bundle_name]['by_accession'][$accession];
+      $field = $this->fields[$site][$bundle_name][$field_id]['field'];
+      $instance = $this->fields[$site][$bundle_name][$field_id]['instance'];
       $field_name = $field['field_name'];
 
       // If we only have one item for this value then add it.

+ 67 - 52
tripal/includes/TripalFieldDownloaders/TripalFieldDownloader.inc

@@ -60,31 +60,37 @@ abstract class TripalFieldDownloader {
   protected $remote_entity = '';
 
   /**
-   * An array that associates a field ID with a term.  The key is the bundle
-   * name, followed by two subkeys: by_field and by_accession.  To lookup
-   * a field's term you use the 'by_field' subkey with the field_id as the next
-   * level.  To lookup the field ID for a term use the 'by_accession' subkey
-   * with the accession as the next level.  Below is an example of the structure
-   * of this array.
+   * An array that associates a field ID with a term.
+   *
+   * The first-level key is the site ID. For the local site this will be
+   * the word 'local' for all others it will be the numeric id.  The second
+   * level key is the bundle bundle name.  For local bundles this will
+   * always be bio_data_xxxx.  Third, are two subkeys: by_field and
+   * by_accession.  To lookup a field's term you use the 'by_field' subkey
+   * with the field_id as the next level.  To lookup the field ID for a term
+   * use the 'by_accession' subkey with the accession as the next level.  Below
+   * is an example of the structure of this array.
    *
    * @code
     Array (
-      [bio_data_7] => Array(
-        [by_field] => Array(
-          [56] => data:2091,
-          [57] => OBI:0100026,
-          [17] => schema:name,
-          [58] => data:2044,
-          [34] => data:0842,
-          [67] => schema:alternateName,
-        ),
-        [by_accession] => Array (
-          [data:2091] => 56,
-          [OBI:0100026] => 57,
-          [schema:name] => 17,
-          [data:2044] => 58,
-          [data:0842] => 34,
-          [schema:alternateName] => 67,
+      [local] => Array(
+        [bio_data_7] => Array(
+          [by_field] => Array(
+            [56] => data:2091,
+            [57] => OBI:0100026,
+            [17] => schema:name,
+            [58] => data:2044,
+            [34] => data:0842,
+            [67] => schema:alternateName,
+          ),
+          [by_accession] => Array (
+            [data:2091] => 56,
+            [OBI:0100026] => 57,
+            [schema:name] => 17,
+            [data:2044] => 58,
+            [data:0842] => 34,
+            [schema:alternateName] => 67,
+          ),
         ),
       ),
     )
@@ -94,9 +100,11 @@ abstract class TripalFieldDownloader {
 
 
   /**
-   * A list of field and instance items, indexed first by bundle_name and
-   * then by field_id and then by the keys 'field' or 'instance' where the
-   * value is the field or instance details respectively.
+   * 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 keys 'field' or 'instance' where the
+   * value of each is the field or instance details respectively.
    */
   protected $fields = array();
 
@@ -134,12 +142,11 @@ abstract class TripalFieldDownloader {
 
     // A data collection may have multiple bundles.  We'll need to get
     // them all and store them.
-    $this->collection_bundles = db_select('tripal_collection_bundle')
+    $collection_bundles = db_select('tripal_collection_bundle')
       ->fields('tripal_collection_bundle')
       ->condition('collection_id', $collection_id, '=')
-      ->execute()
-      ->fetchAll();
-    foreach ($this->collection_bundles as $collection_bundle) {
+      ->execute();
+    while ($collection_bundle = $collection_bundles->fetchObject()) {
       $collection_bundle->ids = unserialize($collection_bundle->ids);
       $collection_bundle->fields = unserialize($collection_bundle->fields);
       $this->collection_bundles[] = $collection_bundle;
@@ -240,7 +247,6 @@ abstract class TripalFieldDownloader {
 
       foreach ($entity_ids as $entity_id) {
 
-
         // if we have a site_id then we need to get the entity from the
         // remote service. Otherwise create the entity from the local system.
         if ($site_id) {
@@ -334,6 +340,7 @@ abstract class TripalFieldDownloader {
   protected function loadRemoteEntity($remote_id, $site_id, $bundle_name) {
 
     // Get the site documentation
+    $site = empty($site_id) ? 'local' : $site_id;
     $site_doc = $this->retrieveRemoteAPIDoc($site_id);
 
     // Get the remote entity and create the fake entity.
@@ -350,6 +357,7 @@ abstract class TripalFieldDownloader {
     $entity->id = $remote_id;
     $entity->type = 'TripalEntity';
     $entity->bundle = $bundle_name;
+    $entity->site_id = $site_id;
 
     // Get the context JSON for this remote entity, we'll use it to map
     // the properties to the correct fields.
@@ -360,15 +368,15 @@ abstract class TripalFieldDownloader {
     // Iterate through the fields that are printable and get those values
     // from the results.
     foreach ($this->printable_fields as $accession => $label) {
-      $field_id = $this->fields2terms[$bundle_name]['by_accession'][$accession];
+      $field_id = $this->fields2terms[$site][$bundle_name]['by_accession'][$accession];
 
       // If the field isn't part of this bundle then skip it.
       if (!$field_id) {
         continue;
       }
 
-      $field = $this->fields[$bundle_name][$field_id]['field'];
-      $instance = $this->fields[$bundle_name][$field_id]['instance'];
+      $field = $this->fields[$site][$bundle_name][$field_id]['field'];
+      $instance = $this->fields[$site][$bundle_name][$field_id]['instance'];
       $field_name = $field['field_name'];
       $accession = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];
 
@@ -435,6 +443,7 @@ abstract class TripalFieldDownloader {
   private function setLocalFields() {
     foreach ($this->collection_bundles as $collection_bundle) {
       $bundle_name = $collection_bundle->bundle_name;
+      $site = empty($collection_bundle->site_id) ? 'local' : $collection_bundle->site_id;
       // Skip remote fields.
       if ($collection_bundle->site_id) {
         continue;
@@ -442,8 +451,8 @@ abstract class TripalFieldDownloader {
       foreach ($collection_bundle->fields as $field_id) {
         $field = field_info_field_by_id($field_id);
         $instance = field_info_instance('TripalEntity', $field['field_name'], $bundle_name);
-        $this->fields[$bundle_name][$field_id]['field'] = $field;
-        $this->fields[$bundle_name][$field_id]['instance'] = $instance;
+        $this->fields[$site][$bundle_name][$field_id]['field'] = $field;
+        $this->fields[$site][$bundle_name][$field_id]['instance'] = $instance;
       }
     }
   }
@@ -461,6 +470,7 @@ abstract class TripalFieldDownloader {
         continue;
       }
 
+      $site = empty($site_id) ? 'local' : $site_id;
       $site_doc = $this->retrieveRemoteAPIDoc($collection_bundle->site_id);
 
       // Get the class that matches this bundle.
@@ -496,8 +506,8 @@ abstract class TripalFieldDownloader {
           'entity_type' => 'TripalEntity',
           'bundle_name' => $bundle_name,
         );
-        $this->fields[$bundle_name][$field_id]['field'] = $field;
-        $this->fields[$bundle_name][$field_id]['instance'] = $instance;
+        $this->fields[$site][$bundle_name][$field_id]['field'] = $field;
+        $this->fields[$site][$bundle_name][$field_id]['instance'] = $instance;
       }
     }
   }
@@ -538,12 +548,15 @@ abstract class TripalFieldDownloader {
    * to it's accession number.
    **/
   protected function setFields2Terms() {
-    foreach ($this->fields as $bundle_name => $bundle_fields) {
-      foreach ($bundle_fields as $field_id => $info) {
-        $instance = $info['instance'];
-        $accession = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];
-        $this->fields2terms[$bundle_name]['by_field'][$field_id] = $accession;
-        $this->fields2terms[$bundle_name]['by_accession'][$accession] = $field_id;
+
+    foreach ($this->fields as $site => $bundles) {
+      foreach ($bundles as $bundle_name => $bundle_fields) {
+        foreach ($bundle_fields as $field_id => $info) {
+          $instance = $info['instance'];
+          $accession = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];
+          $this->fields2terms[$site][$bundle_name]['by_field'][$field_id] = $accession;
+          $this->fields2terms[$site][$bundle_name]['by_accession'][$accession] = $field_id;
+        }
       }
     }
   }
@@ -557,15 +570,17 @@ abstract class TripalFieldDownloader {
    */
   protected function setPrintableFields() {
 
-    foreach ($this->fields as $bundle_name => $bundle_fields) {
-      foreach ($bundle_fields as $field_id => $info) {
-        $instance = $info['instance'];
-        $accession = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];
-        if (!array_key_exists($accession, $this->printable_fields)) {
-          // Only include fields that support this downloader type in
-          // or list of printable fields.
-          if ($this->isFieldSupported($field, $instance)) {
-            $this->printable_fields[$accession] = $instance['label'];
+    foreach ($this->fields as $site => $bundles) {
+      foreach ($bundles as $bundle_name => $bundle_fields) {
+        foreach ($bundle_fields as $field_id => $info) {
+          $instance = $info['instance'];
+          $accession = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];
+          if (!array_key_exists($accession, $this->printable_fields)) {
+            // Only include fields that support this downloader type in
+            // or list of printable fields.
+            if ($this->isFieldSupported($field, $instance)) {
+              $this->printable_fields[$accession] = $instance['label'];
+            }
           }
         }
       }

+ 90 - 67
tripal/includes/TripalFieldDownloaders/TripalNucFASTADownloader.inc

@@ -24,93 +24,116 @@ class TripalNucFASTADownloader extends TripalFieldDownloader {
    */
   protected function formatEntity($entity) {
     $lines = array();
+    $site = !property_exists($entity, 'site_id') ? 'local' : $entity->site_id;
+    $bundle_name = $entity->bundle;
 
-    // Get the list of all fields that have been attached to the entity
-    $instances = field_info_instances('TripalEntity', $entity->bundle);
-    $available_fields = array();
-    foreach ($instances as $field_name => $instance) {
-      if ($instance['field_name'] == 'entity_id') {
-        continue;
-      }
-      $available_fields[$instance['field_name']] = $instance;
-    }
-return array();
+    // 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 = '';
 
-    foreach ($this->fields as $field_id) {
-      $field = field_info_field_by_id($field_id);
+    // 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'];
-        // If the single element is not an array then this is good.
-        if (!is_array($value)) {
-
-          // We need to make sure we have some fields for the definition line.
-          // those may or may not have been included, so we should add them.
-          $defline = '>';
-          $found_identifier = FALSE;
-          if (property_exists($entity, 'data__identifier')) {
-            $found_identifier = TRUE;
-            $defline .= $entity->{'data__identifier'}['und'][0]['value'] . ' ';
-          }
-          if (property_exists($entity, 'schema__name')) {
-            $found_identifier = TRUE;
-            $defline .= $entity->{'schema__name'}['und'][0]['value'] . ' ';
-          }
-          if (property_exists($entity, 'data__accession')) {
-            $found_identifier = TRUE;
-            $defline .= $entity->{'data__accession'}['und'][0]['value'] . ' ';
-          }
-          if (!$found_identifier) {
-            $defline .= "Unknown feature identifier. Please add a name field to the data collection";
-          }
-          if (property_exists($entity, 'data__sequence_coordinates')) {
-            $location = strip_tags(drupal_render(field_view_field('TripalEntity', $entity, 'data__sequence_coordinates'))) . '; ';
-            $location = preg_replace('/\&nbsp\;/', ' ', $location);
-            $defline .= $location;
-          }
-          // Add to the defnition line values from any single valued fields.
-          foreach ($available_fields as $fname => $instance) {
-            if (count($entity->{$fname}['und']) == 1) {
-              if (!is_array($entity->{$fname}['und'][0]['value'])) {
-                // Skip the identifier fields and the residues fields.
-                if (!in_array($fname, array('data__identifier',
-                    'schema__name', 'data__protein_sequence', $field_name))) {
-                  $fvalue = $entity->{$fname}['und'][0]['value'];
-                  if ($fvalue) {
-                    $defline .= $instance['label'] . ': ' . $fvalue . '; ';
-                  }
-                }
-              }
-              else {
-                if (array_key_exists('rdfs:label', $entity->{$fname}['und'][0]['value'])) {
-                  $defline .= $instance['label'] . ': ' . strip_tags($entity->{$fname}['und'][0]['value']['rdfs:label']) . '; ';
-                }
-              }
-            }
-          }
-          $defline = rtrim($defline, '; ');
 
-          // Now add the residues.
-          $lines[] = $defline;
-          $residues = explode('|', wordwrap($value, 50, "|", TRUE));
-          foreach ($residues as $line) {
-            $lines[] = $line;
-          }
+        // 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 {
-          // TODO: What to do with fields that are arrays?
+          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;
   }
 

+ 90 - 66
tripal/includes/TripalFieldDownloaders/TripalProteinFASTADownloader.inc

@@ -22,92 +22,116 @@ class TripalProteinFASTADownloader extends TripalFieldDownloader {
    */
   protected function formatEntity($entity) {
     $lines = array();
+    $site = !property_exists($entity, 'site_id') ? 'local' : $entity->site_id;
+    $bundle_name = $entity->bundle;
 
-    // Get the list of all fields that have been attached to the entity
-    $instances = field_info_instances('TripalEntity', $entity->bundle);
-    $available_fields = array();
-    foreach ($instances as $field_name => $instance) {
-      if ($instance['field_name'] == 'entity_id') {
-        continue;
-      }
-      $available_fields[$instance['field_name']] = $instance;
-    }
+    // 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 = '';
 
-    foreach ($this->fields as $field_id) {
-      $field = field_info_field_by_id($field_id);
+    // 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'];
-        // If the single element is not an array then this is good.
-        if (!is_array($value)) {
 
-          // We need to make sure we have some fields for the definition line.
-          // those may or may not have been included, so we should add them.
-          $defline = '>';
-          $found_identifier = FALSE;
-          if (property_exists($entity, 'data__identifier')) {
-            $found_identifier = TRUE;
-            $defline .= $entity->{'data__identifier'}['und'][0]['value'] . ' ';
-          }
-          if (property_exists($entity, 'schema__name')) {
-            $found_identifier = TRUE;
-            $defline .= $entity->{'schema__name'}['und'][0]['value'] . ' ';
-          }
-          if (property_exists($entity, 'data__accession')) {
-            $found_identifier = TRUE;
-            $defline .= $entity->{'data__accession'}['und'][0]['value'] . ' ';
-          }
-          if (!$found_identifier) {
-            $defline .= "Unknown feature identifier. Please add a name field to the data collection";
-          }
-          if (property_exists($entity, 'data__sequence_coordinates')) {
-            $location = strip_tags(drupal_render(field_view_field('TripalEntity', $entity, 'data__sequence_coordinates'))) . '; ';
-            $location = preg_replace('/\&nbsp\;/', ' ', $location);
-            $defline .= $location;
-          }
-          // Add to the defnition line values from any single valued fields.
-          foreach ($available_fields as $fname => $instance) {
-            if (count($entity->{$fname}['und']) == 1) {
-              if (!is_array($entity->{$fname}['und'][0]['value'])) {
-                // Skip the identifier fields and the residues fields.
-                if (!in_array($fname, array('data__identifier',
-                  'schema__name', 'data__sequence', $field_name))) {
-                  $fvalue = $entity->{$fname}['und'][0]['value'];
-                  if ($fvalue) {
-                    $defline .= $instance['label'] . ': ' . $fvalue . '; ';
-                  }
-                }
-              }
-              else {
-                if (array_key_exists('rdfs:label', $entity->{$fname}['und'][0]['value'])) {
-                  $defline .= $instance['label'] . ': ' . strip_tags($entity->{$fname}['und'][0]['value']['rdfs:label']) . '; ';
-                }
-              }
-            }
-          }
-          $defline = rtrim($defline, '; ');
+        $value = $entity->{$field_name}['und'][0]['value'];
 
-          // Now add the residues.
-          $lines[] = $defline;
-          $residues = explode('|', wordwrap($value, 50, "|", TRUE));
-          foreach ($residues as $line) {
-            $lines[] = $line;
-          }
+        // 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"];
+        }
+        // Skip the nuclotide sequence.
+        else if ($accession == 'data:2044') {
+          // do nothing.
         }
+        // Get the protein sequence if it exists.
+        else if ($accession == 'data:2976') {
+          $residues = $entity->{$field_name}['und'][0]['value'];
+        }
+        // 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 {
-          // TODO: What to do with fields that are arrays?
+          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;
   }
 

+ 5 - 4
tripal/includes/TripalFieldDownloaders/TripalTabDownloader.inc

@@ -33,6 +33,7 @@ class TripalTabDownloader extends TripalFieldDownloader {
    */
    protected function formatEntity($entity) {
      $bundle_name = $entity->bundle;
+     $site = !property_exists($entity, 'site_id') ? 'local' : $entity->site_id;
      $row = array();
 
      // Iterate through all of the printable fields and add the value to
@@ -41,15 +42,15 @@ class TripalTabDownloader extends TripalFieldDownloader {
 
        // If this field is not present for this entity then add an empty
        // element and move on.
-       if (!array_key_exists($accession, $this->fields2terms[$bundle_name]['by_accession'])) {
+       if (!array_key_exists($accession, $this->fields2terms[$site][$bundle_name]['by_accession'])) {
          $row[] = '';
          continue;
        }
 
        // Get the field from the class variables.
-       $field_id = $this->fields2terms[$bundle_name]['by_accession'][$accession];
-       $field = $this->fields[$bundle_name][$field_id]['field'];
-       $instance = $this->fields[$bundle_name][$field_id]['instance'];
+       $field_id = $this->fields2terms[$site][$bundle_name]['by_accession'][$accession];
+       $field = $this->fields[$site][$bundle_name][$field_id]['field'];
+       $instance = $this->fields[$site][$bundle_name][$field_id]['instance'];
        $field_name = $field['field_name'];
 
        // If we only have one item for this value then add it.

+ 3 - 3
tripal/includes/tripal.collections.inc

@@ -7,7 +7,7 @@
 function tripal_user_collections_page() {
   global $user;
 
-  $headers = array('Name', 'Description', 'Create Date', 'Downloads Formats',
+  $headers = array('Name', 'Description', 'Create Date', 'Download Formats',
     'Generate File', 'Actions');
   $rows = array();
 
@@ -216,9 +216,9 @@ function tripal_user_collections_generate_file_form($form, &$form_state,  $uid,
   $collection  = new TripalEntityCollection();
   $collection->load($collection_id);
   $form = confirm_form($form,
-      t('Click the button below to generate the collection filed: %title',
+      t('Confirm creation of files for the data collection named: "%title"',
           array('%title' => $collection->getName())), 'user/' . $uid . '/data-collections',
-      '<p>' .t('This action cannot be undone.') .'</p>', t('Generate File'), t('Cancel'), 'confirm');
+      '<p>' .t('It may take some time for the file(s) to be generated.  An email will be sent when files are ready.') .'</p>', t('Generate File'), t('Cancel'), 'confirm');
 
   return $form;
 }

+ 1 - 1
tripal/views_handlers/tripal_views_handler_area_collections.inc

@@ -138,7 +138,7 @@ function tripal_views_handler_area_collections_form($form, $form_state, $view, $
     $field_formatters = tripal_get_field_field_formatters($field, $instance);
     foreach ($field_formatters as $class_name => $label) {
       tripal_load_include_downloader_class($class_name);
-      $formatters[] = $label;
+      $formatters[] = $class_name::$label;
     }
 
     // Add the field to those supported.

+ 1 - 1
tripal_chado/includes/tripal_chado.fields.inc

@@ -1337,7 +1337,7 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
       'entity_type' => $entity_type,
       'bundle' => $bundle->name,
       'label' => 'Sequence',
-      'description' => 'All available sequences for this record.',
+      'description' => 'One or more molecular sequences, possibly with associated annotation.',
       'required' => FALSE,
       'settings' => array(
         'auto_attach' => FALSE,