go__gene_expression.inc 6.9 KB

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