analysis.views.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. /**
  3. * Purpose: this function returns the portion of the data array
  4. * which describes the analysis table, it's fields and any joins between it and other tables
  5. * @see tripal_analysis_views_data() --in tripal_analysis.views.inc
  6. *
  7. * @todo Add support for analysisprop table
  8. * @todo Add support for multiple analysis' listed per feature
  9. * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
  10. *
  11. * BASE TABLE: analysis
  12. * @code
  13. * create table analysis (
  14. * analysis_id serial not null,
  15. * primary key (analysis_id),
  16. * name varchar(255),
  17. * description text,
  18. * program varchar(255) not null,
  19. * programversion varchar(255) not null,
  20. * algorithm varchar(255),
  21. * sourcename varchar(255),
  22. * sourceversion varchar(255),
  23. * sourceuri text,
  24. * timeexecuted timestamp not null default current_timestamp,
  25. * constraint analysis_c1 unique (program,programversion,sourcename)
  26. * );
  27. * @endcode
  28. *
  29. * @ingroup tripal_analysis_views
  30. */
  31. function retrieve_analysis_views_data() {
  32. global $db_url;
  33. $data = array();
  34. // if the chado database is not local to the drupal database
  35. // then we need to set the database name. This should always
  36. // be 'chado'.
  37. if(is_array($db_url) and array_key_exists('chado',$db_url)){
  38. $database = 'chado';
  39. }
  40. // Basic table definition
  41. $data['analysis']['table']['group'] = 'Chado Analysis';
  42. $data['analysis']['table']['base'] = array(
  43. 'field' => 'analysis_id',
  44. 'title' => t('Chado Analysis'),
  45. 'help' => t("An analysis is a particular type of a computational analysis; it may be a blast of one sequence against another, or an all by all blast, or a different kind of analysis altogether. It is a single unit of computation."),
  46. );
  47. if($database){
  48. $data['analysis']['table']['base']['database'] = $database;
  49. }
  50. // Define relationships between this table and others
  51. $data['analysis']['table']['join'] = array(
  52. 'analysisfeature' => array(
  53. 'left_field' => 'analysis_id',
  54. 'field' => 'analysis_id',
  55. ),
  56. 'feature' => array(
  57. 'left_table' => 'analysisfeature',
  58. 'left_field' => 'analysis_id',
  59. 'field' => 'analysis_id',
  60. ),
  61. );
  62. // Describe the joins with the analysis_feature table
  63. $data['analysisfeature']['table']['join'] = array(
  64. 'feature' => array(
  65. 'left_field' => 'feature_id',
  66. 'field' => 'feature_id',
  67. ),
  68. );
  69. // Table Field Definitions----------------------
  70. // Field: analysis_id (primary key)
  71. $data['analysis']['analysis_id'] = array(
  72. 'title' => 'analysis ID',
  73. 'help' => 'The primary key of the analysis table.',
  74. 'field' => array(
  75. 'handler' => 'views_handler_field_numeric',
  76. 'click sortable' => TRUE,
  77. ),
  78. 'filter' => array(
  79. 'handler' => 'views_handler_filter_numeric',
  80. ),
  81. 'sort' => array(
  82. 'handler' => 'views_handler_sort',
  83. ),
  84. );
  85. // Calculated Field: Node ID
  86. // use custom field handler to query drupal for the node ID
  87. // this is only needed if chado is in a separate database from drupal
  88. if($database){
  89. $data['analysis']['analysis_nid'] = array(
  90. 'title' => 'Node ID',
  91. 'help' => 'The node ID for the current analysis',
  92. 'field' => array(
  93. 'handler' => 'views_handler_field_computed_analysis_nid',
  94. ),
  95. );
  96. }
  97. // Field: name (varchar 255)
  98. $data['analysis']['name'] = array(
  99. 'title' => t('Name'),
  100. 'help' => t(''),
  101. 'field' => array(
  102. 'handler' => 'views_handler_field',
  103. 'click sortable' => TRUE,
  104. ),
  105. 'sort' => array(
  106. 'handler' => 'views_handler_sort',
  107. ),
  108. 'filter' => array(
  109. 'handler' => 'views_handler_filter_string',
  110. ),
  111. 'argument' => array(
  112. 'handler' => 'views_handler_argument_string',
  113. ),
  114. );
  115. // if joined to the node table add a "Link to Node" option for the field
  116. if (!$database) {
  117. $data['analysis']['name']['field']['handler'] = 'views_handler_field_node_optional';
  118. }
  119. // Field: description (text)
  120. $data['analysis']['description'] = array(
  121. 'title' => t('Description'),
  122. 'help' => t(''),
  123. 'field' => array(
  124. 'handler' => 'views_handler_field',
  125. 'click sortable' => TRUE,
  126. ),
  127. 'sort' => array(
  128. 'handler' => 'views_handler_sort',
  129. ),
  130. 'filter' => array(
  131. 'handler' => 'views_handler_filter_string',
  132. ),
  133. 'argument' => array(
  134. 'handler' => 'views_handler_argument_string',
  135. ),
  136. );
  137. // Field: program (varchar 255)
  138. $data['analysis']['program'] = array(
  139. 'title' => t('Program'),
  140. 'help' => t('Program name, e.g. blastx, blastp, sim4, genscan.'),
  141. 'field' => array(
  142. 'handler' => 'views_handler_field',
  143. 'click sortable' => TRUE,
  144. ),
  145. 'sort' => array(
  146. 'handler' => 'views_handler_sort',
  147. ),
  148. 'filter' => array(
  149. 'handler' => 'views_handler_filter_chado_select_string',
  150. ),
  151. 'argument' => array(
  152. 'handler' => 'views_handler_argument_string',
  153. ),
  154. );
  155. // Field: program version (varchar 255)
  156. $data['analysis']['programversion'] = array(
  157. 'title' => t('Program Version'),
  158. 'help' => t('Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000].'),
  159. 'field' => array(
  160. 'handler' => 'views_handler_field',
  161. 'click sortable' => TRUE,
  162. ),
  163. 'sort' => array(
  164. 'handler' => 'views_handler_sort',
  165. ),
  166. 'filter' => array(
  167. 'handler' => 'views_handler_filter_chado_select_string',
  168. ),
  169. 'argument' => array(
  170. 'handler' => 'views_handler_argument_string',
  171. ),
  172. );
  173. // Field: algorithm (varchar 255)
  174. $data['analysis']['algorithm'] = array(
  175. 'title' => t('Algorithm'),
  176. 'help' => t('Algorithm name, e.g. blast.'),
  177. 'field' => array(
  178. 'handler' => 'views_handler_field',
  179. 'click sortable' => TRUE,
  180. ),
  181. 'sort' => array(
  182. 'handler' => 'views_handler_sort',
  183. ),
  184. 'filter' => array(
  185. 'handler' => 'views_handler_filter_chado_select_string',
  186. ),
  187. 'argument' => array(
  188. 'handler' => 'views_handler_argument_string',
  189. ),
  190. );
  191. $data['analysis']['sourcename'] = array(
  192. 'title' => t('Source Name'),
  193. 'help' => t('Source name, e.g. cDNA, SwissProt.'),
  194. 'field' => array(
  195. 'handler' => 'views_handler_field',
  196. 'click sortable' => TRUE,
  197. ),
  198. 'sort' => array(
  199. 'handler' => 'views_handler_sort',
  200. ),
  201. 'filter' => array(
  202. 'handler' => 'views_handler_filter_string',
  203. ),
  204. 'argument' => array(
  205. 'handler' => 'views_handler_argument_string',
  206. ),
  207. );
  208. // Field: source version (varchar 255)
  209. $data['analysis']['sourceversion'] = array(
  210. 'title' => t('Source Version'),
  211. 'help' => t('The version of the source.'),
  212. 'field' => array(
  213. 'handler' => 'views_handler_field',
  214. 'click sortable' => TRUE,
  215. ),
  216. 'sort' => array(
  217. 'handler' => 'views_handler_sort',
  218. ),
  219. 'filter' => array(
  220. 'handler' => 'views_handler_filter_string',
  221. ),
  222. 'argument' => array(
  223. 'handler' => 'views_handler_argument_string',
  224. ),
  225. );
  226. // Field: source URI/URL (text)
  227. $data['analysis']['sourceuri'] = array(
  228. 'title' => t('Source URL'),
  229. 'help' => t('This is an optional, permanent URL or URI for the source of the analysis.'),
  230. 'field' => array(
  231. 'handler' => 'views_handler_field',
  232. 'click sortable' => TRUE,
  233. ),
  234. 'sort' => array(
  235. 'handler' => 'views_handler_sort',
  236. ),
  237. 'filter' => array(
  238. 'handler' => 'views_handler_filter_string',
  239. ),
  240. 'argument' => array(
  241. 'handler' => 'views_handler_argument_string',
  242. ),
  243. );
  244. // Field: time executed (datetime)
  245. $data['analysis']['timeexecuted'] = array(
  246. 'title' => 'Time Executed',
  247. 'help' => 'The date & time when this analysis was executed.',
  248. 'field' => array(
  249. 'handler' => 'views_handler_field_readable_date',
  250. 'click sortable' => TRUE,
  251. ),
  252. 'sort' => array(
  253. 'handler' => 'views_handler_sort_date',
  254. ),
  255. );
  256. return $data;
  257. }