tripal_feature.admin.inc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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 contig'),
  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. get_tripal_feature_admin_form_cleanup_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. *
  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('Sync all Features') :
  172. tripal_add_job('Sync all features', 'tripal_feature',
  173. 'tripal_feature_sync_features', $job_args, $user->uid);
  174. break;
  175. case t('Set/Reset Taxonomy for all feature nodes') :
  176. tripal_add_job('Set all feature taxonomy', 'tripal_feature',
  177. 'tripal_features_set_taxonomy', $job_args, $user->uid);
  178. break;
  179. case t('Reindex all feature nodes') :
  180. tripal_add_job('Reindex all features', 'tripal_feature',
  181. 'tripal_features_reindex', $job_args, $user->uid);
  182. break;
  183. case t('Clean up orphaned features') :
  184. tripal_add_job('Cleanup orphaned features', 'tripal_feature',
  185. 'tripal_features_cleanup', $job_args, $user->uid);
  186. break;
  187. case t('Set Browser') :
  188. variable_set('tripal_feature_browse_setting', $form_state['values']['browse_features']);
  189. variable_set('tripal_library_feature_browse_setting', $form_state['values']['browse_features_library']);
  190. variable_set('tripal_analysis_feature_browse_setting', $form_state['values']['browse_features_analysis']);
  191. break;
  192. case t('Set Summary') :
  193. variable_set('tripal_feature_summary_setting', $form_state['values']['feature_summary']);
  194. variable_set('tripal_feature_summary_report_mapping', $form_state['values']['feature_mapping']);
  195. break;
  196. case t('Set Feature URLs') :
  197. variable_set('chado_feature_url', $form_state['values']['feature_url']);
  198. tripal_add_job('Set Feature URLs', 'tripal_feature',
  199. 'tripal_feature_set_urls', $job_args, $user->uid);
  200. break;
  201. }
  202. }
  203. /**
  204. *
  205. *
  206. * @ingroup tripal_feature
  207. */
  208. function get_tripal_feature_admin_form_cleanup_set(&$form) {
  209. $form['cleanup'] = array(
  210. '#type' => 'fieldset',
  211. '#title' => t('Clean Up'),
  212. '#collapsible' => TRUE,
  213. '#collapsed' => TRUE,
  214. );
  215. $form['cleanup']['description'] = array(
  216. '#type' => 'item',
  217. '#value' => t("With Drupal and chado residing in different databases " .
  218. "it is possible that nodes in Drupal and features in Chado become " .
  219. "\"orphaned\". This can occur if a feature node in Drupal is " .
  220. "deleted but the corresponding chado feature is not and/or vice " .
  221. "versa. The Cleanup function will also remove nodes for features " .
  222. "that are not in the list of allowed feature types as specified " .
  223. "above. This is helpful when a feature type needs to be " .
  224. "removed but was previously present as Drupal nodes. " .
  225. "Click the button below to resolve these discrepancies."),
  226. '#weight' => 1,
  227. );
  228. $form['cleanup']['button'] = array(
  229. '#type' => 'submit',
  230. '#value' => t('Clean up orphaned features'),
  231. '#weight' => 2,
  232. );
  233. }
  234. /**
  235. *
  236. *
  237. * @ingroup tripal_feature
  238. */
  239. function get_tripal_feature_admin_form_reindex_set(&$form) {
  240. $form['reindex'] = array(
  241. '#type' => 'fieldset',
  242. '#title' => t('Index/Reindex'),
  243. '#collapsible' => TRUE,
  244. '#collapsed' => TRUE,
  245. );
  246. $form['reindex']['description'] = array(
  247. '#type' => 'item',
  248. '#value' => t("Indexing or reindexing of nodes is required for Drupal's full text searching. " .
  249. "Index features for the first time to allow for searching of content, and later when content for features " .
  250. "is updated. Depending on the number of features this may take " .
  251. "quite a while. Click the button below to begin reindexing of " .
  252. "features. "),
  253. '#weight' => 1,
  254. );
  255. $form['reindex']['button'] = array(
  256. '#type' => 'submit',
  257. '#value' => t('Reindex all feature nodes'),
  258. '#weight' => 2,
  259. );
  260. }
  261. /**
  262. *
  263. *
  264. * @ingroup tripal_feature
  265. */
  266. function get_tripal_feature_admin_form_taxonomy_set(&$form) {
  267. $form['taxonomy'] = array(
  268. '#type' => 'fieldset',
  269. '#title' => t('Set Taxonomy'),
  270. '#collapsible' => TRUE,
  271. '#collapsed' => TRUE,
  272. );
  273. $form['taxonomy']['description'] = array(
  274. '#type' => 'item',
  275. '#value' => t("Drupal allows for assignment of \"taxonomy\" or " .
  276. "catagorical terms to nodes. These terms allow for advanced " .
  277. "filtering during searching."),
  278. '#weight' => 1,
  279. );
  280. $tax_options = array(
  281. 'organism' => t('Organism name'),
  282. 'feature_type' => t('Feature Type (e.g. EST, mRNA, etc.)'),
  283. 'analysis' => t('Analysis Name'),
  284. 'library' => t('Library Name'),
  285. );
  286. $form['taxonomy']['tax_classes'] = array(
  287. '#title' => t('Available Taxonomic Classes'),
  288. '#type' => t('checkboxes'),
  289. '#description' => t("Please select the class of terms to assign to " .
  290. "chado features"),
  291. '#required' => FALSE,
  292. '#prefix' => '<div id="taxclass_boxes">',
  293. '#suffix' => '</div>',
  294. '#options' => $tax_options,
  295. '#weight' => 2,
  296. '#default_value' => variable_get('tax_classes', array()),
  297. );
  298. $form['taxonomy']['button'] = array(
  299. '#type' => 'submit',
  300. '#value' => t('Set/Reset Taxonomy for all feature nodes'),
  301. '#weight' => 3,
  302. );
  303. }
  304. /**
  305. *
  306. * @param $form
  307. */
  308. function get_tripal_feature_admin_form_title_set(&$form) {
  309. $form['title'] = array(
  310. '#type' => 'fieldset',
  311. '#title' => t('Feature Page Titles'),
  312. '#collapsible' => TRUE,
  313. '#collapsed' => TRUE,
  314. );
  315. $form['title']['desc'] = array(
  316. '#type' => 'markup',
  317. '#value' => t('Each synced feature must have a unique page title, however, features
  318. may have the same name if they are of different types or from
  319. different organisms. Therefore, we must be sure that the
  320. page titles can uniquely identify the feature being viewed. Select
  321. an option below that will uniquely identify all features on your site.'),
  322. );
  323. $options = array(
  324. 'feature_unique_name' => 'Feature unique name',
  325. 'feature_name' => 'Feature name',
  326. 'unique_constraint' => 'Feature Name, uniquename, type and species',
  327. );
  328. $form['title']['chado_feature_title'] = array(
  329. '#title' => t('Feature Page Titles'),
  330. '#type' => 'radios',
  331. '#description' => t('Choose a title type from the list above that is
  332. guaranteed to be unique for all features. If in doubt it is safest to
  333. choose the last option as that guarantees uniqueness. Click the
  334. \'Save Configuration\' button at the bottom to save your selection.'),
  335. '#required' => FALSE,
  336. '#options' => $options,
  337. '#default_value' => variable_get('chado_feature_title', 'unique_constraint'),
  338. );
  339. }
  340. /**
  341. *
  342. * @param $form
  343. */
  344. function get_tripal_feature_admin_form_url_set(&$form) {
  345. $form['url'] = array(
  346. '#type' => 'fieldset',
  347. '#title' => t('Feature URL Path'),
  348. '#collapsible' => TRUE,
  349. '#collapsed' => TRUE,
  350. );
  351. $options = array(
  352. 'SID[id]' => '[id]:' . t('The Chado feature_id'),
  353. 'feature' => 'feature:' . t('Chado table name'),
  354. '[genus]' => '[genus]:' . t('Genus to which the feature belongs'),
  355. '[species]' => '[species]:' . t('Species to which the feature belongs'),
  356. '[type]' => '[type]:' . t('The type of feature'),
  357. '[uniquename]' => '[uniquename]:' . t('The feature unique name'),
  358. '[name]' => '[name]:' . t('The feature name'),
  359. 'reset' => t('Reset'),
  360. );
  361. $form['url']['chado_feature_url_string'] = array(
  362. '#title' => 'URL Syntax',
  363. '#type' => 'textfield',
  364. '#description' => t('You may rearrange elements in this text box to
  365. customize the URLs. The available tags include: [id],
  366. [uniquename]. [name], [species], [genus], [type]. You can separate or
  367. include any text between the tags. Click the "Set Feature URLs" button to
  368. reset the URLs for all feature pages. Click the "Save Configuration" button to
  369. simply save this setup. <b>Important</b>: be sure that whatever you choose will always be unique even considering
  370. future data that may be added. If you include the Chado table name, genus, species, type
  371. and uniquename you are guaranteed to have a unique URL. For example feature/[genus]/[species]/[type]/[uniquename]'),
  372. '#size' => 150,
  373. '#default_value' => variable_get('chado_feature_url_string', '/feature/[genus]/[species]/[type]/[uniquename]'),
  374. );
  375. $form['url']['chado_feature_url'] = array(
  376. '#title' => t('URL components'),
  377. '#type' => 'checkboxes',
  378. '#required' => FALSE,
  379. '#options' => $options,
  380. '#description' => t('Click the item above to make it appear in the URL Syntax box'),
  381. '#attributes' => array(
  382. 'onclick' => '
  383. box = $(\'#edit-chado-feature-url-string\');
  384. if (this.value == \'reset\') {
  385. box.val(\'\');
  386. }
  387. else {
  388. box.val(box.val() + "/" + this.value);
  389. }
  390. this.checked = false;
  391. ',
  392. ),
  393. );
  394. $form['url']['button'] = array(
  395. '#type' => 'submit',
  396. '#value' => t('Set Feature URLs'),
  397. );
  398. }
  399. /**
  400. *
  401. *
  402. * @ingroup tripal_feature
  403. */
  404. function tripal_features_set_taxonomy($max_sync = 0, $job_id = NULL) {
  405. // make sure our vocabularies are cleaned and reset before proceeding
  406. tripal_feature_del_vocabulary();
  407. tripal_feature_set_vocabulary();
  408. // iterate through all drupal feature nodes and set the taxonomy
  409. $results = db_query("SELECT * FROM {chado_feature}");
  410. $nsql = "
  411. SELECT * FROM {node}
  412. WHERE nid = :nid
  413. ";
  414. $i = 0;
  415. // load into ids array
  416. $count = 0;
  417. $chado_features = array();
  418. while ($chado_feature = $results->fetchObject()) {
  419. $chado_features[$count] = $chado_feature;
  420. $count++;
  421. }
  422. // Iterate through features that need to be synced
  423. $interval = intval($count * 0.01);
  424. foreach ($chado_features as $chado_feature) {
  425. // update the job status every 1% features
  426. if ($job_id and $i % $interval == 0) {
  427. tripal_job_set_progress($job_id, intval(($i/$count)*100));
  428. }
  429. print "$i of $count: ";
  430. $node = db_query($nsql, array(':nid' => $chado_feature->nid))->fetchObject();
  431. tripal_feature_set_taxonomy($node, $chado_feature->feature_id);
  432. $i++;
  433. }
  434. }
  435. /**
  436. *
  437. *
  438. * @ingroup tripal_feature
  439. */
  440. function tripal_feature_set_taxonomy($node, $feature_id) {
  441. // iterate through the taxonomy classes that have been
  442. // selected by the admin user and make sure we only set those
  443. $tax_classes = variable_get('tax_classes', array());
  444. $do_ft = 0;
  445. $do_op = 0;
  446. $do_lb = 0;
  447. $do_an = 0;
  448. foreach ($tax_classes as $class) {
  449. if (strcmp($class , 'organism')==0) {
  450. $do_op = 1;
  451. }
  452. if (strcmp($class, 'feature_type')==0) {
  453. $do_ft = 1;
  454. }
  455. if (strcmp($class, 'library')==0) {
  456. $do_lb = 1;
  457. }
  458. if (strcmp($class, 'analysis')==0) {
  459. $do_an = 1;
  460. }
  461. }
  462. // get the list of vocabularies and find our two vocabularies of interest
  463. $vocabularies = taxonomy_get_vocabularies();
  464. $ft_vid = NULL;
  465. $op_vid = NULL;
  466. $lb_vid = NULL;
  467. $an_vid = NULL;
  468. foreach ($vocabularies as $vocab) {
  469. if ($vocab->name == 'Feature Type') {
  470. $ft_vid = $vocab->vid;
  471. }
  472. if ($vocab->name == 'Organism') {
  473. $op_vid = $vocab->vid;
  474. }
  475. if ($vocab->name == 'Library') {
  476. $lb_vid = $vocab->vid;
  477. }
  478. if ($vocab->name == 'Analysis') {
  479. $an_vid = $vocab->vid;
  480. }
  481. }
  482. // get the cvterm and the organism for this feature
  483. $sql = "
  484. SELECT CVT.name AS cvname, O.genus, O.species
  485. FROM {cvterm} CVT
  486. INNER JOIN {feature} F on F.type_id = CVT.cvterm_id
  487. INNER JOIN {organism} O ON F.organism_id = O.organism_id
  488. WHERE F.feature_id = :feature_id
  489. ";
  490. $feature = chado_query($sql, array(':feature_id' => $feature_id))->fetchObject();
  491. // Set the feature type for this feature
  492. if ($do_ft && $ft_vid) {
  493. $tags["$ft_vid"] = "$feature->cvname";
  494. }
  495. // Set the organism for this feature type
  496. if ($do_op && $op_vid) {
  497. $tags["$op_vid"] = "$feature->genus $feature->species";
  498. }
  499. // get the library that this feature may belong to and add it as taxonomy
  500. if ($do_lb && $lb_vid) {
  501. $sql = "
  502. SELECT L.name
  503. FROM {Library} L
  504. INNER JOIN {Library_feature} LF ON LF.library_id = L.library_id
  505. WHERE LF.feature_id = :feature_id
  506. ";
  507. $library = chado_query($sql, array(':feature_id' => $feature_id))->fetchObject();
  508. $tags["$lb_vid"] = "$library->name";
  509. }
  510. // now add the taxonomy to the node
  511. $terms['tags'] = $tags;
  512. taxonomy_node_save($node, $terms);
  513. // print "Setting $node->name: " . implode(", ",$tags) . "\n";
  514. // get the analysis that this feature may belong to and add it as taxonomy
  515. // We'll add each one individually since there may be more than one analysis
  516. if ($do_an && $an_vid) {
  517. $sql = "
  518. SELECT A.name
  519. FROM {Analysis} A
  520. INNER JOIN {analysisfeature} AF ON AF.analysis_id = A.analysis_id
  521. WHERE AF.feature_id = :feature_id
  522. ";
  523. $results = chado_query($sql, array(':feature_id' => $feature_id));
  524. $analysis_terms = array();
  525. while ($analysis = $results->fetchObject()) {
  526. $tags2["$an_vid"] = "$analysis->name";
  527. $terms['tags'] = $tags2;
  528. taxonomy_node_save($node, $terms);
  529. }
  530. }
  531. }
  532. /**
  533. *
  534. * Remove orphaned drupal nodes
  535. *
  536. * @param $dummy
  537. * Not Used -kept for backwards compatibility
  538. * @param $job_id
  539. * The id of the tripal job executing this function
  540. *
  541. * @ingroup tripal_feature
  542. */
  543. function tripal_features_cleanup($dummy = NULL, $job_id = NULL) {
  544. return tripal_core_clean_orphaned_nodes('feature', $job_id);
  545. }
  546. /**
  547. * This function is an extension of the chado_feature_view by providing
  548. * the markup for the feature object THAT WILL BE INDEXED.
  549. *
  550. * @ingroup tripal_feature
  551. */
  552. function theme_tripal_feature_search_index($node) {
  553. $feature = $node->feature;
  554. $content = '';
  555. // get the accession prefix
  556. $aprefix = variable_get('chado_feature_accession_prefix', 'FID');
  557. $content .= "<h1>$feature->uniquename</h1>. ";
  558. $content .= "<strong>$aprefix$feature->feature_id.</strong> ";
  559. $content .= "$feature->cvname ";
  560. $content .= "$feature->common_name ";
  561. // add the synonyms of this feature to the text for searching
  562. $synonyms = $node->synonyms;
  563. if (count($synonyms) > 0) {
  564. foreach ($synonyms as $result) {
  565. $content .= "$result->name ";
  566. }
  567. }
  568. return $content;
  569. }
  570. /**
  571. * This function is an extension of the chado_feature_view by providing
  572. * the markup for the feature object THAT WILL BE INDEXED.
  573. *
  574. * @ingroup tripal_feature
  575. */
  576. function theme_tripal_feature_search_results($node) {
  577. $feature = $node->feature;
  578. $content = '';
  579. // get the accession prefix
  580. $aprefix = variable_get('chado_feature_accession_prefix', 'FID');
  581. $content .= "Feature Name: <h1>$feature->uniquename</h1>. ";
  582. $content .= "<strong>Accession: $aprefix$feature->feature_id.</strong>";
  583. $content .= "Type: $feature->cvname. ";
  584. $content .= "Organism: $feature->common_name. ";
  585. // add the synonyms of this feature to the text for searching
  586. $synonyms = $node->synonyms;
  587. if (count($synonyms) > 0) {
  588. $content .= "Synonyms: ";
  589. foreach ($synonyms as $result) {
  590. $content .= "$result->name, ";
  591. }
  592. }
  593. return $content;
  594. }
  595. /**
  596. *
  597. *
  598. * @ingroup tripal_feature
  599. */
  600. function tripal_feature_set_vocabulary() {
  601. //include the file containing the required functions for adding taxonomy vocabs
  602. module_load_include('inc', 'taxonomy', 'taxonomy.admin');
  603. // get the vocabularies so that we make sure we don't recreate
  604. // the vocabs that already exist
  605. $vocabularies = taxonomy_get_vocabularies();
  606. $ft_vid = NULL;
  607. $op_vid = NULL;
  608. $lb_vid = NULL;
  609. $an_vid = NULL;
  610. // These taxonomic terms are hard coded because we
  611. // konw we have these relationships in the chado tables
  612. // through foreign key relationships. The tripal
  613. // modules that correspond to these chado "modules" don't
  614. // need to be installed for the taxonomy to work.
  615. foreach ($vocabularies as $vocab) {
  616. if ($vocab->name == 'Feature Type') {
  617. $ft_vid = $vocab->vid;
  618. }
  619. if ($vocab->name == 'Organism') {
  620. $op_vid = $vocab->vid;
  621. }
  622. if ($vocab->name == 'Library') {
  623. $lb_vid = $vocab->vid;
  624. }
  625. if ($vocab->name == 'Analysis') {
  626. $an_vid = $vocab->vid;
  627. }
  628. }
  629. if (!$ft_vid) {
  630. $form_state = array();
  631. $values = array(
  632. 'name' => t('Feature Type'),
  633. 'nodes' => array('chado_feature' => 'chado_feature'),
  634. 'description' => t('The feature type (or SO cvterm for this feature).'),
  635. 'help' => t('Select the term that matches the feature'),
  636. 'tags' => 0,
  637. 'hierarchy' => 1,
  638. 'relations' => 1,
  639. 'multiple' => 0,
  640. 'required' => 0,
  641. 'weight' => 1,
  642. );
  643. drupal_form_submit('taxonomy_form_vocabulary', $form_state, $values);
  644. drupal_form_submit('taxonomy_form_vocabulary', $form_state);
  645. }
  646. if (!$op_vid) {
  647. $form_state = array();
  648. $values = array(
  649. 'name' => t('Organism'),
  650. 'nodes' => array('chado_feature' => 'chado_feature'),
  651. 'description' => t('The organism to which this feature belongs.'),
  652. 'help' => t('Select the term that matches the feature'),
  653. 'tags' => 0,
  654. 'hierarchy' => 1,
  655. 'relations' => 1,
  656. 'multiple' => 0,
  657. 'required' => 0,
  658. 'weight' => 2,
  659. );
  660. drupal_form_submit('taxonomy_form_vocabulary', $form_state, $values);
  661. drupal_form_submit('taxonomy_form_vocabulary', $form_state);
  662. }
  663. if (!$lb_vid) {
  664. $form_state = array();
  665. $values = array(
  666. 'name' => t('Library'),
  667. 'nodes' => array('chado_feature' => 'chado_feature'),
  668. 'description' => t('Chado features associated with a library are assigned the term associated with the library'),
  669. 'help' => t('Select the term that matches the feature'),
  670. 'tags' => 0,
  671. 'hierarchy' => 1,
  672. 'relations' => 1,
  673. 'multiple' => 0,
  674. 'required' => 0,
  675. 'weight' => 3,
  676. );
  677. drupal_form_submit('taxonomy_form_vocabulary', $form_state, $values);
  678. drupal_form_submit('taxonomy_form_vocabulary', $form_state);
  679. }
  680. if (!$an_vid) {
  681. $form_state = array();
  682. $values = array(
  683. 'name' => t('Analysis'),
  684. 'nodes' => array('chado_feature' => 'chado_feature'),
  685. 'description' => t('Any analysis to which this feature belongs.'),
  686. 'help' => t('Select the term that matches the feature'),
  687. 'tags' => 0,
  688. 'hierarchy' => 1,
  689. 'relations' => 1,
  690. 'multiple' => 1,
  691. 'required' => 0,
  692. 'weight' => 4,
  693. );
  694. drupal_form_submit('taxonomy_form_vocabulary', $form_state, $values);
  695. drupal_form_submit('taxonomy_form_vocabulary', $form_state);
  696. }
  697. }