feature.views.inc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * Purpose: this function returns the portion of the data array
  4. * which describes the feature table, it's fields and any joins between it and other tables
  5. * @see tripal_feature_views_data() --in tripal_feature.views.inc
  6. *
  7. * @todo Add better handler for is_analysis, is_obsolete: something which changes the t/f to a true boolean
  8. * @todo Add support for the following tables: featureprop, featureloc, featurepos, feature_synonym, feature_relationship
  9. * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
  10. *
  11. * BASE TABLE: feature
  12. * @code
  13. * create table feature (
  14. * feature_id serial not null,
  15. * primary key (feature_id),
  16. * dbxref_id int,
  17. * foreign key (dbxref_id) references dbxref (dbxref_id) on delete set null INITIALLY DEFERRED,
  18. * organism_id int not null,
  19. * foreign key (organism_id) references organism (organism_id) on delete cascade INITIALLY DEFERRED,
  20. * name varchar(255),
  21. * uniquename text not null,
  22. * residues text,
  23. * seqlen int,
  24. * md5checksum char(32),
  25. * type_id int not null,
  26. * foreign key (type_id) references cvterm (cvterm_id) on delete cascade INITIALLY DEFERRED,
  27. * is_analysis boolean not null default 'false',
  28. * is_obsolete boolean not null default 'false',
  29. * timeaccessioned timestamp not null default current_timestamp,
  30. * timelastmodified timestamp not null default current_timestamp,
  31. * constraint feature_c1 unique (organism_id,uniquename,type_id)
  32. * );
  33. * @endcode
  34. */
  35. function retrieve_feature_views_data() {
  36. global $db_url;
  37. $data = array();
  38. // if the chado database is not local to the drupal database
  39. // then we need to set the database name. This should always
  40. // be 'chado'.
  41. if(is_array($db_url) and array_key_exists('chado',$db_url)){
  42. $database = 'chado';
  43. }
  44. // Basic table definition
  45. $data['feature']['table']['group'] = 'Chado Feature';
  46. $data['feature']['table']['base'] = array(
  47. 'field' => 'feature_id',
  48. 'title' => 'Chado Features',
  49. 'help' => 'Features are Sequence Data Records in Chado.',
  50. );
  51. if($database){
  52. $data['feature']['table']['database'] = $database;
  53. }
  54. // Table Field Definitions----------------------
  55. // Field: feature_id (primary key)
  56. $data['feature']['feature_id'] = array(
  57. 'title' => 'Feature ID',
  58. 'help' => 'The primary key of a feature',
  59. 'field' => array(
  60. 'handler' => 'views_handler_field_numeric',
  61. 'click sortable' => TRUE,
  62. ),
  63. 'filter' => array(
  64. 'handler' => 'views_handler_filter_numeric',
  65. ),
  66. 'sort' => array(
  67. 'handler' => 'views_handler_sort',
  68. ),
  69. );
  70. // Calculated Field: Node ID
  71. // use custom field handler to query drupal for the node ID
  72. // this is only needed if chado is in a separate database from drupal
  73. if($database){
  74. $data['feature']['feature_nid'] = array(
  75. 'title' => 'Node ID',
  76. 'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
  77. 'field' => array(
  78. 'handler' => 'views_handler_field_computed_feature_nid',
  79. ),
  80. );
  81. }
  82. // Field: organism_id (forgeign key)
  83. // join between organism table and this one in tripal_organism/views/organism.views.inc
  84. // Field: dbxref_id (forgeign key)
  85. // join between dbxref table and this one in tripal_db/views/dbxref.views.inc
  86. // Field: type_id (forgeign key)
  87. // join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
  88. // Field: name (varchar 255)
  89. $data['feature']['name'] = array(
  90. 'title' => 'Name',
  91. 'help' => 'The human-readable, non-unique name of a feature.',
  92. 'field' => array(
  93. 'handler' => 'views_handler_field',
  94. 'click sortable' => TRUE,
  95. ),
  96. 'sort' => array(
  97. 'handler' => 'views_handler_sort',
  98. ),
  99. 'filter' => array(
  100. 'handler' => 'views_handler_filter_string',
  101. ),
  102. 'argument' => array(
  103. 'handler' => 'views_handler_argument_string',
  104. ),
  105. );
  106. // Field: unique name (text)
  107. $data['feature']['uniquename'] = array(
  108. 'title' => 'Unique Name',
  109. 'help' => 'The unique name of a feature.',
  110. 'field' => array(
  111. 'handler' => 'views_handler_field',
  112. 'click sortable' => TRUE,
  113. ),
  114. 'sort' => array(
  115. 'handler' => 'views_handler_sort',
  116. ),
  117. 'filter' => array(
  118. 'handler' => 'views_handler_filter_string',
  119. ),
  120. 'argument' => array(
  121. 'handler' => 'views_handler_argument_string',
  122. ),
  123. );
  124. // Field: residues (text)
  125. $data['feature']['residues'] = array(
  126. 'title' => 'Residues',
  127. 'help' => 'The sequence of a feature.',
  128. 'field' => array(
  129. 'handler' => 'views_handler_field',
  130. 'click sortable' => TRUE,
  131. ),
  132. 'sort' => array(
  133. 'handler' => 'views_handler_sort',
  134. ),
  135. 'filter' => array(
  136. 'handler' => 'views_handler_filter_string',
  137. ),
  138. 'argument' => array(
  139. 'handler' => 'views_handler_argument_string',
  140. ),
  141. );
  142. // Field: sequence length (integer)
  143. $data['feature']['seqlen'] = array(
  144. 'title' => 'Sequence Length',
  145. 'help' => 'The length of the sequence',
  146. 'field' => array(
  147. 'handler' => 'views_handler_field_numeric',
  148. 'click sortable' => TRUE,
  149. ),
  150. 'filter' => array(
  151. 'handler' => 'views_handler_filter_numeric',
  152. ),
  153. 'sort' => array(
  154. 'handler' => 'views_handler_sort',
  155. ),
  156. );
  157. // Field: is analysis (boolean -t/f)
  158. $data['feature']['is_analysis'] = array(
  159. 'title' => 'Is Analysis',
  160. 'help' => 'A boolean indicating whether this feature was annotated by means of automated analysis.',
  161. 'field' => array(
  162. 'handler' => 'views_handler_field',
  163. 'click sortable' => TRUE,
  164. ),
  165. 'filter' => array(
  166. 'handler' => 'views_handler_filter',
  167. ),
  168. 'sort' => array(
  169. 'handler' => 'views_handler_sort',
  170. ),
  171. );
  172. // Field: is obsolete (boolean -t/f)
  173. $data['feature']['is_obsolete'] = array(
  174. 'title' => 'Is Obsolete',
  175. 'help' => 'A boolean indicating whether this feature is obsolete.',
  176. 'field' => array(
  177. 'handler' => 'views_handler_field',
  178. 'click sortable' => TRUE,
  179. ),
  180. 'filter' => array(
  181. 'handler' => 'views_handler_filter',
  182. ),
  183. 'sort' => array(
  184. 'handler' => 'views_handler_sort',
  185. ),
  186. );
  187. // Field: time accessioned (datetime)
  188. $data['feature']['timeaccessioned'] = array(
  189. 'title' => 'Time Accessioned',
  190. 'help' => 'The date & time when this feature was accessioned (added into the database)',
  191. 'field' => array(
  192. 'handler' => 'views_handler_field_readable_date',
  193. 'click sortable' => TRUE,
  194. ),
  195. 'sort' => array(
  196. 'handler' => 'views_handler_sort_date',
  197. ),
  198. );
  199. // Field: time last modified (datetime)
  200. $data['feature']['timelastmodified'] = array(
  201. 'title' => 'Time Last Modified',
  202. 'help' => 'The date & time when this feature was last modified.',
  203. 'field' => array(
  204. 'handler' => 'views_handler_field_readable_date',
  205. 'click sortable' => TRUE,
  206. ),
  207. 'sort' => array(
  208. 'handler' => 'views_handler_sort_date',
  209. ),
  210. );
  211. return $data;
  212. }