tripal_feature.admin.inc 24 KB

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