Browse Source

Added new local_source_data field for dealing with the analysis source fields. Also added a dummy tripal_views module to help with upgrading from t2 to T2

Stephen Ficklin 8 years ago
parent
commit
68f0017cda

+ 6 - 0
legacy/tripal_views/tripal_views.info

@@ -0,0 +1,6 @@
+name = Tripal Views
+description = Deprecated-- no longer provides any functionality. See Tripal Chado Views instead. Kept for backwards compatibility for Tripal v2 to v3 upgrade.
+core = 7.x
+project = tripal
+package = Tripal v2 Legacy
+version = 7.x-3.0-alpha1

+ 6 - 0
legacy/tripal_views/tripal_views.module

@@ -0,0 +1,6 @@
+<?php
+
+// For backwards compatibility during upgrade of T2 to T3 we need these
+// APIs to be available.
+module_load_include('inc', 'tripal_chado', 'api/tripal_chado.schema.api');
+module_load_include('inc', 'tripal_chado_views', 'api/tripal_chado_views.api');

+ 1 - 7
tripal_chado/includes/TripalFields/data__sequence/data__sequence_formatter.inc

@@ -8,13 +8,7 @@ class data__sequence_formatter extends ChadoFieldFormatter {
   public static $field_types = array('data__sequence');
 
   /**
-   *
-   * @param unknown $element
-   * @param unknown $entity_type
-   * @param unknown $entity
-   * @param unknown $langcode
-   * @param unknown $items
-   * @param unknown $display
+   * @see TripalFieldFormatter::view()
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
 

+ 83 - 0
tripal_chado/includes/TripalFields/local__source_data/local__source_data.inc

@@ -0,0 +1,83 @@
+<?php
+
+class local__source_data 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 = 'Source of Data';
+
+  // The default description for this field.
+  public static $description = 'The source data used for this analysis.';
+
+  // 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' => 'source_data',
+    // The unique ID (i.e. accession) of the term.
+    'term_accession' => 'source_data',
+    // 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 default widget for this field.
+  public static $default_widget = 'local__source_data_widget';
+
+  // The default formatter for this field.
+  public static $default_formatter = 'local__source_data_formatter';
+
+  // --------------------------------------------------------------------------
+  //              PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
+  // --------------------------------------------------------------------------
+  // An array containing details about the field. The format of this array
+  // is the same as that returned by field_info_fields()
+  protected $field;
+  // An array containing details about an instance of the field. A field does
+  // not have to have an instance.  But if dealing with an instance (such as
+  // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
+  protected $instance;
+
+
+  /**
+   *
+   * @see TripalField::load()
+   */
+  public function load($entity, $details = array()) {
+    $analysis = $details['record'];
+    $field_name = $this->field['field_name'];
+    $field_type = $this->field['type'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
+
+    $entity->{$field_name}['und'][0] = array(
+      'value' => array(
+        // The name of the data source.
+        'schema:name' => $analysis->sourcename,
+        // The version of the data source.
+        'IAO:0000129' => $analysis->sourceversion,
+        // The URI of the data source.
+        'data:1047' => $analysis->sourceuri,
+      ),
+      'chado-analysis__sourcename' => $analysis->sourcename,
+      'chado-analysis__sourceversion' => $analysis->sourceversion,
+      'chado-analysis__sourceuri' => $analysis->sourceuri,
+    );
+  }
+}

+ 35 - 0
tripal_chado/includes/TripalFields/local__source_data/local__source_data_formatter.inc

@@ -0,0 +1,35 @@
+<?php
+
+class local__source_data_formatter extends ChadoFieldFormatter {
+  // The default lable for this field.
+  public static $default_label = 'Data Source';
+
+  // The list of field types for which this formatter is appropriate.
+  public static $field_types = array('local__source_data');
+
+
+  /**
+   * @see TripalFieldFormatter::view()
+   */
+  public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
+
+    $content = 'The data source is not provided.';
+    if ($items[0]['value']) {
+      $content = "
+        <dl class=\"tripal-dl\">
+           <dt>Source Name</dt>
+           <dd>: " . $items[0]['value']['schema:name'] . " </dd>
+           <dt>Source Version</dt>
+           <dd>: " . $items[0]['value']['IAO:0000129'] . " </dd>
+           <dt>Source URI</dt>
+           <dd>: " . $items[0]['value']['data:1047'] . " </dd>
+        </dl>
+      ";
+    }
+    $element[0] = array(
+      // We create a render array to produce the desired markup,
+      '#type' => 'markup',
+      '#markup' => $content,
+    );
+  }
+}

+ 92 - 0
tripal_chado/includes/TripalFields/local__source_data/local__source_data_widget.inc

