chado_gene__transcripts.inc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. class chado_gene__transcripts extends TripalField {
  3. // The default lable for this field.
  4. public static $default_label = 'Transcripts';
  5. // The default description for this field.
  6. public static $default_description = 'Transcripts of genes.';
  7. // Add any default settings elements. If you override the globalSettingsForm()
  8. // or the instanceSettingsForm() functions then you need to be sure that
  9. // any settings you want those functions to manage are listed in this
  10. // array.
  11. public static $default_settings = array(
  12. 'chado_table' => '',
  13. 'chado_column' => '',
  14. 'base_table' => '',
  15. 'semantic_web' => '',
  16. );
  17. // Set this to the name of the storage backend that by default will support
  18. // this field.
  19. public static $default_storage = 'field_chado_storage';
  20. /**
  21. * @see TripalField::formatter_settings_summary()
  22. */
  23. public function formatterSettingsSummary($view_mode) {
  24. }
  25. /**
  26. * @see TripalField::formatter_settings_form()
  27. */
  28. public function formatterSettingsForm($view_mode, $form, &$form_state) {
  29. }
  30. /**
  31. * @see TripalField::formatterView()
  32. */
  33. public function formatterView(&$element, $entity_type, $entity, $langcode, $items, $display) {
  34. // Get the settings
  35. $settings = $display['settings'];
  36. $headers = array('Transcript Name', 'Identifier', 'Type', 'Location');
  37. $rows = array();
  38. foreach ($items as $delta => $item) {
  39. if (!$item['value']) {
  40. continue;
  41. }
  42. $transcript = $item['value'];
  43. // Get the field values
  44. $feature_name = $transcript['name'];
  45. $feature_uname = $transcript['identifier'];
  46. $loc = $transcript['location'];
  47. $type = $transcript['type'];
  48. // Add a link i there is an entity.
  49. if (array_key_exists('entity', $item['value']) and $item['value']['entity']) {
  50. list($entity_type, $entity_id) = explode(':', $item['value']['entity']);
  51. $feature_name = l($feature_name, "bio_data/" . $entity_id, array('attributes' => array('target' => "_blank")));
  52. }
  53. $rows[] = array($feature_name, $feature_uname, $type, $loc);
  54. }
  55. $table = array(
  56. 'header' => $headers,
  57. 'rows' => $rows,
  58. 'attributes' => array(
  59. 'id' => 'tripal_feature-table-transcripts-object',
  60. 'class' => 'tripal-data-table'
  61. ),
  62. 'sticky' => FALSE,
  63. 'caption' => "",
  64. 'colgroups' => array(),
  65. 'empty' => 'This feature has no transcripts',
  66. );
  67. $content = theme_table($table);
  68. // once we have our table array structure defined, we call Drupal's theme_table()
  69. // function to generate the table.
  70. if (count($items) > 0) {
  71. $element[0] = array(
  72. '#type' => 'markup',
  73. '#markup' => $content,
  74. );
  75. }
  76. }
  77. /**
  78. * @see TripalField::load()
  79. */
  80. public function load($entity, $details = array()) {
  81. $record = $details['record'];
  82. $field_name = $this->field['field_name'];
  83. // Set some defaults for the empty record.
  84. $entity->{$field_name}['und'][0] = array(
  85. 'value' => array(
  86. 'type' => '',
  87. 'name' => '',
  88. 'identifier' => '',
  89. 'location' => '',
  90. ),
  91. );
  92. // TODO: If the tripal_get_feature_relationships() slows this down then
  93. // we may need to write a custom function to get the data.
  94. $rels = tripal_get_feature_relationships($record);
  95. // TODO: what if other transcripts names from SO are used. In that
  96. // case we should support those too (using cvtermpath table to find them).
  97. // mRNA should not be hard-coded below.
  98. // Set the value to be a array of "table" rows.
  99. $transcripts = array();
  100. if (key_exists('part of', $rels['object']) &&
  101. key_exists('mRNA', $rels['object']['part of'])) {
  102. $transcripts = $rels['object']['part of']['mRNA'];
  103. }
  104. $headers = array('Name' ,'Identifier', 'Location');
  105. $rows = array();
  106. $i = 0;
  107. foreach ($transcripts as $transcript) {
  108. // link the feature to it's node
  109. $feature_name = $transcript->record->subject_id->name;
  110. $locations = $transcript->child_featurelocs;
  111. $loc = "";
  112. foreach ($locations AS $location) {
  113. $loc .= $location->srcfeature_name . ":" . $location->fmin . ".." . $location->fmax;
  114. }
  115. $type = $transcript->record->subject_id->type_id;
  116. $entity->{$field_name}['und'][$i]['value'] = array(
  117. 'type' => $type->name,
  118. 'name' => $feature_name,
  119. 'identifier' => $transcript->record->subject_id->uniquename,
  120. 'location' => $loc,
  121. );
  122. // Add in the semantic web information that describes each key in the
  123. // value array.
  124. $entity->{$field_name}['und'][$i]['semantic_web'] = array(
  125. 'type' => $type->dbxref_id->db_id->name . ":" . $type->dbxref_id->accession,
  126. 'name' => tripal_get_chado_semweb_term('cvterm', 'name'),
  127. 'identifier' => tripal_get_chado_semweb_term('feature', 'uniquename'),
  128. 'location' => '',
  129. );
  130. if (property_exists($transcript->record->subject_id, 'entity_id')) {
  131. $entity_id = $transcript->record->subject_id->entity_id;
  132. $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $entity_id;
  133. }
  134. $i++;
  135. }
  136. }
  137. /**
  138. * We don't want a widget so override this function.
  139. */
  140. public static function widgetInfo() {
  141. return array();
  142. }
  143. }