feature.views.inc 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. } else {
  90. // Add relationship between chado_feature and feature
  91. $data['feature']['feature_nid'] = array(
  92. 'group' => 'Feature',
  93. 'title' => 'Feature Node',
  94. 'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
  95. 'real field' => 'feature_id',
  96. 'relationship' => array(
  97. 'handler' => 'views_handler_relationship',
  98. 'title' => t('Feature => Chado'),
  99. 'label' => t('Feature => Chado'),
  100. 'real field' => 'feature_id',
  101. 'base' => 'chado_feature',
  102. 'base field' => 'feature_id'
  103. ),
  104. );
  105. }
  106. // Field: organism_id (forgeign key)
  107. // join between organism table and this one in tripal_organism/views/organism.views.inc
  108. // Field: dbxref_id (forgeign key)
  109. // join between dbxref table and this one in tripal_db/views/dbxref.views.inc
  110. // Field: type_id (forgeign key)
  111. // join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
  112. // Field: name (varchar 255)
  113. $data['feature']['name'] = array(
  114. 'title' => 'Name',
  115. 'help' => 'The human-readable, non-unique name of a feature.',
  116. 'field' => array(
  117. 'handler' => 'views_handler_field',
  118. 'click sortable' => TRUE,
  119. ),
  120. 'sort' => array(
  121. 'handler' => 'views_handler_sort',
  122. ),
  123. 'filter' => array(
  124. 'handler' => 'views_handler_filter_string',
  125. ),
  126. 'argument' => array(
  127. 'handler' => 'views_handler_argument_string',
  128. ),
  129. );
  130. // if joined to the node table add a "Link to Node" option for the field
  131. if (!$database) {
  132. $data['feature']['name']['field']['handler'] = 'views_handler_field_node_optional';
  133. }
  134. // Field: unique name (text)
  135. $data['feature']['uniquename'] = array(
  136. 'title' => 'Unique Name',
  137. 'help' => 'The unique name of a feature.',
  138. 'field' => array(
  139. 'handler' => 'views_handler_field',
  140. 'click sortable' => TRUE,
  141. ),
  142. 'sort' => array(
  143. 'handler' => 'views_handler_sort',
  144. ),
  145. 'filter' => array(
  146. 'handler' => 'views_handler_filter_string',
  147. ),
  148. 'argument' => array(
  149. 'handler' => 'views_handler_argument_string',
  150. ),
  151. );
  152. // if joined to the node table add a "Link to Node" option for the field
  153. if (!$database) {
  154. $data['feature']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
  155. }
  156. // Field: residues (text)
  157. $data['feature']['residues'] = array(
  158. 'title' => 'Residues',
  159. 'help' => 'The sequence of a feature.',
  160. 'field' => array(
  161. 'handler' => 'views_handler_field_residues',
  162. 'click sortable' => TRUE,
  163. ),
  164. 'sort' => array(
  165. 'handler' => 'views_handler_sort',
  166. ),
  167. 'filter' => array(
  168. 'handler' => 'views_handler_filter_string',
  169. ),
  170. 'argument' => array(
  171. 'handler' => 'views_handler_argument_string',
  172. ),
  173. );
  174. // Field: sequence length (integer)
  175. $data['feature']['seqlen'] = array(
  176. 'title' => 'Sequence Length',
  177. 'help' => 'The length of the sequence',
  178. 'field' => array(
  179. 'handler' => 'views_handler_field_numeric',
  180. 'click sortable' => TRUE,
  181. ),
  182. 'filter' => array(
  183. 'handler' => 'views_handler_filter_numeric',
  184. ),
  185. 'sort' => array(
  186. 'handler' => 'views_handler_sort',
  187. ),
  188. );
  189. // Field: is analysis (boolean -t/f)
  190. $data['feature']['is_analysis'] = array(
  191. 'title' => 'Is Analysis',
  192. 'help' => 'A boolean indicating whether this feature was annotated by means of automated analysis.',
  193. 'field' => array(
  194. 'handler' => 'views_handler_field_chado_tf_boolean',
  195. 'click sortable' => TRUE,
  196. 'label' => t('Is Analysis?'),
  197. 'type' => 'yes-no',
  198. ),
  199. 'filter' => array(
  200. 'handler' => 'views_handler_filter_chado_boolean',
  201. 'label' => t('Is Analysis?'),
  202. 'type' => 'yes-no',
  203. ),
  204. 'sort' => array(
  205. 'handler' => 'views_handler_sort',
  206. ),
  207. );
  208. // Field: is obsolete (boolean -t/f)
  209. $data['feature']['is_obsolete'] = array(
  210. 'title' => 'Is Obsolete',
  211. 'help' => 'A boolean indicating whether this feature is obsolete.',
  212. 'field' => array(
  213. 'handler' => 'views_handler_field_chado_tf_boolean',
  214. 'click sortable' => TRUE,
  215. 'label' => t('Is Obsolete?'),
  216. 'type' => 'yes-no',
  217. ),
  218. 'filter' => array(
  219. 'handler' => 'views_handler_filter_chado_boolean',
  220. 'label' => t('Is Obsolete?'),
  221. 'type' => 'yes-no',
  222. ),
  223. 'sort' => array(
  224. 'handler' => 'views_handler_sort',
  225. ),
  226. );
  227. // Field: time accessioned (datetime)
  228. $data['feature']['timeaccessioned'] = array(
  229. 'title' => 'Time Accessioned',
  230. 'help' => 'The date & time when this feature was accessioned (added into the database)',
  231. 'field' => array(
  232. 'handler' => 'views_handler_field_readable_date',
  233. 'click sortable' => TRUE,
  234. ),
  235. 'sort' => array(
  236. 'handler' => 'views_handler_sort_date',
  237. ),
  238. );
  239. // Field: time last modified (datetime)
  240. $data['feature']['timelastmodified'] = array(
  241. 'title' => 'Time Last Modified',
  242. 'help' => 'The date & time when this feature was last modified.',
  243. 'field' => array(
  244. 'handler' => 'views_handler_field_readable_date',
  245. 'click sortable' => TRUE,
  246. ),
  247. 'sort' => array(
  248. 'handler' => 'views_handler_sort_date',
  249. ),
  250. );
  251. // Calculated Field: Number of Analysis' (Count -Int)
  252. // Provides the number of analysis' for a given feature
  253. // @see tripal_analysis/views/misc_tables.views.inc
  254. //Calculated Field: Number of Libraries (Count -Int)
  255. // Provides the number of libraries for a given feature
  256. // @see tripal_library/views/misc_tables.views.inc
  257. // Calculated Field: feature relationships
  258. // uses a custom field handler which pulls results from the view
  259. $data['feature']['relationships'] = array(
  260. 'title' => t('Feature Relationships'),
  261. 'help' => t('Relationships including the current feature.'),
  262. 'field' => array(
  263. 'title' => t('Relationships'),
  264. 'help' => t('Display a given type of relationships including the current feature.'),
  265. 'handler' => 'views_handler_field_chado_rel_by_type',
  266. ),
  267. );
  268. return $data;
  269. }