go__gene_expression.inc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. class go__gene_expression extends TripalField {
  3. // --------------------------------------------------------------------------
  4. // EDITABLE STATIC CONSTANTS
  5. //
  6. // The following constants SHOULD be set for each descendent class. They are
  7. // used by the static functions to provide information to Drupal about
  8. // the field and it's default widget and formatter.
  9. // --------------------------------------------------------------------------
  10. // The term that this field maps to. The format for the term should be:
  11. // [vocab]:[accession] where [vocab] is the short name of the vocabulary
  12. // and [acession] is the unique accession number for the term. This term
  13. // must already exist in the vocabulary storage backend. This
  14. // value should never be changed once fields exist for this type.
  15. public static $term = 'GO:0010467';
  16. // The default lable for this field.
  17. public static $label = 'Gene expression';
  18. // The default description for this field.
  19. public static $description = 'The process in which a gene\'s sequence is converted into a
  20. mature gene product or products (proteins or RNA). This includes the production of an
  21. RNA transcript as well as any processing to produce a mature RNA product or an
  22. mRNA (for protein-coding genes) and the translation of that mRNA into protein.
  23. Protein maturation is included when required to form an active form of a product from
  24. an inactive precursor form.';
  25. // Provide a list of global settings. These can be accessed witihn the
  26. // globalSettingsForm. When the globalSettingsForm is submitted then
  27. // Drupal will automatically change these settings for all fields.
  28. public static $settings = array(
  29. 'chado_table' => '',
  30. 'chado_column' => '',
  31. 'base_table' => '',
  32. );
  33. // Provide a list of instance specific settings. These can be access within
  34. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  35. // then Drupal with automatically change these settings for the instnace.
  36. // It is recommended to put settings at the instance level whenever possible.
  37. public static $instance_settings = array();
  38. // Set this to the name of the storage backend that by default will support
  39. // this field.
  40. public static $storage = 'tripal_no_storage';
  41. // The default widget for this field.
  42. public static $default_widget = 'go__gene_expression_widget';
  43. // The default formatter for this field.
  44. public static $default_formatter = 'go__gene_expression_formatter';
  45. // --------------------------------------------------------------------------
  46. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  47. // --------------------------------------------------------------------------
  48. // An array containing details about the field. The format of this array
  49. // is the same as that returned by field_info_fields()
  50. protected $field;
  51. // An array containing details about an instance of the field. A field does
  52. // not have to have an instance. But if dealing with an instance (such as
  53. // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
  54. protected $instance;
  55. /**
  56. *
  57. * @see TripalField::validate()
  58. */
  59. public function validate($entity_type, $entity, $field, $items, &$errors) {
  60. }
  61. /**
  62. *
  63. * @see TripalField::load()
  64. */
  65. public function load($entity, $details = array()) {
  66. $record = $details['record'];
  67. $field_name = $this->field['field_name'];
  68. $field_type = $this->field['type'];
  69. $field_table = $this->field['settings']['chado_table'];
  70. $field_column = $this->field['settings']['chado_column'];
  71. // Get the FK that links to the base record.
  72. $schema = chado_get_schema($field_table);
  73. $base_table = $details['record']->tablename;
  74. $pkey = $schema['primary key'][0];
  75. $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
  76. $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
  77. // Set some defaults for the empty record.
  78. $entity->{$field_name}['und'][0] = array(
  79. 'value' => array(),
  80. );
  81. $linker_table = $base_table . '_expression';
  82. $options = array(
  83. 'return_array' => 1,
  84. );
  85. $record = chado_expand_var($record, 'table', $linker_table, $options);
  86. $exp_linkers = $record->$linker_table;
  87. if ($exp_linkers) {
  88. foreach ($exp_linkers as $i => $exp_linker) {
  89. // Because the unqiuename is a text field we must expand it.
  90. $expression = $exp_linker->expression_id;
  91. $expression = chado_expand_var($expression, 'field', 'expression.uniquename', $options);
  92. // Set the values that will be seen by the user on the page and in
  93. // web services, or anwhere this field is viewed.
  94. $entity->{$field_name}['und'][$i]['value'] = array(
  95. 'name' => $expression->uniquename,
  96. 'description' => $expression->description,
  97. //'md5checksum' => $expression->md5checksum,
  98. );
  99. // Add the pub information if a real pub is associated with the record.
  100. $pub = $exp_linker->pub_id;
  101. if ($pub->uniquename != 'null') {
  102. $pub_details = tripal_get_minimal_pub_info($pub);
  103. $entity->{$field_name}['und'][$i]['value']['publication'] = $pub_details;
  104. $entity->{$field_name}['und'][$i]['value']['publication']['type'] = $pub->type_id->name;
  105. if (property_exists($pub, 'entity_id')) {
  106. $entity->{$field_name}['und'][$i]['publication'][0]['value']['entity'] = 'TripalEntity:' . $pub->entity_id;
  107. }
  108. }
  109. // Add the linker_expressionprop
  110. $linkerprop_table = $linker_table . 'prop';
  111. if (db_table_exists('chado.' . $linkerprop_table)) {
  112. $exp_linker = chado_expand_var($exp_linker, 'table', $linkerprop_table, $options);
  113. $exp_linkerprops = $exp_linker->feature_expressionprop;
  114. if ($exp_linkerprops) {
  115. foreach ($exp_linkerprops AS $linkerprop) {
  116. $entity->{$field_name}['und'][$i]['value'][$linkerprop->type_id->name] = $linkerprop->value;
  117. }
  118. }
  119. }
  120. // Add the fields for the widget form. The name requres the following
  121. // format if the fields should be used as values for insertint/updating
  122. // into the chado table: [table_name]__[field_name]
  123. $entity->{$field_name}['und'][$i][$linker_table . '__expression_id'] = $expression->expression_id;
  124. $entity->{$field_name}['und'][$i][$linker_table . '__uniquename'] = $expression->uniquename;
  125. //$entity->{$field_name}['und'][$i][$linker_table . '__md5checksum'] = $expression->md5checksum;
  126. $entity->{$field_name}['und'][$i][$linker_table . '__description'] = $expression->description;
  127. }
  128. }
  129. }
  130. /**
  131. *
  132. * @see TripalField::settingsForm()
  133. */
  134. public function settingsForm($has_data) {
  135. }
  136. /**
  137. *
  138. * @param unknown $form
  139. * @param unknown $form_state
  140. */
  141. public function settingsFormValidate($form, &$form_state) {
  142. }
  143. /**
  144. *
  145. * @see TripalField::instanceSettingsForm()
  146. */
  147. public function instanceSettingsForm() {
  148. }
  149. /**
  150. *
  151. * @see TripalField::instanceSettingsFormValidate()
  152. */
  153. public function instanceSettingsFormValidate($form, &$form_state) {
  154. }
  155. }