@@ -0,0 +1,92 @@
+<?php
+
+class local__source_data_widget extends ChadoFieldWidget {
+  // The default lable for this field.
+  public static $default_label = 'Data Source';
+
+  // The list of field types for which this formatter is appropriate.
+  public static $field_types = array('local__source_data');
+
+  /**
+   *
+   * @see TripalFieldWidget::form()
+   */
+  public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
+
+    $settings = $this->field['settings'];
+    $field_name = $this->field['field_name'];
+    $field_type = $this->field['type'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
+
+    // Get the field defaults.
+    $sourcename = '';
+    $sourceversion = '';
+    $sourceuri = '';
+
+    // Set defaults based on incoming item values.
+    if (count($items) > 0 and array_key_exists('value', $items[0])) {
+      $sourcename = $items[0]['chado-analysis__sourcename'];
+      $sourceversion = $items[0]['chado-analysis__sourceversion'];
+      $sourceuri = $items[0]['chado-analysis__sourceuri'];
+    }
+
+    // Set defaults based on incoming form state (happens on a failed form
+    // submit).
+    if (array_key_exists('values', $form_state) and
+        array_key_exists($field_name, $form_state['values'])) {
+      $sourcename = $form_state['values'][$field_name][$langcode][$delta]['chado-analysis__sourcename'];
+      $sourceversion = $form_state['values'][$field_name][$langcode][$delta]['chado-analysis__sourceversion'];
+      $sourceuri = $form_state['values'][$field_name][$langcode][$delta]['chado-analysis__sourceuri'];
+    }
+
+    $widget['value'] = array(
+      '#type' => 'value',
+      '#value' => $sourcename,
+    );
+    $widget['source_data'] = array(
+      '#type' => 'fieldset',
+      '#title' => 'Source Data',
+      '#description' => t('The following fields help viewers identify the source
+          where data was obtained for this analysis.'),
+      '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
+      '#delta' => $delta,
+    );
+    $widget['source_data']['chado-analysis__sourcename'] = array(
+      '#type' => 'textfield',
+      '#title' => 'Data Source Name',
+      '#description' => 'The name of the source where data was obtained for this analysis.',
+      '#default_value' => $sourcename,
+    );
+    $widget['source_data']['chado-analysis__sourceversion'] = array(
+      '#type' => 'textfield',
+      '#title' => 'Data Source Version',
+      '#description' => 'The version number of the data source (if applicable).',
+      '#default_value' => $sourceversion,
+    );
+    $widget['source_data']['chado-analysis__sourceuri'] = array(
+      '#type' => 'textfield',
+      '#title' => 'Data Source URI',
+      '#description' => 'The URI (e.g. web URL) where the source data can be retreived.',
+      '#default_value' => $sourceuri,
+    );
+  }
+  /**
+   * @see TripalFieldWidget::submit()
+   */
+  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+    $field_name = $this->field['field_name'];
+    $field_type = $this->field['type'];
+    $table_name = $this->instance['settings']['chado_table'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
+    $base_table = $this->instance['settings']['base_table'];
+
+    // Using a fieldset in our widget above throws off the structure
+    // of the values array.  So we need to reorganize it a bit:
+    $value = $form_state['values'][$field_name][$langcode][$delta]['value'];
+    $form_state['values'][$field_name][$langcode][$delta] = $form_state['values'][$field_name][$langcode][$delta]['source_data'];
+    $form_state['values'][$field_name][$langcode][$delta]['value'] = $value;
+  }
+}

+ 72 - 20
tripal_chado/includes/tripal_chado.fields.inc

@@ -60,6 +60,14 @@ function tripal_chado_bundle_create_fields_base(&$info, $details, $entity_type,
   // Get the list of columns for this table and create a new field for each one.
   $columns = $schema['fields'];
   foreach ($columns as $column_name => $details) {
+
+    // Skip the source columns  in the analysis table. We have a custom
+    // field for those columns
+    if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
+        $column_name == 'sourceversion' or $column_name == 'sourcename')) {
+      continue;
+    }
+
     // Don't create base fields for the primary key and the type_id field.
     if ($column_name == $pkey or $column_name == $type_field) {
       continue;
@@ -154,13 +162,7 @@ function tripal_chado_bundle_create_fields_base(&$info, $details, $entity_type,
       $base_info['settings']['text_processing'] = 0;
     }
 
-    //
-    // ANALYSIS TABLE
-    //
-    elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
-      $base_info['type'] = 'text';
-      $base_info['settings']['text_processing'] = 0;
-    }
+
 
     $info[$field_name] = $base_info;
   }
@@ -321,6 +323,21 @@ function tripal_chado_bundle_create_fields_custom(&$info, $details, $entity_type
     );
   }
 
