Explorar o código

While trying to fix this the wrong CDS problem I needed the so__cds field to work (which it now is with this commit). I also added a jbrowse viewer so I could easily see how the genes are supposed to look

Stephen Ficklin %!s(int64=6) %!d(string=hai) anos
pai
achega
a27b2f798a

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

@@ -1008,14 +1008,14 @@ function tripal_get_default_title_format($bundle) {
 /**
  * Returns an array of tokens based on Tripal Entity Fields.
  *
- * @param TripalBundle $entity
+ * @param TripalBundle $bundle
  *    The bundle entity for which you want tokens.
  * @return
  *    An array of tokens where the key is the machine_name of the token.
  *
  * @ingroup tripal_entities_api
  */
-function tripal_get_entity_tokens($entity, $options = array()) {
+function tripal_get_entity_tokens($bundle, $options = array()) {
   $tokens = array();
 
   // Set default options.
@@ -1042,7 +1042,7 @@ function tripal_get_entity_tokens($entity, $options = array()) {
     );
   }
 
-  $fields = field_info_instances('TripalEntity', $entity->name);
+  $fields = field_info_instances('TripalEntity', $bundle->name);
   foreach ($fields as $f) {
 
     // Build the token from the field information.

+ 1 - 1
tripal/includes/TripalBundleUIController.inc

@@ -289,7 +289,7 @@ function tripal_tripal_bundle_form($form, &$form_state, $entityDataType) {
   );
 
 
-  $tokens = tripal_get_entity_tokens($bundle, array('required only' => TRUE));
+  $tokens = tripal_get_entity_tokens($bundle);
   $form['url']['tokens'] = array(
     '#type' => 'hidden',
     '#value' => serialize($tokens)

+ 153 - 0
tripal_chado/includes/TripalFields/local__gbrowse_image/local__gbrowse_image.inc

@@ -0,0 +1,153 @@
+<?php
+
+class local__gbrowse_image extends ChadoField {
+
+
+  // --------------------------------------------------------------------------
+  //                     EDITABLE STATIC CONSTANTS
+  //
+  // The following constants SHOULD be set for each descendent class.  They are
+  // used by the static functions to provide information to Drupal about
+  // the field and it's default widget and formatter.
+  // --------------------------------------------------------------------------
+
+  // The default lable for this field.
+  public static $default_label = 'GBrowse View';
+
+  // The default description for this field.
+  public static $description = 'A GBrowse image of a feature alignment to another sequence.';
+
+  // Provide a list of instance specific settings. These can be access within
+  // the instanceSettingsForm.  When the instanceSettingsForm is submitted
+  // then Drupal with automatically change these settings for the instnace.
+  // It is recommended to put settings at the instance level whenever possible.
+  // If you override this variable in a child class be sure to replicate the
+  // term_name, term_vocab, term_accession and term_fixed keys as these are
+  // required for all TripalFields.
+  public static $default_instance_settings  = array(
+    // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
+    'term_vocabulary' => 'local',
+    // The name of the term.
+    'term_name' => 'Gbrowse Image',
+    // The unique ID (i.e. accession) of the term.
+    'term_accession' => 'gbrowse_image',
+    // Set to TRUE if the site admin is allowed to change the term
+    // type. This will create form elements when editing the field instance
+    // to allow the site admin to change the term settings above.
+    'term_fixed' => FALSE,    
+    // The URL for the GBrowse image
+    'gbrowse_url' => '',
+  );
+
+  // The default widget for this field.
+  public static $default_widget = 'local__gbrowse_image_widget';
+
+  // The default formatter for this field.
+  public static $default_formatter = 'local__gbrowse_image_formatter';
+
+
+  /**
+   * @see TripalField::elementInfo()
+   */
+  public function elementInfo() {
+    $field_term = $this->getFieldTermID();
+    return array(
+      $field_term => array(
+        'sortable' => FALSE,
+        'searchable' => FALSE,
+        'type' => 'xs:string',
+        'readonly' => TRUE,
+      ),
+    );
+  }
+
+  /**
+   * @see TripalField::load()
+   */
+  public function load($entity) {
+    $field_name = $this->field['field_name'];
+    $feature = $entity->chado_record;
+    
+    $record = $entity->chado_record;
+    $settings = $this->instance['settings'];
+
+    // Set some defauls for the empty record
+    $entity->{$field_name}['und'][0] = array(
+      'value' => '',
+    );
+    
+    // If we don't have a record then just return
+    if (!$record) {
+      return;
+    }
+    
+    // Replace any tokens in the string.
+    $bundle = tripal_load_bundle_entity(['name' => $this->instance['bundle']]);
+    $gbrowse_url = $settings['gbrowse_url'];   
+    $gbrowse_url = tripal_replace_entity_tokens($gbrowse_url, $entity, $bundle);
+        
+    // Use the term associated to the db.url table of Chado.
+    $url_term = chado_get_semweb_term('db', 'url');
+    
+    // Add the URL to the values
+    $entity->{$field_name}['und'][0]['value'] = [
+      $url_term => $gbrowse_url
+    ];
+  }
+  
+  /**
+   * @see TripalField::globalSettingsForm()
+   */
+  public function instanceSettingsForm() {
+    $element = parent::instanceSettingsForm();
+    
+    $settings = $this->instance['settings'];
+    
+    $element['gbrowse_url'] = array(
+      '#type' => 'textarea',
+      '#title' => 'GBrowse URL',
+      '#description' => t('Please enter the URL for generating feature ' . 
+        'images on the remote GBrowse site. You may use tokens to substitute ' .
+        'field values from this content type. Open the "Available Tokens" fieldset below. ' .
+        'For example, to show a view of a gene from the rice genome GBrowse the ' .
+        'following URL with tokens can be used: ' . 
+        'http://rice.plantbiology.msu.edu/cgi-bin/gbrowse_img/rice/?name=[schema__name];type=Landmarks%3Aregion+Genes+Rice_Annotation'),
+      '#default_value' => $settings['gbrowse_url'],
+    );
+    
+    $element['tokens'] = array(
+      '#type' => 'fieldset',
+      '#collapsed' => TRUE,
+      '#collapsible' => TRUE,
+      '#title' => 'Available Tokens'
+    );
+    $headers = array('Token', 'Description');
+    $rows = array();
+    
+    // Get the bundle tokens
+    $bundle = tripal_load_bundle_entity(['name' => $this->instance['bundle']]);
+    $tokens = tripal_get_entity_tokens($bundle);
+    foreach ($tokens as $token) {
+      $rows[] = array(
+        $token['token'],
+        $token['description'],
+      );
+    }
+    
+    $table_vars = array(
+      'header'     => $headers,
+      'rows'       => $rows,
+      'attributes' => array(),
+      'sticky'     => FALSE,
+      'caption'    => '',
+      'colgroups'  => array(),
+      'empty'      => 'There are no tokens',
+    );
+    $element['tokens']['list'] = array(
+      '#type' => 'item',
+      '#markup' => theme_table($table_vars),
+    );
+    
+    return $element;
+  }
+}

+ 26 - 0
tripal_chado/includes/TripalFields/local__gbrowse_image/local__gbrowse_image_formatter.inc

@@ -0,0 +1,26 @@
+<?php
+
+class local__gbrowse_image_formatter extends ChadoFieldFormatter {
+  // The default lable for this field.
+  public static $default_label = 'GBrowse View';
+
+  // The list of field types for which this formatter is appropriate.
+  public static $field_types = array('local__gbrowse_image');
+
+  /**
+   * @see TripalFieldFormatter::view()
+   */
+  public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
+    $content = '';
+    if (count($items) > 0) {
+      $url_term = chado_get_semweb_term('db', 'url');
+      $content = '<img src="' . $items[0]['value'][$url_term] . '" class="tripal-local--gbrowse-image"/>';
+      
+      $element[0] = array(
+        // We create a render array to produce the desired markup,
+        '#type' => 'markup',
+        '#markup' => $content,
+      );
+    }
+  }
+}

+ 29 - 0
tripal_chado/includes/TripalFields/local__gbrowse_image/local__gbrowse_image_widget.inc

@@ -0,0 +1,29 @@
+<?php
+
+class local__gbrowse_image_widget extends ChadoFieldWidget {
+  // The default lable for this field.
+  public static $default_label = 'GBrowse View';
+
+  // The list of field types for which this formatter is appropriate.
+  public static $field_types = array('local__gbrowse_image');
+
+  /**
+   *
+   * @see TripalFieldWidget::form()
+   */
+  public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
+
+    // TODO: add a widget...
+  }
+
+
+  /**
+   *
+   * @see TripalFieldWidget::submit()
+   */
+  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+    $field_name = $this->field['field_name'];
+
+  }
+}

+ 88 - 39
tripal_chado/includes/tripal_chado.fields.inc

@@ -399,17 +399,29 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
       ),
     );
 
