feature.views.inc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. * @ingroup tripal_feature_views
  36. */
  37. function retrieve_feature_views_data() {
  38. global $db_url;
  39. $data = array();
  40. // if the chado database is not local to the drupal database
  41. // then we need to set the database name. This should always
  42. // be 'chado'.
  43. if(is_array($db_url) and array_key_exists('chado',$db_url)){
  44. $database = 'chado';
  45. }
  46. // Basic table definition
  47. $data['feature']['table']['group'] = 'Chado Feature';
  48. $data['feature']['table']['base'] = array(
  49. 'field' => 'feature_id',
  50. 'title' => 'Chado Features',
  51. 'help' => 'Features are Sequence Data Records in Chado.',
  52. );
  53. if($database){
  54. $data['feature']['table']['base']['database'] = $database;
  55. }
  56. //Relationship Definitions---------------------------------
  57. //Join: feature => nd_reagent
  58. $data['feature']['table']['join']['nd_reagent'] = array(
  59. 'left_field' => 'feature_id',
  60. 'field' => 'feature_id',
  61. );
  62. // Table Field Definitions----------------------
  63. // Field: feature_id (primary key)
  64. $data['feature']['feature_id'] = array(
  65. 'title' => 'Feature ID',
  66. 'help' => 'The primary key of a feature',
  67. 'field' => array(
  68. 'handler' => 'views_handler_field_numeric',
  69. 'click sortable' => TRUE,
  70. ),
  71. 'filter' => array(
  72. 'handler' => 'views_handler_filter_numeric',
  73. ),
  74. 'sort' => array(
  75. 'handler' => 'views_handler_sort',
  76. ),
  77. );
  78. // Calculated Field: Node ID
  79. // use custom field handler to query drupal for the node ID
  80. // this is only needed if chado is in a separate database from drupal
  81. if($database){
  82. $data['feature']['feature_nid'] = array(
  83. 'title' => 'Node ID',
  84. 'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
  85. 'field' => array(
  86. 'handler' => 'views_handler_field_computed_feature_nid',
  87. ),
  88. );
  89. }
  90. // Field: organism_id (forgeign key)
  91. // join between organism table and this one in tripal_organism/views/organism.views.inc
  92. // Field: dbxref_id (forgeign key)
  93. // join between dbxref table and this one in tripal_db/views/dbxref.views.inc
  94. // Field: type_id (forgeign key)
  95. // join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
  96. // Field: name (varchar 255)
  97. $data['feature']['name'] = array(
  98. 'title' => 'Name',
  99. 'help' => 'The human-readable, non-unique name of a feature.',
  100. 'field' => array(
  101. 'handler' => 'views_handler_field',
  102. 'click sortable' => TRUE,
  103. ),
  104. 'sort' => array(
  105. 'handler' => 'views_handler_sort',
  106. ),
  107. 'filter' => array(
  108. 'handler' => 'views_handler_filter_string',
  109. ),
  110. 'argument' => array(
  111. 'handler' => 'views_handler_argument_string',
  112. ),
  113. );
  114. // if joined to the node table add a "Link to Node" option for the field
  115. if (!$database) {
  116. $data['feature']['name']['field']['handler'] = 'views_handler_field_node_optional';
  117. }
  118. // Field: unique name (text)
  119. $data['feature']['uniquename'] = array(
  120. 'title' => 'Unique Name',
  121. 'help' => 'The unique name of a feature.',
  122. 'field' => array(
  123. 'handler' => 'views_handler_field',
  124. 'click sortable' => TRUE,
  125. ),
  126. 'sort' => array(
  127. 'handler' => 'views_handler_sort',
  128. ),
  129. 'filter' => array(
  130. 'handler' => 'views_handler_filter_string',
  131. ),
  132. 'argument' => array(
  133. 'handler' => 'views_handler_argument_string',
  134. ),
  135. );
  136. // if joined to the node table add a "Link to Node" option for the field
  137. if (!$database) {
  138. $data['feature']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
  139. }
  140. // Field: residues (text)
  141. $data['feature']['residues'] = array(
  142. 'title' => 'Residues',
  143. 'help' => 'The sequence of a feature.',
  144. 'field' => array(
  145. 'handler' => 'views_handler_field_residues',
  146. 'click sortable' => TRUE,
  147. ),
  148. 'sort' => array(
  149. 'handler' => 'views_handler_sort',
  150. ),
  151. 'filter' => array(
  152. 'handler' => 'views_handler_filter_string',
  153. ),
  154. 'argument' => array(
  155. 'handler' => 'views_handler_argument_string',
  156. ),
  157. );
  158. // Field: sequence length (integer)
  159. $data['feature']['seqlen'] = array(
  160. 'title' => 'Sequence Length',
  161. 'help' => 'The length of the sequence',
  162. 'field' => array(
  163. 'handler' => 'views_handler_field_numeric',
  164. 'click sortable' => TRUE,
  165. ),
  166. 'filter' => array(
  167. 'handler' => 'views_handler_filter_numeric',
  168. ),
  169. 'sort' => array(
  170. 'handler' => 'views_handler_sort',
  171. ),
  172. );
  173. // Field: is analysis (boolean -t/f)
  174. $data['feature']['is_analysis'] = array(
  175. 'title' => 'Is Analysis',
  176. 'help' => 'A boolean indicating whether this feature was annotated by means of automated analysis.',
  177. 'field' => array(
  178. 'handler' => 'views_handler_field_chado_tf_boolean',
  179. 'click sortable' => TRUE,
  180. 'label' => t('Is Analysis?'),
  181. 'type' => 'yes-no',
  182. ),
  183. 'filter' => array(
  184. 'handler' => 'views_handler_filter_chado_boolean',
  185. 'label' => t('Is Analysis?'),
  186. 'type' => 'yes-no',
  187. ),
  188. 'sort' => array(
  189. 'handler' => 'views_handler_sort',
  190. ),
  191. );
  192. // Field: is obsolete (boolean -t/f)
  193. $data['feature']['is_obsolete'] = array(
  194. 'title' => 'Is Obsolete',
  195. 'help' => 'A boolean indicating whether this feature is obsolete.',
  196. 'field' => array(
  197. 'handler' => 'views_handler_field_chado_tf_boolean',
  198. 'click sortable' => TRUE,
  199. 'label' => t('Is Obsolete?'),
  200. 'type' => 'yes-no',
  201. ),
  202. 'filter' => array(
  203. 'handler' => 'views_handler_filter_chado_boolean',
  204. 'label' => t('Is Obsolete?'),
  205. 'type' => 'yes-no',
  206. ),
  207. 'sort' => array(
  208. 'handler' => 'views_handler_sort',
  209. ),
  210. );
  211. // Field: time accessioned (datetime)
  212. $data['feature']['timeaccessioned'] = array(
  213. 'title' => 'Time Accessioned',
  214. 'help' => 'The date & time when this feature was accessioned (added into the database)',
  215. 'field' => array(
  216. 'handler' => 'views_handler_field_readable_date',
  217. 'click sortable' => TRUE,
  218. ),
  219. 'sort' => array(
  220. 'handler' => 'views_handler_sort_date',
  221. ),
  222. );
  223. // Field: time last modified (datetime)
  224. $data['feature']['timelastmodified'] = array(
  225. 'title' => 'Time Last Modified',
  226. 'help' => 'The date & time when this feature was last modified.',
  227. 'field' => array(
  228. 'handler' => 'views_handler_field_readable_date',
  229. 'click sortable' => TRUE,
  230. ),
  231. 'sort' => array(
  232. 'handler' => 'views_handler_sort_date',
  233. ),
  234. );
  235. // Calculated Field: Number of Analysis' (Count -Int)
  236. // Provides the number of analysis' for a given feature
  237. // @see tripal_analysis/views/misc_tables.views.inc
  238. //Calculated Field: Number of Libraries (Count -Int)
  239. // Provides the number of libraries for a given feature
  240. // @see tripal_library/views/misc_tables.views.inc
  241. return $data;
  242. }