tripal_feature.admin.inc 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. <?php
  2. /**
  3. * Purpose: Provide Guidance to new Tripal Admin
  4. *
  5. * @return
  6. * HTML Formatted text
  7. *
  8. * @ingroup tripal_feature
  9. */
  10. function tripal_feature_module_description_page() {
  11. $text .= '<h3>Tripal Feature Administrative Tools Quick Links:</h3>';
  12. $text .= "<ul>";
  13. $text .= "<li><a href=\"".url("admin/tripal/tripal_feature/configuration") . "\">Feature Configuration</a></li>";
  14. $text .= "<li><a href=\"".url("admin/tripal/tripal_feature/fasta_loader"). "\">Import a multi-FASTA file</a></li>";
  15. $text .= "<li><a href=\"".url("admin/tripal/tripal_feature/gff3_load"). "\">Import a GFF3 file</a></li>";
  16. $text .= "<li><a href=\"".url("admin/tripal/tripal_feature/aggregate"). "\">Feature Relationship Aggegators</a></li>";
  17. $text .= "</ul>";
  18. $text .= '<h3>Module Description:</h3>';
  19. $text .= '<p>This module provides an interface for the Chado feature module which stores information
  20. related to genomic features. This module provides support for bulk loading of data in
  21. FASTA or GFF format, visualization of "feature" pages, editing and updating. The feature
  22. module relies heavily on
  23. </p>';
  24. $text .= '<h3>Setup Instructions:</h3>';
  25. $text .= '<p>After installation of the feature module. The following tasks should be performed
  26. <ol>
  27. <li><b>Themeing</b>: Before content from Chado can be visualized the Tripal base theme must
  28. be installed. This should have been done prior to this point. But is mentioned here in the event you
  29. follow the instructions below and cannot see content. In this case, if you do not see content
  30. check that Tripal theming is properly installed</li>
  31. <li><b>Loading of Ontologies</b>: If you do not have an existing Chado database or if you
  32. used Tripal to create Chado, then you must load ontologies before proceeding. Visit the
  33. page to <a href="'.url('admin/tripal/tripal_cv/obo_loader').'">load ontologies</a> and load at
  34. least the following ontologies:
  35. <ul>
  36. <li>Chado Feature Properties</li>
  37. <li>Relationship Ontology</li>
  38. <li>Sequence Ontology</li>
  39. <li>Gene Ontology (if loading GO terms for features)</li>
  40. </ul></li>
  41. <li><b>Data Import</b>: if you do not already have an existing Chado database with preloaded data
  42. then you will want
  43. to import data. You can do so using the Chado perl scripts that come with the normal
  44. <a href="http://gmod.org/wiki/Chado">distribution of Chado</a> or you can use the <a href="'.url('admin/tripal/tripal_feature/fasta_loader').'">FASTA loader</a> and
  45. <a href="'.url('admin/tripal/tripal_feature/gff3_load').'">GFF loader</a> provided here. If you
  46. created the Chado database using Tripal then you\'ll most likely want to use the Tripal loaders.</li>
  47. <li><b>Sync Features</b>: After data is loaded you need to sync features. This process is what
  48. creates the pages for viewing online. Not all features need be synced. For instance, if you
  49. have loaded whole genome sequence with fully defined gene models with several features to define
  50. a gene and its products (e.g. gene, mRNA, CDS, 5\'UTR, 3\'UTR, etc) you probably only want to create
  51. pages for genes or genes and mRNA. You probably do not want a page for a 5\'UTR.
  52. Using the <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a>
  53. you can sync (or create pages) for the desired feature types. </li>
  54. <li><b>Set Feature URL</b>: It is often convenient to have a simple URL for each feature page.
  55. For example, http://www.mygenomesite.org/[feature], where [feature] is a unique identifier for a feature page.
  56. With this, people can easily include links to feature pages of interest. Use the
  57. <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a>
  58. to specify whether to use the feature name, unique name or internal ID as the [feature] portion of the
  59. URL. Select the one that will guarantee a unique identifier for feature pages.</li>
  60. <li><b>Indexing</b>: Once all data has been loaded (including analysis data--e.g. blast, interpro, etc.)
  61. you can index all feature pages for searching if you want to ues the Drupal default search mechanism.
  62. Use the <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a>
  63. to either Index (for the first time) or "Reindex" (after adding new data)
  64. the feature pages for searching. Once the site is 100% indexed the pages will be searchable using Drupal\'s
  65. full text searching. <i>Note:</i> This process can take quite a while if you have a lot of data</li>
  66. <li><b>Set Taxonomy</b>: Drupal provides a mechanism for categorizing content to allow
  67. for advanced searching. Drupal calls this "Taxonomy", but is essentially categorizing the pages.
  68. You can categorize feature pages by their type (e.g. gene, mRNA, contig, EST, etc.) and by the
  69. organism to which they belong. This allows for filtering of search results by organism and feature type.
  70. Use the <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a> to
  71. set the Taxonomy.
  72. </ol>
  73. </p>';
  74. $text .= '<h3>Features of this Module:</h3>';
  75. $text .= '<p>Aside from data loading and feature page setup (as described in the post-installation section above),
  76. The Tripal feature module also provides the following functionality
  77. <ul>
  78. <li><b>Feature Browser:</b> The feature browser is a tabular list of features with links to their
  79. feature pages which appears on the organism
  80. page. It was created to provide a mechanism to allow site visitors to quickly
  81. accesss feature pages when they do not know what to search for. For sites with large numbers of features, this
  82. method for finding a specific pages is inadequate, but may still be included to aid new site
  83. visitors. This browser can be toggled on or off using the
  84. <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a></li>
  85. <li><b>Feature Summary:</b> The feature summary is a pie chart that indicates the types and quantities
  86. of feature types (Sequence Ontology terms) that are loaded in the database. It appears on the organism
  87. page. The summary can be toggled on or off using the
  88. <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a></li>
  89. <li><b>Integration with Drupal Views</b>: <a href="http://drupal.org/project/views">Drupal Views</a> is
  90. a powerful tool that allows the site administrator to create lists or basic searching forms of Chado content.
  91. It provides a graphical interface within Drupal to allow the site admin to directly query the Chado database
  92. and create custom lists without PHP programming or customization of Tripal source code. Views can also
  93. be created to filter content that has not yet been synced with Druapl in order to protect access to non
  94. published data (only works if Chado was installed using Tripal). You can see a list of available pre-existing
  95. Views <a href="'.url('admin/build/views/').'">here</a>, as well as create your own. </li>
  96. <li><b>Basic Feature Lookup View</b>: This module provides a basic <a href="'.url('features').'">feature search
  97. tool</a> for finding or listing features in Chado. It does not require indexing for Drupal searching but relies
  98. on Drupal Views. <a href="http://drupal.org/project/views">Drupal Views</a> must be installed. </li>
  99. </li>
  100. </ul>
  101. </p>';
  102. $text .= '<h3>Page Customizations</h3>';
  103. $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
  104. Below is a description of several methods. These methods may be used in conjunction with one another to
  105. provide fine-grained control.
  106. <ul>
  107. <li><b>Integration with Drupal Panels</b>: <a href="http://drupal.org/project/views">Drupal Panels</a>
  108. allows for customization of a page layout and you don\'t want to do PHP/Javascript/CSS programming. Tripal comes with pre-set layouts for feature pages. However,
  109. Panels become useful if you prefer a layout that that is different from the pre-set layouts. Chado content
  110. is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the
  111. Panel\'s GUI.</li>
  112. <li><b>Drupal\'s Content Construction Kit (CCK)</b>: the
  113. <a href="http://drupal.org/project/cck">Content Construction Kit (CCK) </a> is a powerful way to add non-Chado content
  114. to any page without need to edit template files or knowing PHP. You must first download and install CCK.
  115. With CCK, the site administartor can create a new field to appear on the content page. For example, currently,
  116. the Chado publication module is not yet supported by Tripal. Therefore, the site administrator can add a text
  117. field to the feature pages. This content is not stored in Chado, but will appear on the feature page. A field
  118. added by CCK will also appear in the form when editing a feature to allow users to manually enter the appropriate
  119. text. If the default pre-set layout and themeing for Tripal is used, it is better to create the CCK element,
  120. indicate that it is not to be shown (using the CCK interface). Then manually add the new content type
  121. where desired by editing the templates (as described below). If using Panels, the CCK field can be added to the
  122. location desired using the Panels interface.
  123. <li><b>Drupal Node Templates</b>: The Tripal packages comes with a "theme_tripal" directory that contains the
  124. themeing for Chado content. You should be familiar with this as you had to install this theme during Tripal
  125. installation. The feature module has a template file for feature "nodes" (Tripal feature pages). This file
  126. is named "node-chado_feature.tpl.php", and provides javascript, HTML and PHP code for display of the feature
  127. pages. You can edit this file to control which types of information (or which feature "blocks") are displayed for features. Be sure to
  128. copy these template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
  129. future Tripal updates may overwrite your customizations.</li>
  130. <li><b>Feature "Block" Templates</b>: In the "theme_tripal" directory is a subdirectory named "tripal_feature".
  131. Inside this directory is a set of templates that control distinct types of information for features. For example,
  132. there is a "base" template for displaying of data directly from the Chado feature table, and a "references"
  133. template for showing external site references for a feature (data from the feature_dbxref table). These templates are used both by Drupal blocks
  134. for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template
  135. provides (also desribed above). You can customize these templates as you desire. Be sure to copy these
  136. template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
  137. future Tripal updates may overwrite your customizations.
  138. </li>
  139. <li><b>Adding Links to the "Resources" Sidebar</b>: If you use the pre-set default Tripal layout for theming, you
  140. will see a "Resources" sidebar on each page. The links that appear on the sidebar are automatically generated
  141. using Javascript for all of the feature "Blocks" that appear on the page. If you want to add additional links
  142. (e.g. a dynamic link to GBrowse for the feature) and you want that link to appear in the
  143. "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the
  144. section at the bottom of the template file where the resources section is found.</li>
  145. </ul>
  146. </p>';
  147. return $text;
  148. }
  149. /**
  150. *
  151. *
  152. * @ingroup tripal_feature
  153. */
  154. function tripal_feature_admin () {
  155. // before proceeding check to see if we have any
  156. // currently processing jobs. If so, we don't want
  157. // to give the opportunity to sync libraries
  158. $active_jobs = FALSE;
  159. if(tripal_get_module_active_jobs('tripal_feature')){
  160. $active_jobs = TRUE;
  161. }
  162. if(!$active_jobs){
  163. $form['chado_feature_accession_prefix'] = array (
  164. '#title' => t('Internal ID Prefix'),
  165. '#type' => t('textfield'),
  166. '#description' => t("Internal ID numbers for features consist of the ".
  167. "chado feature_id and a site specific prefix. Set the prefix that ".
  168. "will be incorporated in front of each feature_id to form a unique ".
  169. "accession number for this site."),
  170. '#required' => TRUE,
  171. '#default_value' => variable_get('chado_feature_accession_prefix','ID'),
  172. );
  173. $form['chado_feature_types'] = array(
  174. '#title' => t('Feature Types'),
  175. '#type' => 'textarea',
  176. '#description' => t('Enter the names of the sequence types that the ".
  177. "site will support with independent pages. Pages for these data ".
  178. "types will be built automatically for features that exist in the ".
  179. "chado database. The names listed here should be spearated by ".
  180. "spaces or entered separately on new lines. The names must match ".
  181. "exactly (spelling and case) with terms in the sequence ontology'),
  182. '#required' => TRUE,
  183. '#default_value' => variable_get('chado_feature_types','EST contig'),
  184. );
  185. get_tripal_feature_admin_form_sync_set($form);
  186. get_tripal_feature_admin_form_url_set($form);
  187. $form['browser'] = array(
  188. '#type' => 'fieldset',
  189. '#title' => t('Feature Browser')
  190. );
  191. $allowedoptions1 = array (
  192. 'show_feature_browser' => "Show the feature browser on the organism page. The browser loads when page loads. This may be slow for large sites.",
  193. 'hide_feature_browser' => "Hide the feature browser on the organism page. Disables the feature browser completely.",
  194. );
  195. // $allowedoptions ['allow_feature_browser'] = "Allow loading of the feature browsing through AJAX. For large sites the initial page load will be quick with the feature browser loading afterwards.";
  196. $form['browser']['browse_features'] = array(
  197. '#title' => 'Feature Browser on Organism Page',
  198. '#description' => 'A feature browser can be added to an organism page to allow users to quickly '.
  199. 'access a feature. This will most likely not be the ideal mechanism for accessing feature '.
  200. 'information, especially for large sites, but it will alow users exploring the site (such '.
  201. 'as students) to better understand the data types available on the site.',
  202. '#type' => 'radios',
  203. '#options' => $allowedoptions1,
  204. '#default_value'=>variable_get('tripal_feature_browse_setting', 'show_feature_browser'),
  205. );
  206. $form['browser']['set_browse_button'] = array(
  207. '#type' => 'submit',
  208. '#value' => t('Set Browser'),
  209. '#weight' => 2,
  210. );
  211. $form['summary'] = array(
  212. '#type' => 'fieldset',
  213. '#title' => t('Feature Summary')
  214. );
  215. $allowedoptions2 ['show_feature_summary'] = "Show the feature summary on the organism page. The summary loads when page loads.";
  216. $allowedoptions2 ['hide_feature_summary'] = "Hide the feature summary on the organism page. Disables the feature summary.";
  217. $form['summary']['feature_summary'] = array(
  218. '#title' => 'Feature Summary on Organism Page',
  219. '#description' => 'A feature summary can be added to an organism page to allow users to see the '.
  220. 'type and quantity of features available for the organism.',
  221. '#type' => 'radios',
  222. '#options' => $allowedoptions2,
  223. '#default_value'=>variable_get('tripal_feature_summary_setting', 'show_feature_summary'),
  224. );
  225. $form['summary']['set_summary_button'] = array(
  226. '#type' => 'submit',
  227. '#value' => t('Set Summary'),
  228. '#weight' => 2,
  229. );
  230. get_tripal_feature_admin_form_taxonomy_set($form);
  231. get_tripal_feature_admin_form_reindex_set($form);
  232. get_tripal_feature_admin_form_cleanup_set($form);
  233. } else {
  234. $form['notice'] = array(
  235. '#type' => 'fieldset',
  236. '#title' => t('Feature Management Temporarily Unavailable')
  237. );
  238. $form['notice']['message'] = array(
  239. '#value' => t('Currently, feature management jobs are waiting or ".
  240. "are running. Managemment features have been hidden until these ".
  241. "jobs complete. Please check back later once these jobs have ".
  242. "finished. You can view the status of pending jobs in the Tripal ".
  243. "jobs page.'),
  244. );
  245. }
  246. return system_settings_form($form);
  247. }
  248. /**
  249. *
  250. *
  251. * @ingroup tripal_feature
  252. */
  253. function tripal_feature_admin_validate($form, &$form_state) {
  254. global $user; // we need access to the user info
  255. $job_args = array();
  256. // if the user wants to sync up the chado features then
  257. // add the job to the management queue
  258. switch ($form_state['values']['op']){
  259. case t('Sync all Features') :
  260. tripal_add_job('Sync all features','tripal_feature',
  261. 'tripal_feature_sync_features',$job_args,$user->uid);
  262. break;
  263. case t('Set/Reset Taxonomy for all feature nodes') :
  264. tripal_add_job('Set all feature taxonomy','tripal_feature',
  265. 'tripal_features_set_taxonomy',$job_args,$user->uid);
  266. break;
  267. case t('Reindex all feature nodes') :
  268. tripal_add_job('Reindex all features','tripal_feature',
  269. 'tripal_features_reindex',$job_args,$user->uid);
  270. break;
  271. case t('Clean up orphaned features') :
  272. tripal_add_job('Cleanup orphaned features','tripal_feature',
  273. 'tripal_features_cleanup',$job_args,$user->uid);
  274. break;
  275. case t('Set Browser') :
  276. variable_set('tripal_feature_browse_setting',$form_state['values']['browse_features']);
  277. break;
  278. case t('Set Summary') :
  279. variable_set('tripal_feature_summary_setting',$form_state['values']['feature_summary']);
  280. break;
  281. case t('Set Feature URLs') :
  282. variable_set('chado_feature_url',$form_state['values']['feature_url']);
  283. tripal_add_job('Set Feature URLs','tripal_feature',
  284. 'tripal_feature_set_urls',$job_args,$user->uid);
  285. break;
  286. }
  287. }
  288. /**
  289. *
  290. *
  291. * @ingroup tripal_feature
  292. */
  293. function get_tripal_feature_admin_form_cleanup_set(&$form) {
  294. $form['cleanup'] = array(
  295. '#type' => 'fieldset',
  296. '#title' => t('Clean Up')
  297. );
  298. $form['cleanup']['description'] = array(
  299. '#type' => 'item',
  300. '#value' => t("With Drupal and chado residing in different databases ".
  301. "it is possible that nodes in Drupal and features in Chado become ".
  302. "\"orphaned\". This can occur if a feature node in Drupal is ".
  303. "deleted but the corresponding chado feature is not and/or vice ".
  304. "versa. The Cleanup function will also remove nodes for features ".
  305. "that are not in the list of allowed feature types as specified ".
  306. "above. This is helpful when a feature type needs to be ".
  307. "removed but was previously present as Drupal nodes. ".
  308. "Click the button below to resolve these discrepancies."),
  309. '#weight' => 1,
  310. );
  311. $form['cleanup']['button'] = array(
  312. '#type' => 'submit',
  313. '#value' => t('Clean up orphaned features'),
  314. '#weight' => 2,
  315. );
  316. }
  317. /**
  318. *
  319. *
  320. * @ingroup tripal_feature
  321. */
  322. function get_tripal_feature_admin_form_reindex_set(&$form) {
  323. $form['reindex'] = array(
  324. '#type' => 'fieldset',
  325. '#title' => t('Index/Reindex')
  326. );
  327. $form['reindex']['description'] = array(
  328. '#type' => 'item',
  329. '#value' => t("Indexing or reindexing of nodes is required for Drupal's full text searching. ".
  330. "Index features for the first time to allow for searching of content, and later when content for features ".
  331. "is updated. Depending on the number of features this may take ".
  332. "quite a while. Click the button below to begin reindexing of ".
  333. "features. "),
  334. '#weight' => 1,
  335. );
  336. $form['reindex']['button'] = array(
  337. '#type' => 'submit',
  338. '#value' => t('Reindex all feature nodes'),
  339. '#weight' => 2,
  340. );
  341. }
  342. /**
  343. *
  344. *
  345. * @ingroup tripal_feature
  346. */
  347. function get_tripal_feature_admin_form_taxonomy_set (&$form) {
  348. $form['taxonomy'] = array(
  349. '#type' => 'fieldset',
  350. '#title' => t('Set Taxonomy')
  351. );
  352. $form['taxonomy']['description'] = array(
  353. '#type' => 'item',
  354. '#value' => t("Drupal allows for assignment of \"taxonomy\" or ".
  355. "catagorical terms to nodes. These terms allow for advanced ".
  356. "filtering during searching."),
  357. '#weight' => 1,
  358. );
  359. $tax_options = array (
  360. 'organism' => t('Organism name'),
  361. 'feature_type' => t('Feature Type (e.g. EST, mRNA, etc.)'),
  362. 'analysis' => t('Analysis Name'),
  363. 'library' => t('Library Name'),
  364. );
  365. $form['taxonomy']['tax_classes'] = array (
  366. '#title' => t('Available Taxonomic Classes'),
  367. '#type' => t('checkboxes'),
  368. '#description' => t("Please select the class of terms to assign to ".
  369. "chado features"),
  370. '#required' => FALSE,
  371. '#prefix' => '<div id="taxclass_boxes">',
  372. '#suffix' => '</div>',
  373. '#options' => $tax_options,
  374. '#weight' => 2,
  375. '#default_value' => variable_get('tax_classes',''),
  376. );
  377. $form['taxonomy']['button'] = array(
  378. '#type' => 'submit',
  379. '#value' => t('Set/Reset Taxonomy for all feature nodes'),
  380. '#weight' => 3,
  381. );
  382. }
  383. /**
  384. *
  385. *
  386. * @ingroup tripal_feature
  387. */
  388. function get_tripal_feature_admin_form_sync_set (&$form) {
  389. // get the list of organisms which will be synced.
  390. $feature_sql = "SELECT * FROM {Feature} WHERE uniquename = '%s' and organism_id = %d";
  391. $previous_db = tripal_db_set_active('chado');
  392. $feature = db_fetch_object(db_query($feature_sql,$node->title,$node->organism_id));
  393. tripal_db_set_active($previous_db);
  394. // define the fieldsets
  395. $form['sync'] = array(
  396. '#type' => 'fieldset',
  397. '#title' => t('Sync Features')
  398. );
  399. $form['sync']['description'] = array(
  400. '#type' => 'item',
  401. '#value' => t("Click the 'Sync all Features' button to create Drupal ".
  402. "content for features in chado. Only features of the types listed ".
  403. "above in the Feature Types box will be synced. Depending on the ".
  404. "number of features in the chado database this may take a long ".
  405. "time to complete. "),
  406. '#weight' => 1,
  407. );
  408. $orgs = tripal_organism_get_synced();
  409. $org_list = '';
  410. foreach($orgs as $org){
  411. $org_list .= "$org->genus $org->species, ";
  412. }
  413. $form['sync']['description2'] = array(
  414. '#type' => 'item',
  415. '#value' => "Only features for the following organisms will be synced: ".
  416. " $org_list",
  417. '#weight' => 1,
  418. );
  419. $form['sync']['button'] = array(
  420. '#type' => 'submit',
  421. '#value' => t('Sync all Features'),
  422. '#weight' => 3,
  423. );
  424. }
  425. function get_tripal_feature_admin_form_url_set (&$form) {
  426. $form['url'] = array(
  427. '#type' => 'fieldset',
  428. '#title' => t('Feature URL Path')
  429. );
  430. $form['url']['chado_feature_url'] = array(
  431. '#title' => t('Feature URL'),
  432. '#type' => 'radios',
  433. '#description' => t('Each synced feature will have a unique URL which consists of '.
  434. 'the site domain followed by a unique identifer: for '.
  435. 'example http://my-tripal-site.org/ID1034, where the '.
  436. 'element just after the final slash is the unique '.
  437. 'identifier for the feature. Choose a feature descriptor '.
  438. 'from the list that is guaranteed to be unique in your synced '.
  439. 'dataset. If in doubt it is safest to coose the internal ID. '.
  440. 'The descrpitor need not be unique amont the total dataset. '.
  441. 'It only need be unique among the synced dataset.'),
  442. '#required' => FALSE,
  443. '#options' => array('internal ID' => 'internal ID',
  444. 'feature unique name' => 'feature unique name',
  445. 'feature name' => 'feature name'),
  446. '#default_value' => variable_get('chado_feature_url','internal ID'),
  447. );
  448. $form['url']['button'] = array(
  449. '#type' => 'submit',
  450. '#value' => t('Set Feature URLs'),
  451. '#weight' => 3,
  452. );
  453. }
  454. /**
  455. *
  456. *
  457. * @ingroup tripal_feature
  458. */
  459. function tripal_feature_aggregator_page(){
  460. $add_url = url("admin/tripal/tripal_feature/aggregate/new");
  461. $output = "<a href=\"$add_url\">Add a new aggregator</a>";
  462. $output .= drupal_get_form('tripal_feature_aggregator_select_form');
  463. $output .= '<div id="db-edit-div">Please select an aggregator base type to view or edit</div>';
  464. return $output;
  465. }
  466. /**
  467. *
  468. *
  469. * @ingroup tripal_feature
  470. */
  471. function tripal_feature_aggregator_select_form(){
  472. // get a list of base terms from chado for user to choose
  473. $sql = "SELECT DISTINCT type_id FROM {tripal_feature_relagg} ORDER BY type_id ";
  474. $results = db_query ($sql);
  475. $sql = "SELECT * FROM {cvterm} WHERE cvterm_id = %d";
  476. $previous_db = tripal_db_set_active('chado');
  477. $types = array();
  478. $types[] = '';
  479. while($base = db_fetch_object($results)){
  480. $term = db_fetch_object(db_query($sql,$base->type_id));
  481. $types[$base->type_id] = $term->name;
  482. }
  483. tripal_db_set_active($previous_db);
  484. $form['type_id'] = array(
  485. '#title' => t('Aggregator Base Type'),
  486. '#type' => 'select',
  487. '#options' => $types,
  488. '#ahah' => array(
  489. 'path' => 'admin/tripal/tripal_feature/aggregate/edit/js',
  490. 'wrapper' => 'db-edit-div',
  491. 'effect' => 'fade',
  492. 'event' => 'change',
  493. 'method' => 'replace',
  494. ),
  495. );
  496. return $form;
  497. }
  498. /**
  499. *
  500. *
  501. * @ingroup tripal_feature
  502. */
  503. function tripal_feature_aggregator_form(&$form_state = NULL,$type_id = NULL){
  504. // get this requested database
  505. if($type_id){
  506. $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d ";
  507. $tsql = "SELECT * FROM {cvterm} WHERE cvterm_id = %d ";
  508. // get the default list of terms
  509. $results = db_query($sql,$type_id);
  510. while($type = db_fetch_object($results)){
  511. $previous_db = tripal_db_set_active('chado');
  512. $term = db_fetch_object(db_query($tsql,$type->rel_type_id));
  513. tripal_db_set_active($previous_db);
  514. $default_others .= $term->name . " ";
  515. }
  516. $default_base = $base->name;
  517. $action = 'Update';
  518. $form['type_id'] = array(
  519. '#type' => 'hidden',
  520. '#value' => $type_id
  521. );
  522. } else {
  523. $action = 'Add';
  524. $form['base']= array(
  525. '#type' => 'textfield',
  526. '#title' => t('Base Feature type'),
  527. '#description' => t('Please enter the Sequence Ontology (SO) term for the base feature type for this aggregator.'),
  528. '#default_value' => $default_base,
  529. '#required' => TRUE,
  530. '#weight' => 1
  531. );
  532. }
  533. $form['others']= array(
  534. '#type' => 'textarea',
  535. '#title' => t('Aggregate these types if a relationship exists'),
  536. '#description' => t('Please enter the Sequence Ontology (SO) terms that should be aggregated with the base feature type listed above. Separate each by a space or newline'),
  537. '#default_value' => $default_others,
  538. '#required' => TRUE,
  539. '#weight' => 2
  540. );
  541. if(strcmp($action,'Update')==0){
  542. $form['update'] = array (
  543. '#type' => 'submit',
  544. '#value' => t('Update'),
  545. '#weight' => 5,
  546. '#executes_submit_callback' => TRUE,
  547. );
  548. $form['delete'] = array (
  549. '#type' => 'submit',
  550. '#value' => t('Delete'),
  551. '#weight' => 6,
  552. '#executes_submit_callback' => TRUE,
  553. );
  554. } else {
  555. $form['add'] = array (
  556. '#type' => 'submit',
  557. '#value' => t('Add'),
  558. '#weight' => 5,
  559. '#executes_submit_callback' => TRUE,
  560. );
  561. }
  562. $form['#redirect'] = 'admin/tripal/tripal_feature/aggregate';
  563. return $form;
  564. }
  565. /**
  566. *
  567. *
  568. * @ingroup tripal_feature
  569. */
  570. function tripal_feature_aggregator_form_validate($form, &$form_state){
  571. $type_id = $form_state['values']['type_id'];
  572. $base = $form_state['values']['base'];
  573. $others = $form_state['values']['others'];
  574. $op = $form_state['values']['op'];
  575. // split apart the feature types to be aggregated
  576. $types = preg_split('/\s+/',$others);
  577. // the SQL for finding the term
  578. $tsql = "
  579. SELECT *
  580. FROM {cvterm} CVT
  581. INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
  582. WHERE CVT.name = '%s' and CV.name = 'sequence'";
  583. // make sure the base type exists
  584. if($base){
  585. $previous_db = tripal_db_set_active('chado');
  586. $term = db_fetch_object(db_query($tsql,$base));
  587. tripal_db_set_active($previous_db);
  588. if(!$term){
  589. form_set_error('base',t('The specified base type is not a valid SO term'));
  590. }
  591. // make sure this type doesn't already in the table
  592. $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d ";
  593. $agg = db_fetch_object(db_query($sql,$term->cvterm_id));
  594. if($agg){
  595. form_set_error('base',t('The specified base type is already used as a base type for another aggregator and cannot be readded.'));
  596. }
  597. }
  598. // iterate through each type to be aggregated and make sure they are valid
  599. foreach($types as $type){
  600. $previous_db = tripal_db_set_active('chado');
  601. $term = db_fetch_object(db_query($tsql,$type));
  602. tripal_db_set_active($previous_db);
  603. if(!$term){
  604. form_set_error('others',t('The specified type ') . $type . t(' is not a valid SO term'));
  605. }
  606. }
  607. }
  608. /**
  609. *
  610. *
  611. * @ingroup tripal_feature
  612. */
  613. function tripal_feature_aggregator_form_submit($form, &$form_state){
  614. $type_id = $form_state['values']['type_id'];
  615. $base = $form_state['values']['base'];
  616. $others = $form_state['values']['others'];
  617. $op = $form_state['values']['op'];
  618. // split apart the feature types to be aggregated
  619. $types = preg_split('/\s+/',$others);
  620. // the SQL for finding the term
  621. $tsql = "
  622. SELECT *
  623. FROM {cvterm} CVT
  624. INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
  625. WHERE CVT.name = '%s' and CV.name = 'sequence'";
  626. // the SQL for deleting an aggregator
  627. $dsql = "
  628. DELETE FROM {tripal_feature_relagg}
  629. WHERE type_id = %d
  630. ";
  631. // if this is an insert then we have a base type name. We
  632. // need to get the corresponding term id
  633. if($base){
  634. $previous_db = tripal_db_set_active('chado');
  635. $term = db_fetch_object(db_query($tsql,$base));
  636. tripal_db_set_active($previous_db);
  637. $type_id = $term->cvterm_id;
  638. }
  639. if(strcmp($op,'Delete')==0){
  640. $result = db_query($dsql,$type_id);
  641. if($result){
  642. drupal_set_message("Aggregator deleted");
  643. } else {
  644. drupal_set_message("Failed to delete mailing list.");
  645. }
  646. }
  647. else {
  648. // for an update, first remove all the current aggregator settings
  649. // and we'll add them again
  650. $result = db_query($dsql,$type_id);
  651. // the SQL for inserting the aggregated types
  652. $isql = "
  653. INSERT INTO {tripal_feature_relagg}
  654. (type_id,rel_type_id)
  655. VALUES
  656. (%d,%d)
  657. ";
  658. // iterate through each type to be aggregated and add an entry in the table
  659. foreach($types as $type){
  660. $previous_db = tripal_db_set_active('chado');
  661. $term = db_fetch_object(db_query($tsql,$type));
  662. tripal_db_set_active($previous_db);
  663. $result = db_query($isql,$type_id,$term->cvterm_id);
  664. }
  665. drupal_set_message("Aggregator added");
  666. }
  667. return '';
  668. }
  669. /**
  670. *
  671. *
  672. * @ingroup tripal_feature
  673. */
  674. function tripal_feature_aggregator_ajax_edit (){
  675. // get the database id, build the form and then return the JSON object
  676. $type_id = $_POST['type_id'];
  677. $form = drupal_get_form('tripal_feature_aggregator_form',$type_id);
  678. drupal_json(array('status' => TRUE, 'data' => $form));
  679. }