go__gene_expression.inc 6.3 KB

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