tripal_analysis.admin.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions displaying administrative pages and forms
  5. */
  6. /**
  7. * Purpose: Provide Guidance to new Tripal Admin
  8. *
  9. * @return
  10. * HTML Formatted text
  11. *
  12. * @ingroup tripal_analysis
  13. */
  14. function tripal_analysis_module_description_page() {
  15. $text .= '<h3>Tripal Analysis Administrative Tools Quick Links:</h3>';
  16. $text .= "<ul>
  17. <li><a href=\"" . url("admin/tripal/tripal_analysis/configuration") . "\">Analysis Configuration</a></li>
  18. </ul>";
  19. $text .= '<h3>Module Description:</h3>';
  20. $text .= '<p>The Tripal Analysis module provides a generic analysis content type that is intended to be
  21. used when a more specialized analysis module does not exist. Because it is generic, it does not
  22. provide any visualization or data loading tools for analysis data. Specialized analysis modules,
  23. such as the Tripal Analysis Blast or Tripal Analysis KEGG modules provide loading and custom
  24. visualizations for the analysis results. These modules must be installed separately.
  25. </p>';
  26. $text .= '<h3>Setup Instructions:</h3>';
  27. $text .= '<p>After installation of the analysis module or any specialized analysis module. The following tasks should be performed
  28. <ol>
  29. <li><p><b>Set Permissions</b>: Each analysis module supports the Drupal user permissions interface for
  30. controlling access to the content and functions. These permissions include viewing,
  31. creating, editing or administering of
  32. analysis content. The default is that only the original site administrator has these
  33. permissions. You can <a href="' . url('admin/user/roles') . '">add roles</a> for classifying users,
  34. <a href="' . url('admin/user/user') . '">assign users to roles</a> and
  35. <a href="' . url('admin/user/permissions') . '">assign permissions</a> for the analysis content to
  36. those roles. For a simple setup, allow anonymous users access to view organism content and
  37. allow the site administrator all other permissions.</p></li>
  38. <li><p><b>Create Analysis</b>: An analysis should be <a href="' . url('node/add') . '">created</a> before data is imported into
  39. chado. The generic analysis type should only be used when a more specialized analysis module
  40. (e.g. Tripal Analysis Blast module) does not already exists. All data imported into
  41. Chado should be associated with an analysis.
  42. <li><p><b>Sync Analyses</b>: If Chado has preloaded analyses then you can sync those. This process is what
  43. creates the pages for viewing an analysis on the site. Analyses can be synced using the
  44. <a href="' . url('admin/tripal/tripal_analysis/configuration') . '">Analysis Configuration page</a>.
  45. However, syncing an analyses will always create a generic analysis content type. If you would like
  46. to use a specialized analysis module for visualization of data then do not sync the analysis but recreate it
  47. using the appropriate specialized analysis content type.</p></li>
  48. </ol>
  49. </p>';
  50. $text .= '<h3>Features of this Module:</h3>';
  51. $text .= '<p>Aside from providing a generic content type the Tripal Analysis module also provides the following functionality
  52. <ul>
  53. <li><p><b>Basic Analysis Lookup View</b>: This module provides a basic <a href="' . url('analyses') . '">analysis search
  54. tool</a> for finding or listing analyses in Chado. It does not require indexing for Drupal searching but relies
  55. on Drupal Views. <a href="http://drupal.org/project/views">Drupal Views</a> must be installed. </p></li>
  56. </ul>
  57. </p>';
  58. $text .= '<h3>Page Customizations</h3>';
  59. $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
  60. Below is a description of several methods. These methods may be used in conjunction with one another to
  61. provide fine-grained control.
  62. <ul>
  63. <li><p><b>Integration with Drupal Panels</b>: <a href="http://drupal.org/project/views">Drupal Panels</a>
  64. allows for customization of a page layout if you don\'t want to do PHP/Javascript/CSS programming.
  65. Tripal comes with pre-set layouts for analysis pages. However,
  66. Panels become useful if you prefer a layout that is different from the pre-set layouts. Chado content
  67. is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the
  68. Panel\'s GUI.</p></li>
  69. <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the
  70. <a href="http://drupal.org/project/cck">Content Construction Kit (CCK) </a> is a powerful way to add non-Chado content
  71. to any page without need to edit template files or knowing PHP. You must first download and install CCK.
  72. With CCK, the site administartor can create a new field to appear on the page. For example, currently,
  73. the Chado publication module is not yet supported by Tripal. Therefore, the site administrator can add a text
  74. field to the analysis pages. This content is not stored in Chado, but will appear on the analysis page. A field
  75. added by CCK will also appear in the form when editing a analysis to allow users to manually enter the appropriate
  76. text. If the default pre-set layout and themeing for Tripal is used, it is better to create the CCK element,
  77. indicate that it is not to be shown (using the CCK interface), then manually add the new content type
  78. where desired by editing the templates (as described below). If using Panels, the CCK field can be added to the
  79. location desired using the Panels interface.</p></li>
  80. <li><p><b>Drupal Node Templates</b>: The Tripal packages comes with a "theme_tripal" directory that contains the
  81. themeing for Chado content. The analysis module has a template file for analysis "nodes" (Tripal analysis pages). This file
  82. is named "node-chado_analysis.tpl.php", and provides javascript, HTML and PHP code for display of the analysis
  83. pages. Specialized analysis modules will have their own template files as well, such as "node-chado_analysis-blast.tpl.php" for the
  84. Tripal Analysis Blast module. You can edit the template file to control which types of information (or which analysis "blocks") are displayed
  85. for analysis. Be sure to
  86. copy these template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
  87. future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
  88. for instructions on how to access variables and other Chado content within the template file.</p></li>
  89. <li><p><b>Analysis "Block" Templates</b>: In the "theme_tripal" directory are subdirectories named after each tripal module (e.g. "tripal_feature", "tripal_library", etc.).
  90. Inside each directory is a set of templates that control distinct types of information for each content type. For example,
  91. there is a "base" template for displaying of data directly from the Chado feature table, and a "references"
  92. template for showing external site references for a feature (data from the feature_dbxref table).
  93. These templates are used both by Drupal blocks
  94. for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template
  95. provides (also desribed above). Analyses block templates can exist in any of these directories. For example, the Tripal Analysis Unigene
  96. module uses templates in the tripal_analysis_unigene, tripal_organism, and tripal_feature directories. Content for a unigene is then
  97. cusotmizable within each of these contexts.
  98. You can customize block template as you desire. Be sure to copy the
  99. template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
  100. future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
  101. for instructions on how to access variables and other Chado content within the template files.</p></li>
  102. </li>
  103. <li><p><b>Adding Links to the "Resources" Sidebar</b>: If you use the pre-set default Tripal layout for theming, you
  104. will see a "Resources" sidebar on each page. The links that appear on the sidebar are automatically generated
  105. using Javascript for all of the analysis "Blocks" that appear on the page. If you want to add additional links
  106. (e.g. a dynamic link to GBrowse for the analysis) and you want that link to appear in the
  107. "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the
  108. section at the bottom of the template file where the resources section is found.</p></li>
  109. </ul>
  110. </p>';
  111. return $text;
  112. }
  113. /**
  114. * Administration page callbacks for the Tripal Analysis module
  115. *
  116. * We have defined a hook_get_settings() function. When a sub-module
  117. * is enabled, we'll look for this function to provide a form for the
  118. * administrative setting.
  119. *
  120. * @return
  121. * A form API array describing an administrative form
  122. *
  123. * @ingroup tripal_analysis
  124. */
  125. function tripal_analysis_admin() {
  126. // Create a new administrative form. We'll add main functions to the form
  127. // first (Sync, Reindex, Clean, Taxonify). Thereafter, any sub-module that
  128. // has a setting will be added.
  129. $form = array();
  130. // before proceeding check to see if we have any
  131. // currently processing jobs. If so, we don't want
  132. // to give the opportunity to sync libraries
  133. $active_jobs = FALSE;
  134. if (tripal_get_module_active_jobs('tripal_organism')) {
  135. $active_jobs = TRUE;
  136. }
  137. // add the field set for syncing libraries
  138. if (!$active_jobs) {
  139. // add the field set for syncing analyses
  140. get_tripal_analysis_admin_form_sync_set($form);
  141. // get_tripal_analysis_admin_form_reindex_set($form);
  142. // get_tripal_analysis_admin_form_taxonomy_set($form);
  143. get_tripal_analysis_admin_form_cleanup_set($form);
  144. }
  145. else {
  146. $form['notice'] = array(
  147. '#type' => 'fieldset',
  148. '#title' => t('Analysis Management Temporarily Unavailable')
  149. );
  150. $form['notice']['message'] = array(
  151. '#value' => t('Currently, analysis management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete. Please check back later once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.'),
  152. );
  153. }
  154. // Add sub-module settings. Pull all sub-module information from
  155. // {tripal_analysis} table
  156. $sql = "SELECT modulename FROM {tripal_analysis}";
  157. $result = db_query($sql);
  158. $counter = 0; //keep track of the number of sub-modules
  159. while ($data = db_fetch_object($result)) {
  160. // Check if the hook_get_settings() function is already defined.
  161. $func = $data->modulename . "_get_settings";
  162. $functions = get_defined_functions();
  163. $settings;
  164. foreach ($functions['user'] as $function) {
  165. if ($function == $func) {
  166. $settings = $func();
  167. }
  168. }
  169. // Add sub-module's specific settings to the administrative view
  170. if ($settings) {
  171. // Define a fieldset for the sub-module
  172. $form["field$counter"] = array(
  173. '#type' => 'fieldset',
  174. '#title' => "$settings->title",
  175. '#collapsible' => TRUE
  176. );
  177. $form["field$counter"]["$settings->title"] = $settings->form;
  178. }
  179. $counter ++;
  180. }
  181. return system_settings_form($form);
  182. }
  183. /**
  184. * Displays the Set Drupal Taxonomy for Analysis Features From
  185. *
  186. * @param $form
  187. * The administrative form as it is currently
  188. *
  189. * @return
  190. * A form API array describing an administrative form
  191. *
  192. * @ingroup tripal_analysis
  193. */
  194. function get_tripal_analysis_admin_form_taxonomy_set(&$form) {
  195. $form['taxonify'] = array(
  196. '#type' => 'fieldset',
  197. '#title' => t('Assign Drupal Taxonomy to Analysis Features')
  198. );
  199. // get the list of analyses
  200. $sql = "SELECT * FROM {Analysis} ORDER BY name";
  201. $previous_db = tripal_db_set_active('chado'); // use chado database
  202. $lib_rset = db_query($sql);
  203. tripal_db_set_active($previous_db); // now use drupal database
  204. // iterate through all of the libraries
  205. $lib_boxes = array();
  206. while ($analysis = db_fetch_object($lib_rset)) {
  207. $lib_boxes[$analysis->analysis_id] = "$analysis->name";
  208. }
  209. $form['taxonify']['description'] = array(
  210. '#type' => 'item',
  211. '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
  212. "nodes. These terms allow for advanced filtering during searching. This option allows ".
  213. "for setting taxonomy only for features that belong to the selected analyses below. All other features will be unaffected. To set taxonomy for all features in the site see the Feature Administration page."),
  214. '#weight' => 1,
  215. );
  216. $form['taxonify']['tx-analyses'] = array(
  217. '#title' => t('Analyses'),
  218. '#type' => t('checkboxes'),
  219. '#description' => t("Check the analyses whose features you want to reset taxonomy. Note: this list contains all analyses, even those that may not be synced."),
  220. '#required' => FALSE,
  221. '#prefix' => '<div id="lib_boxes">',
  222. '#suffix' => '</div>',
  223. '#options' => $lib_boxes,
  224. '#weight' => 2
  225. );
  226. $form['taxonify']['tx-button'] = array(
  227. '#type' => 'submit',
  228. '#value' => t('Set Feature Taxonomy'),
  229. '#weight' => 3
  230. );
  231. }
  232. /**
  233. * The "Reindex Analysis Nodes" form
  234. *
  235. * @param $form
  236. * The administrative form as it is currently
  237. *
  238. * @return
  239. * A form API array describing an administrative form
  240. *
  241. * @ingroup tripal_analysis
  242. */
  243. function get_tripal_analysis_admin_form_reindex_set(&$form) {
  244. // define the fieldsets
  245. $form['reindex'] = array(
  246. '#type' => 'fieldset',
  247. '#title' => t('Reindex Analysis Features')
  248. );
  249. // get the list of libraries
  250. $sql = "SELECT * FROM {Analysis} ORDER BY name";
  251. $previous_db = tripal_db_set_active('chado'); // use chado database
  252. $lib_rset = db_query($sql);
  253. tripal_db_set_active($previous_db); // now use drupal database
  254. // iterate through all of the libraries
  255. $lib_boxes = array();
  256. while ($analysis = db_fetch_object($lib_rset)) {
  257. $lib_boxes[$analysis->analysis_id] = "$analysis->name";
  258. }
  259. $form['reindex']['description'] = array(
  260. '#type' => 'item',
  261. '#value' => t("This option allows for reindexing of only those features that belong to the selected analyses below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."),
  262. '#weight' => 1,
  263. );
  264. $form['reindex']['re-analyses'] = array(
  265. '#title' => t('Libraries'),
  266. '#type' => t('checkboxes'),
  267. '#description' => t("Check the analyses whoee features you want to reindex. Note: this list contains all analyses, even those that may not be synced."),
  268. '#required' => FALSE,
  269. '#prefix' => '<div id="lib_boxes">',
  270. '#suffix' => '</div>',
  271. '#options' => $lib_boxes,
  272. '#weight' => 2,
  273. );
  274. $form['reindex']['re-button'] = array(
  275. '#type' => 'submit',
  276. '#value' => t('Reindex Features'),
  277. '#weight' => 3,
  278. );
  279. }
  280. /**
  281. * The "Clean-up orphaned analysis & nodes" Form
  282. *
  283. * @param $form
  284. * The administrative form as it is currently
  285. *
  286. * @return
  287. * A form API array describing an administrative form
  288. *
  289. * @ingroup tripal_analysis
  290. */
  291. function get_tripal_analysis_admin_form_cleanup_set(&$form) {
  292. $form['cleanup'] = array(
  293. '#type' => 'fieldset',
  294. '#title' => t('Clean Up')
  295. );
  296. $form['cleanup']['description'] = array(
  297. '#type' => 'item',
  298. '#value' => t("With Drupal and chado residing in different databases ".
  299. "it is possible that nodes in Drupal and analyses in Chado become ".
  300. "\"orphaned\". This can occur if an analysis node in Drupal is ".
  301. "deleted but the corresponding chado analysis is not and/or vice ".
  302. "versa. Click the button below to resolve these discrepancies."),
  303. '#weight' => 1,
  304. );
  305. $form['cleanup']['button'] = array(
  306. '#type' => 'submit',
  307. '#value' => t('Clean up orphaned analyses'),
  308. '#weight' => 2,
  309. );
  310. }
  311. /**
  312. * The "sync Analysis in chado with drupal" form
  313. *
  314. * @param $form
  315. * The administrative form as it is currently
  316. *
  317. * @return
  318. * A form API array describing an administrative form
  319. *
  320. * @ingroup tripal_analysis
  321. */
  322. function get_tripal_analysis_admin_form_sync_set(&$form) {
  323. // define the fieldsets
  324. $form['sync'] = array(
  325. '#type' => 'fieldset',
  326. '#title' => t('Sync Analyses')
  327. );
  328. // before proceeding check to see if we have any
  329. // currently processing jobs. If so, we don't want
  330. // to give the opportunity to sync analyses
  331. $active_jobs = FALSE;
  332. if (tripal_get_module_active_jobs('tripal_analysis')) {
  333. $active_jobs = TRUE;
  334. }
  335. if (!$active_jobs) {
  336. // get the list of analyses
  337. $sql = "SELECT * FROM {analysis} ORDER BY name";
  338. $previous_db = tripal_db_set_active('chado'); // use chado database
  339. $ana_rset = db_query($sql);
  340. tripal_db_set_active($previous_db); // now use drupal database
  341. // if we've added any analyses to the list that can be synced
  342. // then we want to build the form components to allow the user
  343. // to select one or all of them. Otherwise, just present
  344. // a message stating that all analyses are currently synced.
  345. $ana_boxes = array();
  346. $added = 0;
  347. while ($analysis = db_fetch_object($ana_rset)) {
  348. // check to see if the analysis is already present as a node in drupal.
  349. // if so, then skip it.
  350. $sql = "SELECT * FROM {chado_analysis} WHERE analysis_id = %d";
  351. if (!db_fetch_object(db_query($sql, $analysis->analysis_id))) {
  352. $ana_boxes[$analysis->analysis_id] = "$analysis->name";
  353. $added++;
  354. }
  355. }
  356. // if we have analyses we need to add to the checkbox then
  357. // build that form element
  358. if ($added > 0) {
  359. $ana_boxes['all'] = "All analyses";
  360. $form['sync']['analyses'] = array(
  361. '#title' => t('Available analyses'),
  362. '#type' => t('checkboxes'),
  363. '#description' => t("Check the analyses you want to sync. Drupal ".
  364. "content will be created for each of the analyses listed above. ".
  365. "Select 'All analyses' to sync all of them."),
  366. '#required' => FALSE,
  367. '#prefix' => '<div id="ana_boxes">',
  368. '#suffix' => '</div>',
  369. '#options' => $ana_boxes,
  370. );
  371. $form['sync']['button'] = array(
  372. '#type' => 'submit',
  373. '#value' => t('Submit Sync Job')
  374. );
  375. }
  376. // we don't have any analyses to select from
  377. else {
  378. $form['sync']['value'] = array(
  379. '#value' => t('All analyses in Chado are currently synced with Drupal.')
  380. );
  381. }
  382. }
  383. // we don't want to present a form since we have an active job running
  384. else {
  385. $form['sync']['value'] = array(
  386. '#value' => t('Currently, jobs exist related to chado analyses. Please check back later for analyses that can by synced once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.')
  387. );
  388. }
  389. }
  390. /**
  391. * Validate the administrative form
  392. * @todo Stephen: Why is validate used rather then submit?
  393. *
  394. * @param $form
  395. * The form API array of the form to be validated
  396. * @form_state
  397. * The user submitted values
  398. *
  399. * @ingroup tripal_analysis
  400. */
  401. function tripal_analysis_admin_validate($form, &$form_state) {
  402. global $user; // we need access to the user info
  403. $job_args = array();
  404. if ($form_state['values']['op'] == t('Submit Sync Job')) {
  405. // check to see if the user wants to sync chado and drupal. If
  406. // so then we need to register a job to do so with tripal
  407. $analyses = $form_state['values']['analyses'];
  408. $do_all = FALSE;
  409. $to_sync = array();
  410. foreach ($analyses as $analysis_id) {
  411. if (preg_match("/^all$/i", $analysis_id)) {
  412. $do_all = TRUE;
  413. }
  414. if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
  415. // get the list of analyses
  416. $sql = "SELECT * FROM {analysis} WHERE analysis_id = %d";
  417. $previous_db = tripal_db_set_active('chado'); // use chado database
  418. $analysis = db_fetch_object(db_query($sql, $analysis_id));
  419. tripal_db_set_active($previous_db); // now use drupal database
  420. $to_sync[$analysis_id] = $analysis->name;
  421. }
  422. }
  423. // submit the job the tripal job manager
  424. if ($do_all) {
  425. tripal_add_job('Sync all analyses', 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid);
  426. }
  427. else{
  428. foreach ($to_sync as $analysis_id => $name) {
  429. $job_args[0] = $analysis_id;
  430. tripal_add_job("Sync analysis: $name", 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid);
  431. }
  432. }
  433. }
  434. // -------------------------------------
  435. // Submit the Reindex Job if selected
  436. if ($form_state['values']['op'] == t('Reindex Features')) {
  437. global $user; // we need access to the user info
  438. $job_args = array();
  439. $analyses = $form_state['values']['re-analyses'];
  440. foreach ($analyses as $analysis_id) {
  441. if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
  442. // get the analysis info
  443. $sql = "SELECT * FROM {analysis} WHERE analysis_id = %d";
  444. $previous_db = tripal_db_set_active('chado'); // use chado database
  445. $analysis = db_fetch_object(db_query($sql, $analysis_id));
  446. tripal_db_set_active($previous_db); // now use drupal database
  447. $job_args[0] = $analysis_id;
  448. tripal_add_job("Reindex features for analysis: $analysis->name", 'tripal_analysis',
  449. 'tripal_analysis_reindex_features', $job_args, $user->uid);
  450. }
  451. }
  452. }
  453. // -------------------------------------
  454. // Submit the Taxonomy Job if selected
  455. if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
  456. global $user; // we need access to the user info
  457. $job_args = array();
  458. $analyses = $form_state['values']['tx-analyses'];
  459. foreach ($analyses as $analysis_id) {
  460. if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
  461. // get the analysis info
  462. $sql = "SELECT * FROM {analysis} WHERE analysis_id = %d";
  463. $previous_db = tripal_db_set_active('chado'); // use chado database
  464. $analysis = db_fetch_object(db_query($sql, $analysis_id));
  465. tripal_db_set_active($previous_db); // now use drupal database
  466. $job_args[0] = $analysis_id;
  467. tripal_add_job("Set taxonomy for features in analysis: $analysis->name", 'tripal_analysis',
  468. 'tripal_analysis_taxonify_features', $job_args, $user->uid);
  469. }
  470. }
  471. }
  472. // -------------------------------------
  473. // Submit the Cleanup Job if selected
  474. if ($form_state['values']['op'] == t('Clean up orphaned analyses')) {
  475. tripal_add_job('Cleanup orphaned analyses', 'tripal_analysis',
  476. 'tripal_analyses_cleanup', $job_args, $user->uid);
  477. }
  478. }