chado_gene__transcripts.inc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /**
  3. * Implements hook_info() for fields.
  4. *
  5. * This is a hook provided by the tripal_chado module for offloading the
  6. * hook_field_info() hook for each field to specify.
  7. */
  8. function chado_gene__transcripts_info() {
  9. return array(
  10. 'label' => t('Transcripts'),
  11. 'description' => t('Transcripts of genes.'),
  12. 'default_widget' => 'chado_gene__transcripts_widget',
  13. 'default_formatter' => 'chado_gene__transcripts_formatter',
  14. 'settings' => array(),
  15. 'storage' => array(
  16. 'type' => 'field_chado_storage',
  17. 'module' => 'tripal_chado',
  18. 'active' => TRUE
  19. ),
  20. );
  21. }
  22. /**
  23. * Implements hook_attach_info().
  24. *
  25. * This is a hook provided by the tripal_Chado module. It allows the field
  26. * to specify which bundles it will attach to and to specify thee settings.
  27. *
  28. * @param $entity_type
  29. * @param $entity
  30. * @param $term
  31. *
  32. * @return
  33. * A field array
  34. */
  35. function chado_gene__transcripts_attach_info($entity_type, $bundle, $target) {
  36. $field_info = array();
  37. $table_name = $target['data_table'];
  38. $type_table = $target['type_table'];
  39. $type_field = $target['field'];
  40. $cv_id = $target['cv_id'];
  41. $cvterm_id = $target['cvterm_id'];
  42. // If the linker table does not exists or this is not a gene then we don't want to add attach.
  43. $rel_table = $table_name . '_relationship';
  44. if (!chado_table_exists($rel_table) || $bundle->label != 'gene') {
  45. return $field_info;
  46. }
  47. $schema = chado_get_schema($rel_table);
  48. $pkey = $schema['primary key'][0];
  49. // Initialize the field array.
  50. $field_info = array(
  51. 'field_name' => 'gene__transcripts',
  52. 'field_type' => 'chado_gene__transcripts',
  53. 'widget_type' => 'chado_gene__transcripts_widget',
  54. 'widget_settings' => array('display_label' => 1),
  55. 'description' => '',
  56. 'label' => 'Transcripts',
  57. 'is_required' => 0,
  58. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  59. 'storage' => 'field_chado_storage',
  60. 'field_settings' => array(
  61. 'chado_table' => $rel_table,
  62. 'chado_column' => $pkey,
  63. 'base_table' => $table_name,
  64. 'semantic_web' => array(
  65. 'type' => '',
  66. 'ns' => '',
  67. 'nsurl' => '',
  68. ),
  69. ),
  70. );
  71. return $field_info;
  72. }
  73. /**
  74. * Implements hook_widget_info.
  75. *
  76. * This is a hook provided by the tripal_chado module for offloading
  77. * the hook_field_widget_info() hook for each field to specify.
  78. */
  79. function chado_gene__transcripts_widget_info() {
  80. return array(
  81. 'label' => t('Transcripts Settings'),
  82. 'field types' => array('chado_gene__transcripts')
  83. );
  84. }
  85. /**
  86. * Implements hook_formatter_info.
  87. *
  88. * This is a hook provided by the tripal_chado module for
  89. * offloading the hook_field_formatter_info() for each field
  90. * to specify.
  91. *
  92. */
  93. function chado_gene__transcripts_formatter_info() {
  94. return array(
  95. 'label' => t('Transcripts'),
  96. 'field types' => array('chado_gene__transcripts'),
  97. 'settings' => array(
  98. ),
  99. );
  100. }
  101. /**
  102. * Implements hook_formatter_settings_summary.
  103. *
  104. * This is a hook provided by the tripal_chado module for
  105. * offloading the hook_field_formatter_settings_summary() for each field
  106. * to specify.
  107. *
  108. */
  109. function chado_gene__transcripts_formatter_settings_summary($field, $instance,
  110. $view_mode) {
  111. }
  112. /**
  113. * Provides a settings form for the formatter.
  114. *
  115. * This is a hook provided by the tripal_chado module for
  116. * offloading the hook_field_formatter_settings_form() for each field
  117. * to specify.
  118. */
  119. function chado_gene__transcripts_formatter_settings_form($field, $instance,
  120. $view_mode, $form, &$form_state) {
  121. }
  122. /**
  123. * Validation function for the chado_gene_featureloc_formatter_settings_form.
  124. */
  125. function chado_gene__transcripts_formatter_settings_form_validate(&$form, &$form_state) {
  126. // Place here as an example for validating the settings form.
  127. }
  128. /**
  129. * TODO: because this field is meant to handle any xxxxx_transcripts table
  130. * then feature hard-coding needs to be replaced as it won't work for
  131. * stocks, etc.
  132. */
  133. function chado_gene__transcripts_formatter(&$element, $entity_type, $entity,
  134. $field, $instance, $langcode, $items, $display) {
  135. // Get the settings
  136. $settings = $display['settings'];
  137. $record = $entity->chado_record;
  138. foreach ($items as $delta => $item) {
  139. $all_transcripts = key_exists('part of', $item['all_transcripts']['object']) &&
  140. key_exists('mRNA', $item['all_transcripts']['object']['part of']) ?
  141. $item['all_transcripts']['object']['part of']['mRNA'] : array();
  142. $headers = array('Feature Name' ,'Unique Name', 'Location');
  143. $rows = array();
  144. foreach ($all_transcripts AS $transcript) {
  145. // link the feature to it's node
  146. $feature_name = $transcript->record->subject_id->name;
  147. $entity_id = $transcript->record->subject_id->entity_id;
  148. if ($entity_id) {
  149. $feature_name = l($feature_name, "bio_data/" . $entity_id, array('attributes' => array('target' => "_blank")));
  150. }
  151. $locations = $transcript->child_featurelocs;
  152. $loc = "";
  153. foreach ($locations AS $location) {
  154. $loc .= $location->srcfeature_name . ":" . $location->fmin . ".." . $location->fmax . "<br>";
  155. }
  156. $rows[] = array(
  157. array('data' => $feature_name, 'width' => '30%'),
  158. array('data' => $transcript->record->subject_id->uniquename, 'width' => '30%'),
  159. array('data' => $loc, 'width' => '30%'),
  160. );
  161. }
  162. $table = array(
  163. 'header' => $headers,
  164. 'rows' => $rows,
  165. 'attributes' => array(
  166. 'id' => 'tripal_feature-table-transcripts-object',
  167. 'class' => 'tripal-data-table'
  168. ),
  169. 'sticky' => FALSE,
  170. 'caption' => "",
  171. 'colgroups' => array(),
  172. 'empty' => '',
  173. );
  174. $content = theme_table($table);
  175. }
  176. // once we have our table array structure defined, we call Drupal's theme_table()
  177. // function to generate the table.
  178. $element[$delta] = array(
  179. '#type' => 'markup',
  180. '#markup' => $content,
  181. );
  182. }
  183. /**
  184. * Loads the field values with appropriate data.
  185. *
  186. * This function is called by the tripal_chado_field_storage_load() for
  187. * each property managed by the field_chado_storage storage type. This is
  188. * an optional hook function that is only needed if the field has
  189. * multiple form elements.
  190. */
  191. function chado_gene__transcripts_load($field, $entity, $base_table, $record) {
  192. $field_name = $field['field_name'];
  193. $entity->{$field_name}['und'][0]['all_transcripts'] = tripal_get_feature_relationships($record);
  194. }
  195. /**
  196. * Implements hook_ws_formatter().
  197. */
  198. // function chado_gene__transcripts_ws_formatter(&$element, $entity_type, $entity,
  199. // $field, $instance, $items) {
  200. // foreach ($items as $delta => $item) {
  201. // }
  202. // }
  203. /**
  204. * Implements hook_widget().
  205. */
  206. function chado_gene__transcripts_widget(&$widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element) {
  207. }
  208. /**
  209. * Callback function for validating the chado_gene_featureloc_widget.
  210. */
  211. function chado_gene__transcripts_widget_validate($element, &$form_state) {
  212. }