فهرست منبع

Updates to fields

Stephen Ficklin 8 سال پیش
والد
کامیت
2c82e9cd6f

+ 1 - 1
legacy/tripal_feature/theme/tripal_feature.theme.inc

@@ -31,7 +31,7 @@ function tripal_feature_preprocess_tripal_feature_sequence(&$variables) {
   // if this feature has associated protein sequences (or others via relationships
   // then we want to make sure the relationships are added so that we can
   // show the protein sequences
-  if (!$feature->all_relationships) {
+  if (!property_exists($feature, 'all_relationships')) {
     $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
   }
 }

+ 111 - 0
tripal_chado/api/modules/tripal_chado.pub.api.inc

@@ -996,3 +996,114 @@ function tripal_pub_create_citation($pub) {
 
   return $citation;
 }
+
+/**
+ * Retrieves the minimal information to uniquely describe any publication.
+ *
+ * @param $pub
+ *   A publication object as created by chado_generate_var()
+ *
+ * @return
+ *   An array with the following keys:  'Citation', 'Abstract', 'Authors',
+ *   'URL'. All keys are term names in the Tripal Publication Ontology :TPUB.
+ */
+function tripal_get_minimal_pub_info($pub) {
+  // Chado has a null pub as default.  We don't return anything for this.
+  if ($pub->uniquename == 'null') {
+    return array();
+  }
+
+  // expand the title
+  $pub = chado_expand_var($pub, 'field', 'pub.title');
+  $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
+
+  // get the citation
+  $values = array(
+    'pub_id' => $pub->pub_id,
+    'type_id' => array(
+      'name' => 'Citation',
+    ),
+  );
+  $options = array(
+    'include_fk' => array(
+    ),
+  );
+  $citation = chado_generate_var('pubprop', $values, $options);
+  $citation = chado_expand_var($citation, 'field', 'pubprop.value');
+  $citation = $citation->value;
+
+  // get the abstract
+  $values = array(
+    'pub_id' => $pub->pub_id,
+    'type_id' => array(
+      'name' => 'Abstract',
+    ),
+  );
+  $options = array(
+    'include_fk' => array(
+    ),
+  );
+  $abstract = chado_generate_var('pubprop', $values, $options);
+  $abstract = chado_expand_var($abstract, 'field', 'pubprop.value');
+  $abstract_text = '';
+  if ($abstract) {
+    $abstract_text = htmlspecialchars($abstract->value);
+  }
+
+  // get the author list
+  $values = array(
+    'pub_id' => $pub->pub_id,
+    'type_id' => array(
+      'name' => 'Authors',
+    ),
+  );
+  $options = array(
+    'include_fk' => array(
+    ),
+  );
+  $authors = chado_generate_var('pubprop', $values, $options);
+  $authors = chado_expand_var($authors, 'field', 'pubprop.value');
+  $authors_list = 'N/A';
+  if ($authors) {
+    $authors_list = $authors->value;
+  }
+
+  // get the first database cross-reference with a url
+  $options = array('return_array' => 1);
+  $pub = chado_expand_var($pub, 'table', 'pub_dbxref', $options);
+  $dbxref = NULL;
+  if ($pub->pub_dbxref) {
+    foreach ($pub->pub_dbxref as $index => $pub_dbxref) {
+      if ($pub_dbxref->dbxref_id->db_id->urlprefix) {
+        $dbxref = $pub_dbxref->dbxref_id;
+      }
+    }
+  }
+
+  // get the URL
+  // get the author list
+  $values = array(
+    'pub_id' => $pub->pub_id,
+    'type_id' => array(
+      'name' => 'URL',
+    ),
+  );
+
+  $options = array(
+    'return_array' => 1,
+    'include_fk' => array(),
+  );
+  $urls = chado_generate_var('pubprop', $values, $options);
+  $urls = chado_expand_var($urls, 'field', 'pubprop.value');
+  $url = '';
+  if (count($urls) > 0) {
+    $url = $urls[0]->value;
+  }
+  return array(
+    'Title' => $pub->title,
+    'Citation' => $citation,
+    'Abstract' => $abstract_text,
+    'Authors' => $authors_list,
+    'URL' => $url,
+  );
+}

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

@@ -138,17 +138,7 @@ class chado_feature__residues extends TripalField {
   }
 
   /**
-   *
-   * @param unknown $field_name
-   * @param unknown $widget
-   * @param unknown $form
-   * @param unknown $form_state
-   * @param unknown $field
-   * @param unknown $instance
-   * @param unknown $langcode
-   * @param unknown $items
-   * @param unknown $delta
-   * @param unknown $element
+   * @see TripalField::widget_form()
    */
   function widget_form(&$widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element) {
 

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

@@ -192,9 +192,11 @@ class chado_gene__transcripts extends TripalField {
       foreach ($locations AS $location) {
         $loc .= $location->srcfeature_name . ":" . $location->fmin . ".." . $location->fmax;
       }
+      $type = $transcript->record->subject_id->type_id;
       $entity->{$field_name}['und'][$i]['value'] = array(
+        '@type' => $type->dbxref_id->db_id->name . ":" . $type->dbxref_id->accession,
+        'type' => $type->name,
         'name' => $feature_name,
-        'type' => $transcript->record->subject_id->type_id->name,
         'unique name' => $transcript->record->subject_id->uniquename,
         'location' => $loc,
 

+ 38 - 19
tripal_chado/includes/fields/chado_linker__contact.inc

@@ -91,18 +91,23 @@ class chado_linker__contact extends TripalField {
         // Get the settings
         $settings = $display['settings'];
         $record = $entity->chado_record;
-        
+
         $headers = array('Name', 'Description', 'Type');
         $rows = array();
+
         foreach ($items as $delta => $item) {
-        
           $contact = $item['value'];
-        
+          if (!$contact) {
+            continue;
+          }
+          $contact_id = $contact['contact_id'];
+
+
           // Get the field values
           $contact_name = $contact['name'];
           $description = $contact['description'];
           $type = $contact['type_id'];
-        
+
           // Add a link i there is an entity.
           if (array_key_exists('entity_id', $contact) and $contact['$entity_id']) {
             $entity_id = $contact['entity_id'];
@@ -120,10 +125,10 @@ class chado_linker__contact extends TripalField {
           'sticky' => FALSE,
           'caption' => "",
           'colgroups' => array(),
-          'empty' => '',
+          'empty' => 'No contacts available',
         );
         $content = theme_table($table);
-        
+
         // once we have our table array structure defined, we call Drupal's theme_table()
         // function to generate the table.
         $element[$delta] = array(
@@ -139,39 +144,53 @@ class chado_linker__contact extends TripalField {
   }
 
   public function load($field, $entity, $details) {
+    $record = $details['record'];
     $field_name = $field['field_name'];
     $field_type = $field['type'];
     $field_table = $field['settings']['chado_table'];
     $field_column = $field['settings']['chado_column'];
-    
+
     // Get the FK that links to the base record.
     $schema = chado_get_schema($field_table);
     $base_table = $details['record']->tablename;
     $pkey = $schema['primary key'][0];
     $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
     $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
-    
+
     $linker_table = $base_table . '_contact';
     $options = array(
       'return_array' => 1,
+      'include_fk' => array(
+        'contact_id' => array(
+          'type_id' => array(
+            'dbxref_id' => array(
+              'db_id' => TRUE,
+            ),
+          ),
+        ),
+      ),
     );
-    $details = chado_expand_var($details, 'table', $linker_table, $options);
-    $record = $details['record'];
-    $exp = $record->$linker_table;
-    $exp = is_array($exp) ? $exp : array($exp);
-    if (count($exp) > 0) {
-      $i = 0;
-      foreach ($exp as $index => $linker) {
-        $contact = $linker->contact_id;
+    $record = chado_expand_var($record, 'table', $linker_table, $options);
+    $contact_linkers = $record->$linker_table;
+    if ($contact_linkers) {
+      foreach ($contact_linkers as $i => $contact_linker) {
+        $contact = $contact_linker->contact_id;
+        dpm($contact);
         $entity->{$field_name}['und'][$i]['value'] = array(
-          'contact_id' => $contact->contact_id,
+          '@type' => $contact->type_id->dbxref_id->db_id->name . ':' . $contact->type_id->dbxref_id->accession,
+          'type' => $contact->type_id->name,
           'name' => $contact->name,
           'description' => $contact->description,
-          'type_id' => $contact->type_id
         );
-        $i++;
+        $entity->$field_name['und'][$i]['contact_id'] = $contact->contact_id;
+
+        if (property_exists($contact, 'entity_id')) {
+          $entity->{$field_name}['und'][$i]['entity_id'] = $contact->entity_id;
+          $entity->{$field_name}['und'][$i]['entity_type'] = 'TripalEntity';
+        }
       }
     }
+
   }
 
   /**

+ 101 - 50
tripal_chado/includes/fields/chado_linker__expression.inc

@@ -88,48 +88,73 @@ class chado_linker__expression extends TripalField {
 
   public function formatter_view(&$element, $entity_type, $entity,
       $field, $instance, $langcode, $items, $display) {
-        // Get the settings
-        $settings = $display['settings'];
-        $record = $entity->chado_record;
-        
-        $headers = array('Uniquename', 'Description', 'Publication');
-        $rows = array();
-        foreach ($items as $delta => $item) {
-        
-          $expression = $item['value'];
-        
-          // Get the field values
-          $expression_uname = $expression['uniquename'];
-          $description = $expression['description'];
-          $pub = $expression['publication'];
-        
-          // Add a link i there is an entity.
-          if (array_key_exists('entity_id', $expression) and $expression['$entity_id']) {
-            $entity_id = $expression['entity_id'];
-            $expression_uname = l($expression_uname, "bio_data/" . $entity_id, array('attributes' => array('target' => "_blank")));
+
+    // Get the settings
+    $settings = $display['settings'];
+    $record = $entity->chado_record;
+
+    $content = '';
+    foreach ($items as $delta => $item) {
+      if (!$item['value']) {
+        continue;
+      }
+      // Iterate through all of the children of the $item['value']. Add each
+      // one as an independent row in the table.
+      $rows = array();
+      foreach ($item['value'] as $key => $value) {
+
+        // If this key is the name, then we want to link to the entity if one
+        // exists.
+        if ($key == 'name') {
+          if (array_key_exists('entity_id', $item) and $item['$entity_id']) {
+            $entity_id = $item['entity_id'];
+            $value = l($value, "bio_data/" . $entity_id, array('attributes' => array('target' => "_blank")));
           }
-          $rows[] = array($expression_uname, $description, $pub->title);
         }
-        $table = array(
-          'header' => $headers,
-          'rows' => $rows,
-          'attributes' => array(
-            'id' => 'tripal_linker-table-expression-object',
-            'class' => 'tripal-data-table'
+        // If this key is the publication then we want to get the citation
+        // and link to the pub if an entity exits.
+        if ($key == 'publication') {
+          $pub = $value['Citation'];
+          if (array_key_exists('publication', $item) and array_key_exists('entity_id', $item['publication'][0])) {
+            $entity_id = $item['publication'][0]['entity_id'];
+            $title =  $item['value']['publication']['Title'];
+            $link = l($title, 'bio_data/' . $entity_id);
+            $pub = preg_replace("/$title/", $link, $pub);
+          }
+          $value = $pub;
+        }
+        // Add the item as a new row.
+        $rows[] = array(
+          array(
+            'data' => ucfirst($key),
+            'header' => TRUE,
+            'width' => '20%',
           ),
-          'sticky' => FALSE,
-          'caption' => "",
-          'colgroups' => array(),
-          'empty' => '',
-        );
-        $content = theme_table($table);
-        
-        // once we have our table array structure defined, we call Drupal's theme_table()
-        // function to generate the table.
-        $element[$delta] = array(
-          '#type' => 'markup',
-          '#markup' => $content,
+          $value
         );
+      }
+      $table = array(
+        'header' => array(),
+        'rows' => $rows,
+        'attributes' => array(
+          'id' => 'tripal_linker-table-expression-object',
+          'class' => 'tripal-data-table'
+        ),
+        'sticky' => FALSE,
+        'caption' => "",
+        'colgroups' => array(),
+        'empty' => '',
+      );
+      $content .= theme_table($table);
+    }
+
+
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    $element[$delta] = array(
+      '#type' => 'markup',
+      '#markup' => $content,
+    );
   }
 
 
@@ -139,6 +164,8 @@ class chado_linker__expression extends TripalField {
   }
 
   public function load($field, $entity, $details) {
+    $record = $details['record'];
+
     $field_name = $field['field_name'];
     $field_type = $field['type'];
     $field_table = $field['settings']['chado_table'];
@@ -155,21 +182,45 @@ class chado_linker__expression extends TripalField {
     $options = array(
       'return_array' => 1,
     );
-    $details = chado_expand_var($details, 'table', $linker_table, $options);
-    $record = $details['record'];
-    $exp = $record->$linker_table;
-    $exp = is_array($exp) ? $exp : array($exp);
-    if (count($exp) > 0) {
-      $i = 0;
-      foreach ($exp as $index => $linker) {
-        $expression = $linker->expression_id;
+    $record = chado_expand_var($record, 'table', $linker_table, $options);
+    $exp_linkers = $record->$linker_table;
+    if ($exp_linkers) {
+      foreach ($exp_linkers as $i => $exp_linker) {
+
+        // Because the unqiuename is a text field we must expand it.
+        $expression = $exp_linker->expression_id;
+        $expression = chado_expand_var($expression, 'field', 'expression.uniquename', $options);
+
+        // Set the values that will be seen by the user on the page and in
+        // web services, or anwhere this field is viewed.
         $entity->{$field_name}['und'][$i]['value'] = array(
-          'expression_id' => $expression->expression_id,
-          'uniquename' => $expression->uniquename,
+          'name' => $expression->uniquename,
           'description' => $expression->description,
-          'publication' => $linker->pub_id
+          //'md5checksum' => $expression->md5checksum,
         );
-        $i++;
+
+        // Add the pub information if a real pub is associated with the record.
+        $pub = $exp_linker->pub_id;
+        if ($pub->uniquename != 'null') {
+          $pub_details = tripal_get_minimal_pub_info($pub);
+
+          $entity->{$field_name}['und'][$i]['value']['publication'] = $pub_details;
+          $entity->{$field_name}['und'][$i]['value']['publication']['@type'] = $pub->type_id->dbxref_id->db_id->name . ':' . $pub->type_id->dbxref_id->accession;
+          $entity->{$field_name}['und'][$i]['value']['publication']['type'] = $pub->type_id->name;
+          if (property_exists($pub, 'entity_id')) {
+            $entity->{$field_name}['und'][$i]['publication'][0]['entity_id'] = $pub->entity_id;
+            $entity->{$field_name}['und'][$i]['publication'][0]['entity_type'] = 'TripalEntity';
+          }
+        }
+
+        // Add the fields for the widget form.  The name requres the following
+        // format if the fields should be used as values for insertint/updating
+        // into the chado table:  [table_name]__[field_name]
+        $entity->{$field_name}['und'][$i][$linker_table . '__expression_id'] = $expression->expression_id;
+        $entity->{$field_name}['und'][$i][$linker_table . '__uniquename'] = $expression->uniquename;
+        //$entity->{$field_name}['und'][$i][$linker_table . '__md5checksum'] = $expression->md5checksum;
+        $entity->{$field_name}['und'][$i][$linker_table . '__description'] = $expression->description;
+
       }
     }
   }

+ 17 - 3
tripal_chado/includes/fields/chado_linker__relationship.inc

@@ -107,6 +107,9 @@ class chado_linker__relationship extends TripalField {
     }
 
     foreach ($items as $delta => $item) {
+      if (!$item['value']) {
+        continue;
+      }
       $subject_name = $item['value']['subject']['name'];
       $subject_type = $item['value']['subject']['type'];
       $object_name = $item['value']['object']['name'];
@@ -159,7 +162,7 @@ class chado_linker__relationship extends TripalField {
       'sticky' => FALSE,
       'caption' => '',
       'colgroups' => array(),
-      'empty' => '',
+      'empty' => 'There are no relationships',
     );
 
     // once we have our table array structure defined, we call Drupal's theme_table()
@@ -187,7 +190,6 @@ class chado_linker__relationship extends TripalField {
     // Expand the object to include the relationships.
     $options = array(
       'return_array' => 1,
-      'order_by' => array('rank' => 'ASC'),
       // we don't want to fully recurse we only need information about the
       // relationship type and the object and subject  (including feature type
       // and organism)
@@ -204,7 +206,14 @@ class chado_linker__relationship extends TripalField {
       ),
     );
     $rel_table = $base_table . '_relationship';
+    $schema = chado_get_schema($rel_table);
+    if (array_key_exists('rank', $schema['fields'])) {
+      $options['order_by'] = array('rank' => 'ASC');
+    }
     $record = chado_expand_var($record, 'table', $rel_table, $options);
+    if (!$record->$rel_table) {
+      return;
+    }
     $srelationships = $record->$rel_table->subject_id;
     $orelationships = $record->$rel_table->object_id;
 
@@ -229,6 +238,9 @@ class chado_linker__relationship extends TripalField {
           ),
           'type' => $relationship->type_id->name,
           'object' => array(
+            '@type' => $relationship->object_id->type_id->dbxref_id->db_id->name .
+               ':' . $relationship->object_id->type_id->dbxref_id->accession,
+            // TODO the entity_id should not be here.... wherre to put it.
             'entity_id' => $entity->id,
             'entity_type' => 'TripalEntity',
             'type' =>  $object_type,
@@ -269,6 +281,8 @@ class chado_linker__relationship extends TripalField {
         $entity->{$field_name}['und'][$i]['value'] = array(
           '@type' => $rel_acc,
           'subject' => array(
+            '@type' => $relationship->subject_id->type_id->dbxref_id->db_id->name .
+               ':' . $relationship->subject_id->type_id->dbxref_id->accession,
             'type' =>  $subject_type,
             'name' => $subject_name,
             'entity_id' => $entity->id,
@@ -277,7 +291,7 @@ class chado_linker__relationship extends TripalField {
           'type' => $relationship->type_id->name,
           'object' => array(
             '@type' => $relationship->object_id->type_id->dbxref_id->db_id->name .
-               ':' . $relationship->subject_id->type_id->dbxref_id->accession,
+               ':' . $relationship->object_id->type_id->dbxref_id->accession,
             'type' =>  $object_type,
             'name' => $object_name,
           )

+ 1 - 1
tripal_chado/includes/loaders/tripal_chado.pub_importers.inc

@@ -77,7 +77,7 @@ function tripal_pub_importers_list() {
     'caption' => '',
     'sticky' => TRUE,
     'colgroups' => array(),
-    'empty' => 'There are currently importers',
+    'empty' => 'There are no currently importers',
   );
 
   $page .= theme_table($table);