-//     $field_name = 'so__cds';
-//     $field_type = 'so__cds';
-//     $info[$field_name] = array(
-//       'field_name' => $field_name,
-//       'type' => $field_type,
-//       'cardinality' => 1,
-//       'locked' => FALSE,
-//       'storage' => array(
-//         'type' => 'field_chado_storage',
-//       ),
-//     );
+    $field_name = 'so__cds';
+    $field_type = 'so__cds';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => 1,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
+    
+    $field_name = 'local__gbrowse_image';
+    $field_type = 'local__gbrowse_image';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => 1,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
   }
 
 //   // GENE TRANSCRIPTS
@@ -1693,34 +1705,71 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
       ),
     );
 
-//     $field_name = 'so__cds';
-//     $info[$field_name] = array(
-//       'field_name' => $field_name,
-//       'entity_type' => $entity_type,
-//       'bundle' => $bundle->name,
-//       'label' => 'Coding Sequence',
-//       'description' => 'Coding sequences.',
-//       'required' => FALSE,
-//       'settings' => array(
-//         'auto_attach' => FALSE,
-//         'chado_table' => 'featureloc',
-//         'chado_column' => '',
-//         'base_table' => 'featureloc',
-//       ),
-//       'widget' => array(
-//         'type' => 'so__cds_widget',
-//         'settings' => array(
-//           'display_label' => 1,
-//         ),
-//       ),
-//       'display' => array(
-//         'default' => array(
-//           'label' => 'above',
-//           'type' => 'so__cds_formatter',
-//           'settings' => array(),
-//         ),
-//       ),
-//     );
+    $field_name = 'so__cds';
+    $info[$field_name] = array(
+     'field_name' => $field_name,
+     'entity_type' => $entity_type,
+     'bundle' => $bundle->name,
+     'label' => 'Coding Sequence (CDS)',
+     'description' => 'Coding sequences.',
+     'required' => FALSE,
+     'settings' => array(
+       'auto_attach' => FALSE,
+       'chado_table' => 'featureprop',
+       'chado_column' => 'value',
+       'base_table' => 'feature',
+       'term_vocabulary' => 'SO',
+       'term_name' => 'CDS',
+       'term_accession' => '0000316',
+     ),
+     'widget' => array(
+       'type' => 'so__cds_widget',
+       'settings' => array(
+         'display_label' => 1,
+       ),
+     ),
+     'display' => array(
+       'default' => array(
+         'label' => 'above',
+         'type' => 'so__cds_formatter',
+         'settings' => array(),
+       ),
+     ),
+    );
+    
+    $field_name = 'local__gbrowse_image';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'GBrowse image',
+      'description' => 'A GBrowse image of a feature alignment.',
+      'required' => FALSE,
+      'settings' => array(
+        'auto_attach' => FALSE,
+        'chado_table' => '',
+        'chado_column' => '',
+        'base_table' => 'feature',
+        'term_vocabulary' => 'local',
+        'term_name' => 'Gbrowse Image',
+        'term_accession' => 'gbrowse_image',
+        'gbrowse_url' => '',
+      ),
+      'widget' => array(
+        'type' => 'local__gbrowse_image_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'above',
+          'type' => 'local__gbrowse_image_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+    
   }
 
 

