tripal_feature.module 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <?php
  2. /**
  3. * @file
  4. * Basic functionality for the tripal module
  5. */
  6. /**
  7. * @defgroup tripal_legacy feature Legacy Feature Module
  8. * @ingroup tripal_legacy_modules
  9. * @{
  10. * Integrates the Chado Sequence module with Drupal Nodes & Views
  11. * @}
  12. */
  13. require_once 'api/tripal_feature.DEPRECATED.inc';
  14. require_once 'theme/tripal_feature.theme.inc';
  15. require_once 'includes/tripal_feature.admin.inc';
  16. require_once 'includes/tripal_feature.delete.inc';
  17. require_once 'includes/tripal_feature.chado_node.inc';
  18. /**
  19. * Implements hook_views_api().
  20. *
  21. * Essentially this hook tells drupal that there is views support for
  22. * for this module which then includes tripal_db.views.inc where all the
  23. * views integration code is
  24. *
  25. * @ingroup tripal_legacy_feature
  26. */
  27. function tripal_feature_views_api() {
  28. return array(
  29. 'api' => 3.0,
  30. );
  31. }
  32. /**
  33. * Implements hook_help().
  34. *
  35. * Display help and module information
  36. *
  37. * @param
  38. * path which path of the site we're displaying help
  39. * @param
  40. * arg array that holds the current path as would be returned from arg() function
  41. *
  42. * @return
  43. * help text for the path
  44. *
  45. * @ingroup tripal_legacy_feature
  46. */
  47. function tripal_feature_help($path, $arg) {
  48. $output = '';
  49. switch ($path) {
  50. case "admin/help#tripal_feature":
  51. $output='<p>' . t("Displays links to nodes created on this date") . '</p>';
  52. break;
  53. }
  54. return $output;
  55. }
  56. /**
  57. * Implements hook_permission().
  58. *
  59. * Set the permission types that the chado module uses. Essentially we
  60. * want permissionis that protect creation, editing and deleting of chado
  61. * data objects
  62. *
  63. * @ingroup tripal_legacy_feature
  64. */
  65. function tripal_feature_permission() {
  66. return array(
  67. /*
  68. 'access chado_feature content' => array(
  69. 'title' => t('View Features'),
  70. 'description' => t('Allow users to view feature pages.'),
  71. ),
  72. 'create chado_feature content' => array(
  73. 'title' => t('Create Features'),
  74. 'description' => t('Allow users to create new feature pages.'),
  75. ),
  76. 'delete chado_feature content' => array(
  77. 'title' => t('Delete Features'),
  78. 'description' => t('Allow users to delete feature pages.'),
  79. ),
  80. 'edit chado_feature content' => array(
  81. 'title' => t('Edit Features'),
  82. 'description' => t('Allow users to edit feature pages.'),
  83. ),
  84. 'administer tripal feature' => array(
  85. 'title' => t('Administer Features'),
  86. 'description' => t('Allow users to administer all features.'),
  87. ),
  88. */
  89. );
  90. }
  91. /**
  92. * Implements hook_menu().
  93. *
  94. * Menu items are automatically added for the new node types created
  95. * by this module to the 'Create Content' Navigation menu item. This function
  96. * adds more menu items needed for this module.
  97. *
  98. * @ingroup tripal_legacy_feature
  99. */
  100. function tripal_feature_menu() {
  101. $items = array();
  102. // the administative settings menu
  103. $items['admin/tripal/legacy/tripal_feature'] = array(
  104. 'title' => 'Features',
  105. 'description' => 'A biological sequence or a section of a biological sequence, or a collection of such sections.',
  106. 'page callback' => 'tripal_feature_admin_feature_view',
  107. 'access arguments' => array('administer tripal feature'),
  108. 'type' => MENU_NORMAL_ITEM,
  109. );
  110. $items['admin/tripal/legacy/tripal_feature/delete'] = array(
  111. 'title' => ' Delete',
  112. 'description' => 'Delete multiple features from Chado',
  113. 'page callback' => 'drupal_get_form',
  114. 'page arguments' => array('tripal_feature_delete_form'),
  115. 'access arguments' => array('administer tripal feature'),
  116. 'type' => MENU_LOCAL_TASK,
  117. 'weight' => 2
  118. );
  119. $items['admin/tripal/legacy/tripal_feature/sync'] = array(
  120. 'title' => ' Sync',
  121. 'description' => 'Create pages on this site for features stored in Chado',
  122. 'page callback' => 'drupal_get_form',
  123. 'page arguments' => array('chado_node_sync_form', 'tripal_feature', 'chado_feature'),
  124. 'access arguments' => array('administer tripal feature'),
  125. 'type' => MENU_LOCAL_TASK,
  126. 'weight' => 1
  127. );
  128. $items['admin/tripal/legacy/tripal_feature/chado_feature_toc'] = array(
  129. 'title' => ' TOC',
  130. 'description' => 'Manage the table of contents for feature nodes.',
  131. 'page callback' => 'drupal_get_form',
  132. 'page arguments' => array('tripal_core_content_type_toc_form', 'chado_feature'),
  133. 'access arguments' => array('administer tripal feature'),
  134. 'type' => MENU_LOCAL_TASK,
  135. 'file' => 'includes/tripal_core.toc.inc',
  136. 'file path' => drupal_get_path('module', 'tripal_core'),
  137. 'weight' => 3
  138. );
  139. $items['admin/tripal/legacy/tripal_feature/configuration'] = array(
  140. 'title' => 'Settings',
  141. 'description' => 'Configure the Tripal Feature module.',
  142. 'page callback' => 'drupal_get_form',
  143. 'page arguments' => array('tripal_feature_admin'),
  144. 'access arguments' => array('administer tripal feature'),
  145. 'type' => MENU_LOCAL_TASK,
  146. 'weight' => 5
  147. );
  148. $items['admin/tripal/legacy/tripal_feature/help'] = array(
  149. 'title' => 'Help',
  150. 'description' => 'Help with the Tripal Feature module.',
  151. 'page callback' => 'theme',
  152. 'page arguments' => array('tripal_feature_help'),
  153. 'access arguments' => array('administer tripal feature'),
  154. 'type' => MENU_LOCAL_TASK,
  155. 'weight' => 10
  156. );
  157. // Enable admin view
  158. $items['admin/tripal/legacy/tripal_feature/views/features/enable'] = array(
  159. 'title' => 'Enable feature Administrative View',
  160. 'page callback' => 'tripal_enable_view',
  161. 'page arguments' => array('tripal_feature_admin_features', 'admin/tripal/legacy/tripal_feature'),
  162. 'access arguments' => array('administer tripal feature'),
  163. 'type' => MENU_CALLBACK,
  164. );
  165. return $items;
  166. }
  167. /**
  168. * Implements hook_search_biological_data_views().
  169. *
  170. * Adds the described views to the "Search Data" Page created by Tripal Views
  171. */
  172. function tripal_feature_search_biological_data_views() {
  173. return array(
  174. 'tripal_feature_user_features' => array(
  175. 'machine_name' => 'tripal_feature_user_features',
  176. 'human_name' => 'Features',
  177. 'description' => 'A biological sequence or a section of a biological sequence, or a collection of such sections.',
  178. 'link' => 'chado/feature'
  179. ),
  180. );
  181. }
  182. /**
  183. * Implements hook_theme().
  184. *
  185. * We need to let drupal know about our theme functions and their arguments.
  186. * We create theme functions to allow users of the module to customize the
  187. * look and feel of the output generated in this module
  188. *
  189. * @ingroup tripal_legacy_feature
  190. */
  191. function tripal_feature_theme($existing, $type, $theme, $path) {
  192. $core_path = drupal_get_path('module', 'tripal_core');
  193. // Feature Node Page Templates.
  194. $items = array(
  195. 'node__chado_feature' => array(
  196. 'template' => 'node--chado-generic',
  197. 'render element' => 'node',
  198. 'base hook' => 'node',
  199. 'path' => "$core_path/theme/templates",
  200. ),
  201. 'tripal_feature_alignments' => array(
  202. 'variables' => array('node' => NULL),
  203. 'template' => 'tripal_feature_alignments',
  204. 'path' => "$path/theme/templates",
  205. ),
  206. 'tripal_feature_analyses' => array(
  207. 'variables' => array('node' => NULL),
  208. 'template' => 'tripal_feature_analyses',
  209. 'path' => "$path/theme/templates",
  210. ),
  211. 'tripal_feature_base' => array(
  212. 'variables' => array('node' => NULL),
  213. 'template' => 'tripal_feature_base',
  214. 'path' => "$path/theme/templates",
  215. ),
  216. 'tripal_feature_sequence' => array(
  217. 'variables' => array('node' => NULL),
  218. 'template' => 'tripal_feature_sequence',
  219. 'path' => "$path/theme/templates",
  220. ),
  221. 'tripal_feature_proteins' => array(
  222. 'variables' => array('node' => NULL),
  223. 'template' => 'tripal_feature_proteins',
  224. 'path' => "$path/theme/templates",
  225. ),
  226. 'tripal_feature_publications' => array(
  227. 'variables' => array('node' => NULL),
  228. 'template' => 'tripal_feature_publications',
  229. 'path' => "$path/theme/templates",
  230. ),
  231. 'tripal_feature_synonyms' => array(
  232. 'variables' => array('node' => NULL),
  233. 'template' => 'tripal_feature_synonyms',
  234. 'path' => "$path/theme/templates",
  235. ),
  236. 'tripal_feature_references' => array(
  237. 'variables' => array('node' => NULL),
  238. 'template' => 'tripal_feature_references',
  239. 'path' => "$path/theme/templates",
  240. ),
  241. 'tripal_feature_properties' => array(
  242. 'variables' => array('node' => NULL),
  243. 'template' => 'tripal_feature_properties',
  244. 'path' => "$path/theme/templates",
  245. ),
  246. 'tripal_feature_terms' => array(
  247. 'variables' => array('node' => NULL),
  248. 'template' => 'tripal_feature_terms',
  249. 'path' => "$path/theme/templates",
  250. ),
  251. 'tripal_feature_relationships' => array(
  252. 'variables' => array('node' => NULL),
  253. 'template' => 'tripal_feature_relationships',
  254. 'path' => "$path/theme/templates",
  255. ),
  256. );
  257. // Feature Node Teaser
  258. $items['tripal_feature_teaser'] = array(
  259. 'variables' => array('node' => NULL),
  260. 'template' => 'tripal_feature_teaser',
  261. 'path' => "$path/theme/templates",
  262. );
  263. // Templates for other node pages.
  264. // Organism Feature Browser.
  265. $items['tripal_organism_feature_browser'] = array(
  266. 'variables' => array('node' => NULL),
  267. 'template' => 'tripal_organism_feature_browser',
  268. 'path' => "$path/theme/templates",
  269. );
  270. $items['tripal_organism_feature_counts'] = array(
  271. 'variables' => array('node' => NULL),
  272. 'template' => 'tripal_organism_feature_counts',
  273. 'path' => "$path/theme/templates",
  274. );
  275. // Administrative Help Template.
  276. $items['tripal_feature_help'] = array(
  277. 'template' => 'tripal_feature_help',
  278. 'variables' => array(NULL),
  279. 'path' => "$path/theme/templates"
  280. );
  281. // D3 Charts.
  282. // Feature Type/Organism Stacked Bar Chart.
  283. $items['tripal_feature_bar_chart_type_organism_summary'] = array(
  284. 'template' => 'tripal_feature_bar_chart_type_organism_summary',
  285. 'variables' => array(NULL),
  286. 'path' => "$path/theme/templates"
  287. );
  288. return $items;
  289. }
  290. /**
  291. * Implements hook_job_describe_args() in order to describe the various feature jobs
  292. * to the tripal jobs interface.
  293. *
  294. * @ingroup tripal_legacy_feature
  295. */
  296. function tripal_feature_job_describe_args($callback, $args) {
  297. $new_args = array();
  298. if ($callback == 'tripal_feature_load_fasta') {
  299. $new_args['FASTA file'] = $args[0];
  300. // Add in the organism.
  301. if ($args[1] AND is_numeric($args[1])) {
  302. $organism = chado_select_record('organism', array('genus', 'species'), array('organism_id' => $args[1]));
  303. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  304. }
  305. $new_args['Sequence Type'] = $args[2];
  306. if (isset($args[14])) {
  307. $new_args['Name Match Type'] = $args[14];
  308. $new_args['Name RE'] = $args[4];
  309. $new_args['Unique Name RE'] = $args[5];
  310. }
  311. // add in the relationship arguments
  312. if ($args[8]) {
  313. $new_args['Relationship Type'] = $args[8];
  314. $new_args['Relationship Parent RE'] = $args[9];
  315. $new_args['Relationship Parent Type'] = $args[10];
  316. }
  317. // add in the database reference arguments
  318. if ($args[7] AND is_numeric($args[7])) {
  319. $db = chado_select_record('db', array('name'), array('db_id' => $args[7]));
  320. $new_args['Database Reference'] = $db[0]->name;
  321. $new_args['Accession RE'] = $args[6];
  322. $new_args['Method'] = $args[11];
  323. }
  324. // add in the analysis
  325. if ($args[12] AND is_numeric($args[12])) {
  326. $analysis = chado_select_record('analysis', array('name'), array('analysis_id' => $args[12]));
  327. $new_args['Analysis'] = $analysis[0]->name;
  328. }
  329. }
  330. if ($callback == 'tripal_feature_delete_features') {
  331. if ($args[0]) {
  332. $organism = chado_select_record('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  333. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  334. }
  335. else {
  336. $new_args['Organism'] = '';
  337. }
  338. if ($args[1]) {
  339. $analysis = chado_select_record('analysis', array('name'), array('analysis_id' => $args[1]));
  340. $new_args['Analysis'] = $analysis[0]->name;
  341. }
  342. else {
  343. $new_args['Analysis'] = '';
  344. }
  345. $new_args['Sequence Type'] = $args[2];
  346. $new_args['Is Unique Name'] = $args[3] ? 'Yes' : 'No';
  347. $new_args['Features Names'] = $args[4];
  348. }
  349. elseif ($callback == 'tripal_feature_load_gff3') {
  350. $new_args['GFF File'] = $args[0];
  351. $organism = chado_select_record('organism', array('genus', 'species'), array('organism_id' => $args[1]));
  352. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  353. $analysis = chado_select_record('analysis', array('name'), array('analysis_id' => $args[2]));
  354. $new_args['Analysis'] = $analysis[0]->name;
  355. $new_args['Use a Transaction'] = ($args[7] == 1) ? "Yes" : "No";
  356. $new_args['Import only new features'] = ($args[3] == 1) ? "Yes" : "No";
  357. $new_args['Import all and update'] = ($args[4] == 1) ? "Yes" : "No";
  358. $new_args['Import all and replace'] = ($args[5] == 1) ? "Yes" : "No";
  359. $new_args['Delete features'] = ($args[6] == 1) ? "Yes" : "No";
  360. if ($args[8]) {
  361. $target_organism = chado_select_record('organism', array('genus', 'species'), array('organism_id' => $args[8]));
  362. $new_args['Target organism'] = $target_organism[0]->genus . " " . $target_organism[0]->species;
  363. }
  364. else {
  365. $new_args['Target organism'] = '';
  366. }
  367. $new_args['Target type'] = $args[9];
  368. $new_args['Create target'] = ($args[10] == 1) ? "Yes" : "No";
  369. $new_args['Starting line'] = $args[11];
  370. $new_args['Landmark Type'] = $args[12];
  371. $new_args['Alternate ID attribute'] = $args[13];
  372. $new_args['Create Organism'] = ($args[14] == 1) ? "Yes" : "No";
  373. }
  374. return $new_args;
  375. }
  376. /**
  377. * Implements hook_coder_ignore().
  378. *
  379. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for
  380. * coder are stored
  381. *
  382. * @ingroup tripal_legacy_feature
  383. */
  384. function tripal_feature_coder_ignore() {
  385. return array(
  386. 'path' => drupal_get_path('module', 'tripal_feature'),
  387. 'line prefix' => drupal_get_path('module', 'tripal_feature'),
  388. );
  389. }
  390. /**
  391. * Implementation of hook_form_alter()
  392. *
  393. * @param $form
  394. * @param $form_state
  395. * @param $form_id
  396. *
  397. * @ingroup tripal_legacy_feature
  398. */
  399. function tripal_feature_form_alter(&$form, &$form_state, $form_id) {
  400. // turn off preview button for insert/updates
  401. if ($form_id == "chado_feature_node_form") {
  402. $form['actions']['preview']['#access'] = FALSE;
  403. //remove the body field
  404. unset($form['body']);
  405. }
  406. }
  407. /**
  408. * Implements hook_exclude_field_from_<tablename>_by_default()
  409. *
  410. * This hooks allows fields from a specified table that match a specified criteria to be excluded by
  411. * default from any table when chado_generate_var() is called. Keep in mind that if
  412. * fields are excluded by default they can always be expanded at a later date using
  413. * chado_expand_var().
  414. *
  415. * Criteria are php strings that evaluate to either TRUE or FALSE. These strings are evaluated using
  416. * drupal_eval() which suppresses syntax errors and throws watchdog entries of type php. There are
  417. * also watchdog entries of type tripal_core stating the exact criteria evaluated. Criteria can
  418. * contain the following tokens:
  419. * - <field_name>
  420. * Replaced by the name of the field to be excluded
  421. * - <field_value>
  422. * Replaced by the value of the field in the current record
  423. * Also keep in mind that if your criteria doesn't contain the <field_value> token then it will be
  424. * evaluated before the query is executed and if the field is excluded it won't be included in the
  425. * query.
  426. *
  427. * @return
  428. * An array of field => criteria where the type is excluded if the criteria evaluates to TRUE
  429. *
  430. * @ingroup tripal_legacy_feature
  431. */
  432. function tripal_feature_exclude_field_from_feature_by_default() {
  433. return array('residues' => 'TRUE');
  434. }