feature.views.inc 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /**
  3. * @file
  4. * Purpose: this function returns the portion of the data array
  5. * which describes the feature table, it's fields and any joins between it and other tables
  6. * @see tripal_feature_views_data() --in tripal_feature.views.inc
  7. *
  8. * @todo Add better handler for is_analysis, is_obsolete: something which changes the t/f to a true boolean
  9. * @todo Add support for the following tables: featureprop, featureloc, featurepos, feature_synonym, feature_relationship
  10. * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
  11. *
  12. * BASE TABLE: feature
  13. * @code
  14. * create table feature (
  15. * feature_id serial not null,
  16. * primary key (feature_id),
  17. * dbxref_id int,
  18. * foreign key (dbxref_id) references dbxref (dbxref_id) on delete set null INITIALLY DEFERRED,
  19. * organism_id int not null,
  20. * foreign key (organism_id) references organism (organism_id) on delete cascade INITIALLY DEFERRED,
  21. * name varchar(255),
  22. * uniquename text not null,
  23. * residues text,
  24. * seqlen int,
  25. * md5checksum char(32),
  26. * type_id int not null,
  27. * foreign key (type_id) references cvterm (cvterm_id) on delete cascade INITIALLY DEFERRED,
  28. * is_analysis boolean not null default 'false',
  29. * is_obsolete boolean not null default 'false',
  30. * timeaccessioned timestamp not null default current_timestamp,
  31. * timelastmodified timestamp not null default current_timestamp,
  32. * constraint feature_c1 unique (organism_id,uniquename,type_id)
  33. * );
  34. * @endcode
  35. *
  36. * @ingroup tripal_feature_views
  37. */
  38. function retrieve_feature_views_data() {
  39. global $db_url;
  40. $data = array();
  41. // if the chado database is not local to the drupal database
  42. // then we need to set the database name. This should always
  43. // be 'chado'.
  44. if (is_array($db_url) and array_key_exists('chado', $db_url)) {
  45. $database = 'chado';
  46. }
  47. // Basic table definition
  48. $data['feature']['table']['group'] = 'Chado Feature';
  49. $data['feature']['table']['base'] = array(
  50. 'field' => 'feature_id',
  51. 'title' => 'Chado Features',
  52. 'help' => 'Features are Sequence Data Records in Chado.',
  53. );
  54. if ($database) {
  55. $data['feature']['table']['base']['database'] = $database;
  56. }
  57. //Relationship Definitions---------------------------------
  58. //Join: feature => nd_reagent
  59. $data['feature']['table']['join']['nd_reagent'] = array(
  60. 'left_field' => 'feature_id',
  61. 'field' => 'feature_id',
  62. );
  63. // Table Field Definitions----------------------
  64. // Field: feature_id (primary key)
  65. $data['feature']['feature_id'] = array(
  66. 'title' => 'Feature ID',
  67. 'help' => 'The primary key of a feature',
  68. 'field' => array(
  69. 'handler' => 'views_handler_field_numeric',
  70. 'click sortable' => TRUE,
  71. ),
  72. 'filter' => array(
  73. 'handler' => 'views_handler_filter_numeric',
  74. ),
  75. 'sort' => array(
  76. 'handler' => 'views_handler_sort',
  77. ),
  78. );
  79. // Calculated Field: Node ID
  80. // use custom field handler to query drupal for the node ID
  81. // this is only needed if chado is in a separate database from drupal
  82. if ($database) {
  83. $data['feature']['feature_nid'] = array(
  84. 'title' => 'Node ID',
  85. 'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
  86. 'field' => array(
  87. 'handler' => 'views_handler_field_computed_feature_nid',
  88. ),
  89. );
  90. }
  91. else {
  92. // Add relationship between chado_feature and feature
  93. $data['feature']['feature_nid'] = array(
  94. 'group' => 'Feature',
  95. 'title' => 'Feature Node',
  96. 'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
  97. 'real field' => 'feature_id',
  98. 'relationship' => array(
  99. 'handler' => 'views_handler_relationship',
  100. 'title' => t('Feature => Chado'),
  101. 'label' => t('Feature => Chado'),
  102. 'real field' => 'feature_id',
  103. 'base' => 'chado_feature',
  104. 'base field' => 'feature_id'
  105. ),
  106. );
  107. }
  108. // Field: organism_id (forgeign key)
  109. // join between organism table and this one in tripal_organism/views/organism.views.inc
  110. // Field: dbxref_id (forgeign key)
  111. // join between dbxref table and this one in tripal_db/views/dbxref.views.inc
  112. // Field: type_id (forgeign key)
  113. // join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
  114. // Field: name (varchar 255)
  115. $data['feature']['name'] = array(
  116. 'title' => 'Name',
  117. 'help' => 'The human-readable, non-unique name of a feature.',
  118. 'field' => array(
  119. 'handler' => 'views_handler_field',
  120. 'click sortable' => TRUE,
  121. ),
  122. 'sort' => array(
  123. 'handler' => 'views_handler_sort',
  124. ),
  125. 'filter' => array(
  126. 'handler' => 'views_handler_filter_string',
  127. ),
  128. 'argument' => array(
  129. 'handler' => 'views_handler_argument_string',
  130. ),
  131. );
  132. // if joined to the node table add a "Link to Node" option for the field
  133. if (!$database && module_exists('tripal_views')) {
  134. $data['feature']['name']['field']['handler'] = 'views_handler_field_node_optional';
  135. }
  136. // Field: unique name (text)
  137. $data['feature']['uniquename'] = array(
  138. 'title' => 'Unique Name',
  139. 'help' => 'The unique name of a feature.',
  140. 'field' => array(
  141. 'handler' => 'views_handler_field',
  142. 'click sortable' => TRUE,
  143. ),
  144. 'sort' => array(
  145. 'handler' => 'views_handler_sort',
  146. ),
  147. 'filter' => array(
  148. 'handler' => 'views_handler_filter_string',
  149. ),
  150. 'argument' => array(
  151. 'handler' => 'views_handler_argument_string',
  152. ),
  153. );
  154. // if joined to the node table add a "Link to Node" option for the field
  155. if (!$database && module_exists('tripal_views')) {
  156. $data['feature']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
  157. }
  158. // Field: residues (text)
  159. $data['feature']['residues'] = array(
  160. 'title' => 'Residues',
  161. 'help' => 'The sequence of a feature.',
  162. 'field' => array(
  163. 'handler' => 'views_handler_field_residues',
  164. 'click sortable' => TRUE,
  165. ),
  166. 'sort' => array(
  167. 'handler' => 'views_handler_sort',
  168. ),
  169. 'filter' => array(
  170. 'handler' => 'views_handler_filter_string',
  171. ),
  172. 'argument' => array(
  173. 'handler' => 'views_handler_argument_string',
  174. ),
  175. );
  176. // Field: sequence length (integer)
  177. $data['feature']['seqlen'] = array(
  178. 'title' => 'Sequence Length',
  179. 'help' => 'The length of the sequence',
  180. 'field' => array(
  181. 'handler' => 'views_handler_field_numeric',
  182. 'click sortable' => TRUE,
  183. ),
  184. 'filter' => array(
  185. 'handler' => 'views_handler_filter_numeric',
  186. ),
  187. 'sort' => array(
  188. 'handler' => 'views_handler_sort',
  189. ),
  190. );
  191. // Field: is analysis (boolean -t/f)
  192. $data['feature']['is_analysis'] = array(
  193. 'title' => 'Is Analysis',
  194. 'help' => 'A boolean indicating whether this feature was annotated by means of automated analysis.',
  195. 'field' => array(
  196. 'handler' => 'views_handler_field_chado_tf_boolean',
  197. 'click sortable' => TRUE,
  198. 'label' => t('Is Analysis?'),
  199. 'type' => 'yes-no',
  200. ),
  201. 'filter' => array(
  202. 'handler' => 'views_handler_filter_chado_boolean',
  203. 'label' => t('Is Analysis?'),
  204. 'type' => 'yes-no',
  205. ),
  206. 'sort' => array(
  207. 'handler' => 'views_handler_sort',
  208. ),
  209. );
  210. // Field: is obsolete (boolean -t/f)
  211. $data['feature']['is_obsolete'] = array(
  212. 'title' => 'Is Obsolete',
  213. 'help' => 'A boolean indicating whether this feature is obsolete.',
  214. 'field' => array(
  215. 'handler' => 'views_handler_field_chado_tf_boolean',
  216. 'click sortable' => TRUE,
  217. 'label' => t('Is Obsolete?'),
  218. 'type' => 'yes-no',
  219. ),
  220. 'filter' => array(
  221. 'handler' => 'views_handler_filter_chado_boolean',
  222. 'label' => t('Is Obsolete?'),
  223. 'type' => 'yes-no',
  224. ),
  225. 'sort' => array(
  226. 'handler' => 'views_handler_sort',
  227. ),
  228. );
  229. // Field: time accessioned (datetime)
  230. $data['feature']['timeaccessioned'] = array(
  231. 'title' => 'Time Accessioned',
  232. 'help' => 'The date & time when this feature was accessioned (added into the database)',
  233. 'field' => array(
  234. 'handler' => 'views_handler_field_readable_date',
  235. 'click sortable' => TRUE,
  236. ),
  237. 'sort' => array(
  238. 'handler' => 'views_handler_sort_date',
  239. ),
  240. );
  241. // Field: time last modified (datetime)
  242. $data['feature']['timelastmodified'] = array(
  243. 'title' => 'Time Last Modified',
  244. 'help' => 'The date & time when this feature was last modified.',
  245. 'field' => array(
  246. 'handler' => 'views_handler_field_readable_date',
  247. 'click sortable' => TRUE,
  248. ),
  249. 'sort' => array(
  250. 'handler' => 'views_handler_sort_date',
  251. ),
  252. );
  253. // Calculated Field: Number of Analysis' (Count -Int)
  254. // Provides the number of analysis' for a given feature
  255. // @see tripal_analysis/views/misc_tables.views.inc
  256. //Calculated Field: Number of Libraries (Count -Int)
  257. // Provides the number of libraries for a given feature
  258. // @see tripal_library/views/misc_tables.views.inc
  259. // Calculated Field: feature relationships
  260. // uses a custom field handler which pulls results from the view
  261. $data['feature']['relationships'] = array(
  262. 'title' => t('Feature Relationships'),
  263. 'help' => t('Relationships including the current feature.'),
  264. 'field' => array(
  265. 'title' => t('Relationships'),
  266. 'help' => t('Display a given type of relationships including the current feature.'),
  267. 'handler' => 'views_handler_field_chado_rel_by_type',
  268. ),
  269. );
  270. return $data;
  271. }