tripal_feature.views.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions for views integration of
  5. * chado/tripal organism tables. Supplementary functions can be found in
  6. * ./views/
  7. *
  8. * Documentation on views integration can be found at
  9. * http://views2.logrus.com/doc/html/index.html.
  10. */
  11. /**
  12. * @defgroup tripal_feature_views Feature Views Integration
  13. * @ingroup views
  14. */
  15. /**
  16. * Implements hook_views_handlers()
  17. *
  18. * Purpose: Register all custom handlers with views
  19. * where a handler describes either "the type of field",
  20. * "how a field should be filtered", "how a field should be sorted"
  21. *
  22. * @return: An array of handler definitions
  23. *
  24. * @ingroup tripal_feature_views
  25. */
  26. function tripal_feature_views_handlers() {
  27. return array(
  28. 'info' => array(
  29. 'path' => drupal_get_path('module', 'tripal_feature') . '/views_handlers',
  30. ),
  31. 'handlers' => array(
  32. 'views_handler_field_residues' => array(
  33. 'parent' => 'views_handler_field',
  34. ),
  35. ),
  36. );
  37. }
  38. /**
  39. *
  40. * @ingroup tripal_feature_views
  41. */
  42. function tripal_feature_views_default_views() {
  43. $views = array();
  44. if (!module_exists('tripal_views')) {
  45. return $views;
  46. }
  47. // Main default view
  48. $view = new view;
  49. $view->name = 'feature_listing';
  50. $view->description = 'A listing of chado sequence features.';
  51. $view->tag = 'chado default';
  52. $view->base_table = 'feature';
  53. $view->core = 0;
  54. $view->api_version = '2';
  55. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  56. $handler = $view->new_display('default', 'features_all', 'default');
  57. $handler->override_option('fields', array(
  58. 'uniquename' => array(
  59. 'label' => 'Unique Name',
  60. 'alter' => array(
  61. 'alter_text' => 0,
  62. 'text' => '',
  63. 'make_link' => 0,
  64. 'path' => 'node/[nid]',
  65. 'link_class' => '',
  66. 'alt' => '',
  67. 'prefix' => '',
  68. 'suffix' => '',
  69. 'target' => '',
  70. 'help' => '',
  71. 'trim' => 0,
  72. 'max_length' => '',
  73. 'word_boundary' => 1,
  74. 'ellipsis' => 1,
  75. 'html' => 0,
  76. 'strip_tags' => 0,
  77. ),
  78. 'empty' => '',
  79. 'hide_empty' => 0,
  80. 'empty_zero' => 0,
  81. 'link_to_node' => 0,
  82. 'exclude' => 0,
  83. 'id' => 'uniquename',
  84. 'table' => 'feature',
  85. 'field' => 'uniquename',
  86. 'relationship' => 'none',
  87. 'override' => array(
  88. 'button' => 'Override',
  89. ),
  90. ),
  91. 'name' => array(
  92. 'label' => 'Name',
  93. 'alter' => array(
  94. 'alter_text' => 0,
  95. 'text' => '',
  96. 'make_link' => 0,
  97. 'path' => '',
  98. 'link_class' => '',
  99. 'alt' => '',
  100. 'prefix' => '',
  101. 'suffix' => '',
  102. 'target' => '',
  103. 'help' => '',
  104. 'trim' => 0,
  105. 'max_length' => '',
  106. 'word_boundary' => 1,
  107. 'ellipsis' => 1,
  108. 'html' => 0,
  109. 'strip_tags' => 0,
  110. ),
  111. 'empty' => '',
  112. 'hide_empty' => 0,
  113. 'empty_zero' => 0,
  114. 'link_to_node' => 1,
  115. 'exclude' => 0,
  116. 'id' => 'name',
  117. 'table' => 'feature',
  118. 'field' => 'name',
  119. 'relationship' => 'none',
  120. 'override' => array(
  121. 'button' => 'Override',
  122. ),
  123. ),
  124. 'name_1' => array(
  125. 'label' => 'Type',
  126. 'alter' => array(
  127. 'alter_text' => 0,
  128. 'text' => '',
  129. 'make_link' => 0,
  130. 'path' => '',
  131. 'link_class' => '',
  132. 'alt' => '',
  133. 'prefix' => '',
  134. 'suffix' => '',
  135. 'target' => '',
  136. 'help' => '',
  137. 'trim' => 0,
  138. 'max_length' => '',
  139. 'word_boundary' => 1,
  140. 'ellipsis' => 1,
  141. 'html' => 0,
  142. 'strip_tags' => 0,
  143. ),
  144. 'empty' => '',
  145. 'hide_empty' => 0,
  146. 'empty_zero' => 0,
  147. 'exclude' => 0,
  148. 'id' => 'name_1',
  149. 'table' => 'cvterm',
  150. 'field' => 'name',
  151. 'relationship' => 'none',
  152. ),
  153. 'common_name' => array(
  154. 'label' => 'Common Name',
  155. 'alter' => array(
  156. 'alter_text' => 0,
  157. 'text' => '',
  158. 'make_link' => 0,
  159. 'path' => '',
  160. 'link_class' => '',
  161. 'alt' => '',
  162. 'prefix' => '',
  163. 'suffix' => '',
  164. 'target' => '',
  165. 'help' => '',
  166. 'trim' => 0,
  167. 'max_length' => '',
  168. 'word_boundary' => 1,
  169. 'ellipsis' => 1,
  170. 'html' => 0,
  171. 'strip_tags' => 0,
  172. ),
  173. 'empty' => '',
  174. 'hide_empty' => 0,
  175. 'empty_zero' => 0,
  176. 'link_to_node' => 1,
  177. 'exclude' => 0,
  178. 'id' => 'common_name',
  179. 'table' => 'organism',
  180. 'field' => 'common_name',
  181. 'relationship' => 'none',
  182. 'override' => array(
  183. 'button' => 'Override',
  184. ),
  185. ),
  186. 'seqlen' => array(
  187. 'label' => 'Sequence Length',
  188. 'alter' => array(
  189. 'alter_text' => 0,
  190. 'text' => '',
  191. 'make_link' => 0,
  192. 'path' => '',
  193. 'link_class' => '',
  194. 'alt' => '',
  195. 'prefix' => '',
  196. 'suffix' => '',
  197. 'target' => '',
  198. 'help' => '',
  199. 'trim' => 0,
  200. 'max_length' => '',
  201. 'word_boundary' => 1,
  202. 'ellipsis' => 1,
  203. 'html' => 0,
  204. 'strip_tags' => 0,
  205. ),
  206. 'empty' => '',
  207. 'hide_empty' => 0,
  208. 'empty_zero' => 0,
  209. 'set_precision' => FALSE,
  210. 'precision' => 0,
  211. 'decimal' => '.',
  212. 'separator' => ',',
  213. 'prefix' => '',
  214. 'suffix' => '',
  215. 'exclude' => 0,
  216. 'id' => 'seqlen',
  217. 'table' => 'feature',
  218. 'field' => 'seqlen',
  219. 'relationship' => 'none',
  220. ),
  221. 'is_obsolete' => array(
  222. 'label' => 'Is Obsolete',
  223. 'alter' => array(
  224. 'alter_text' => 0,
  225. 'text' => '',
  226. 'make_link' => 0,
  227. 'path' => '',
  228. 'absolute' => 0,
  229. 'link_class' => '',
  230. 'alt' => '',
  231. 'rel' => '',
  232. 'prefix' => '',
  233. 'suffix' => '',
  234. 'target' => '',
  235. 'help' => '',
  236. 'trim' => 0,
  237. 'max_length' => '',
  238. 'word_boundary' => 1,
  239. 'ellipsis' => 1,
  240. 'html' => 0,
  241. 'strip_tags' => 0,
  242. ),
  243. 'empty' => '',
  244. 'hide_empty' => 0,
  245. 'empty_zero' => 0,
  246. 'hide_alter_empty' => 1,
  247. 'type' => 'separator',
  248. 'not' => 0,
  249. 'separator' => ', ',
  250. 'exclude' => 0,
  251. 'id' => 'is_obsolete',
  252. 'table' => 'feature',
  253. 'field' => 'is_obsolete',
  254. 'relationship' => 'none',
  255. ),
  256. 'timeaccessioned' => array(
  257. 'label' => 'Accessioned On',
  258. 'alter' => array(
  259. 'alter_text' => 0,
  260. 'text' => '',
  261. 'make_link' => 0,
  262. 'path' => '',
  263. 'absolute' => 0,
  264. 'link_class' => '',
  265. 'alt' => '',
  266. 'rel' => '',
  267. 'prefix' => '',
  268. 'suffix' => '',
  269. 'target' => '',
  270. 'help' => '',
  271. 'trim' => 0,
  272. 'max_length' => '',
  273. 'word_boundary' => 1,
  274. 'ellipsis' => 1,
  275. 'html' => 0,
  276. 'strip_tags' => 0,
  277. ),
  278. 'empty' => '',
  279. 'hide_empty' => 0,
  280. 'empty_zero' => 0,
  281. 'hide_alter_empty' => 1,
  282. 'date_format' => 'large',
  283. 'custom_date_format' => '',
  284. 'type' => 'separator',
  285. 'separator' => ', ',
  286. 'exclude' => 0,
  287. 'id' => 'timeaccessioned',
  288. 'table' => 'feature',
  289. 'field' => 'timeaccessioned',
  290. 'relationship' => 'none',
  291. ),
  292. ));
  293. $handler->override_option('sorts', array(
  294. 'common_name' => array(
  295. 'order' => 'ASC',
  296. 'id' => 'common_name',
  297. 'table' => 'organism',
  298. 'field' => 'common_name',
  299. 'relationship' => 'none',
  300. ),
  301. 'name' => array(
  302. 'order' => 'ASC',
  303. 'id' => 'name',
  304. 'table' => 'cvterm',
  305. 'field' => 'name',
  306. 'relationship' => 'none',
  307. ),
  308. 'name_1' => array(
  309. 'order' => 'ASC',
  310. 'id' => 'name_1',
  311. 'table' => 'feature',
  312. 'field' => 'name',
  313. 'relationship' => 'none',
  314. ),
  315. ));
  316. $handler->override_option('filters', array(
  317. 'common_name' => array(
  318. 'operator' => '=',
  319. 'value' => array(),
  320. 'group' => '0',
  321. 'exposed' => TRUE,
  322. 'expose' => array(
  323. 'use_operator' => 0,
  324. 'operator' => 'common_name_op',
  325. 'identifier' => 'organism',
  326. 'label' => 'Organism Common Name',
  327. 'remember' => 0,
  328. ),
  329. 'case' => 1,
  330. 'id' => 'common_name',
  331. 'table' => 'organism',
  332. 'field' => 'common_name',
  333. 'relationship' => 'none',
  334. 'values_form_type' => 'select',
  335. 'multiple' => 1,
  336. 'optional' => 0,
  337. 'override' => array(
  338. 'button' => 'Override',
  339. ),
  340. 'agg' => array(
  341. 'records_with' => 1,
  342. 'aggregates_with' => 1,
  343. ),
  344. ),
  345. 'type_id' => array(
  346. 'operator' => '=',
  347. 'value' => array(),
  348. 'group' => '0',
  349. 'exposed' => TRUE,
  350. 'expose' => array(
  351. 'use_operator' => 0,
  352. 'operator' => 'type_id_op',
  353. 'identifier' => 'type_id',
  354. 'label' => 'Type',
  355. 'remember' => 0,
  356. ),
  357. 'case' => 1,
  358. 'id' => 'type_id',
  359. 'table' => 'feature',
  360. 'field' => 'type_id',
  361. 'relationship' => 'none',
  362. 'values_form_type' => 'select',
  363. 'multiple' => 1,
  364. 'optional' => 0,
  365. 'show_all' => 0,
  366. 'agg' => array(
  367. 'records_with' => 1,
  368. 'aggregates_with' => 1,
  369. ),
  370. ),
  371. 'name_1' => array(
  372. 'operator' => '~',
  373. 'value' => '',
  374. 'group' => '0',
  375. 'exposed' => TRUE,
  376. 'expose' => array(
  377. 'use_operator' => 0,
  378. 'operator' => 'name_1_op',
  379. 'identifier' => 'name',
  380. 'label' => 'Name Contains',
  381. 'bef_filter_description' => '',
  382. 'remember' => 0,
  383. ),
  384. 'case' => 0,
  385. 'id' => 'name_1',
  386. 'table' => 'feature',
  387. 'field' => 'name',
  388. 'relationship' => 'none',
  389. 'agg' => array(
  390. 'records_with' => 1,
  391. 'aggregates_with' => 1,
  392. ),
  393. ),
  394. 'search_results' => array(
  395. 'operator' => '=',
  396. 'value' => '',
  397. 'group' => '0',
  398. 'exposed' => FALSE,
  399. 'expose' => array(
  400. 'operator' => FALSE,
  401. 'label' => '',
  402. ),
  403. 'id' => 'search_results',
  404. 'table' => 'views',
  405. 'field' => 'search_results',
  406. 'relationship' => 'none',
  407. 'apply_button' => 'Show',
  408. 'no_results_text' => 'Click "Show" to see a list of all features matching the entered criteria. If you leave a any of the criteria blank then the features will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all features will be listed.',
  409. ),
  410. ));
  411. $handler->override_option('access', array(
  412. 'type' => 'perm',
  413. 'perm' => 'access chado_feature content',
  414. ));
  415. $handler->override_option('cache', array(
  416. 'type' => 'none',
  417. ));
  418. $handler->override_option('title', 'Sequence Features');
  419. $handler->override_option('header', 'Click "Show" to see a list of all features matching the entered criteria. If you leave a any of the criteria blank then the features will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all features will be listed.');
  420. $handler->override_option('header_format', '2');
  421. $handler->override_option('header_empty', 0);
  422. $handler->override_option('empty', 'No features matched the supplied criteria.');
  423. $handler->override_option('empty_format', '2');
  424. $handler->override_option('items_per_page', 50);
  425. $handler->override_option('use_pager', '1');
  426. $handler->override_option('style_plugin', 'table');
  427. $handler->override_option('style_options', array(
  428. 'grouping' => '',
  429. 'override' => 1,
  430. 'sticky' => 0,
  431. 'order' => 'asc',
  432. 'columns' => array(
  433. 'accession' => 'accession',
  434. 'accession_link' => 'accession_link',
  435. 'name' => 'name',
  436. 'uniquename' => 'uniquename',
  437. 'name_1' => 'name_1',
  438. 'common_name' => 'common_name',
  439. 'seqlen' => 'seqlen',
  440. 'is_obsolete' => 'is_obsolete',
  441. 'is_analysis' => 'is_analysis',
  442. 'nid' => 'nid',
  443. ),
  444. 'info' => array(
  445. 'accession' => array(
  446. 'sortable' => 1,
  447. 'separator' => '',
  448. ),
  449. 'accession_link' => array(
  450. 'sortable' => 1,
  451. 'separator' => '',
  452. ),
  453. 'name' => array(
  454. 'sortable' => 1,
  455. 'separator' => '',
  456. ),
  457. 'uniquename' => array(
  458. 'sortable' => 1,
  459. 'separator' => '',
  460. ),
  461. 'name_1' => array(
  462. 'sortable' => 1,
  463. 'separator' => '',
  464. ),
  465. 'common_name' => array(
  466. 'sortable' => 1,
  467. 'separator' => '',
  468. ),
  469. 'seqlen' => array(
  470. 'sortable' => 1,
  471. 'separator' => '',
  472. ),
  473. 'is_obsolete' => array(
  474. 'sortable' => 1,
  475. 'separator' => '',
  476. ),
  477. 'is_analysis' => array(
  478. 'sortable' => 1,
  479. 'separator' => '',
  480. ),
  481. 'nid' => array(
  482. 'separator' => '',
  483. ),
  484. ),
  485. 'default' => '-1',
  486. ));
  487. $default_handler = $handler;
  488. $handler = $view->new_display('page', 'Page', 'page_1');
  489. $handler->override_option('path', 'chado/features');
  490. $handler->override_option('menu', array(
  491. 'type' => 'normal',
  492. 'title' => 'Features',
  493. 'description' => 'A feature is a biological sequence or a section of a biological sequence, or a collection of such sections. Examples include genes, exons, transcripts, regulatory regions, polypeptides, protein domains, chromosome sequences, sequence variations, cross-genome match regions such as hits and HSPs and so on.',
  494. 'weight' => '10',
  495. 'name' => 'navigation',
  496. ));
  497. $handler->override_option('tab_options', array(
  498. 'type' => 'none',
  499. 'title' => '',
  500. 'description' => '',
  501. 'weight' => 0,
  502. 'name' => 'navigation',
  503. ));
  504. // Add code specific to a local chado installation
  505. // NOTE: Edit $handler above to $default_handler for the default display
  506. if (tripal_core_chado_schema_exists()) {
  507. // Add nid field
  508. $fields = $view->get_items('field', 'default');
  509. $new_fields = array(
  510. 'nid' => array(
  511. 'label' => 'Nid',
  512. 'alter' => array(
  513. 'alter_text' => 0,
  514. 'text' => '',
  515. 'make_link' => 0,
  516. 'path' => '',
  517. 'absolute' => 0,
  518. 'link_class' => '',
  519. 'alt' => '',
  520. 'rel' => '',
  521. 'prefix' => '',
  522. 'suffix' => '',
  523. 'target' => '',
  524. 'help' => '',
  525. 'trim' => 0,
  526. 'max_length' => '',
  527. 'word_boundary' => 1,
  528. 'ellipsis' => 1,
  529. 'html' => 0,
  530. 'strip_tags' => 0,
  531. ),
  532. 'empty' => '',
  533. 'hide_empty' => 0,
  534. 'empty_zero' => 0,
  535. 'hide_alter_empty' => 1,
  536. 'link_to_node' => 0,
  537. 'exclude' => 1,
  538. 'id' => 'nid',
  539. 'table' => 'node',
  540. 'field' => 'nid',
  541. 'relationship' => 'none',
  542. )
  543. );
  544. $fields = $new_fields + $fields;
  545. // Adds feature => Node relationship
  546. $default_handler->override_option('relationships', array(
  547. 'nid' => array(
  548. 'label' => 'Feature to Node',
  549. 'required' => 0,
  550. 'id' => 'nid',
  551. 'table' => 'chado_feature',
  552. 'field' => 'nid',
  553. 'relationship' => 'none',
  554. ),
  555. ));
  556. // Change analysis.name to have a link to the node
  557. $fields['name']['alter']['link_to_node'] = 1;
  558. $default_handler->override_option('fields', $fields);
  559. // Only show records with published nodes
  560. /**
  561. $filters = $view->get_items('filter', 'default');
  562. $filters['status'] = array(
  563. 'operator' => '=',
  564. 'value' => '1',
  565. 'group' => '0',
  566. 'exposed' => FALSE,
  567. 'expose' => array(
  568. 'operator' => FALSE,
  569. 'label' => '',
  570. ),
  571. 'id' => 'status',
  572. 'table' => 'node',
  573. 'field' => 'status',
  574. 'relationship' => 'none',
  575. );
  576. $default_handler->override_option('filters', $filters);
  577. */
  578. }
  579. $views[$view->name] = $view;
  580. return $views;
  581. }