tripal_feature.views.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. * @ingroup tripal_feature
  15. */
  16. /**
  17. * Implements hook_views_data()
  18. *
  19. * Purpose: Describe chado/tripal tables & fields to views
  20. *
  21. * @return: a data array which follows the structure outlined in the
  22. * views2 documentation for this hook. Essentially, it's an array of table
  23. * definitions keyed by chado/tripal table name. Each table definition
  24. * includes basic details about the table, fields in that table and
  25. * relationships between that table and others (joins)
  26. *
  27. * @ingroup tripal_feature_views
  28. */
  29. function tripal_feature_views_data() {
  30. $data = array();
  31. if (module_exists('tripal_views')) {
  32. $tables = array(
  33. 'feature',
  34. );
  35. foreach ($tables as $tablename) {
  36. $priority = 9;
  37. // check to see if the table is integrated. If it is then integrate it's
  38. // corresponding 'chado_[table]' table.
  39. if (!tripal_views_is_integrated($tablename, $priority)) {
  40. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority);
  41. // Add in node relationships if chado is in the same db as drupal
  42. if (tripal_core_chado_schema_exists()) {
  43. $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array);
  44. foreach ($integrations as $integration) {
  45. tripal_views_integration_add_entry($integration);
  46. }
  47. }
  48. else {
  49. tripal_views_integration_add_entry($table_integration_array);
  50. }
  51. }
  52. }
  53. $tables = array(
  54. 'feature_cvterm',
  55. 'feature_cvterm_dbxref',
  56. 'feature_cvterm_pub',
  57. 'feature_cvtermprop',
  58. 'feature_dbxref',
  59. 'feature_pub',
  60. 'feature_pubprop',
  61. 'feature_relationship',
  62. 'feature_relationship_pub',
  63. 'feature_relationshipprop',
  64. 'feature_relationshipprop_pub',
  65. 'feature_synonym',
  66. 'featureloc',
  67. 'featureloc_pub',
  68. 'featureprop',
  69. 'featureprop_pub',
  70. 'featuremap',
  71. 'featuremap_pub',
  72. 'featurepos',
  73. 'featurerange'
  74. );
  75. foreach ($tables as $tablename) {
  76. $priority = 9;
  77. if (!tripal_views_is_integrated($tablename, $priority)) {
  78. $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE, $priority);
  79. tripal_views_integration_add_entry($table_integration_array);
  80. }
  81. }
  82. }
  83. return $data;
  84. }
  85. /**
  86. * Implements hook_views_handlers()
  87. *
  88. * Purpose: Register all custom handlers with views
  89. * where a handler describes either "the type of field",
  90. * "how a field should be filtered", "how a field should be sorted"
  91. *
  92. * @return: An array of handler definitions
  93. *
  94. * @ingroup tripal_feature_views
  95. */
  96. function tripal_feature_views_handlers() {
  97. return array(
  98. 'info' => array(
  99. 'path' => drupal_get_path('module', 'tripal_feature') . '/views_handlers',
  100. ),
  101. 'handlers' => array(
  102. 'views_handler_field_residues' => array(
  103. 'parent' => 'views_handler_field',
  104. ),
  105. ),
  106. );
  107. }
  108. /**
  109. * Implementation of hook_views_data_alter().
  110. */
  111. function tripal_feature_views_data_alter(&$data) {
  112. if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
  113. // Add featuer relationship to node
  114. $data['node']['feature_chado_nid'] = array(
  115. 'group' => 'Feature',
  116. 'title' => 'Feature Node',
  117. 'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
  118. 'real field' => 'nid',
  119. 'relationship' => array(
  120. 'handler' => 'views_handler_relationship',
  121. 'title' => t('Node => Chado'),
  122. 'label' => t('Node => Chado'),
  123. 'real field' => 'nid',
  124. 'base' => 'chado_feature',
  125. 'base field' => 'nid'
  126. ),
  127. );
  128. }
  129. }
  130. /**
  131. *
  132. * @ingroup tripal_feature_views
  133. */
  134. function tripal_feature_views_default_views() {
  135. $views = array();
  136. if (!module_exists('tripal_views')) {
  137. return $views;
  138. }
  139. // Main default view
  140. $view = new view;
  141. $view->name = 'feature_listing';
  142. $view->description = 'A listing of chado sequence features.';
  143. $view->tag = 'chado default';
  144. $view->base_table = 'feature';
  145. $view->core = 0;
  146. $view->api_version = '2';
  147. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  148. $handler = $view->new_display('default', 'features_all', 'default');
  149. $handler->override_option('fields', array(
  150. 'uniquename' => array(
  151. 'label' => 'Unique Name',
  152. 'alter' => array(
  153. 'alter_text' => 0,
  154. 'text' => '',
  155. 'make_link' => 0,
  156. 'path' => 'node/[nid]',
  157. 'link_class' => '',
  158. 'alt' => '',
  159. 'prefix' => '',
  160. 'suffix' => '',
  161. 'target' => '',
  162. 'help' => '',
  163. 'trim' => 0,
  164. 'max_length' => '',
  165. 'word_boundary' => 1,
  166. 'ellipsis' => 1,
  167. 'html' => 0,
  168. 'strip_tags' => 0,
  169. ),
  170. 'empty' => '',
  171. 'hide_empty' => 0,
  172. 'empty_zero' => 0,
  173. 'link_to_node' => 0,
  174. 'exclude' => 0,
  175. 'id' => 'uniquename',
  176. 'table' => 'feature',
  177. 'field' => 'uniquename',
  178. 'relationship' => 'none',
  179. 'override' => array(
  180. 'button' => 'Override',
  181. ),
  182. ),
  183. 'name' => array(
  184. 'label' => 'Name',
  185. 'alter' => array(
  186. 'alter_text' => 0,
  187. 'text' => '',
  188. 'make_link' => 0,
  189. 'path' => '',
  190. 'link_class' => '',
  191. 'alt' => '',
  192. 'prefix' => '',
  193. 'suffix' => '',
  194. 'target' => '',
  195. 'help' => '',
  196. 'trim' => 0,
  197. 'max_length' => '',
  198. 'word_boundary' => 1,
  199. 'ellipsis' => 1,
  200. 'html' => 0,
  201. 'strip_tags' => 0,
  202. ),
  203. 'empty' => '',
  204. 'hide_empty' => 0,
  205. 'empty_zero' => 0,
  206. 'link_to_node' => 1,
  207. 'exclude' => 0,
  208. 'id' => 'name',
  209. 'table' => 'feature',
  210. 'field' => 'name',
  211. 'relationship' => 'none',
  212. 'override' => array(
  213. 'button' => 'Override',
  214. ),
  215. ),
  216. 'name_1' => array(
  217. 'label' => 'Type',
  218. 'alter' => array(
  219. 'alter_text' => 0,
  220. 'text' => '',
  221. 'make_link' => 0,
  222. 'path' => '',
  223. 'link_class' => '',
  224. 'alt' => '',
  225. 'prefix' => '',
  226. 'suffix' => '',
  227. 'target' => '',
  228. 'help' => '',
  229. 'trim' => 0,
  230. 'max_length' => '',
  231. 'word_boundary' => 1,
  232. 'ellipsis' => 1,
  233. 'html' => 0,
  234. 'strip_tags' => 0,
  235. ),
  236. 'empty' => '',
  237. 'hide_empty' => 0,
  238. 'empty_zero' => 0,
  239. 'exclude' => 0,
  240. 'id' => 'name_1',
  241. 'table' => 'cvterm',
  242. 'field' => 'name',
  243. 'relationship' => 'none',
  244. ),
  245. 'common_name' => array(
  246. 'label' => 'Common Name',
  247. 'alter' => array(
  248. 'alter_text' => 0,
  249. 'text' => '',
  250. 'make_link' => 0,
  251. 'path' => '',
  252. 'link_class' => '',
  253. 'alt' => '',
  254. 'prefix' => '',
  255. 'suffix' => '',
  256. 'target' => '',
  257. 'help' => '',
  258. 'trim' => 0,
  259. 'max_length' => '',
  260. 'word_boundary' => 1,
  261. 'ellipsis' => 1,
  262. 'html' => 0,
  263. 'strip_tags' => 0,
  264. ),
  265. 'empty' => '',
  266. 'hide_empty' => 0,
  267. 'empty_zero' => 0,
  268. 'link_to_node' => 1,
  269. 'exclude' => 0,
  270. 'id' => 'common_name',
  271. 'table' => 'organism',
  272. 'field' => 'common_name',
  273. 'relationship' => 'none',
  274. 'override' => array(
  275. 'button' => 'Override',
  276. ),
  277. ),
  278. 'seqlen' => array(
  279. 'label' => 'Sequence Length',
  280. 'alter' => array(
  281. 'alter_text' => 0,
  282. 'text' => '',
  283. 'make_link' => 0,
  284. 'path' => '',
  285. 'link_class' => '',
  286. 'alt' => '',
  287. 'prefix' => '',
  288. 'suffix' => '',
  289. 'target' => '',
  290. 'help' => '',
  291. 'trim' => 0,
  292. 'max_length' => '',
  293. 'word_boundary' => 1,
  294. 'ellipsis' => 1,
  295. 'html' => 0,
  296. 'strip_tags' => 0,
  297. ),
  298. 'empty' => '',
  299. 'hide_empty' => 0,
  300. 'empty_zero' => 0,
  301. 'set_precision' => FALSE,
  302. 'precision' => 0,
  303. 'decimal' => '.',
  304. 'separator' => ',',
  305. 'prefix' => '',
  306. 'suffix' => '',
  307. 'exclude' => 0,
  308. 'id' => 'seqlen',
  309. 'table' => 'feature',
  310. 'field' => 'seqlen',
  311. 'relationship' => 'none',
  312. ),
  313. 'is_obsolete' => array(
  314. 'label' => 'Is Obsolete',
  315. 'alter' => array(
  316. 'alter_text' => 0,
  317. 'text' => '',
  318. 'make_link' => 0,
  319. 'path' => '',
  320. 'absolute' => 0,
  321. 'link_class' => '',
  322. 'alt' => '',
  323. 'rel' => '',
  324. 'prefix' => '',
  325. 'suffix' => '',
  326. 'target' => '',
  327. 'help' => '',
  328. 'trim' => 0,
  329. 'max_length' => '',
  330. 'word_boundary' => 1,
  331. 'ellipsis' => 1,
  332. 'html' => 0,
  333. 'strip_tags' => 0,
  334. ),
  335. 'empty' => '',
  336. 'hide_empty' => 0,
  337. 'empty_zero' => 0,
  338. 'hide_alter_empty' => 1,
  339. 'type' => 'separator',
  340. 'not' => 0,
  341. 'separator' => ', ',
  342. 'exclude' => 0,
  343. 'id' => 'is_obsolete',
  344. 'table' => 'feature',
  345. 'field' => 'is_obsolete',
  346. 'relationship' => 'none',
  347. ),
  348. 'timeaccessioned' => array(
  349. 'label' => 'Accessioned On',
  350. 'alter' => array(
  351. 'alter_text' => 0,
  352. 'text' => '',
  353. 'make_link' => 0,
  354. 'path' => '',
  355. 'absolute' => 0,
  356. 'link_class' => '',
  357. 'alt' => '',
  358. 'rel' => '',
  359. 'prefix' => '',
  360. 'suffix' => '',
  361. 'target' => '',
  362. 'help' => '',
  363. 'trim' => 0,
  364. 'max_length' => '',
  365. 'word_boundary' => 1,
  366. 'ellipsis' => 1,
  367. 'html' => 0,
  368. 'strip_tags' => 0,
  369. ),
  370. 'empty' => '',
  371. 'hide_empty' => 0,
  372. 'empty_zero' => 0,
  373. 'hide_alter_empty' => 1,
  374. 'date_format' => 'large',
  375. 'custom_date_format' => '',
  376. 'type' => 'separator',
  377. 'separator' => ', ',
  378. 'exclude' => 0,
  379. 'id' => 'timeaccessioned',
  380. 'table' => 'feature',
  381. 'field' => 'timeaccessioned',
  382. 'relationship' => 'none',
  383. ),
  384. ));
  385. $handler->override_option('sorts', array(
  386. 'common_name' => array(
  387. 'order' => 'ASC',
  388. 'id' => 'common_name',
  389. 'table' => 'organism',
  390. 'field' => 'common_name',
  391. 'relationship' => 'none',
  392. ),
  393. 'name' => array(
  394. 'order' => 'ASC',
  395. 'id' => 'name',
  396. 'table' => 'cvterm',
  397. 'field' => 'name',
  398. 'relationship' => 'none',
  399. ),
  400. 'name_1' => array(
  401. 'order' => 'ASC',
  402. 'id' => 'name_1',
  403. 'table' => 'feature',
  404. 'field' => 'name',
  405. 'relationship' => 'none',
  406. ),
  407. ));
  408. $handler->override_option('filters', array(
  409. 'common_name' => array(
  410. 'operator' => '=',
  411. 'value' => array(),
  412. 'group' => '0',
  413. 'exposed' => TRUE,
  414. 'expose' => array(
  415. 'use_operator' => 0,
  416. 'operator' => 'common_name_op',
  417. 'identifier' => 'organism',
  418. 'label' => 'Organism Common Name',
  419. 'remember' => 0,
  420. ),
  421. 'case' => 1,
  422. 'id' => 'common_name',
  423. 'table' => 'organism',
  424. 'field' => 'common_name',
  425. 'relationship' => 'none',
  426. 'values_form_type' => 'select',
  427. 'multiple' => 1,
  428. 'optional' => 0,
  429. 'override' => array(
  430. 'button' => 'Override',
  431. ),
  432. 'agg' => array(
  433. 'records_with' => 1,
  434. 'aggregates_with' => 1,
  435. ),
  436. ),
  437. 'type_id' => array(
  438. 'operator' => '=',
  439. 'value' => array(),
  440. 'group' => '0',
  441. 'exposed' => TRUE,
  442. 'expose' => array(
  443. 'use_operator' => 0,
  444. 'operator' => 'type_id_op',
  445. 'identifier' => 'type_id',
  446. 'label' => 'Type',
  447. 'remember' => 0,
  448. ),
  449. 'case' => 1,
  450. 'id' => 'type_id',
  451. 'table' => 'feature',
  452. 'field' => 'type_id',
  453. 'relationship' => 'none',
  454. 'values_form_type' => 'select',
  455. 'multiple' => 1,
  456. 'optional' => 0,
  457. 'show_all' => 0,
  458. 'agg' => array(
  459. 'records_with' => 1,
  460. 'aggregates_with' => 1,
  461. ),
  462. ),
  463. 'name_1' => array(
  464. 'operator' => 'allwords',
  465. 'value' => '',
  466. 'group' => '0',
  467. 'exposed' => TRUE,
  468. 'expose' => array(
  469. 'use_operator' => 0,
  470. 'operator' => 'name_1_op',
  471. 'identifier' => 'name',
  472. 'label' => 'Name Contains',
  473. 'bef_filter_description' => '',
  474. 'remember' => 0,
  475. ),
  476. 'case' => 0,
  477. 'id' => 'name_1',
  478. 'table' => 'feature',
  479. 'field' => 'name',
  480. 'relationship' => 'none',
  481. 'agg' => array(
  482. 'records_with' => 1,
  483. 'aggregates_with' => 1,
  484. ),
  485. ),
  486. 'search_results' => array(
  487. 'operator' => '=',
  488. 'value' => '',
  489. 'group' => '0',
  490. 'exposed' => FALSE,
  491. 'expose' => array(
  492. 'operator' => FALSE,
  493. 'label' => '',
  494. ),
  495. 'id' => 'search_results',
  496. 'table' => 'views',
  497. 'field' => 'search_results',
  498. 'relationship' => 'none',
  499. 'apply_button' => 'Show',
  500. '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.',
  501. ),
  502. ));
  503. $handler->override_option('access', array(
  504. 'type' => 'perm',
  505. 'perm' => 'access chado_feature content',
  506. ));
  507. $handler->override_option('cache', array(
  508. 'type' => 'none',
  509. ));
  510. $handler->override_option('title', 'Sequence Features');
  511. $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.');
  512. $handler->override_option('header_format', '2');
  513. $handler->override_option('header_empty', 0);
  514. $handler->override_option('empty', 'No features matched the supplied criteria.');
  515. $handler->override_option('empty_format', '2');
  516. $handler->override_option('items_per_page', 50);
  517. $handler->override_option('use_pager', '1');
  518. $handler->override_option('style_plugin', 'table');
  519. $handler->override_option('style_options', array(
  520. 'grouping' => '',
  521. 'override' => 1,
  522. 'sticky' => 0,
  523. 'order' => 'asc',
  524. 'columns' => array(
  525. 'accession' => 'accession',
  526. 'accession_link' => 'accession_link',
  527. 'name' => 'name',
  528. 'uniquename' => 'uniquename',
  529. 'name_1' => 'name_1',
  530. 'common_name' => 'common_name',
  531. 'seqlen' => 'seqlen',
  532. 'is_obsolete' => 'is_obsolete',
  533. 'is_analysis' => 'is_analysis',
  534. 'nid' => 'nid',
  535. ),
  536. 'info' => array(
  537. 'accession' => array(
  538. 'sortable' => 1,
  539. 'separator' => '',
  540. ),
  541. 'accession_link' => array(
  542. 'sortable' => 1,
  543. 'separator' => '',
  544. ),
  545. 'name' => array(
  546. 'sortable' => 1,
  547. 'separator' => '',
  548. ),
  549. 'uniquename' => array(
  550. 'sortable' => 1,
  551. 'separator' => '',
  552. ),
  553. 'name_1' => array(
  554. 'sortable' => 1,
  555. 'separator' => '',
  556. ),
  557. 'common_name' => array(
  558. 'sortable' => 1,
  559. 'separator' => '',
  560. ),
  561. 'seqlen' => array(
  562. 'sortable' => 1,
  563. 'separator' => '',
  564. ),
  565. 'is_obsolete' => array(
  566. 'sortable' => 1,
  567. 'separator' => '',
  568. ),
  569. 'is_analysis' => array(
  570. 'sortable' => 1,
  571. 'separator' => '',
  572. ),
  573. 'nid' => array(
  574. 'separator' => '',
  575. ),
  576. ),
  577. 'default' => '-1',
  578. ));
  579. $default_handler = $handler;
  580. $handler = $view->new_display('page', 'Page', 'page_1');
  581. $handler->override_option('path', 'chado/features');
  582. $handler->override_option('menu', array(
  583. 'type' => 'normal',
  584. 'title' => 'Features',
  585. '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.',
  586. 'weight' => '10',
  587. 'name' => 'navigation',
  588. ));
  589. $handler->override_option('tab_options', array(
  590. 'type' => 'none',
  591. 'title' => '',
  592. 'description' => '',
  593. 'weight' => 0,
  594. 'name' => 'navigation',
  595. ));
  596. // Add code specific to a local chado installation
  597. // NOTE: Edit $handler above to $default_handler for the default display
  598. if (tripal_core_chado_schema_exists()) {
  599. // Add nid field
  600. $fields = $view->get_items('field', 'default');
  601. $new_fields = array(
  602. 'nid' => array(
  603. 'label' => 'Nid',
  604. 'alter' => array(
  605. 'alter_text' => 0,
  606. 'text' => '',
  607. 'make_link' => 0,
  608. 'path' => '',
  609. 'absolute' => 0,
  610. 'link_class' => '',
  611. 'alt' => '',
  612. 'rel' => '',
  613. 'prefix' => '',
  614. 'suffix' => '',
  615. 'target' => '',
  616. 'help' => '',
  617. 'trim' => 0,
  618. 'max_length' => '',
  619. 'word_boundary' => 1,
  620. 'ellipsis' => 1,
  621. 'html' => 0,
  622. 'strip_tags' => 0,
  623. ),
  624. 'empty' => '',
  625. 'hide_empty' => 0,
  626. 'empty_zero' => 0,
  627. 'hide_alter_empty' => 1,
  628. 'link_to_node' => 0,
  629. 'exclude' => 1,
  630. 'id' => 'nid',
  631. 'table' => 'node',
  632. 'field' => 'nid',
  633. 'relationship' => 'none',
  634. )
  635. );
  636. $fields = $new_fields + $fields;
  637. // Adds feature => Node relationship
  638. $default_handler->override_option('relationships', array(
  639. 'nid' => array(
  640. 'label' => 'Feature to Node',
  641. 'required' => 0,
  642. 'id' => 'nid',
  643. 'table' => 'chado_feature',
  644. 'field' => 'nid',
  645. 'relationship' => 'none',
  646. ),
  647. ));
  648. // Change analysis.name to have a link to the node
  649. $fields['name']['alter']['make_link'] = 1;
  650. $fields['name']['alter']['path'] = 'node/[nid]';
  651. $default_handler->override_option('fields', $fields);
  652. // Only show records with published nodes
  653. $filters = $view->get_items('filter', 'default');
  654. $filters['status'] = array(
  655. 'operator' => '=',
  656. 'value' => '1',
  657. 'group' => '0',
  658. 'exposed' => FALSE,
  659. 'expose' => array(
  660. 'operator' => FALSE,
  661. 'label' => '',
  662. ),
  663. 'id' => 'status',
  664. 'table' => 'node',
  665. 'field' => 'status',
  666. 'relationship' => 'none',
  667. );
  668. $default_handler->override_option('filters', $filters);
  669. }
  670. $views[$view->name] = $view;
  671. return $views;
  672. }