+  // Analysis source
+  if ($table_name == 'analysis') {
+    $field_name = 'local__source_data';
+    $field_type = 'local__source_data';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => 1,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
+  }
+
   // Add an image field to the Organism type.  This is a Drupal field and
   // not stored in Chado, but is used for backwards compatibility.
   if ($table_name == 'organism') {
@@ -620,6 +637,14 @@ function tripal_chado_bundle_create_instances_base(&$info, $entity_type, $bundle
 
   $columns = $schema['fields'];
   foreach ($columns as $column_name => $details) {
+
+    // Skip the source columns  in the analysis table. We have a custom
+    // field for those columns
+    if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
+        $column_name == 'sourceversion' or $column_name == 'sourcename')) {
+      continue;
+    }
+
     // Don't create base fields for the primary key and the type_id field.
     if ($column_name == $pkey or $column_name == $type_field) {
       continue;
@@ -764,19 +789,6 @@ function tripal_chado_bundle_create_instances_base(&$info, $entity_type, $bundle
       $base_info['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
       $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
     }
-    elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
-      $base_info['widget_type'] = 'text_textfield';
-      $base_info['label'] = 'Source URL';
-      $base_info['description'] = 'The URL where the original source data was derived.  Ideally, this should link to the page where more information about the source data can be found.';
-    }
-    elseif ($table_name == 'analysis' and $column_name == 'sourcename') {
-      $base_info['label'] = 'Source Name';
-      $base_info['description'] = 'The name of the source data. This could be a file name, data set or a small description for how the data was collected. For long descriptions use the larger description field.';
-    }
-    elseif ($table_name == 'analysis' and $column_name == 'sourceversion') {
-      $base_info['label'] = 'Source Version';
-      $base_info['description'] = 'If the source data set has a version include it here.';
-    }
     elseif ($table_name == 'analysis' and $column_name == 'algorithm') {
       $base_info['label'] = 'Source Version';
       $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
@@ -785,6 +797,13 @@ function tripal_chado_bundle_create_instances_base(&$info, $entity_type, $bundle
       $base_info['label'] = 'Program Version';
       $base_info['description'] = 'The version of the program used to perform this analysis. (e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter "n/a" if no version is available or applicable.';
     }
+
+    if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
+        $column_name == 'sourceversion' or $column_name == 'sourcename')) {
+      // Skip the source columns  in the analysis table. We have a custom
+      // field for those columns
+      continue;
+    }
     //
     // PROJECT TABLE
     //
@@ -1124,6 +1143,39 @@ function tripal_chado_bundle_create_instances_custom(&$info, $entity_type, $bund
       ),
     );
   }
+
+  // the analysis source.
+  if ($table_name == 'analysis') {
+    $field_name = 'local__source_data';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'Data Source',
+      'description' => 'The source where data was obtained for this analysis.',
+      'required' => FALSE,
+      'settings' => array(
+        'auto_attach' => TRUE,
+        'chado_table' => $table_name,
+        'chado_column' => 'analysis_id',
+        'base_table' => $table_name,
+      ),
+      'widget' => array(
+        'type' => 'local__source_data_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'inline',
+          'type' => 'local__source_data_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+
+  }
   // Add an image field to the Organism type.  This is a Drupal field and
   // not stored in Chado, but is used for backwards compatibility.
   if ($table_name == 'organism') {

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

@@ -307,6 +307,14 @@ function tripal_chado_populate_vocab_EDAM() {
     'definition' => 'The name of a biological or bioinformatics database.',
   ));
   tripal_associate_chado_semweb_term('db', 'name', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'data:1047',
+    'name' => 'URI',
+    'cv_name' => 'EDAM',
+    'definition' => 'The name of a biological or bioinformatics database.',
+  ));
+  tripal_associate_chado_semweb_term('analysis', 'sourceuri', $term);
 }
 
 /**
@@ -1069,6 +1077,13 @@ function tripal_chado_populate_vocab_LOCAL() {
     'cv_name' => 'local',
   ));
 
+  tripal_insert_cvterm(array(
+    'id' => 'local:source_data',
+    'name' => 'source_data',
+    'definition' => 'The location where data that is being used come from.',
+    'cv_name' => 'local',
+  ));
+
   //--------------
   // Terms for Content Types
   //--------------
@@ -1187,6 +1202,19 @@ function tripal_chado_populate_vocab_SWO() {
   ));
   tripal_associate_chado_semweb_term('analysis', 'program', $term);
 
+  $term = tripal_insert_cvterm(array(
+    'id' => 'SWO:0000001',
+    'name' => 'software',
+    'cv_name' => 'swo',
+    'definition' => 'Computer software, or generally just software, is any ' .
+    'set of machine-readable instructions (most often in the form of a ' .
+    'computer program) that conform to a given syntax (sometimes ' .
+    'referred to as a language) that is interpretable by a given ' .
+    'processor and that directs a computer\'s processor to perform ' .
+    'specific operations.',
+  ));
+  tripal_associate_chado_semweb_term('analysis', 'program', $term);
+
 }
 
 /**