Browse Source

Adjustment to update function

Stephen Ficklin 7 years ago
parent
commit
6f149131f6

+ 17 - 30
tripal_chado/includes/TripalFields/chado_linker__cvterm/chado_linker__cvterm.inc → tripal_chado/includes/TripalFields/sio__annotation/sio__annotation.inc

@@ -1,6 +1,6 @@
 <?php
 
-class chado_linker__cvterm extends ChadoField {
+class sio__annotation extends ChadoField {
 
 
   // --------------------------------------------------------------------------
@@ -12,11 +12,10 @@ class chado_linker__cvterm extends ChadoField {
   // --------------------------------------------------------------------------
 
   // The default lable for this field.
-  public static $default_label = 'Chado Annotation';
+  public static $default_label = 'Annotations';
 
   // The default description for this field.
-  public static $description = 'This record can be annotated with terms from other
-              vocabularies.';
+  public static $description = 'This record is annotated with controlled vocabulary terms.';
 
   // Provide a list of instance specific settings. These can be access within
   // the instanceSettingsForm.  When the instanceSettingsForm is submitted
@@ -27,11 +26,11 @@ class chado_linker__cvterm extends ChadoField {
   // 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',
+    'term_vocabulary' => 'SIO',
     // The name of the term.
-    'term_name' => 'cvterm',
+    'term_name' => 'annotation',
     // The unique ID (i.e. accession) of the term.
-    'term_accession' => 'cvterm',
+    'term_accession' => '001166',
     // 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.
@@ -50,8 +49,6 @@ class chado_linker__cvterm extends ChadoField {
   // and field_create_instance().
   public static $no_ui = FALSE;
 
-
-
   /**
    *
    * @see TripalField::load()
@@ -63,17 +60,9 @@ class chado_linker__cvterm extends ChadoField {
     $field_column = $this->instance['settings']['chado_column'];
     $base_table = $this->instance['settings']['base_table'];
 
-    $vocabulary = $this->instance['settings']['term_vocabulary'];
-    $accession = $this->instance['settings']['term_accession'];
-    $cvterm = tripal_get_cvterm(array(
-      'dbxref_id' => array(
-        'db_id' => array(
-          'name' => $vocabulary,
-        ),
-        'accession' => $accession,
-      ),
-    ));
-    $cvterm_id = $cvterm->cvterm_id;
+    $vocabulary = tripal_get_chado_semweb_term('db', 'name');
+    $accession = tripal_get_chado_semweb_term('db', 'accession');
+    $definition = tripal_get_chado_semweb_term('cvterm', 'definition');
 
     // Get the FK that links to the base record.
     $schema = chado_get_schema($field_table);
@@ -85,7 +74,8 @@ class chado_linker__cvterm extends ChadoField {
     $chado_record = $entity->chado_record;
     $entity->{$field_name}['und'][0] = array(
       'value' => '',
-      'chado-' . $field_table . '__' . $fkey_lcolumn => '',
+      'chado-' . $field_table . '__' . $pkey => '',
+      'chado-' . $field_table . '__' . $fkey_lcolumn => $chado_record->$fkey_rcolumn,
       'chado-' . $field_table . '__' . 'cvterm_id' => '',
       // The pub column is present in the cell_line_cvterm, feature_cvterm,
       // library_cvterm, phenotype_comparision_cvterm, phenotype_cvterm,
@@ -97,18 +87,12 @@ class chado_linker__cvterm extends ChadoField {
       // feature_cvterm, phenotype_comparision_cvterm, phenotype_cvterm,
       // and stock_cvterm tables.
       'chado-' . $field_table . '__' . 'rank' => '',
-      // The cvterm_type_id is present in the expression_cvterm table.
-      'cvterm_type_id' => '',
-      // The following field are to help link the cvterm.
-      'cv__cv_id' => '',
-      'cvterm__name' => '',
     );
 
     // Get the annotations associated with this base record for this fields type.
     $columns = array('*');
     $match = array(
       $fkey_lcolumn => $chado_record->$fkey_rcolumn,
-      'cvterm_id' => $cvterm_id,
     );
     $options = array(
       'return_array' => TRUE,
@@ -119,15 +103,18 @@ class chado_linker__cvterm extends ChadoField {
       $linker = $fcvterms[$i];
       $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $linker->cvterm_id));
       $entity->{$field_name}['und'][$i] = array(
-        'value' => $linker->$pkey,
+        'value' => array(
+          $vocabulary => $cvterm->dbxref_id->db_id->name,
+          $accession => $cvterm->dbxref_id->accession,
+          $definition => $cvterm->cvterm_id->name
+        ),
+        'chado-' . $field_table . '__' . $pkey => $linker->$pkey,
         'chado-' . $field_table . '__' . $fkey_lcolumn => $linker->$fkey_lcolumn,
         'chado-' . $field_table . '__' . 'cvterm_id' => $linker->cvterm_id,
         'chado-' . $field_table . '__' . 'pub_id' => property_exists($linker, 'pub_id') ? $linker->pub_id : '',
         'chado-' . $field_table . '__' . 'is_not' => property_exists($linker, 'is_not') ? $linker->is_not : '',
         'chado-' . $field_table . '__' . 'rank' => property_exists($linker, 'rank') ? $linker->rank : '',
         'chado-' . $field_table . '__' . 'cvterm_type_id' => property_exists($linker, 'cvterm_type_id') ? $linker->cvterm_type_id : '',
-        'cv__cv_id' => $cvterm->cv_id->cv_id,
-        'cvterm__name' => $cvterm->name,
       );
     }
   }

+ 4 - 11
tripal_chado/includes/TripalFields/chado_linker__cvterm/chado_linker__cvterm_formatter.inc → tripal_chado/includes/TripalFields/sio__annotation/sio__annotation_formatter.inc

@@ -1,6 +1,6 @@
 <?php
 
-class chado_linker__cvterm_formatter extends ChadoFieldFormatter {
+class sio__annotation_formatter extends ChadoFieldFormatter {
   // The default lable for this field.
   public static $default_label = 'Chado Annotation';
 
@@ -74,9 +74,10 @@ class chado_linker__cvterm_formatter extends ChadoFieldFormatter {
    * @see TripalFieldFormatter::view()
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
-    $headers = array('Term', 'Definition', 'Is Not', 'Publication');
+    $headers = array('Term', 'Definition', 'Is Not');
     $rows = array();
 
+    dpm($items);
     $chado_table = $this->instance['settings']['chado_table'];
     foreach ($items as $delta => $item) {
       if ($item['chado-' . $chado_table . '__cvterm_id']) {
@@ -89,18 +90,10 @@ class chado_linker__cvterm_formatter extends ChadoFieldFormatter {
           $accession = l($accession, tripal_get_dbxref_url($dbxref), array('attributes' => array('target' => '_blank')));
         }
 
-        // Build the publication reference.
-        $pub_ref = '';
-        $pub_id = $item['chado-' . $chado_table . '__pub_id'];
-        if ($pub_id) {
-          $pub = chado_generate_var('pub', array('pub_id' => $pub_id));
-          $pub_ref = $pub->uniquename;
-        }
         $rows[] = array(
           $accession,
           $cvterm->definition,
           $item['chado-' . $chado_table . '__is_not'] ? 'Yes' : '',
-          $pub_ref,
         );
       }
     }
@@ -116,7 +109,7 @@ class chado_linker__cvterm_formatter extends ChadoFieldFormatter {
         'id' => "$chado_table-table-terms",
         'class' => 'tripal-data-table'
       ),
-      'caption' => '',
+      'caption' => 'This record is associated with the following annotations:',
       'sticky' => FALSE,
       'colgroups' => array(),
       'empty' => 'There are no annotations of this type',

+ 1 - 1
tripal_chado/includes/TripalFields/chado_linker__cvterm/chado_linker__cvterm_widget.inc → tripal_chado/includes/TripalFields/sio__annotation/sio__annotation_widget.inc

@@ -1,6 +1,6 @@
 <?php
 
-class chado_linker__cvterm_widget extends ChadoFieldWidget {
+class sio__annotation_widget extends ChadoFieldWidget {
   // The default lable for this field.
   public static $default_label = 'Chado Annotation';
 

+ 59 - 0
tripal_chado/includes/tripal_chado.fields.inc

@@ -563,6 +563,27 @@ function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type,
     }
   }
 
+  // CVTERMS
+  $term_table = $table_name . '_cvterm';
+  if (chado_table_exists($term_table)) {
+    $schema = chado_get_schema($term_table);
+    $pkey = $schema['primary key'][0];
+    $lkey = key($schema['foreign keys'][$table_name]['columns']);
+    $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
+
+    $field_name = 'sio__annotation';
+    $field_type = 'sio__annotation';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
+  }
+
   // PUBLICATIONS
   $pub_table = $table_name . '_pub';
   if (chado_table_exists($pub_table)) {
@@ -1742,6 +1763,44 @@ function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle
      }
    }
 
+  // CVTERMS
+  $term_table = $table_name . '_cvterm';
+  if (chado_table_exists($term_table)) {
+    $schema = chado_get_schema($term_table);
+    $pkey = $schema['primary key'][0];
+    $lkey = key($schema['foreign keys'][$table_name]['columns']);
+    $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
+
+    $field_name = 'sio__annotation';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'Annotations',
+      'description' => 'Annotations that are associated with this record.',
+      'required' => FALSE,
+      'settings' => array(
+        'auto_attach' => FALSE,
+        'chado_table' => $term_table,
+        'chado_column' => $pkey,
+        'base_table' => $table_name,
+      ),
+      'widget' => array(
+        'type' => 'sio__annotation_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'hidden',
+          'type' => 'sio__annotation_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+  }
+
 
   // PUBLICATIONS
   $pub_table = $table_name . '_pub';

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

@@ -270,6 +270,34 @@ function tripal_chado_populate_vocab_SIO() {
   ));
   tripal_associate_chado_semweb_term('featurepos', 'mappos', $term);
 
+  $term = tripal_insert_cvterm(array(
+    'id' => 'SIO:001166',
+    'name' => 'annotation',
+    'cv_name' => 'SIO',
+    'definition' => 'An annotation is a written explanatory or critical description, or other in-context information (e.g., pattern, motif, link), that has been associated with data or other types of information.',
+  ));
+  tripal_associate_chado_semweb_term('feature_cvterm', 'cvterm_id', $term);
+  tripal_associate_chado_semweb_term('analysis_cvterm', 'cvterm_id', $term);
+  tripal_associate_chado_semweb_term('cell_line_cvterm', 'cvterm_id', $term);
+  tripal_associate_chado_semweb_term('environment_cvterm', 'cvterm_id', $term);
+  tripal_associate_chado_semweb_term('expression_cvterm', 'cvterm_id', $term);
+  tripal_associate_chado_semweb_term('library_cvterm', 'cvterm_id', $term);
+  tripal_associate_chado_semweb_term('organism_cvterm', 'cvterm_id', $term);
+  tripal_associate_chado_semweb_term('phenotype_cvterm', 'cvterm_id', $term);
+  tripal_associate_chado_semweb_term('stock_cvterm', 'cvterm_id', $term);
+  tripal_associate_chado_semweb_term('stock_relationship_cvterm', 'cvterm_id', $term);
+
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'SIO:000281',
+    'name' => 'negation',
+    'cv_name' => 'SIO',
+    'definition' => 'NOT is a logical operator in that has the value true if its operand is false.',
+  ));
+  tripal_associate_chado_semweb_term('feature_cvterm', 'is_not', $term);
+  tripal_associate_chado_semweb_term('analysis_cvterm', 'is_not', $term);
+  tripal_associate_chado_semweb_term('organism_cvterm', 'is_not', $term);
+  tripal_associate_chado_semweb_term('stock_cvterm', 'is_not', $term);
 
   $term = tripal_insert_cvterm(array(
     'id' => 'SIO:001080',

+ 38 - 0
tripal_chado/tripal_chado.install

@@ -1071,4 +1071,42 @@ function tripal_chado_update_7308() {
   }
 }
 
+/**
+ * Add cvterm 'annotation' and maps to cvterm linking tables.
+ */
+function tripal_chado_update_7309() {
+  try {
+    $term = tripal_insert_cvterm(array(
+      'id' => 'SIO:001166',
+      'name' => 'annotation',
+      'cv_name' => 'SIO',
+      'definition' => 'An annotation is a written explanatory or critical description, or other in-context information (e.g., pattern, motif, link), that has been associated with data or other types of information.',
+    ));
+    tripal_associate_chado_semweb_term('feature_cvterm', 'cvterm_id', $term);
+    tripal_associate_chado_semweb_term('analysis_cvterm', 'cvterm_id', $term);
+    tripal_associate_chado_semweb_term('cell_line_cvterm', 'cvterm_id', $term);
+    tripal_associate_chado_semweb_term('environment_cvterm', 'cvterm_id', $term);
+    tripal_associate_chado_semweb_term('expression_cvterm', 'cvterm_id', $term);
+    tripal_associate_chado_semweb_term('library_cvterm', 'cvterm_id', $term);
+    tripal_associate_chado_semweb_term('organism_cvterm', 'cvterm_id', $term);
+    tripal_associate_chado_semweb_term('phenotype_cvterm', 'cvterm_id', $term);
+    tripal_associate_chado_semweb_term('stock_cvterm', 'cvterm_id', $term);
+    tripal_associate_chado_semweb_term('stock_relationship_cvterm', 'cvterm_id', $term);
 
+
+    $term = tripal_insert_cvterm(array(
+      'id' => 'SIO:000281',
+      'name' => 'negation',
+      'cv_name' => 'SIO',
+      'definition' => 'NOT is a logical operator in that has the value true if its operand is false.',
+    ));
+    tripal_associate_chado_semweb_term('feature_cvterm', 'is_not', $term);
+    tripal_associate_chado_semweb_term('analysis_cvterm', 'is_not', $term);
+    tripal_associate_chado_semweb_term('organism_cvterm', 'is_not', $term);
+    tripal_associate_chado_semweb_term('stock_cvterm', 'is_not', $term);
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
+}