Browse Source

Added a new field for the content type if it's not used to identify the content. And fixed a few bugs

Stephen Ficklin 8 years ago
parent
commit
fe0d5b9b97

+ 7 - 1
tripal/api/tripal.entities.api.inc

@@ -222,10 +222,16 @@ function tripal_create_bundle($args, &$error = '') {
     $bundle_name = 'bio_data_' . $term->id;
     $einfo = entity_get_info('TripalEntity');
     if (!in_array($bundle_name, array_keys($einfo['bundles']))) {
+      // Make the label for the content type have capitalized words.  The
+      // exception is 'mRNA' which we know should not be uppercased.
+      $label = ucwords(preg_replace('/_/', ' ', $term_name));
+      if ($term_name == 'mRNA') {
+        $label = $term_name;
+      }
       // Insert the bundle.
       db_insert('tripal_bundle')
         ->fields(array(
-          'label' => $term_name,
+          'label' => $label,
           'type' => 'TripalEntity',
           'name' => $bundle_name,
           'term_id' => $term->id,

+ 9 - 1
tripal/includes/TripalBundleUIController.inc

@@ -110,11 +110,19 @@ function tripal_tripal_bundle_form($form, &$form_state, $entityDataType) {
       array(
         array(
           'header' => TRUE,
-          'data' => 'Term',
+          'data' => 'Term Name',
           'class' => array('side-header')
         ),
         $term->name
       ),
+      array(
+        array(
+          'header' => TRUE,
+          'data' => 'Accession',
+          'class' => array('side-header')
+        ),
+        $term->accession
+      ),
       array(
         array(
           'header' => TRUE,

+ 1 - 3
tripal/includes/TripalEntityUIController.inc

@@ -333,9 +333,7 @@ function tripal_view_entity($entity, $view_mode = 'full') {
    $num_records = $cquery->execute();
 
    // Calculate the range and create a pager.
-   $num_per_page = 25;
-   $offset = array_key_exists('page', $_GET) ? $_GET['page'] : 0;
-   $query->pager($num_per_page);
+   $query->pager(25);
    $query->tableSort($headers);
    $results = $query->execute();
    $pager = theme('pager');

+ 69 - 0
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type.inc

@@ -0,0 +1,69 @@
+<?php
+
+class schema__additional_type 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 = 'Type';
+
+  // The default description for this field.
+  public static $description = 'An additional type for this field.';
+
+  // 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' => 'schema',
+    // The name of the term.
+    'term_name' => 'additionalType',
+    // The unique ID (i.e. accession) of the term.
+    'term_accession' => 'additionalType',
+    // 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 = 'schema__additional_type_widget';
+
+  // The default formatter for this field.
+  public static $default_formatter = 'schema__additional_type_formatter';
+
+
+
+  /**
+   *
+   * @see TripalField::load()
+   */
+  public function load($entity, $details = array()) {
+    $record = $details['record'];
+    $base_table = $this->instance['settings']['base_table'];
+
+    $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'];
+
+
+    // Set some defaults for the empty record.
+    $entity->{$field_name}['und'][0] = array(
+      'value' => $record->type_id->name,
+      'chado-' . $field_table . '__type_id' => $record->type_id->cvterm_id,
+    );
+  }
+
+}

+ 30 - 0
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type_formatter.inc

@@ -0,0 +1,30 @@
+<?php
+
+class schema__additional_type_formatter extends ChadoFieldFormatter {
+  // The default lable for this field.
+  public static $default_label = 'Type';
+
+  // The list of field types for which this formatter is appropriate.
+  public static $field_types = array('schema__additional_type');
+
+  /**
+   *
+   * @see TripalFieldFormatter::settingsForm()
+   */
+  public function settingsForm($view_mode, $form, &$form_state) {
+
+  }
+
+  /**
+   *
+   * @see TripalFieldFormatter::view()
+   */
+  public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
+    foreach ($items as $delta => $item) {
+      $element[$delta] = array(
+        '#type' => 'markup',
+        '#markup' => $item['value'],
+      );
+    }
+  }
+}

+ 26 - 0
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type_widget.inc

@@ -0,0 +1,26 @@
+<?php
+
+class schema__additional_type_widget extends ChadoFieldWidget {
+  // The default lable for this field.
+  public static $default_label = 'Type';
+
+  // The list of field types for which this formatter is appropriate.
+  public static $field_types = array('schema__additional_type');
+
+  /**
+   *
+   * @see TripalFieldWidget::form()
+   */
+  public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
+
+  }
+
+  /**
+   *
+   * @see TripalFieldWidget::submit()
+   */
+  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+
+  }
+}

+ 1 - 13
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name.inc

@@ -15,7 +15,7 @@ class schema__alternate_name extends ChadoField {
   public static $default_label = 'Synonyms';
 
   // The default description for this field.
-  public static $description = 'Adds an alternative name (synonym or alias) to this record.';
+  public static $description = 'An alternative name (synonym or alias) to this record.';
 
   // Provide a list of instance specific settings. These can be access within
   // the instanceSettingsForm.  When the instanceSettingsForm is submitted
@@ -43,18 +43,6 @@ class schema__alternate_name extends ChadoField {
   // The default formatter for this field.
   public static $default_formatter = 'schema__alternate_name_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()

+ 3 - 0
tripal_chado/includes/loaders/tripal_chado.pub_importers.inc

@@ -1001,6 +1001,9 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
     $action = 'skipped';
     return FALSE;
   }
+  if(count($pub_ids) == 1 and $update_if_exists) {
+    $pub_id = $pub_ids[0];
+  }
 
   // get the publication type (use the first publication type)
   if (array_key_exists('Publication Type', $pub_details)) {

+ 62 - 2
tripal_chado/includes/tripal_chado.fields.inc

@@ -89,8 +89,9 @@ function tripal_chado_bundle_create_fields_base(&$info, $details, $entity_type,
       continue;
     }
 
-    // Skip the type field.
-    if ($table_name == $type_table and $column_name == $type_field) {
+    // Skip the type field that will always be custom
+    if (($table_name == $type_table and $column_name == $type_field) or
+         $column_name == 'type_id') {
       continue;
     }
 
@@ -185,6 +186,21 @@ function tripal_chado_bundle_create_fields_custom(&$info, $details, $entity_type
 
   $schema = chado_get_schema($table_name);
 
+  // BASE TYPE_ID
+  if (array_key_exists('type_id', $schema['fields'])) {
+    $field_name = 'schema__additional_type';
+    $field_type = 'schema__additional_type';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => 1,
+      'locked' => TRUE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
+  }
+
   // BASE ORGANISM_ID
   if ($table_name != 'organism' and
       array_key_exists('organism_id', $schema['fields'])) {
@@ -573,6 +589,13 @@ function tripal_chado_bundle_create_instances_base(&$info, $entity_type, $bundle
     if ($column_name == $pkey or $column_name == $type_field) {
       continue;
     }
+
+    // Skip the type field that will always be custom
+    if (($table_name == $type_table and $column_name == $type_field) or
+        $column_name == 'type_id') {
+      continue;
+    }
+
     $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
     if (!$cvterm) {
       // We already provided an error when creating the base field.  So
@@ -752,6 +775,43 @@ function tripal_chado_bundle_create_instances_custom(&$info, $entity_type, $bund
   $cvterm_id  = $details['chado_cvterm_id'];
   $schema = chado_get_schema($table_name);
 
+  // BASE TYPE_ID
+  if (array_key_exists('type_id', $schema['fields'])) {
+    $field_name = 'schema__additional_type';
+    $is_required = FALSE;
+    if (array_key_exists('not null', $schema['fields']['type_id']) and
+        $schema['fields']['type_id']['not null']) {
+      $is_required = TRUE;
+    }
+    $info[$field_name] =  array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'Type',
+      'description' => 'Select a type for this record.',
+      'required' => $is_required,
+      'settings' => array(
+        'auto_attach' => TRUE,
+        'chado_table' => $table_name,
+        'chado_column' => 'type_id',
+        'base_table' => $table_name,
+      ),
+      'widget' => array(
+        'type' => 'schema__additional_type_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'inline',
+          'type' => 'schema__additional_type_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+  }
+
   // BASE ORGANISM_ID
   if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
     $field_name = 'obi__organism';

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

@@ -197,6 +197,26 @@ function tripal_chado_populate_vocab_SCHEMA() {
     'definition' => 'URL of the item.',
   ));
   tripal_associate_chado_semweb_term('db', 'URL', $term);
+
+  // Typically the type_id field is used for distinguishing between records
+  // but in the case that it isn't then we need to associate a term with it
+  // An entity already has a type so if that type is not dicated by the
+  // type_id field then what is in the type_id should therefore be an
+  // "additionalType".  Therefore we need to add and map this term to all
+  // of the appropriate type_id fields.
+  $term = tripal_insert_cvterm(array(
+    'id' => 'schema:additionalType',
+    'name' => 'additionalType',
+    'cv_name' => 'An additional type for the item, typically used for adding more specific types from external vocabularies in microdata syntax. This is a relationship between something and a class that the thing is in.',
+    'definition' => 'URL of the item.',
+  ));
+  $tables = chado_get_table_names(TRUE);
+  foreach ($tables as $table) {
+    $schema = chado_get_schema($table);
+    if (in_array("type_id", array_keys($schema['fields']))) {
+      tripal_associate_chado_semweb_term($table, 'type_id', $term);
+    }
+  }
 }
 
 /**
@@ -1060,6 +1080,56 @@ function tripal_chado_populate_vocab_LOCAL() {
     'is_relationship' => 0,
     'db_name' => 'local'
   ), array('update_existing' => TRUE));
+
+  // Add a term to be used for an inherent 'type_id' for the organism table.
+  tripal_insert_cvterm(array(
+    'id' => 'local:analysis',
+    'name' => 'analysis',
+    'definition' => 'A process as a method of studying the nature of something ' .
+    'or of determining its essential features and their relations. ' .
+    '(Random House Kernerman Webster\'s College Dictionary, © 2010 K ' .
+    'Dictionaries Ltd).',
+    'cv_name' => 'local',
+  ));
+
+  // TODO: change this to foaf:Project
+  tripal_insert_cvterm(array(
+    'id' => 'local:project',
+    'name' => 'project',
+    'definition' => 'A plan or proposal for accomplishing something. ' .
+    '(American Heritage® Dictionary of the English Language, Fifth Edition. ' .
+    'Copyright © 2011 by Houghton Mifflin Harcourt Publishing Company).',
+    'cv_name' => 'local',
+  ));
+
+  //--------------
+  // Terms for Content Types
+  //--------------
+  tripal_insert_cvterm(array(
+    'id' => 'local:contact',
+    'name' => 'contact',
+    'definition' => 'An entity (e.g. individual or organization) through ' .
+    'whom a person can gain access to information, favors, ' .
+    'influential people, and the like.',
+    'cv_name' => 'local',
+  ));
+
+  tripal_insert_cvterm(array(
+    'id' => 'local:relationship',
+    'name' => 'relationship',
+    'definition' => 'The way in which two things are connected.',
+    'cv_name' => 'local',
+  ));
+
+  tripal_insert_cvterm(array(
+    'id' => 'local:biomaterial',
+    'name' => 'biomaterial',
+    'definition' => 'A biomaterial represents the MAGE concept of BioSource, BioSample, ' .
+    'and LabeledExtract. It is essentially some biological material (tissue, cells, serum) that ' .
+    'may have been processed. Processed biomaterials should be traceable back to raw ' .
+    'biomaterials via the biomaterialrelationship table.',
+    'cv_name' => 'local',
+  ));
 }
 /**
  * Adds the Systems Biology Ontology database and terms.
@@ -1106,6 +1176,22 @@ function tripal_chado_populate_vocab_SO() {
     'urlprefix' => 'http://www.sequenceontology.org/browser/current_svn/term/{db}:{accession}',
   ));
   tripal_insert_cv('sequence','The Sequence Ontology.');
+
+  // Add the terms we need for default content types.  This needs to be
+  // done because the sequence ontology may not already be loaded but we
+  // still want to provide these default content types.
+  $term = tripal_insert_cvterm(array(
+    'id' => 'SO:0000704',
+    'name' => 'gene',
+    'cv_name' => 'sequence',
+    'definition' => 'A region (or regions) that includes all of the sequence elements necessary to encode a functional transcript. A gene may include regulatory regions, transcribed regions and/or other functional sequence regions. [SO:immuno_workshop]',
+  ));
+  $term = tripal_insert_cvterm(array(
+    'id' => 'SO:0000234',
+    'name' => 'mRNA',
+    'cv_name' => 'sequence',
+    'definition' => 'Messenger RNA is the intermediate molecule between DNA and protein. It includes UTR and coding sequences. It does not contain introns. [SO:ma]',
+  ));
 }
 
 /**

+ 31 - 53
tripal_chado/includes/tripal_chado.setup.inc

@@ -220,58 +220,6 @@ function tripal_chado_prepare_chado() {
     module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.semweb');
     tripal_chado_populate_chado_semweb_table();
 
-    // Unfortunately, some Chado base tables do not have a type_id, so we must
-    // take special action for those tables.  These include: organism and
-    // analysis. Until we can find an appropriate controlled vocabulary
-    // that is well supported by the community with types for these tables we
-    // will have to use in-house terms.
-
-    // Add a term to be used for an inherent 'type_id' for the organism table.
-    tripal_insert_cvterm(array(
-      'id' => 'local:analysis',
-      'name' => 'analysis',
-      'definition' => 'A process as a method of studying the nature of something ' .
-        'or of determining its essential features and their relations. ' .
-        '(Random House Kernerman Webster\'s College Dictionary, © 2010 K ' .
-        'Dictionaries Ltd).',
-      'cv_name' => 'local',
-    ));
-
-    // TODO: change this to foaf:Project
-    tripal_insert_cvterm(array(
-      'id' => 'local:project',
-      'name' => 'project',
-      'definition' => 'A plan or proposal for accomplishing something. ' .
-        '(American Heritage® Dictionary of the English Language, Fifth Edition. ' .
-        'Copyright © 2011 by Houghton Mifflin Harcourt Publishing Company).',
-      'cv_name' => 'local',
-    ));
-
-    tripal_insert_cvterm(array(
-      'id' => 'local:contact',
-      'name' => 'contact',
-      'definition' => 'An entity (e.g. individual or organization) through ' .
-         'whom a person can gain access to information, favors, ' .
-         'influential people, and the like.',
-      'cv_name' => 'local',
-    ));
-
-    tripal_insert_cvterm(array(
-      'id' => 'local:relationship',
-      'name' => 'relationship',
-      'definition' => 'The way in which two things are connected.',
-      'cv_name' => 'local',
-    ));
-
-    tripal_insert_cvterm(array(
-      'id' => 'local:biomaterial',
-      'name' => 'biomaterial',
-      'definition' => 'A biomaterial represents the MAGE concept of BioSource, BioSample, ' .
-        'and LabeledExtract. It is essentially some biological material (tissue, cells, serum) that ' .
-        'may have been processed. Processed biomaterials should be traceable back to raw ' .
-        'biomaterials via the biomaterialrelationship table.',
-      'cv_name' => 'local',
-    ));
 
     // We want to provide a set of commonly used entity types by default. This
     // way when a user first installs Tripal there are some commonly used
@@ -321,7 +269,7 @@ function tripal_chado_prepare_chado() {
       throw new Exception($error['!message']);
     }
 
-    // Create the 'Genetic Map' entity type. This uses the local:project term.
+    // Create the 'Map' entity type. This uses the local:project term.
     $error = '';
     $args = array(
       'vocabulary' => 'data',
@@ -349,6 +297,36 @@ function tripal_chado_prepare_chado() {
       throw new Exception($error['!message']);
     }
 
+    // Create the 'Gene' entity type.
+    $error = '';
+    $args = array(
+      'vocabulary' => 'SO',
+      'accession' => '0000704',
+      'term_name' => 'gene',
+      'storage_args' => array(
+        'data_table' => 'feature',
+        'type_column' => 'type_id',
+      )
+    );
+    if (!tripal_create_bundle($args, $error)) {
+      throw new Exception($error['!message']);
+    }
+
+    // Create the 'mRNA' entity type.
+    $error = '';
+    $args = array(
+      'vocabulary' => 'SO',
+      'accession' => '0000234',
+      'term_name' => 'mRNA',
+      'storage_args' => array(
+        'data_table' => 'feature',
+        'type_column' => 'type_id',
+      )
+    );
+    if (!tripal_create_bundle($args, $error)) {
+      throw new Exception($error['!message']);
+    }
+
     // Initialize the population of the chado_cvterm_mapping table.
     tripal_chado_map_cvterms();