+ 19 - 0
tripal_chado/includes/tripal_chado.semweb.inc

@@ -642,6 +642,12 @@ function tripal_chado_populate_vocab_EDAM() {
     'cv_name' => 'EDAM',
     'definition' => 'A phylogenetic tree that is an estimate of the character\'s phylogeny.',
   ));
+  $term = chado_insert_cvterm(array(
+    'id' => 'operation:0564',
+    'name' => 'Sequence visualisation',
+    'cv_name' => 'EDAM',
+    'definition' => 'Visualise, format or render a molecular sequence or sequences such as a sequence alignment, possibly with sequence features or properties shown.',
+  ));
 
 }
 /**
@@ -1652,6 +1658,19 @@ function tripal_chado_populate_vocab_LOCAL() {
     'cv_name' => 'local',
   ));
   chado_associate_semweb_term('arraydesign', 'num_sub_rows', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:gbrowse_image',
+    'name' => 'Gbrowse Image',
+    'definition' => 'A GBrowse image of a feature alignment to another sequence',
+    'cv_name' => 'local',
+  ));
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:jbrowse_image',
+    'name' => 'Jbrowse Image',
+    'definition' => 'A JBrowse image of a feature aligned to another sequence.',
+    'cv_name' => 'local',
+  ));
 }
 /**
  * Adds the Systems Biology Ontology database and terms.

+ 5 - 1
tripal_chado/theme/css/tripal_chado.css

@@ -36,7 +36,7 @@
 
 .residues-formatter {
   color: black;
-  height: 300px;
+  height: 100px;
   max-width: 500px;
   overflow: scroll;
   white-space: normal;
@@ -62,4 +62,8 @@
 
 .properties-field-list {
   margin: 0px;
+}
+
+.tripal-local--gbrowse-image {
+	width: 100%;
 }

+ 29 - 0
tripal_chado/tripal_chado.install

@@ -1550,5 +1550,34 @@ function tripal_chado_update_7326() {
   }
 }
 
+/**
+ * Adding terms for sequence visualization.
+ */
+function tripal_chado_update_7327() {
+  try {
+    $term = chado_insert_cvterm(array(
+      'id' => 'operation:0564',
+      'name' => 'Sequence visualisation',
+      'cv_name' => 'EDAM',
+      'definition' => 'Visualise, format or render a molecular sequence or sequences such as a sequence alignment, possibly with sequence features or properties shown.',
+    ));
+    $term = chado_insert_cvterm(array(
+      'id' => 'local:gbrowse_image',
+      'name' => 'Gbrowse Image',
+      'definition' => 'A GBrowse image of a feature alignment to another sequence',
+      'cv_name' => 'local',
+    ));
+    $term = chado_insert_cvterm(array(
+      'id' => 'local:jbrowse_image',
+      'name' => 'Jbrowse Image',
+      'definition' => 'A JBrowse image of a feature aligned to another sequence.',
+      'cv_name' => 'local',
+    ));
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
+}