go__gene_expression.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 lable 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 access within
  20. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  21. // then Drupal with automatically change these settings for the instnace.
  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 = array(
  27. // The short name for the vocabulary (e.g. shcema, 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. protected function elementInfo() {
  56. $field_term = $this->getFieldTermID();
  57. return array(
  58. $field_term => array(
  59. 'operations' => array(),
  60. 'sortable' => FALSE,
  61. 'searchable' => FALSE,
  62. ),
  63. );
  64. }
  65. /**
  66. *
  67. * @see TripalField::load()
  68. */
  69. public function load($entity) {
  70. $record = $entity->chado_record;
  71. $field_name = $this->field['field_name'];
  72. $field_type = $this->field['type'];
  73. $field_table = $this->instance['settings']['chado_table'];
  74. $field_column = $this->instance['settings']['chado_column'];
  75. // Get the FK that links to the base record.
  76. $schema = chado_get_schema($field_table);
  77. $base_table = $entity->chado_table;
  78. $pkey = $schema['primary key'][0];
  79. $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
  80. $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
  81. // Set some defaults for the empty record.
  82. $entity->{$field_name}['und'][0] = array(
  83. 'value' => array(),
  84. );
  85. $linker_table = $base_table . '_expression';
  86. $options = array(
  87. 'return_array' => 1,
  88. );
  89. $record = chado_expand_var($record, 'table', $linker_table, $options);
  90. $exp_linkers = $record->$linker_table;
  91. if ($exp_linkers) {
  92. foreach ($exp_linkers as $i => $exp_linker) {
  93. // Because the unqiuename is a text field we must expand it.
  94. $expression = $exp_linker->expression_id;
  95. $expression = chado_expand_var($expression, 'field', 'expression.uniquename', $options);
  96. // Set the values that will be seen by the user on the page and in
  97. // web services, or anwhere this field is viewed.
  98. $entity->{$field_name}['und'][$i]['value'] = array(
  99. 'name' => $expression->uniquename,
  100. 'description' => $expression->description,
  101. //'md5checksum' => $expression->md5checksum,
  102. );
  103. // Add the pub information if a real pub is associated with the record.
  104. $pub = $exp_linker->pub_id;
  105. if ($pub->uniquename != 'null') {
  106. $pub_details = tripal_get_minimal_pub_info($pub);
  107. $entity->{$field_name}['und'][$i]['value']['publication'] = $pub_details;
  108. $entity->{$field_name}['und'][$i]['value']['publication']['type'] = $pub->type_id->name;
  109. if (property_exists($pub, 'entity_id')) {
  110. $entity->{$field_name}['und'][$i]['publication'][0]['value']['entity'] = 'TripalEntity:' . $pub->entity_id;
  111. }
  112. }
  113. // Add the linker_expressionprop
  114. $linkerprop_table = $linker_table . 'prop';
  115. if (chado_table_exists($linkerprop_table)) {
  116. $exp_linker = chado_expand_var($exp_linker, 'table', $linkerprop_table, $options);
  117. $exp_linkerprops = $exp_linker->feature_expressionprop;
  118. if ($exp_linkerprops) {
  119. foreach ($exp_linkerprops AS $linkerprop) {
  120. $entity->{$field_name}['und'][$i]['value'][$linkerprop->type_id->name] = $linkerprop->value;
  121. }
  122. }
  123. }
  124. // Add the fields for the widget form. The name requres the following
  125. // format if the fields should be used as values for insertint/updating
  126. // into the chado table: [table_name]__[field_name]
  127. $entity->{$field_name}['und'][$i][$linker_table . '__expression_id'] = $expression->expression_id;
  128. $entity->{$field_name}['und'][$i][$linker_table . '__uniquename'] = $expression->uniquename;
  129. //$entity->{$field_name}['und'][$i][$linker_table . '__md5checksum'] = $expression->md5checksum;
  130. $entity->{$field_name}['und'][$i][$linker_table . '__description'] = $expression->description;
  131. }
  132. }
  133. }
  134. }