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