chado_gene__transcripts.inc 5.2 KB

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