tripal_analysis_kegg.module 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. <?php
  2. /*******************************************************************************
  3. *
  4. ******************************************************************************/
  5. function tripal_analysis_kegg_init(){
  6. // add the tripal_analysis_kegg JS and CSS
  7. drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_analysis_kegg.js');
  8. drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_analysis_kegg.css');
  9. // add the jsTree JS and CSS
  10. drupal_add_css(drupal_get_path('theme', 'tripal').'/js/jsTree/source/tree_component.css');
  11. drupal_add_js (drupal_get_path('theme', 'tripal').'/js/jsTree/source/_lib.js');
  12. drupal_add_js (drupal_get_path('theme', 'tripal').'/js/jsTree/source/tree_component.js');
  13. }
  14. /*******************************************************************************
  15. * Provide information to drupal about the node types that we're creating
  16. * in this module
  17. */
  18. function tripal_analysis_kegg_node_info() {
  19. $nodes = array();
  20. $nodes['chado_analysis_kegg'] = array(
  21. 'name' => t('Analysis: KEGG'),
  22. 'module' => 'chado_analysis_kegg',
  23. 'description' => t('Results from a KEGG/KAAS analysis'),
  24. 'has_title' => FALSE,
  25. 'title_label' => t('Analysis: KEGG'),
  26. 'has_body' => FALSE,
  27. 'body_label' => t('KEGG Analysis Description'),
  28. 'locked' => TRUE
  29. );
  30. return $nodes;
  31. }
  32. /*******************************************************************************
  33. * Menu items are automatically added for the new node types created
  34. * by this module to the 'Create Content' Navigation menu item. This function
  35. * adds more menu items needed for this module.
  36. */
  37. function tripal_analysis_kegg_menu() {
  38. $items['brite/%'] = array(
  39. 'title' => t('KEGG BRITE'),
  40. 'page callback' => 'tripal_analysis_kegg_brite',
  41. 'page arguments' => array(1, 2),
  42. 'access arguments' => array('access content'),
  43. 'type' => MENU_CALLBACK
  44. );
  45. $items['tripal_analysis_kegg_org_report/%'] = array(
  46. 'path' => 'tripal_analysis_kegg_org_report',
  47. 'title' => t('Analysis KEGG report'),
  48. 'page callback' => 'tripal_analysis_kegg_org_report',
  49. 'page arguments' => array(1),
  50. 'access arguments' => array('access chado_analysis_kegg content'),
  51. 'type' => MENU_CALLBACK
  52. );
  53. return $items;
  54. }
  55. /*******************************************************************************
  56. * Set the permission types that the chado module uses. Essentially we
  57. * want permissionis that protect creation, editing and deleting of chado
  58. * data objects
  59. */
  60. function tripal_analysis_kegg_perm(){
  61. return array(
  62. 'access chado_analysis_kegg content',
  63. 'create chado_analysis_kegg content',
  64. 'delete chado_analysis_kegg content',
  65. 'edit chado_analysis_kegg content',
  66. );
  67. }
  68. /*******************************************************************************
  69. * The following function proves access control for users trying to
  70. * perform actions on data managed by this module
  71. */
  72. function chado_analysis_kegg_access($op, $node, $account){
  73. if ($op == 'create') {
  74. return user_access('create chado_analysis_kegg content', $account);
  75. }
  76. if ($op == 'update') {
  77. if (user_access('edit chado_analysis_kegg content', $account)) {
  78. return TRUE;
  79. }
  80. }
  81. if ($op == 'delete') {
  82. if (user_access('delete chado_analysis_kegg content', $account)) {
  83. return TRUE;
  84. }
  85. }
  86. if ($op == 'view') {
  87. if (user_access('access chado_analysis_kegg content', $account)) {
  88. return TRUE;
  89. }
  90. }
  91. return FALSE;
  92. }
  93. /*******************************************************************************
  94. */
  95. function tripal_analysis_kegg_brite($analysis_id, $type_id, $ajax){
  96. // If not called by ajax
  97. if (!$ajax) {
  98. $content .=
  99. "<div id=\"tripal_kegg_brite_results\" class=\"tripal_kegg_brite-info-box\">
  100. <table>
  101. <tr>
  102. <th>KEGG BRITE</th>
  103. <th id=\"tripal_kegg_brite_header\">Hierarchy:</th>
  104. </tr>
  105. <tr>
  106. <td nowrap valign=\"top\">
  107. ";
  108. // List all BRITE terms on the left
  109. $sql = "SELECT DISTINCT CVT.name, CVT.cvterm_id
  110. FROM {cvterm} CVT
  111. INNER JOIN analysisprop AP ON CVT.cvterm_id = AP.type_id
  112. WHERE AP.analysis_id = %d AND CVT.definition LIKE 'KEGG BRITE term: %'
  113. ORDER BY CVT.cvterm_id";
  114. $previous_db = tripal_db_set_active('chado');
  115. $result = db_query($sql, $analysis_id);
  116. tripal_db_set_active($previous_db);
  117. while ($brite_term = db_fetch_object($result)) {
  118. $url = url("brite/$analysis_id/$brite_term->cvterm_id/1");
  119. $content .= "<li class=\"tripal_kegg_brite_terms\"><a onclick=\"return tripal_update_brite(".
  120. "this,$brite_term->cvterm_id)\" href=\"$url\">
  121. $brite_term->name
  122. </a></li>";
  123. }
  124. // Show the hierarchy tree
  125. $content .="</td>
  126. <td nowrap id=\"tripal_kegg_brite_hierarchy\" valign=\"top\">";
  127. $content .= "<i>Note:</i> Click a BRITE term for its functional hierarchy";
  128. // If called by ajax, generate tree structure
  129. } else {
  130. // Get BRITE term from cvterm table
  131. $previous_db = tripal_db_set_active('chado');
  132. $sql = 'SELECT name FROM {cvterm} WHERE cvterm_id=%d';
  133. $brite_term = db_result(db_query($sql, $type_id));
  134. // Get BRITE hierarchy tree
  135. $sql = "SELECT value
  136. FROM {analysisprop} AP
  137. INNER JOIN CVterm CVT on AP.type_id = CVT.cvterm_id
  138. INNER JOIN CV on CVT.cv_id = CV.cv_id
  139. WHERE CV.name = 'tripal' and CVT.name = '%s'
  140. AND AP.analysis_id = %d";
  141. $result = db_fetch_object(db_query($sql, $brite_term, $analysis_id));
  142. tripal_db_set_active($previous_db);
  143. $content .= "<div class=\"tripal_kegg_brite_tree\" id=\"tripal_kegg_brite_tree_$type_id\">$result->value</div>";
  144. }
  145. if (!$ajax) {
  146. $content .= " </td>
  147. </tr>
  148. </table>
  149. </div>";
  150. }
  151. // since this function provides output for addition into
  152. // an analysis page, as well as an AJAX refresh of content
  153. // within the BRITE hierarchy we need to setup the return
  154. // different depending on the request type
  155. if($ajax){
  156. drupal_json(array('update' => $content,
  157. 'id' => "tripal_kegg_brite_tree_$type_id",
  158. 'brite_term' => "Hierarchy: $brite_term"));
  159. } else {
  160. return $content;
  161. }
  162. }
  163. /*******************************************************************************
  164. * Provide a KEGG Analysis form
  165. */
  166. function chado_analysis_kegg_form ($node){
  167. // add in the default fields
  168. $form = chado_analysis_form($node);
  169. // set the defaults
  170. $kegg = $node->analysis->tripal_analysis_kegg;
  171. $query_re = $kegg->query_re;
  172. $query_type = $kegg->query_type;
  173. $query_uniquename = $kegg->query_uniquename;
  174. $hierfile = $kegg->hierfile;
  175. $moreSettings ['kegg'] = 'KEGG Analysis Settings';
  176. $form['kegg'] = array(
  177. '#title' => t('KEGG Settings'),
  178. '#type' => 'fieldset',
  179. '#description' => t('Specific Settings for KEGG Analysis.'),
  180. '#collapsible' => TRUE,
  181. '#attributes' => array('id' => 'kegg-extra-settings'),
  182. '#weight' => 11
  183. );
  184. $form['kegg']['hierfile'] = array(
  185. '#title' => t('KAAS hier.tar.gz Output File'),
  186. '#type' => 'textfield',
  187. '#description' => t('The full path to the hier.tar.gz file generated by KAAS.
  188. Alternatively, you can input the full path to the directory
  189. that contains decompressed kegg files.'),
  190. '#default_value' => $hierfile,
  191. );
  192. $form['kegg']['query_re'] = array(
  193. '#title' => t('Query Name RE'),
  194. '#type' => 'textfield',
  195. '#description' => t('Enter the regular expression that will extract the '.
  196. 'feature name from the results line in the KEGG heir results. This will be '.
  197. 'the same as the definition line in the query FASTA file used for the analysis. This option is '.
  198. 'is only required when the query does not identically match a feature '.
  199. 'in the database.'),
  200. '#default_value' => $query_re,
  201. );
  202. $form['kegg']['query_type'] = array(
  203. '#title' => t('Query Type'),
  204. '#type' => 'textfield',
  205. '#description' => t('Please enter the Sequence Ontology term that describes '.
  206. 'the query sequences used for KEGG. This is only necessary if two '.
  207. 'or more sequences have the same name.'),
  208. '#default_value' => $query_type,
  209. );
  210. $form['kegg']['query_uniquename'] = array(
  211. '#title' => t('Use Unique Name'),
  212. '#type' => 'checkbox',
  213. '#description' => t('Select this checboxk if the feature name in the KEGG heir file '.
  214. 'matches the uniquename in the database. By default, the feature will '.
  215. 'be mapped to the "name" of the feature.'),
  216. '#default_value' => $query_uniquename,
  217. );
  218. $form['kegg']['keggjob'] = array(
  219. '#type' => 'checkbox',
  220. '#title' => t('Submit a job to parse the kegg output into analysisfeatureprop table'),
  221. '#description' => t('Note: features associated with the KAAS results must '.
  222. 'exist in chado before parsing the file. Otherwise, KEGG '.
  223. 'results that cannot be linked to a feature will be '.
  224. 'discarded.'),
  225. );
  226. $form['kegg']['keggkeywordjob'] = array(
  227. '#type' => 'checkbox',
  228. '#title' => t('Submit a job to extract keywords from the KEGG html output'),
  229. '#description' => t('Note: KEGG results are only searchable after keywords are extracted. Do not run this twice if you have already done so.'),
  230. );
  231. return $form;
  232. }
  233. /*******************************************************************************
  234. *
  235. */
  236. function chado_analysis_kegg_insert($node){
  237. // insert the analysis
  238. chado_analysis_insert($node);
  239. // set the type for this analysis
  240. tripal_analysis_insert_property($node->analysis_id,'analysis_type','tripal_analysis_kegg');
  241. // now add in the remaining settings as a single property but separated by bars
  242. tripal_analysis_insert_property($node->analysis_id,'analysis_kegg_settings',$node->hierfile);
  243. tripal_analysis_insert_property($node->analysis_id,'analysis_kegg_query_re',$node->query_re);
  244. tripal_analysis_insert_property($node->analysis_id,'analysis_kegg_query_type',$node->query_type);
  245. tripal_analysis_insert_property($node->analysis_id,'analysis_kegg_query_uniquename',$node->query_uniquename);
  246. // Add a job if the user wants to parse the html output
  247. chado_analysis_kegg_submit_job($node);
  248. }
  249. /**
  250. *
  251. */
  252. function chado_analysis_kegg_submit_job($node){
  253. global $user;
  254. if($node->keggjob) {
  255. $job_args[0] = $node->analysis_id;
  256. $job_args[1] = $node->hierfile;
  257. $job_args[2] = base_path();
  258. $job_args[3] = $node->query_re;
  259. $job_args[4] = $node->query_type;
  260. $job_args[5] = $node->query_uniquename;
  261. if (is_readable($node->hierfile)) {
  262. $fname = preg_replace("/.*\/(.*)/", "$1", $node->hierfile);
  263. tripal_add_job("Parse KAAS output: $fname",'tripal_analysis_kegg',
  264. 'tripal_analysis_kegg_parseHierFile', $job_args, $user->uid);
  265. } else {
  266. drupal_set_message("Can not open KAAS hier.tar.gz output file. Job not scheduled.");
  267. }
  268. }
  269. // Add a job if the user wants to the keywords from the HTML output
  270. if ($node->keggkeywordjob) {
  271. $analysis_id =chado_get_id_for_node('analysis', $node);
  272. $job_args[0] = $analysis_id;
  273. tripal_add_job("Extract keywords for search: $node->analysisname",'tripal_analysis_kegg',
  274. 'tripal_analysis_kegg_extract_keywords', $job_args, $user->uid);
  275. }
  276. }
  277. /*******************************************************************************
  278. * Delete KEGG anlysis
  279. */
  280. function chado_analysis_kegg_delete($node){
  281. chado_analysis_delete($node);
  282. }
  283. /*******************************************************************************
  284. * Update KEGG analysis
  285. */
  286. function chado_analysis_kegg_update($node){
  287. // insert the analysis
  288. chado_analysis_update($node);
  289. // set the type for this analysis
  290. tripal_analysis_update_property($node->analysis_id,'analysis_type','tripal_analysis_kegg',1);
  291. // now add in the remaining settings as a single property but separated by bars
  292. tripal_analysis_update_property($node->analysis_id,'analysis_kegg_settings',$node->hierfile,1);
  293. tripal_analysis_update_property($node->analysis_id,'analysis_kegg_query_re',$node->query_re,1);
  294. tripal_analysis_update_property($node->analysis_id,'analysis_kegg_query_type',$node->query_type,1);
  295. tripal_analysis_update_property($node->analysis_id,'analysis_kegg_query_uniquename',$node->query_uniquename,1);
  296. // Add a job if the user wants to parse the html output
  297. chado_analysis_kegg_submit_job($node);
  298. }
  299. /*******************************************************************************
  300. * When a node is requested by the user this function is called to allow us
  301. * to add auxiliary data to the node object.
  302. */
  303. function chado_analysis_kegg_load($node){
  304. // load the default set of analysis fields
  305. $additions = chado_analysis_load($node);
  306. // create some variables for easier lookup
  307. $analysis = $additions->analysis;
  308. $analysis_id = $analysis->analysis_id;
  309. // get the heirfile name
  310. $hierfile = tripal_analysis_get_property($analysis_id,'analysis_kegg_settings');
  311. $query_re = tripal_analysis_get_property($analysis->analysis_id,'analysis_kegg_query_re');
  312. $query_type = tripal_analysis_get_property($analysis->analysis_id,'analysis_kegg_query_type');
  313. $query_uniquename= tripal_analysis_get_property($analysis->analysis_id,'analysis_kegg_query_uniquename');
  314. $analysis->tripal_analysis_kegg->hierfile = $hierfile->value;
  315. $analysis->tripal_analysis_kegg->query_re = $query_re->value;
  316. $analysis->tripal_analysis_kegg->query_type = $query_type->value;
  317. $analysis->tripal_analysis_kegg->query_uniquename= $query_uniquename->value;
  318. return $additions;
  319. }
  320. /**
  321. *
  322. */
  323. function chado_analysis_kegg_view ($node, $teaser = FALSE, $page = FALSE) {
  324. // use drupal's default node view:
  325. if (!$teaser) {
  326. $node = node_prepare($node, $teaser);
  327. // When previewing a node submitting form, it shows 'Array' instead of
  328. // correct date format. We need to format the date here
  329. $time = $node->timeexecuted;
  330. if(is_array($time)){
  331. $month = $time['month'];
  332. $day = $time['day'];
  333. $year = $time['year'];
  334. $timestamp = $year.'-'.$month.'-'.$day;
  335. $node->timeexecuted = $timestamp;
  336. }
  337. }
  338. return $node;
  339. }
  340. /********************************************************************************
  341. */
  342. function tripal_analysis_kegg_parseHierFile ($analysis_id, $hierfile, $base_path,
  343. $query_re,$query_type,$query_uniquename,$job_id) {
  344. // If user input a file (e.g. hier.tar.gz), decompress it first
  345. if (is_file($hierfile)) {
  346. // generate a unique directory name for extracting and parsing the file
  347. $data_dir = sys_get_temp_dir() . "/" . uniqid();
  348. mkdir($data_dir);
  349. $stderr = shell_exec("cd $data_dir; tar -zxf $hierfile;");
  350. print "$stderr\n";
  351. $hierdir = $data_dir . "/hier";
  352. }
  353. // Otherwise, treat it as a directory
  354. else {
  355. $hierdir = $hierfile;
  356. }
  357. $dir_handle = @opendir($hierdir) or die("Unable to open $hierdir");
  358. $total_files = count(glob($hierdir . '/*.*'));
  359. print "There are $total_files keg file(s).\n";
  360. $interval = intval($total_files * 0.01);
  361. $no_file = 0;
  362. // Remove the analysis feature this analysis
  363. // we will rebuild them from just this parsing
  364. $select = array('analysis_id' => $analysis_id);
  365. if(!tripal_core_chado_delete('analysisfeature',$select)){
  366. print "ERROR: Cannot prepare the analysis for adding features\n";
  367. exit;
  368. }
  369. while ($file = readdir($dir_handle)) {
  370. if(preg_match("/^.*\.keg/",$file)){
  371. // Update the progress
  372. if ($no_file % $interval == 0) {
  373. $percentage = (int) ($no_file / $total_files * 100);
  374. tripal_job_set_progress($job_id, $percentage);
  375. print $percentage."% ";
  376. }
  377. $no_file ++;
  378. # $heirarchy variable will be set in tripal_analysis_kegg_parse_kegg_file()
  379. $results = tripal_analysis_kegg_parse_kegg_file("$hierdir/$file",$heirarchy,
  380. $analysis_id, $base_path, $query_re,$query_type,$query_uniquename);
  381. # add the item to the database
  382. if(count($results) > 0){
  383. //------------------------------------------------------
  384. // Insert into analysisprop table
  385. //------------------------------------------------------
  386. // Remove the property if it already exists we'll replace it
  387. $sql = "DELETE
  388. FROM {analysisprop}
  389. WHERE analysis_id = %d
  390. AND type_id = (SELECT cvterm_id
  391. FROM {cvterm} CVT
  392. INNER JOIN CV ON CVT.cv_id = CV.cv_id
  393. WHERE CV.name = 'tripal' AND CVT.name = '%s'
  394. )
  395. ";
  396. $previous_db = tripal_db_set_active('chado');
  397. db_result(db_query($sql, $analysis_id, $heirarchy));
  398. tripal_db_set_active($previous_db);
  399. $previous_db = tripal_db_set_active('chado'); // Use chado database
  400. // Get type_id for the BRITE term
  401. $sql = "SELECT cvterm_id
  402. FROM {cvterm} CVT
  403. INNER JOIN CV ON CVT.cv_id = CV.cv_id
  404. WHERE CV.name = 'tripal' AND CVT.name = '%s'";
  405. $brite_cvterm_id = db_result(db_query($sql, $heirarchy));
  406. // convert the array to text for saving in the database
  407. // Replace all single quote as HTML code before insert
  408. $i = 0;
  409. $content = '<ul>';
  410. tripal_analysis_kegg_array2list($results,$content,$i);
  411. $content .= '</ul>';
  412. $content = preg_replace("/\'/", "&#39;", $content);
  413. // Insert the value
  414. $sql = "INSERT INTO {analysisprop} (analysis_id, type_id, value)
  415. VALUES (%d, %d,'$content')";
  416. db_query($sql, $analysis_id, $brite_cvterm_id);
  417. tripal_db_set_active($previous_db); // Use drupal database
  418. }
  419. }
  420. }
  421. print "Done.\n";
  422. tripal_job_set_progress($job_id,100);
  423. closedir($dir_handle);
  424. // If user input a file, remove decompressed files after parsing
  425. if (is_file($hierfile)) {
  426. $stderr = shell_exec("rm -r $data_dir;");
  427. print "$stderr\n";
  428. }
  429. return;
  430. }
  431. /**
  432. *
  433. */
  434. function tripal_analysis_kegg_array2list($array,&$content,&$i){
  435. foreach($array as $index => $item){
  436. if(is_array($item)){
  437. if(is_numeric($index)){
  438. tripal_analysis_kegg_array2list($item,$content,$i);
  439. } else {
  440. $content .= "<li id=\"term_$i\"><a></a>$index\n<ul>";
  441. $i++;
  442. tripal_analysis_kegg_array2list($item,$content,$i);
  443. $content .= "</ul>\n</li>\n";
  444. }
  445. } else {
  446. $content .= "<li id=\"term_$i\"><a></a>$item</li>\n";
  447. $i++;
  448. }
  449. }
  450. }
  451. /*******************************************************************************
  452. * Parse *.keg files.
  453. * Each file has a definition line. BRITE term is extracted * from this line
  454. * and added to chado as a cvterm. Tree structure for this cvterm is then
  455. * generated and saved to analysisfeature and analysisfeatureprop tables.
  456. */
  457. function tripal_analysis_kegg_parse_kegg_file ($file, &$heirarchy, $analysis_id,
  458. $base_path, $query_re, $query_type, $query_uniquename)
  459. {
  460. print "Parsing $file\n";
  461. // get the 'kegg_brite_data' cvterm
  462. $select = array('name' => 'kegg_brite_data',
  463. 'cv_id' => array('name' => 'tripal'));
  464. $bdt_arr = tripal_core_chado_select('cvterm',array('cvterm_id'),$select);
  465. $brite_id = $bdt_arr[0]->cvterm_id;
  466. $filepos = 0;
  467. // iterate through the lines of the file and recurse through the various levels
  468. $handle = fopen($file,'r');
  469. while($line = fgets($handle)){
  470. $filepos += strlen($line);
  471. $line = trim($line);
  472. // the first line of the file provides the BRITE heirarchy name
  473. if(preg_match("/#.*nbsp;\s(.*)<\/h2>$/",$line,$matches)){
  474. // For each BRITE heirarchy file we'll add an analysisprop where we'll
  475. // store the report. If the CVTerm doesn't exist then add it.
  476. $heirarchy = $matches[1];
  477. $select = array('name' => $heirarchy,'cv_id' => array('name' => 'tripal'));
  478. $cvt_arr = tripal_core_chado_select('cvterm',array('cvterm_id'),$select);
  479. if (count($cvt_arr) == 0) {
  480. tripal_add_cvterms($type, "KEGG BRITE term: $type");
  481. $cvt_arr = tripal_core_chado_select('cvterm',array('cvterm_id'),$select);
  482. }
  483. $heirarchy_id = $cvt_arr[0]->cvterm_id;
  484. // now that we have the file type we can recurse
  485. $next = tripal_analysis_kegg_get_next_line($handle,$filepos);
  486. $results = tripal_analysis_kegg_recurse_heir($handle,$next,$query_re,
  487. $query_type,$query_uniquename,$base_path,$analysis_id,
  488. $brite_id,$heirarchy,$filepos);
  489. }
  490. }
  491. fclose($handle);
  492. return $results;
  493. }
  494. /**
  495. *
  496. */
  497. function tripal_analysis_kegg_recurse_heir($handle, $line,$query_re,
  498. $query_type, $query_uniquename, $base_path, $analysis_id, $brite_id,
  499. $heirarchy,&$filepos)
  500. {
  501. $results = array();
  502. // get the current level and the value
  503. $level = $line[0];
  504. $value = $line[1];
  505. // now get the next line to see what is coming next. If the
  506. // next level is greater then recurse immediately.
  507. $prevpos = $filepos;
  508. while($next = tripal_analysis_kegg_get_next_line($handle,$filepos)){
  509. $next_level = $next[0];
  510. $next_value = $next[1];
  511. // check this line to see if it has a feature we need to keep
  512. $ret = tripal_analysis_kegg_check_line_handle_feature($query_re,
  513. $query_type, $query_uniquename, $base_path, $analysis_id, $brite_id,
  514. $heirarchy,$value);
  515. if($ret){
  516. $results[] = $ret;
  517. }
  518. // if we're going up a level then recurse immediately and add results to our array
  519. if(ord($next_level) > ord($level)){
  520. // now recurse
  521. $ret = tripal_analysis_kegg_recurse_heir($handle,$next,
  522. $query_re,$query_type, $query_uniquename, $base_path, $analysis_id,
  523. $brite_id,$heirarchy,$filepos);
  524. if(count($ret) > 0){
  525. $results[][$value] = $ret;
  526. }
  527. }
  528. // if we go down a level on the next line then reset the
  529. // filepointer and return
  530. elseif(ord($next_level) < ord($level)){
  531. fseek($handle,$prevpos);
  532. $filepos = $prevpos;
  533. return $results;
  534. }
  535. else {
  536. $line = $next;
  537. $level = $next[0];
  538. $value = $next[1];
  539. }
  540. $prevpos = $filepos;
  541. }
  542. return $results;
  543. }
  544. /**
  545. *
  546. */
  547. function tripal_analysis_kegg_get_next_line($handle,&$filepos){
  548. $good = 0;
  549. // get the next line in the file
  550. $line = fgets($handle);
  551. $filepos += strlen($line);
  552. // we hit the end of the file, so exit with a null
  553. if(!$line){
  554. return null;
  555. }
  556. while(!$good){
  557. $line = trim($line);
  558. preg_match("/^([ABCDEFGHIJKLMNOP])\s*(.*)/",$line,$matches);
  559. $level = $matches[1];
  560. $value = $matches[2];
  561. // skip lines that aren't data or are empty
  562. if($level and $value) {
  563. // change all relative paths to absolute paths pointing to KEGG (www.genome.jp)
  564. // add id to <a> tags so we can link kegg.gif to it in tripal_analysis_kegg.css
  565. $value = preg_replace("/<a href=\"\//i","<a href=\"http://www.genome.jp/",$value);
  566. $value = preg_replace("/<a href=\"/i","<a id=\"tripal_kegg_brite_links\" target=\"_blank\" href=\"",$value);
  567. // this line is good so let's exit out
  568. $good = 1;
  569. } else {
  570. $line = fgets($handle);
  571. $filepos += strlen($line);
  572. // we hit the end of the file, so exit with a null
  573. if(!$line){
  574. return null;
  575. }
  576. }
  577. }
  578. return array($level,$value);
  579. }
  580. /**
  581. *
  582. */
  583. function tripal_analysis_kegg_check_line_handle_feature($query_re,
  584. $query_type, $query_uniquename, $base_path, $analysis_id, $brite_id,
  585. $heirarchy,$value)
  586. {
  587. // extract the features that have been mapped to the KEGG IDs
  588. if(preg_match("/^(.*?);\s*(\<a.+)/",$value,$matches)){
  589. $has_feature = 1;
  590. $fname = $matches[1];
  591. $keggterm = $matches[2];
  592. // get the feature name using the user's regular expression
  593. if ($query_re and preg_match("/$query_re/", $fname, $matches)) {
  594. $feature = $matches[1];
  595. }
  596. // If not in above format then pull up to the first space
  597. else {
  598. if (preg_match('/^(.*?)\s.*$/', $fname, $matches)) {
  599. $feature = $matches[1];
  600. }
  601. // if no match up to the first space then just use the entire string
  602. else {
  603. $feature = $fname;
  604. }
  605. }
  606. // now find the feature in chado
  607. $select = array();
  608. if($query_uniquename){
  609. $select['uniquename'] = $feature;
  610. } else {
  611. $select['name'] = $feature;
  612. }
  613. if($query_type){
  614. $select['type_id'] = array(
  615. 'cv_id' => array(
  616. 'name' => 'sequence'
  617. ),
  618. 'name' => $query_type,
  619. );
  620. }
  621. $feature_arr = tripal_core_chado_select('feature',array('feature_id'),$select);
  622. if(count($feature_arr) > 1){
  623. print "Ambiguous: '$feature' matches more than one feature and is being skipped.\n";
  624. continue;
  625. }
  626. if(count($feature_arr) == 0){
  627. print "Failed: '$feature' cannot find a matching feature in the database.\n";
  628. continue;
  629. }
  630. $feature_id = $feature_arr[0]->feature_id;
  631. if($feature_id){
  632. print "Adding KEGG term for $feature ($feature_id,$analysis_id). $heirarchy\n";
  633. // add this term to the analysis feature properties
  634. tripal_analysis_kegg_insert_featureprop($feature_id,$analysis_id,
  635. $brite_id,$keggterm);
  636. // get the node ID of the feature if one exists
  637. $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
  638. $nid = db_result(db_query($sql, $feature_id));
  639. // Add link to each matched feature
  640. if($nid){
  641. $value = preg_replace("/^(.*?)(;\s*\<a)/","<a id=\"tripal_kegg_feature_links\" target=\"_blank\" href=\"".url("node/$nid")."\">"."$1"."</a>"."$2",$value);
  642. }
  643. // if we have a feature match then add this to our results array
  644. return $value;
  645. }
  646. }
  647. return null;
  648. }
  649. /**
  650. *
  651. */
  652. function tripal_analysis_kegg_insert_featureprop ($feature_id, $analysis_id,
  653. $brite_id,$keggterm)
  654. {
  655. // add the analysisfeature record if it doesn't already exist.
  656. $values = array('feature_id' => $feature_id,'analysis_id' => $analysis_id);
  657. $analysisfeature_arr = tripal_core_chado_select('analysisfeature',
  658. array('analysisfeature_id'),$values);
  659. if(count($analysisfeature_arr) == 0){
  660. tripal_core_chado_insert('analysisfeature',$values);
  661. $analysisfeature_arr = tripal_core_chado_select('analysisfeature',
  662. array('analysisfeature_id'),$values);
  663. }
  664. $analysisfeature_id = $analysisfeature_arr[0]->analysisfeature_id;
  665. // Insert into analysisfeatureprop if the value doesn't already exist
  666. // KEGG heir results sometimes have the same record more than once.
  667. if($analysisfeature_id){
  668. // Get the highest rank for this feature_id in analysisfeatureprop table
  669. $sql = "SELECT rank FROM analysisfeatureprop WHERE analysisfeature_id = %d and type_id = %d ORDER BY rank DESC";
  670. $previous_db = tripal_db_set_active('chado');
  671. $result = db_fetch_object(db_query($sql,$analysisfeature_id,$brite_id));
  672. tripal_db_set_active($previous);
  673. $rank = 0;
  674. if ($result and $result->rank > 0) {
  675. $rank = $result->rank + 1;
  676. }
  677. $values = array(
  678. 'analysisfeature_id' => $analysisfeature_id,
  679. 'type_id' => $brite_id,
  680. 'value' => $keggterm,
  681. 'rank' => $rank,
  682. );
  683. return tripal_core_chado_insert('analysisfeatureprop',$values);
  684. }
  685. else {
  686. return 0;
  687. }
  688. }
  689. /*******************************************************************************
  690. * HOOK: Implementation of hook_nodeapi()
  691. * Display library information for associated features or organisms
  692. * This function also provides contents for indexing
  693. */
  694. function tripal_analysis_kegg_nodeapi(&$node, $op, $teaser, $page) {
  695. switch ($op) {
  696. case 'view':
  697. // add the library to the organism/feature search indexing
  698. if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
  699. $node->content['tripal_analysis_kegg_search_index'] = array(
  700. '#value' => theme('tripal_analysis_kegg_search_index',$node),
  701. '#weight' => 6,
  702. );
  703. } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
  704. $node->content['tripal_analysis_kegg_search_result'] = array(
  705. '#value' => theme('tripal_analysis_kegg_search_result',$node),
  706. '#weight' => 6,
  707. );
  708. } else {
  709. switch($node->type){
  710. case 'chado_organism':
  711. // Show KEGG report on the analysis page
  712. $node->content['tripal_organism_kegg_summary'] = array(
  713. '#value' => theme('tripal_organism_kegg_summary', $node),
  714. );
  715. break;
  716. case 'chado_feature':
  717. // Show KEGG terms on a feature page
  718. $node->content['tripal_feature_kegg_terms'] = array(
  719. '#value' => theme('tripal_feature_kegg_terms', $node),
  720. );
  721. }
  722. }
  723. break;
  724. }
  725. }
  726. /************************************************************************
  727. * We need to let drupal know about our theme functions and their arguments.
  728. * We create theme functions to allow users of the module to customize the
  729. * look and feel of the output generated in this module
  730. */
  731. function tripal_analysis_kegg_theme () {
  732. return array(
  733. 'tripal_analysis_kegg_search_index' => array (
  734. 'arguments' => array('node'),
  735. ),
  736. 'tripal_analysis_kegg_search_result' => array (
  737. 'arguments' => array('node'),
  738. ),
  739. 'tripal_organism_kegg_summary' => array (
  740. 'arguments' => array('node'=> null),
  741. 'template' => 'tripal_organism_kegg_summary',
  742. ),
  743. 'tripal_feature_kegg_terms' => array (
  744. 'arguments' => array('node'=> null),
  745. 'template' => 'tripal_feature_kegg_terms',
  746. ),
  747. 'tripal_analysis_kegg_report' => array (
  748. 'arguments' => array('node'=> null),
  749. 'template' => 'tripal_analysis_kegg_report',
  750. ),
  751. );
  752. }
  753. /**
  754. *
  755. *
  756. * @ingroup tripal_analysis_kegg
  757. */
  758. function tripal_analysis_kegg_preprocess(&$variables){
  759. // if the template file is the default node template file then we want
  760. // to add all of our variables.
  761. if($variables['template_files'][0] == 'node-chado_analysis_kegg'){
  762. $analysis = $variables['node']->analysis;
  763. $report = tripal_analysis_kegg_full_report($analysis->analysis_id);
  764. $analysis->tripal_analysis_kegg->kegg_report = $report;
  765. }
  766. }
  767. /*******************************************************************************
  768. *
  769. */
  770. function tripal_analysis_kegg_preprocess_tripal_organism_kegg_summary(&$variables){
  771. $node = $variables['node'];
  772. $variables['tripal_analysis_kegg']['select_form'] = tripal_analysis_kegg_load_organism_kegg_summary($node);
  773. }
  774. /**
  775. *
  776. */
  777. function tripal_analysis_kegg_preprocess_tripal_feature_kegg_terms(&$variables){
  778. $node = $variables['node'];
  779. $feature = $node->feature;
  780. $variables['tripal_analysis_kegg']['results'] = tripal_analysis_kegg_load_feature_terms($feature);
  781. }
  782. /************************************************************************
  783. */
  784. function theme_tripal_analysis_kegg_search_index($node){
  785. if ($node->type == 'chado_feature') {
  786. // Find cvterm_id for 'kegg_brite_data'
  787. $sql = "SELECT cvterm_id
  788. FROM {cvterm} CVT
  789. INNER JOIN cv ON cv.cv_id = CVT.cv_id
  790. WHERE cv.name = 'tripal'
  791. AND CVT.name = '%s'";
  792. $previous_db = tripal_db_set_active('chado');
  793. $brite_id = db_result(db_query($sql, 'kegg_brite_data'));
  794. // Get analysis id
  795. $sql = "SELECT analysis_id AS aid
  796. FROM {analysisfeature} AF
  797. INNER JOIN analysisfeatureprop AFP ON AF.analysisfeature_id = AFP.analysisfeature_id
  798. WHERE feature_id = %d
  799. AND AFP.type_id = %d
  800. GROUP BY analysis_id";
  801. $feature = $node->feature;
  802. $feature_id = $feature->feature_id;
  803. $hasResult = db_result(db_query($sql, $feature_id, $brite_id));
  804. $result = db_query($sql, $feature->feature_id, $brite_id);
  805. // Show kegg result ORDER BY time
  806. if ($hasResult) { // If there is any result, show expandable box
  807. $content = "";
  808. while ($ana = db_fetch_object($result)) {
  809. // Show analysis date
  810. $sql = "SELECT name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
  811. FROM {analysis}
  812. WHERE analysis_id = %d";
  813. $ana_details = db_fetch_object(db_query($sql, $ana->aid));
  814. // Find node id for the analysis
  815. tripal_db_set_active($previous_db);
  816. $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $ana->aid));
  817. $ana_url = url("node/".$ana_nid);
  818. $previous_db = tripal_db_set_active('chado');
  819. // Show content
  820. $content .= "$ana_details->name";
  821. // Show Kegg results
  822. $sql = "SELECT AFP.value AS afpvalue
  823. FROM {analysisfeatureprop} AFP
  824. INNER JOIN analysisfeature AF on AF.analysisfeature_id = AFP.analysisfeature_id
  825. WHERE AF.analysis_id = %d
  826. AND AF.feature_id = %d
  827. ";
  828. $kegg_results = db_query($sql, $ana->aid, $feature_id);
  829. while ($afp = db_fetch_object($kegg_results)) {
  830. $content .= " $afp->afpvalue";
  831. }
  832. }
  833. }
  834. tripal_db_set_active($previous_db);
  835. return $content;
  836. }
  837. }
  838. /************************************************************************
  839. */
  840. function theme_tripal_analysis_kegg_search_result($node){
  841. $content = theme_tripal_analysis_kegg_node_add($node);
  842. return $content;
  843. }
  844. /************************************************************************
  845. */
  846. function tripal_analysis_kegg_load_organism_kegg_summary($node) {
  847. $organism = $node->organism;
  848. // find analyses that have KEGG terms
  849. $sql = "
  850. SELECT *
  851. FROM {kegg_by_organism} KBO
  852. WHERE organism_id = %d
  853. ORDER BY analysis_id DESC
  854. ";
  855. $previous_db = tripal_db_set_active('chado');
  856. $results = db_fetch_object(db_query($sql,$organism->organism_id));
  857. tripal_db_set_active($previous_db);
  858. $has_results = 0;
  859. if($results){
  860. $has_results = 1;
  861. }
  862. return array (
  863. 'has_results' => $has_results,
  864. 'form' => drupal_get_form('tripal_analysis_kegg_select_form',$node),
  865. );
  866. }
  867. /************************************************************************
  868. // Show Kegg additional information on a KEGG Analysis page
  869. if ($node->type == 'chado_analysis_kegg') {
  870. return tripal_analysis_kegg_full_report($node->analysis_id);
  871. }
  872. // Show Kegg-info-box on a Feature page
  873. else if ($node->type == 'chado_feature') {
  874. return tripal_analysis_kegg_feature_add($node);
  875. }
  876. return $content;
  877. }
  878. */
  879. function tripal_analysis_kegg_org_report($analysis_id){
  880. $content = tripal_analysis_kegg_full_report($analysis_id);
  881. $opt = array($content);
  882. return drupal_json($opt);
  883. }
  884. /************************************************************************
  885. */
  886. function tripal_analysis_kegg_full_report($analysis_id){
  887. // Test if brite data have been parsed into the database
  888. $sql = "SELECT CVT.name, CVT.cvterm_id
  889. FROM {cvterm} CVT
  890. INNER JOIN analysisprop AP ON CVT.cvterm_id = AP.type_id
  891. WHERE AP.analysis_id = %d
  892. AND CVT.definition LIKE 'KEGG BRITE term: %'
  893. ORDER BY CVT.cvterm_id";
  894. $previous_db = tripal_db_set_active('chado');
  895. $result = db_query($sql, $analysis_id);
  896. tripal_db_set_active($previous_db);
  897. if (db_result($result)) {
  898. $content = tripal_analysis_kegg_brite($analysis_id, $type_id, 0);
  899. } else {
  900. $content = "<i>Note:</i> Analysis result is not available. Please schedule and run the job to parse the kegg output.";
  901. }
  902. return $content;
  903. }
  904. /*******************************************************************************
  905. * Tripal Kegg administrative setting form. This function is called by
  906. * tripal_analysis module which asks for an admin form to show on the page
  907. */
  908. function tripal_analysis_kegg_get_settings() {
  909. // Get an array of node types with internal names as keys
  910. $options = node_get_types('names');
  911. // Add 'chado_feature' to allowed content types for showing kegg results
  912. $allowedoptions ['chado_feature'] = "Show KEGG results on feature pages";
  913. $allowedoptions ['chado_analysis_kegg'] = "Show KEGG BRITE results on the analysis page.";
  914. $allowedoptions ['chado_organism'] = "Show KEGG BRITE results on the organism pages.";
  915. $form['description'] = array(
  916. '#type' => 'item',
  917. '#value' => t("Some chado features were analyzed by KEGG automatic annotation server (KAAS). This option allows user to display the kegg analysis results. Please read user manual for storage and display of kegg files. Check the box to enable the analysis results. Uncheck to disable it."),
  918. '#weight' => 0,
  919. );
  920. $form['tripal_analysis_kegg_setting'] = array(
  921. '#type' => 'checkboxes',
  922. '#options' => $allowedoptions,
  923. '#default_value' => variable_get('tripal_analysis_kegg_setting',
  924. array('chado_feature', 'chado_analysis_kegg')),
  925. );
  926. $settings->form = $form;
  927. $settings->title = "Tripal Kegg";
  928. return $settings;
  929. }
  930. /************************************************************************
  931. */
  932. function tripal_analysis_kegg_organism_results($node) {
  933. $node = node_load($node);
  934. return tripal_analysis_kegg_organism_add($node);
  935. }
  936. /************************************************************************
  937. */
  938. function tripal_analysis_kegg_load_feature_terms($feature) {
  939. $feature_id = $feature->feature_id;
  940. // Get the KEGG results stored using the term 'kegg_brite_data'
  941. $select = array(
  942. 'analysisfeature_id' => array(
  943. 'feature_id' => $feature_id,
  944. ),
  945. 'type_id' => array(
  946. 'name' => 'kegg_brite_data',
  947. 'cv_id' => array(
  948. 'name' => 'tripal'
  949. ),
  950. ),
  951. );
  952. $afeatureprops = tripal_core_chado_select('analysisfeatureprop',array('*'),$select);
  953. // iterate through all of the KEGG properties for this feature
  954. $results = array();
  955. foreach ($afeatureprops as $index => $afeatureprop) {
  956. // get the analysis feature record
  957. $analysisfeature_arr = tripal_core_chado_select('analysisfeature',array('analysis_id'),
  958. array('analysisfeature_id' => $afeatureprop->analysisfeature_id));
  959. $analysisfeature = $analysisfeature_arr[0];
  960. // get the analysis record and the analysis_id
  961. $analysis = tripal_core_generate_chado_var('analysis',
  962. array('analysis_id' => $analysisfeature->analysis_id));
  963. $analysis_id = $analysis->analysis_id;
  964. $results[$analysis_id]['analysis'] = $analysis;
  965. }
  966. // now get all the terms for each analysis
  967. foreach($results as $analysis_id => $arr){
  968. $select = array(
  969. 'analysisfeature_id' => array(
  970. 'analysis_id' => $analysis_id,
  971. 'feature_id' => $feature_id,
  972. ),
  973. 'type_id' => array(
  974. 'name' => 'kegg_brite_data',
  975. 'cv_id' => array(
  976. 'name' => 'tripal',
  977. ),
  978. ),
  979. );
  980. $terms = tripal_core_chado_select('analysisfeatureprop',array('*'),$select);
  981. foreach ($terms as $term){
  982. $results[$analysis_id]['terms'][] = $term->value;
  983. }
  984. }
  985. return $results;
  986. }
  987. /************************************************************************
  988. */
  989. function tripal_analysis_kegg_select_form(&$form_state = NULL,$node){
  990. $form = array();
  991. // find analyses that have KEGG terms
  992. $sql = "
  993. SELECT *
  994. FROM {kegg_by_organism} KBO
  995. WHERE organism_id = %d
  996. ORDER BY analysis_id DESC
  997. ";
  998. $previous_db = tripal_db_set_active('chado');
  999. $results = db_query($sql,$node->organism->organism_id);
  1000. tripal_db_set_active($previous_db);
  1001. $analyses = array();
  1002. $analyses[''] = '';
  1003. while($analysis = db_fetch_object($results)){
  1004. $analyses[$analysis->analysis_id] = "$analysis->analysis_name";
  1005. }
  1006. # create the select box
  1007. $form['tripal_analysis_kegg_select'] = array(
  1008. '#title' => t('Select a KEGG report to view'),
  1009. '#description' => t('Any analysis with KEGG results related to this organism are available for viewing. For further information, see the analysis information page.'),
  1010. '#type' => 'select',
  1011. '#options' => $analyses,
  1012. '#attributes' => array (
  1013. 'onchange' => 'tripal_analysis_kegg_org_report(this.options[this.selectedIndex].value)'
  1014. ),
  1015. );
  1016. return $form;
  1017. }
  1018. /*******************************************************************************
  1019. * Parsing KEGG HTML results that are stored in analysisfeatureprop for
  1020. * searching
  1021. * */
  1022. function tripal_analysis_kegg_extract_keywords ($analysis_id) {
  1023. print "Extracting keywords...\n";
  1024. // Get all interpro output hits except for records with 'No hits reported', 'parent', 'children'.
  1025. $output_type_id = tripal_get_cvterm_id('kegg_brite_data');
  1026. $sql = "SELECT AFP.analysisfeature_id, AFP.value FROM {analysisfeatureprop} AFP
  1027. INNER JOIN {analysisfeature} AF ON AF.analysisfeature_id = AFP.analysisfeature_id
  1028. WHERE type_id = $output_type_id
  1029. AND AF.analysis_id = $analysis_id";
  1030. $results = chado_query($sql);
  1031. $keyword_type_id = tripal_get_cvterm_id('analysis_kegg_output_keywords');
  1032. // Define what to be extracted in the array
  1033. $search = array (
  1034. "'<[/!]*?[^<>]*?>'si", // replace HTML tags with a space
  1035. "'\n'", // replace newlines with a space
  1036. );
  1037. $replace = array (
  1038. " ",
  1039. " ",
  1040. );
  1041. while ($record = db_fetch_object($results)) {
  1042. $af_id = $record->analysisfeature_id;
  1043. $value = $record->value;
  1044. // Retrive keywords for this analysisfeature_id if there is any
  1045. $sql = "SELECT value FROM {analysisfeatureprop} WHERE analysisfeature_id =$af_id AND type_id = $keyword_type_id";
  1046. $keywords = db_result(chado_query($sql));
  1047. // Extract new keywords from the interpro html output
  1048. $text = preg_replace($search, $replace, $value);
  1049. $new_keywords = trim(ereg_replace(' +', ' ', $text)); // remove extra spaces
  1050. // Append the new keywords
  1051. if ($keywords) {
  1052. $new_keywords = "$keywords $new_keywords";
  1053. $sql = "UPDATE {analysisfeatureprop} SET value = '$new_keywords' WHERE analysisfeature_id =$af_id AND type_id = $keyword_type_id ";
  1054. } else {
  1055. // Insert the keyword into the analysisfeatureprop table
  1056. $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank) VALUES ($af_id, $keyword_type_id, '$new_keywords', 0)";
  1057. }
  1058. chado_query($sql);
  1059. }
  1060. print "Finished.\n";
  1061. }