feature.views.inc 9.1 KB

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