tripal_feature.admin.inc 24 KB

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