analysis.views.inc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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']['feature'] = array(
  52. 'linking' => array(
  53. 'table' => 'analysisfeature',
  54. 'left_field' => 'feature_id',
  55. 'field' => 'analysis_id',
  56. ),
  57. 'left_field' => 'feature_id',
  58. 'field' => 'analysis_id',
  59. 'handler' => 'views_handler_join_chado_through_linking'
  60. );
  61. // Table Field Definitions----------------------
  62. // Field: analysis_id (primary key)
  63. $data['analysis']['analysis_id'] = array(
  64. 'title' => 'analysis ID',
  65. 'help' => 'The primary key of the analysis table.',
  66. 'field' => array(
  67. 'handler' => 'views_handler_field_numeric',
  68. 'click sortable' => TRUE,
  69. ),
  70. 'filter' => array(
  71. 'handler' => 'views_handler_filter_numeric',
  72. ),
  73. 'sort' => array(
  74. 'handler' => 'views_handler_sort',
  75. ),
  76. );
  77. // Calculated Field: Node ID
  78. // use custom field handler to query drupal for the node ID
  79. // this is only needed if chado is in a separate database from drupal
  80. if($database){
  81. $data['analysis']['analysis_nid'] = array(
  82. 'title' => 'Node ID',
  83. 'help' => 'The node ID for the current analysis',
  84. 'field' => array(
  85. 'handler' => 'views_handler_field_computed_analysis_nid',
  86. ),
  87. );
  88. } else {
  89. // Add relationship between chado_analysis and analysis
  90. $data['analysis']['analysis_nid'] = array(
  91. 'group' => 'Analysis',
  92. 'title' => 'Analysis Node',
  93. 'help' => 'Links Chado Analysis Fields/Data to the Nodes in the current View.',
  94. 'real field' => 'analysis_id',
  95. 'relationship' => array(
  96. 'handler' => 'views_handler_relationship',
  97. 'title' => t('Analysis => Chado'),
  98. 'label' => t('Analysis => Chado'),
  99. 'real field' => 'analysis_id',
  100. 'base' => 'chado_analysis',
  101. 'base field' => 'analysis_id'
  102. ),
  103. );
  104. }
  105. // Field: name (varchar 255)
  106. $data['analysis']['name'] = array(
  107. 'title' => t('Name'),
  108. 'help' => t(''),
  109. 'field' => array(
  110. 'handler' => 'views_handler_field',
  111. 'click sortable' => TRUE,
  112. ),
  113. 'sort' => array(
  114. 'handler' => 'views_handler_sort',
  115. ),
  116. 'filter' => array(
  117. 'handler' => 'views_handler_filter_chado_select_string',
  118. ),
  119. 'argument' => array(
  120. 'handler' => 'views_handler_argument_string',
  121. ),
  122. );
  123. // if joined to the node table add a "Link to Node" option for the field
  124. if (!$database) {
  125. $data['analysis']['name']['field']['handler'] = 'views_handler_field_node_optional';
  126. }
  127. // Field: description (text)
  128. $data['analysis']['description'] = array(
  129. 'title' => t('Description'),
  130. 'help' => t(''),
  131. 'field' => array(
  132. 'handler' => 'views_handler_field',
  133. 'click sortable' => TRUE,
  134. ),
  135. 'sort' => array(
  136. 'handler' => 'views_handler_sort',
  137. ),
  138. 'filter' => array(
  139. 'handler' => 'views_handler_filter_string',
  140. ),
  141. 'argument' => array(
  142. 'handler' => 'views_handler_argument_string',
  143. ),
  144. );
  145. // Field: program (varchar 255)
  146. $data['analysis']['program'] = array(
  147. 'title' => t('Program'),
  148. 'help' => t('Program name, e.g. blastx, blastp, sim4, genscan.'),
  149. 'field' => array(
  150. 'handler' => 'views_handler_field',
  151. 'click sortable' => TRUE,
  152. ),
  153. 'sort' => array(
  154. 'handler' => 'views_handler_sort',
  155. ),
  156. 'filter' => array(
  157. 'handler' => 'views_handler_filter_chado_select_string',
  158. ),
  159. 'argument' => array(
  160. 'handler' => 'views_handler_argument_string',
  161. ),
  162. );
  163. // Field: program version (varchar 255)
  164. $data['analysis']['programversion'] = array(
  165. 'title' => t('Program Version'),
  166. 'help' => t('Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000].'),
  167. 'field' => array(
  168. 'handler' => 'views_handler_field',
  169. 'click sortable' => TRUE,
  170. ),
  171. 'sort' => array(
  172. 'handler' => 'views_handler_sort',
  173. ),
  174. 'filter' => array(
  175. 'handler' => 'views_handler_filter_chado_select_string',
  176. ),
  177. 'argument' => array(
  178. 'handler' => 'views_handler_argument_string',
  179. ),
  180. );
  181. // Field: algorithm (varchar 255)
  182. $data['analysis']['algorithm'] = array(
  183. 'title' => t('Algorithm'),
  184. 'help' => t('Algorithm name, e.g. blast.'),
  185. 'field' => array(
  186. 'handler' => 'views_handler_field',
  187. 'click sortable' => TRUE,
  188. ),
  189. 'sort' => array(
  190. 'handler' => 'views_handler_sort',
  191. ),
  192. 'filter' => array(
  193. 'handler' => 'views_handler_filter_chado_select_string',
  194. ),
  195. 'argument' => array(
  196. 'handler' => 'views_handler_argument_string',
  197. ),
  198. );
  199. $data['analysis']['sourcename'] = array(
  200. 'title' => t('Source Name'),
  201. 'help' => t('Source name, e.g. cDNA, SwissProt.'),
  202. 'field' => array(
  203. 'handler' => 'views_handler_field',
  204. 'click sortable' => TRUE,
  205. ),
  206. 'sort' => array(
  207. 'handler' => 'views_handler_sort',
  208. ),
  209. 'filter' => array(
  210. 'handler' => 'views_handler_filter_string',
  211. ),
  212. 'argument' => array(
  213. 'handler' => 'views_handler_argument_string',
  214. ),
  215. );
  216. // Field: source version (varchar 255)
  217. $data['analysis']['sourceversion'] = array(
  218. 'title' => t('Source Version'),
  219. 'help' => t('The version of the source.'),
  220. 'field' => array(
  221. 'handler' => 'views_handler_field',
  222. 'click sortable' => TRUE,
  223. ),
  224. 'sort' => array(
  225. 'handler' => 'views_handler_sort',
  226. ),
  227. 'filter' => array(
  228. 'handler' => 'views_handler_filter_string',
  229. ),
  230. 'argument' => array(
  231. 'handler' => 'views_handler_argument_string',
  232. ),
  233. );
  234. // Field: source URI/URL (text)
  235. $data['analysis']['sourceuri'] = array(
  236. 'title' => t('Source URL'),
  237. 'help' => t('This is an optional, permanent URL or URI for the source of the analysis.'),
  238. 'field' => array(
  239. 'handler' => 'views_handler_field',
  240. 'click sortable' => TRUE,
  241. ),
  242. 'sort' => array(
  243. 'handler' => 'views_handler_sort',
  244. ),
  245. 'filter' => array(
  246. 'handler' => 'views_handler_filter_string',
  247. ),
  248. 'argument' => array(
  249. 'handler' => 'views_handler_argument_string',
  250. ),
  251. );
  252. // Field: time executed (datetime)
  253. $data['analysis']['timeexecuted'] = array(
  254. 'title' => 'Time Executed',
  255. 'help' => 'The date & time when this analysis was executed.',
  256. 'field' => array(
  257. 'handler' => 'views_handler_field_readable_date',
  258. 'click sortable' => TRUE,
  259. ),
  260. 'sort' => array(
  261. 'handler' => 'views_handler_sort_date',
  262. ),
  263. );
  264. return $data;
  265. }