tripal_feature.admin.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. *
  8. */
  9. function tripal_feature_admin_feature_view() {
  10. $output = '';
  11. // set the breadcrumb
  12. $breadcrumb = array();
  13. $breadcrumb[] = l('Home', '<front>');
  14. $breadcrumb[] = l('Administration', 'admin');
  15. $breadcrumb[] = l('Tripal', 'admin/tripal');
  16. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  17. $breadcrumb[] = l('Features', 'admin/tripal/chado/tripal_feature');
  18. drupal_set_breadcrumb($breadcrumb);
  19. // Add the view
  20. $view = views_embed_view('tripal_feature_admin_features','default');
  21. if (isset($view)) {
  22. $output .= $view;
  23. }
  24. else {
  25. $output .= '<p>The Feature module uses primarily views to provide an '
  26. . 'administrative interface. Currently one or more views needed for this '
  27. . 'administrative interface are disabled. <strong>Click each of the following links to '
  28. . 'enable the pertinent views</strong>:</p>';
  29. $output .= '<ul>';
  30. $output .= '<li>'.l('Features View', 'admin/tripal/chado/tripal_feature/views/features/enable').'</li>';
  31. $output .= '</ul>';
  32. }
  33. return $output;
  34. }
  35. /**
  36. *
  37. *
  38. * @ingroup tripal_feature
  39. */
  40. function tripal_feature_admin() {
  41. /*
  42. // before proceeding check to see if we have any
  43. // currently processing jobs. If so, we don't want
  44. // to give the opportunity to sync libraries
  45. $active_jobs = FALSE;
  46. if (tripal_get_module_active_jobs('tripal_feature')) {
  47. $active_jobs = TRUE;
  48. }
  49. if (!$active_jobs) {
  50. */
  51. get_tripal_feature_admin_form_title_set($form);
  52. get_tripal_feature_admin_form_url_set($form);
  53. $form['browser'] = array(
  54. '#type' => 'fieldset',
  55. '#title' => t('Feature Browser'),
  56. '#collapsible' => TRUE,
  57. '#collapsed' => TRUE,
  58. );
  59. $allowedoptions1 = array(
  60. 'show_feature_browser' => "Show the feature browser on the organism page. The browser loads when page loads. This may be slow for large sites.",
  61. 'hide_feature_browser' => "Hide the feature browser on the organism page. Disables the feature browser completely.",
  62. );
  63. // $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.";
  64. $form['browser']['browser_desc'] = array(
  65. '#type' => 'markup',
  66. '#value' => 'A feature browser can be added to an organism page to allow users to quickly ' .
  67. 'access a feature. This will most likely not be the ideal mechanism for accessing feature ' .
  68. 'information, especially for large sites, but it will alow users exploring the site (such ' .
  69. 'as students) to better understand the data types available on the site.',
  70. );
  71. $form['browser']['feature_types'] = array(
  72. '#title' => t('Feature Types'),
  73. '#type' => 'textarea',
  74. '#description' => t("Enter the Sequence Ontology (SO) terms for the feature types that " .
  75. "will be shown in the feature browser."),
  76. '#default_value' => variable_get('chado_browser_feature_types', 'gene mRNA'),
  77. );
  78. $form['browser']['browse_features'] = array(
  79. '#title' => 'Feature Browser on Organism Page',
  80. '#type' => 'radios',
  81. '#options' => $allowedoptions1,
  82. '#default_value' => variable_get('tripal_feature_browse_setting', 'show_feature_browser'),
  83. );
  84. $form['browser']['browse_features_library'] = array(
  85. '#title' => 'Feature Browser on Library Page',
  86. '#type' => 'radios',
  87. '#options' => array(
  88. 'show_feature_browser' => "Show the feature browse on the library page. The browser loads when page loads. This may be slow for large sites.",
  89. 'hide_feature_browser' => "Hide the feature browser on the library page. Disables the feature browser completely.",
  90. ),
  91. '#default_value' => variable_get('tripal_library_feature_browse_setting', 'show_feature_browser'),
  92. );
  93. $form['browser']['browse_features_analysis'] = array(
  94. '#title' => 'Feature Browser on Analysis Page',
  95. '#type' => 'radios',
  96. '#options' => array(
  97. 'show_feature_browser' => "Show the feature browse on the analysis page. The browser loads when page loads. This may be slow for large sites.",
  98. 'hide_feature_browser' => "Hide the feature browser on the analysis page. Disables the feature browser completely.",
  99. ),
  100. '#default_value' => variable_get('tripal_analysis_feature_browse_setting', 'show_feature_browser'),
  101. );
  102. $form['browser']['set_browse_button'] = array(
  103. '#type' => 'submit',
  104. '#value' => t('Set Browser'),
  105. '#weight' => 2,
  106. );
  107. $form['summary'] = array(
  108. '#type' => 'fieldset',
  109. '#title' => t('Feature Summary Report'),
  110. '#collapsible' => TRUE,
  111. '#collapsed' => TRUE,
  112. );
  113. $allowedoptions2 ['show_feature_summary'] = "Show the feature summary on the organism page. The summary loads when page loads.";
  114. $allowedoptions2 ['hide_feature_summary'] = "Hide the feature summary on the organism page. Disables the feature summary.";
  115. $form['summary']['feature_summary'] = array(
  116. '#title' => 'Feature Summary on Organism Page',
  117. '#description' => 'A feature summary can be added to an organism page to allow users to see the ' .
  118. 'type and quantity of features available for the organism.',
  119. '#type' => 'radios',
  120. '#options' => $allowedoptions2,
  121. '#default_value' => variable_get('tripal_feature_summary_setting', 'show_feature_summary'),
  122. );
  123. $form['summary']['feature_mapping'] = array(
  124. '#title' => 'Map feature types',
  125. '#description' => t('You may specify which Sequence Ontology (SO) terms to show in the ' .
  126. 'feature summary report by listing them in the following text area. Enter one per line. ' .
  127. 'If left blank, all SO terms for all features will be shown in the report. Only those terms ' .
  128. 'listed below will be shown in the report. Terms will appear in the report in the same order listed. To rename a ' .
  129. 'SO term to be more human readable form, use an \'=\' sign after the SO term (e.g. \'polypeptide = Protein\')'),
  130. '#type' => 'textarea',
  131. '#rows' => 15,
  132. '#default_value' => variable_get('tripal_feature_summary_report_mapping', ''),
  133. );
  134. $form['summary']['set_summary_button'] = array(
  135. '#type' => 'submit',
  136. '#value' => t('Set Summary'),
  137. '#weight' => 2,
  138. );
  139. get_tripal_feature_admin_form_taxonomy_set($form);
  140. // get_tripal_feature_admin_form_reindex_set($form);
  141. /* }
  142. else {
  143. $form['notice'] = array(
  144. '#type' => 'fieldset',
  145. '#title' => t('Feature Management Temporarily Unavailable'),
  146. '#collapsible' => FALSE,
  147. '#collapsed' => FALSE,
  148. );
  149. $form['notice']['message'] = array(
  150. '#value' => t('Currently, feature management jobs are waiting or " .
  151. "are running. Managemment features have been hidden until these " .
  152. "jobs complete. Please check back later once these jobs have " .
  153. "finished. You can view the status of pending jobs in the Tripal " .
  154. "jobs page.'),
  155. );
  156. }
  157. */
  158. return system_settings_form($form);
  159. }
  160. /**
  161. *
  162. *
  163. * @ingroup tripal_feature
  164. */
  165. function tripal_feature_admin_validate($form, &$form_state) {
  166. global $user; // we need access to the user info
  167. $job_args = array();
  168. variable_set('chado_browser_feature_types', $form_state['values']['feature_types']);
  169. switch ($form_state['values']['op']) {
  170. case t('Set/Reset Taxonomy for all feature nodes') :
  171. tripal_add_job('Set all feature taxonomy', 'tripal_feature',
  172. 'tripal_features_set_taxonomy', $job_args, $user->uid);
  173. break;
  174. case t('Reindex all feature nodes') :
  175. tripal_add_job('Reindex all features', 'tripal_feature',
  176. 'tripal_features_reindex', $job_args, $user->uid);
  177. break;
  178. case t('Set Browser') :
  179. variable_set('tripal_feature_browse_setting', $form_state['values']['browse_features']);
  180. variable_set('tripal_library_feature_browse_setting', $form_state['values']['browse_features_library']);
  181. variable_set('tripal_analysis_feature_browse_setting', $form_state['values']['browse_features_analysis']);
  182. break;
  183. case t('Set Summary') :
  184. variable_set('tripal_feature_summary_setting', $form_state['values']['feature_summary']);
  185. variable_set('tripal_feature_summary_report_mapping', $form_state['values']['feature_mapping']);
  186. break;
  187. case t('Set Feature URLs') :
  188. variable_set('chado_feature_url', $form_state['values']['feature_url']);
  189. tripal_add_job('Set Feature URLs', 'tripal_feature',
  190. 'tripal_feature_set_urls', $job_args, $user->uid);
  191. break;
  192. }
  193. }
  194. /**
  195. *
  196. *
  197. * @ingroup tripal_feature
  198. */
  199. function get_tripal_feature_admin_form_reindex_set(&$form) {
  200. $form['reindex'] = array(
  201. '#type' => 'fieldset',
  202. '#title' => t('Index/Reindex'),
  203. '#collapsible' => TRUE,
  204. '#collapsed' => TRUE,
  205. );
  206. $form['reindex']['description'] = array(
  207. '#type' => 'item',
  208. '#value' => t("Indexing or reindexing of nodes is required for Drupal's full text searching. " .
  209. "Index features for the first time to allow for searching of content, and later when content for features " .
  210. "is updated. Depending on the number of features this may take " .
  211. "quite a while. Click the button below to begin reindexing of " .
  212. "features. "),
  213. '#weight' => 1,
  214. );
  215. $form['reindex']['button'] = array(
  216. '#type' => 'submit',
  217. '#value' => t('Reindex all feature nodes'),
  218. '#weight' => 2,
  219. );
  220. }
  221. /**
  222. *
  223. *
  224. * @ingroup tripal_feature
  225. */
  226. function get_tripal_feature_admin_form_taxonomy_set(&$form) {
  227. $form['taxonomy'] = array(
  228. '#type' => 'fieldset',
  229. '#title' => t('Set Taxonomy'),
  230. '#collapsible' => TRUE,
  231. '#collapsed' => TRUE,
  232. );
  233. $form['taxonomy']['description'] = array(
  234. '#type' => 'item',
  235. '#value' => t("Drupal allows for assignment of \"taxonomy\" or " .
  236. "catagorical terms to nodes. These terms allow for advanced " .
  237. "filtering during searching."),
  238. '#weight' => 1,
  239. );
  240. $tax_options = array(
  241. 'organism' => t('Organism name'),
  242. 'feature_type' => t('Feature Type (e.g. EST, mRNA, etc.)'),
  243. 'analysis' => t('Analysis Name'),
  244. 'library' => t('Library Name'),
  245. );
  246. $form['taxonomy']['tax_classes'] = array(
  247. '#title' => t('Available Taxonomic Classes'),
  248. '#type' => t('checkboxes'),
  249. '#description' => t("Please select the class of terms to assign to " .
  250. "chado features"),
  251. '#required' => FALSE,
  252. '#prefix' => '<div id="taxclass_boxes">',
  253. '#suffix' => '</div>',
  254. '#options' => $tax_options,
  255. '#weight' => 2,
  256. '#default_value' => variable_get('tax_classes', array()),
  257. );
  258. $form['taxonomy']['button'] = array(
  259. '#type' => 'submit',
  260. '#value' => t('Set/Reset Taxonomy for all feature nodes'),
  261. '#weight' => 3,
  262. );
  263. }
  264. /**
  265. *
  266. * @param $form
  267. */
  268. function get_tripal_feature_admin_form_title_set(&$form) {
  269. $form['title'] = array(
  270. '#type' => 'fieldset',
  271. '#title' => t('Feature Page Titles'),
  272. '#collapsible' => TRUE,
  273. '#collapsed' => TRUE,
  274. );
  275. $form['title']['desc'] = array(
  276. '#type' => 'markup',
  277. '#value' => t('Each synced feature must have a unique page title, however, features
  278. may have the same name if they are of different types or from
  279. different organisms. Therefore, we must be sure that the
  280. page titles can uniquely identify the feature being viewed. Select
  281. an option below that will uniquely identify all features on your site.'),
  282. );
  283. $options = array(
  284. 'feature_unique_name' => 'Feature unique name',
  285. 'feature_name' => 'Feature name',
  286. 'unique_constraint' => 'Feature Name, uniquename, type and species',
  287. );
  288. $form['title']['chado_feature_title'] = array(
  289. '#title' => t('Feature Page Titles'),
  290. '#type' => 'radios',
  291. '#description' => t('Choose a title type from the list above that is
  292. guaranteed to be unique for all features. If in doubt it is safest to
  293. choose the last option as that guarantees uniqueness. Click the
  294. \'Save Configuration\' button at the bottom to save your selection.'),
  295. '#required' => FALSE,
  296. '#options' => $options,
  297. '#default_value' => variable_get('chado_feature_title', 'unique_constraint'),
  298. );
  299. }
  300. /**
  301. *
  302. * @param $form
  303. */
  304. function get_tripal_feature_admin_form_url_set(&$form) {
  305. $form['url'] = array(
  306. '#type' => 'fieldset',
  307. '#title' => t('Feature URL Path'),
  308. '#collapsible' => TRUE,
  309. '#collapsed' => TRUE,
  310. );
  311. $options = array(
  312. 'SID[id]' => '[id]:' . t('The Chado feature_id'),
  313. 'feature' => 'feature:' . t('Chado table name'),
  314. '[genus]' => '[genus]:' . t('Genus to which the feature belongs'),
  315. '[species]' => '[species]:' . t('Species to which the feature belongs'),
  316. '[type]' => '[type]:' . t('The type of feature'),
  317. '[uniquename]' => '[uniquename]:' . t('The feature unique name'),
  318. '[name]' => '[name]:' . t('The feature name'),
  319. 'reset' => t('Reset'),
  320. );
  321. $form['url']['chado_feature_url_string'] = array(
  322. '#title' => 'URL Syntax',
  323. '#type' => 'textfield',
  324. '#description' => t('You may rearrange elements in this text box to
  325. customize the URLs. The available tags include: [id],
  326. [uniquename]. [name], [species], [genus], [type]. You can separate or
  327. include any text between the tags. Click the "Set Feature URLs" button to
  328. reset the URLs for all feature pages. Click the "Save Configuration" button to
  329. simply save this setup. <b>Important</b>: be sure that whatever you choose will always be unique even considering
  330. future data that may be added. If you include the Chado table name, genus, species, type
  331. and uniquename you are guaranteed to have a unique URL. For example feature/[genus]/[species]/[type]/[uniquename]'),
  332. '#size' => 150,
  333. '#default_value' => variable_get('chado_feature_url_string', '/feature/[genus]/[species]/[type]/[uniquename]'),
  334. );
  335. $form['url']['chado_feature_url'] = array(
  336. '#title' => t('URL components'),
  337. '#type' => 'checkboxes',
  338. '#required' => FALSE,
  339. '#options' => $options,
  340. '#description' => t('Click the item above to make it appear in the URL Syntax box'),
  341. '#attributes' => array(
  342. 'onclick' => '
  343. box = $(\'#edit-chado-feature-url-string\');
  344. if (this.value == \'reset\') {
  345. box.val(\'\');
  346. }
  347. else {
  348. box.val(box.val() + "/" + this.value);
  349. }
  350. this.checked = false;
  351. ',
  352. ),
  353. );
  354. $form['url']['button'] = array(
  355. '#type' => 'submit',
  356. '#value' => t('Set Feature URLs'),
  357. );
  358. }
  359. /**
  360. *
  361. *
  362. * @ingroup tripal_feature
  363. */
  364. function tripal_features_set_taxonomy($max_sync = 0, $job_id = NULL) {
  365. // make sure our vocabularies are cleaned and reset before proceeding
  366. tripal_feature_del_vocabulary();
  367. tripal_feature_set_vocabulary();
  368. // iterate through all drupal feature nodes and set the taxonomy
  369. $results = db_query("SELECT * FROM {chado_feature}");
  370. $nsql = "
  371. SELECT * FROM {node}
  372. WHERE nid = :nid
  373. ";
  374. $i = 0;
  375. // load into ids array
  376. $count = 0;
  377. $chado_features = array();
  378. while ($chado_feature = $results->fetchObject()) {
  379. $chado_features[$count] = $chado_feature;
  380. $count++;
  381. }
  382. // Iterate through features that need to be synced
  383. $interval = intval($count * 0.01);
  384. foreach ($chado_features as $chado_feature) {
  385. // update the job status every 1% features
  386. if ($job_id and $i % $interval == 0) {
  387. tripal_job_set_progress($job_id, intval(($i/$count)*100));
  388. }
  389. print "$i of $count: ";
  390. $node = db_query($nsql, array(':nid' => $chado_feature->nid))->fetchObject();
  391. tripal_feature_set_taxonomy($node, $chado_feature->feature_id);
  392. $i++;
  393. }
  394. }
  395. /**
  396. *
  397. *
  398. * @ingroup tripal_feature
  399. */
  400. function tripal_feature_set_taxonomy($node, $feature_id) {
  401. // iterate through the taxonomy classes that have been
  402. // selected by the admin user and make sure we only set those
  403. $tax_classes = variable_get('tax_classes', array());
  404. $do_ft = 0;
  405. $do_op = 0;
  406. $do_lb = 0;
  407. $do_an = 0;
  408. foreach ($tax_classes as $class) {
  409. if (strcmp($class , 'organism')==0) {
  410. $do_op = 1;
  411. }
  412. if (strcmp($class, 'feature_type')==0) {
  413. $do_ft = 1;
  414. }
  415. if (strcmp($class, 'library')==0) {
  416. $do_lb = 1;
  417. }
  418. if (strcmp($class, 'analysis')==0) {
  419. $do_an = 1;
  420. }
  421. }
  422. // get the list of vocabularies and find our two vocabularies of interest
  423. $vocabularies = taxonomy_get_vocabularies();
  424. $ft_vid = NULL;
  425. $op_vid = NULL;
  426. $lb_vid = NULL;
  427. $an_vid = NULL;
  428. foreach ($vocabularies as $vocab) {
  429. if ($vocab->name == 'Feature Type') {
  430. $ft_vid = $vocab->vid;
  431. }
  432. if ($vocab->name == 'Organism') {
  433. $op_vid = $vocab->vid;
  434. }
  435. if ($vocab->name == 'Library') {
  436. $lb_vid = $vocab->vid;
  437. }
  438. if ($vocab->name == 'Analysis') {
  439. $an_vid = $vocab->vid;
  440. }
  441. }
  442. // get the cvterm and the organism for this feature
  443. $sql = "
  444. SELECT CVT.name AS cvname, O.genus, O.species
  445. FROM {cvterm} CVT
  446. INNER JOIN {feature} F on F.type_id = CVT.cvterm_id
  447. INNER JOIN {organism} O ON F.organism_id = O.organism_id
  448. WHERE F.feature_id = :feature_id
  449. ";
  450. $feature = chado_query($sql, array(':feature_id' => $feature_id))->fetchObject();
  451. // Set the feature type for this feature
  452. if ($do_ft && $ft_vid) {
  453. $tags["$ft_vid"] = "$feature->cvname";
  454. }
  455. // Set the organism for this feature type
  456. if ($do_op && $op_vid) {
  457. $tags["$op_vid"] = "$feature->genus $feature->species";
  458. }
  459. // get the library that this feature may belong to and add it as taxonomy
  460. if ($do_lb && $lb_vid) {
  461. $sql = "
  462. SELECT L.name
  463. FROM {Library} L
  464. INNER JOIN {Library_feature} LF ON LF.library_id = L.library_id
  465. WHERE LF.feature_id = :feature_id
  466. ";
  467. $library = chado_query($sql, array(':feature_id' => $feature_id))->fetchObject();
  468. $tags["$lb_vid"] = "$library->name";
  469. }
  470. // now add the taxonomy to the node
  471. $terms['tags'] = $tags;
  472. taxonomy_node_save($node, $terms);
  473. // print "Setting $node->name: " . implode(", ",$tags) . "\n";
  474. // get the analysis that this feature may belong to and add it as taxonomy
  475. // We'll add each one individually since there may be more than one analysis
  476. if ($do_an && $an_vid) {
  477. $sql = "
  478. SELECT A.name
  479. FROM {Analysis} A
  480. INNER JOIN {analysisfeature} AF ON AF.analysis_id = A.analysis_id
  481. WHERE AF.feature_id = :feature_id
  482. ";
  483. $results = chado_query($sql, array(':feature_id' => $feature_id));
  484. $analysis_terms = array();
  485. while ($analysis = $results->fetchObject()) {
  486. $tags2["$an_vid"] = "$analysis->name";
  487. $terms['tags'] = $tags2;
  488. taxonomy_node_save($node, $terms);
  489. }
  490. }
  491. }
  492. /**
  493. * This function is an extension of the chado_feature_view by providing
  494. * the markup for the feature object THAT WILL BE INDEXED.
  495. *
  496. * @ingroup tripal_feature
  497. */
  498. function theme_tripal_feature_search_index($node) {
  499. $feature = $node->feature;
  500. $content = '';
  501. // get the accession prefix
  502. $aprefix = variable_get('chado_feature_accession_prefix', 'FID');
  503. $content .= "<h1>$feature->uniquename</h1>. ";
  504. $content .= "<strong>$aprefix$feature->feature_id.</strong> ";
  505. $content .= "$feature->cvname ";
  506. $content .= "$feature->common_name ";
  507. // add the synonyms of this feature to the text for searching
  508. $synonyms = $node->synonyms;
  509. if (count($synonyms) > 0) {
  510. foreach ($synonyms as $result) {
  511. $content .= "$result->name ";
  512. }
  513. }
  514. return $content;
  515. }
  516. /**
  517. * This function is an extension of the chado_feature_view by providing
  518. * the markup for the feature object THAT WILL BE INDEXED.
  519. *
  520. * @ingroup tripal_feature
  521. */
  522. function theme_tripal_feature_search_results($node) {
  523. $feature = $node->feature;
  524. $content = '';
  525. // get the accession prefix
  526. $aprefix = variable_get('chado_feature_accession_prefix', 'FID');
  527. $content .= "Feature Name: <h1>$feature->uniquename</h1>. ";
  528. $content .= "<strong>Accession: $aprefix$feature->feature_id.</strong>";
  529. $content .= "Type: $feature->cvname. ";
  530. $content .= "Organism: $feature->common_name. ";
  531. // add the synonyms of this feature to the text for searching
  532. $synonyms = $node->synonyms;
  533. if (count($synonyms) > 0) {
  534. $content .= "Synonyms: ";
  535. foreach ($synonyms as $result) {
  536. $content .= "$result->name, ";
  537. }
  538. }
  539. return $content;
  540. }
  541. /**
  542. *
  543. *
  544. * @ingroup tripal_feature
  545. */
  546. function tripal_feature_set_vocabulary() {
  547. //include the file containing the required functions for adding taxonomy vocabs
  548. module_load_include('inc', 'taxonomy', 'taxonomy.admin');
  549. // get the vocabularies so that we make sure we don't recreate
  550. // the vocabs that already exist
  551. $vocabularies = taxonomy_get_vocabularies();
  552. $ft_vid = NULL;
  553. $op_vid = NULL;
  554. $lb_vid = NULL;
  555. $an_vid = NULL;
  556. // These taxonomic terms are hard coded because we
  557. // konw we have these relationships in the chado tables
  558. // through foreign key relationships. The tripal
  559. // modules that correspond to these chado "modules" don't
  560. // need to be installed for the taxonomy to work.
  561. foreach ($vocabularies as $vocab) {
  562. if ($vocab->name == 'Feature Type') {
  563. $ft_vid = $vocab->vid;
  564. }
  565. if ($vocab->name == 'Organism') {
  566. $op_vid = $vocab->vid;
  567. }
  568. if ($vocab->name == 'Library') {
  569. $lb_vid = $vocab->vid;
  570. }
  571. if ($vocab->name == 'Analysis') {
  572. $an_vid = $vocab->vid;
  573. }
  574. }
  575. if (!$ft_vid) {
  576. $form_state = array();
  577. $values = array(
  578. 'name' => t('Feature Type'),
  579. 'nodes' => array('chado_feature' => 'chado_feature'),
  580. 'description' => t('The feature type (or SO cvterm for this feature).'),
  581. 'help' => t('Select the term that matches the feature'),
  582. 'tags' => 0,
  583. 'hierarchy' => 1,
  584. 'relations' => 1,
  585. 'multiple' => 0,
  586. 'required' => 0,
  587. 'weight' => 1,
  588. );
  589. drupal_form_submit('taxonomy_form_vocabulary', $form_state, $values);
  590. drupal_form_submit('taxonomy_form_vocabulary', $form_state);
  591. }
  592. if (!$op_vid) {
  593. $form_state = array();
  594. $values = array(
  595. 'name' => t('Organism'),
  596. 'nodes' => array('chado_feature' => 'chado_feature'),
  597. 'description' => t('The organism to which this feature belongs.'),
  598. 'help' => t('Select the term that matches the feature'),
  599. 'tags' => 0,
  600. 'hierarchy' => 1,
  601. 'relations' => 1,
  602. 'multiple' => 0,
  603. 'required' => 0,
  604. 'weight' => 2,
  605. );
  606. drupal_form_submit('taxonomy_form_vocabulary', $form_state, $values);
  607. drupal_form_submit('taxonomy_form_vocabulary', $form_state);
  608. }
  609. if (!$lb_vid) {
  610. $form_state = array();
  611. $values = array(
  612. 'name' => t('Library'),
  613. 'nodes' => array('chado_feature' => 'chado_feature'),
  614. 'description' => t('Chado features associated with a library are assigned the term associated with the library'),
  615. 'help' => t('Select the term that matches the feature'),
  616. 'tags' => 0,
  617. 'hierarchy' => 1,
  618. 'relations' => 1,
  619. 'multiple' => 0,
  620. 'required' => 0,
  621. 'weight' => 3,
  622. );
  623. drupal_form_submit('taxonomy_form_vocabulary', $form_state, $values);
  624. drupal_form_submit('taxonomy_form_vocabulary', $form_state);
  625. }
  626. if (!$an_vid) {
  627. $form_state = array();
  628. $values = array(
  629. 'name' => t('Analysis'),
  630. 'nodes' => array('chado_feature' => 'chado_feature'),
  631. 'description' => t('Any analysis to which this feature belongs.'),
  632. 'help' => t('Select the term that matches the feature'),
  633. 'tags' => 0,
  634. 'hierarchy' => 1,
  635. 'relations' => 1,
  636. 'multiple' => 1,
  637. 'required' => 0,
  638. 'weight' => 4,
  639. );
  640. drupal_form_submit('taxonomy_form_vocabulary', $form_state, $values);
  641. drupal_form_submit('taxonomy_form_vocabulary', $form_state);
  642. }
  643. }