go__gene_expression.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. class go__gene_expression extends ChadoField {
  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 default label for this field.
  11. public static $default_label = 'Gene expression';
  12. // The default description for this field.
  13. public static $description = 'The process in which a gene\'s sequence is converted into a
  14. mature gene product or products (proteins or RNA). This includes the production of an
  15. RNA transcript as well as any processing to produce a mature RNA product or an
  16. mRNA (for protein-coding genes) and the translation of that mRNA into protein.
  17. Protein maturation is included when required to form an active form of a product from
  18. an inactive precursor form.';
  19. // Provide a list of instance specific settings. These can be accessed within
  20. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  21. // then Drupal will automatically change these settings for the instance.
  22. // It is recommended to put settings at the instance level whenever possible.
  23. // If you override this variable in a child class be sure to replicate the
  24. // term_name, term_vocab, term_accession and term_fixed keys as these are
  25. // required for all TripalFields.
  26. public static $default_instance_settings = [
  27. // The short name for the vocabulary (e.g. schema, SO, GO, PATO, etc.).
  28. 'term_vocabulary' => 'GO',
  29. // The name of the term.
  30. 'term_name' => 'gene expression',
  31. // The unique ID (i.e. accession) of the term.
  32. 'term_accession' => '0010467',
  33. // Set to TRUE if the site admin is allowed to change the term
  34. // type. This will create form elements when editing the field instance
  35. // to allow the site admin to change the term settings above.
  36. 'term_fixed' => FALSE,
  37. ];
  38. // The default widget for this field.
  39. public static $default_widget = 'go__gene_expression_widget';
  40. // The default formatter for this field.
  41. public static $default_formatter = 'go__gene_expression_formatter';
  42. // --------------------------------------------------------------------------
  43. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  44. // --------------------------------------------------------------------------
  45. // An array containing details about the field. The format of this array
  46. // is the same as that returned by field_info_fields()
  47. protected $field;
  48. // An array containing details about an instance of the field. A field does
  49. // not have to have an instance. But if dealing with an instance (such as
  50. // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
  51. protected $instance;
  52. /**
  53. * @see TripalField::elementInfo()
  54. */
  55. public function elementInfo() {
  56. $field_term = $this->getFieldTermID();
  57. return [
  58. $field_term => [
  59. 'operations' => [],
  60. 'sortable' => FALSE,
  61. 'searchable' => FALSE,
  62. 'type' => 'xs:string',
  63. 'readonly' => TRUE,
  64. ],
  65. ];
  66. }
  67. /**
  68. *
  69. * @see TripalField::load()
  70. */
  71. public function load($entity) {
  72. $record = $entity->chado_record;
  73. $field_name = $this->field['field_name'];
  74. $field_type = $this->field['type'];
  75. $field_table = $this->instance['settings']['chado_table'];
  76. $field_column = $this->instance['settings']['chado_column'];
  77. // Get the FK that links to the base record.
  78. $schema = chado_get_schema($field_table);
  79. $base_table = $entity->chado_table;
  80. $pkey = $schema['primary key'][0];
  81. $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
  82. $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
  83. // Set some defaults for the empty record.
  84. $entity->{$field_name}['und'][0] = [
  85. 'value' => [],
  86. ];
  87. $linker_table = $base_table . '_expression';
  88. $options = [
  89. 'return_array' => 1,
  90. ];
  91. $record = chado_expand_var($record, 'table', $linker_table, $options);
  92. $exp_linkers = $record->$linker_table;
  93. if ($exp_linkers) {
  94. foreach ($exp_linkers as $i => $exp_linker) {
  95. // Because the unqiuename is a text field we must expand it.
  96. $expression = $exp_linker->expression_id;
  97. $expression = chado_expand_var($expression, 'field', 'expression.uniquename', $options);
  98. // Set the values that will be seen by the user on the page and in
  99. // web services, or anwhere this field is viewed.
  100. $entity->{$field_name}['und'][$i]['value'] = [
  101. 'name' => $expression->uniquename,
  102. 'description' => $expression->description,
  103. //'md5checksum' => $expression->md5checksum,
  104. ];
  105. // Add the pub information if a real pub is associated with the record.
  106. $pub = $exp_linker->pub_id;
  107. if ($pub->uniquename != 'null') {
  108. $pub_details = chado_get_minimal_pub_info($pub);
  109. $entity->{$field_name}['und'][$i]['value']['publication'] = $pub_details;
  110. $entity->{$field_name}['und'][$i]['value']['publication']['type'] = $pub->type_id->name;
  111. if (property_exists($pub, 'entity_id')) {
  112. $entity->{$field_name}['und'][$i]['publication'][0]['value']['entity'] = 'TripalEntity:' . $pub->entity_id;
  113. }
  114. }
  115. // Add the linker_expressionprop
  116. $linkerprop_table = $linker_table . 'prop';
  117. if (chado_table_exists($linkerprop_table)) {
  118. $exp_linker = chado_expand_var($exp_linker, 'table', $linkerprop_table, $options);
  119. $exp_linkerprops = $exp_linker->feature_expressionprop;
  120. if ($exp_linkerprops) {
  121. foreach ($exp_linkerprops AS $linkerprop) {
  122. $entity->{$field_name}['und'][$i]['value'][$linkerprop->type_id->name] = $linkerprop->value;
  123. }
  124. }
  125. }
  126. // Add the fields for the widget form. The name requres the following
  127. // format if the fields should be used as values for insertint/updating
  128. // into the chado table: [table_name]__[field_name]
  129. $entity->{$field_name}['und'][$i][$linker_table . '__expression_id'] = $expression->expression_id;
  130. $entity->{$field_name}['und'][$i][$linker_table . '__uniquename'] = $expression->uniquename;
  131. //$entity->{$field_name}['und'][$i][$linker_table . '__md5checksum'] = $expression->md5checksum;
  132. $entity->{$field_name}['und'][$i][$linker_table . '__description'] = $expression->description;
  133. }
  134. }
  135. }
  136. }