tripal_feature.admin.inc 24 KB

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