tripal_analysis_interpro.module 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. <?php
  2. require_once "parseInterpro.inc";
  3. /*******************************************************************************
  4. * Tripal Interpro lets users show/hide iprscan results associated with a tripal
  5. * feature
  6. ******************************************************************************/
  7. function tripal_analysis_interpro_init(){
  8. // Add javascript and style sheet
  9. drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_analysis_interpro.css');
  10. // Add javascript and style sheet
  11. drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_analysis_interpro.js');
  12. }
  13. /*******************************************************************************
  14. * Provide information to drupal about the node types that we're creating
  15. * in this module
  16. */
  17. function tripal_analysis_interpro_node_info() {
  18. $nodes = array();
  19. $nodes['chado_analysis_interpro'] = array(
  20. 'name' => t('Analysis: Interpro'),
  21. 'module' => 'chado_analysis_interpro',
  22. 'description' => t('An interpro analysis from the chado database'),
  23. 'has_title' => FALSE,
  24. 'title_label' => t('Analysis: Interpro'),
  25. 'has_body' => FALSE,
  26. 'body_label' => t('Interpro Analysis Description'),
  27. 'locked' => TRUE
  28. );
  29. return $nodes;
  30. }
  31. /*******************************************************************************
  32. *
  33. */
  34. function tripal_analysis_interpro_block($op = 'list', $delta = 0, $edit=array()){
  35. switch($op) {
  36. case 'list':
  37. $blocks['tai_results']['info'] = t('Tripal InterProScan Analysis Results');
  38. $blocks['tai_results']['cache'] = BLOCK_NO_CACHE;
  39. return $blocks;
  40. case 'view':
  41. if(user_access('access chado_analysis_interpro content') and arg(0) == 'node' and is_numeric(arg(1))) {
  42. $nid = arg(1);
  43. $node = node_load($nid);
  44. $block = array();
  45. switch($delta){
  46. case 'tai_results':
  47. $block['subject'] = t('InterProScan Results');
  48. $block['content'] = theme('tripal_analysis_interpro_results', $node);
  49. break;
  50. default :
  51. }
  52. return $block;
  53. }
  54. }
  55. }
  56. /*******************************************************************************
  57. * Provide a Interpro Analysis form
  58. */
  59. function chado_analysis_interpro_form ($node){
  60. // add in the default fields for the analysis
  61. $form = chado_analysis_form($node);
  62. $analysis = $node->analysis;
  63. $interprofile = $analysis->tripal_analysis_interpro->interprofile;
  64. $interproparameters = $analysis->tripal_analysis_interpro->interproparameters;
  65. $parsego = $analysis->tripal_analysis_interpro->parsego;
  66. $parseHTML = $analysis->tripal_analysis_interpro->parseHTML;
  67. $query_re = $analysis->tripal_analysis_interpro->query_re;
  68. $query_type = $analysis->tripal_analysis_interpro->query_type;
  69. $query_uniquename = $analysis->tripal_analysis_interpro->query_uniquename;
  70. $moreSettings ['interpro'] = 'Interpro Settings';
  71. $form['interpro'] = array(
  72. '#title' => t('Interpro Settings'),
  73. '#type' => 'fieldset',
  74. '#description' => t('Specific Settings for Interpro Analysis.'),
  75. '#collapsible' => TRUE,
  76. '#attributes' => array('id' => 'interpro-extra-settings'),
  77. '#weight' => 11
  78. );
  79. $form['interpro']['interprofile'] = array(
  80. '#title' => t('Interproscan Output File (in XML format)'),
  81. '#type' => 'textfield',
  82. '#description' => t('Please provide the full path to the XML output file generated by InterProScan.'),
  83. '#default_value' => $interprofile,
  84. );
  85. $form['interpro']['interprojob'] = array(
  86. '#type' => 'checkbox',
  87. '#title' => t('Submit a job to parse the InterProScan XML file'),
  88. '#description' => t('Note: features associated with the interpro results must '.
  89. 'exist in chado before parsing the file. Otherwise, interpro '.
  90. 'results that cannot be linked to a feature will be '.
  91. 'discarded.'),
  92. '#default_value' => $interprojob,
  93. '#attributes' => array(
  94. 'onclick' => 'return isSubmittingJob(this)'
  95. )
  96. );
  97. $form['interpro']['parseHTML'] = array(
  98. '#type' => 'checkbox',
  99. '#title' => t('The input file is in HTML format (deprecated, only provided for backwards compatibility)'),
  100. '#description' => t('Check the box to use the HTML parser. The feature name must be unique across all organisms and types.'),
  101. '#default_value' => $parseHTML
  102. );
  103. $form['interpro']['parsego'] = array(
  104. '#type' => 'checkbox',
  105. '#title' => t('Load GO terms to the database'),
  106. '#description' => t('Check the box to load GO terms to chado database'),
  107. '#default_value' => $parsego
  108. );
  109. $form['interpro']['interprokeywordjob'] = array(
  110. '#type' => 'checkbox',
  111. '#title' => t('Submit a job to extract keywords from the Interpro html output'),
  112. '#description' => t('Note: Interpro results are only searchable after keywords are extracted. Do not run this twice if you have already done so.'),
  113. );
  114. $form['interpro']['interproparameters'] = array(
  115. '#title' => t('Parameters'),
  116. '#type' => 'textfield',
  117. '#description' => t('The parameters used when running the InterProScan analysis.'),
  118. '#default_value' => $interproparameters,
  119. );
  120. $form['interpro']['query_re'] = array(
  121. '#title' => t('Query Name RE'),
  122. '#type' => 'textfield',
  123. '#description' => t('Enter the regular expression that will extract the '.
  124. 'feature name from the query line in the interpro results. This should be '.
  125. 'the same as the definition line in the query FASTA file. This option is '.
  126. 'is only required when the query does not identically match a feature '.
  127. 'in the database.'),
  128. '#default_value' => $query_re,
  129. );
  130. $form['interpro']['query_type'] = array(
  131. '#title' => t('Query Type'),
  132. '#type' => 'textfield',
  133. '#description' => t('Please enter the Sequence Ontology term that describes '.
  134. 'the query sequences used for InterProScan. This is only necessary if two '.
  135. 'or more sequences have the same name.'),
  136. '#default_value' => $query_type,
  137. );
  138. $form['interpro']['query_uniquename'] = array(
  139. '#title' => t('Use Unique Name'),
  140. '#type' => 'checkbox',
  141. '#description' => t('Select this checboxk if the query name in the results file '.
  142. 'matches the uniquename of the feature. By default, the blast results will '.
  143. 'mapped to the "name" of the feature.'),
  144. '#default_value' => $query_uniquename,
  145. );
  146. return $form;
  147. }
  148. /**
  149. *
  150. *
  151. */
  152. function chado_analysis_interpro_load($node){
  153. // load the default set of analysis fields
  154. $additions = chado_analysis_load($node);
  155. // create some variables for easier lookup
  156. $analysis = $additions->analysis;
  157. $analysis_id = $analysis->analysis_id;
  158. $intepro_settings = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_settings');
  159. $interprofile = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_interprofile');
  160. $interproparameters= tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_interproparameters');
  161. $parsego = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_parsego');
  162. $parseHTML = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_parseHTML');
  163. $query_re = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_query_re');
  164. $query_type = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_query_type');
  165. $query_uniquename = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_query_uniquename');
  166. $analysis->tripal_analysis_interpro->interprofile = $interprofile->value;
  167. $analysis->tripal_analysis_interpro->interproparameters= $interproparameters->value;
  168. $analysis->tripal_analysis_interpro->parsego = $parsego->value;
  169. $analysis->tripal_analysis_interpro->parseHTML = $parseHTML->value;
  170. $analysis->tripal_analysis_interpro->query_re = $query_re->value;
  171. $analysis->tripal_analysis_interpro->query_type = $query_type->value;
  172. $analysis->tripal_analysis_interpro->query_uniquename = $query_uniquename->value;
  173. // if there is an old style 'interpro_settings' array, then break these out for
  174. // use in the new format
  175. if(count($interpro_settings)>0){
  176. $prop_values = explode ("|", $interpro_settings->value);
  177. $analysis->tripal_analysis_interpro->interprofile = $prop_values[0];
  178. $analysis->tripal_analysis_interpro->interproparameters = $prop_values[1];
  179. }
  180. return $additions;
  181. }
  182. /**
  183. *
  184. */
  185. function chado_analysis_interpro_insert($node){
  186. // insert the analysistripal_core_generate_chado_var
  187. chado_analysis_insert($node);
  188. // set the type for this analysis
  189. tripal_analysis_insert_property($node->analysis_id,'analysis_type','tripal_analysis_interpro');
  190. // now add in the remaining settings as a single property but separated by bars
  191. tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_interprofile',$node->interprofile);
  192. tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_interproparameters',$node->interproparameters);
  193. tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_parsego',$node->parsego);
  194. tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_parseHTML',$node->parseHTML);
  195. tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_query_re',$node->query_re);
  196. tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_query_type',$node->query_type);
  197. tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_query_uniquename',$node->query_uniquename);
  198. // submit the parsing jobs
  199. chado_analysis_interpro_submit_job($node);
  200. }
  201. /**
  202. *
  203. */
  204. function chado_analysis_interpro_update($node){
  205. // insert the analysistripal_core_generate_chado_var
  206. chado_analysis_update($node);
  207. // set the type for this analysis
  208. tripal_analysis_update_property($node->analysis_id,'analysis_type','tripal_analysis_interpro',1);
  209. // now add in the remaining settings as a single property but separated by bars
  210. tripal_analysis_update_property($node->analysis_id,'analysis_interpro_interprofile',$node->interprofile,1);
  211. tripal_analysis_update_property($node->analysis_id,'analysis_interpro_interproparameters',$node->interproparameters,1);
  212. tripal_analysis_update_property($node->analysis_id,'analysis_interpro_parsego',$node->parsego,1);
  213. tripal_analysis_update_property($node->analysis_id,'analysis_interpro_parseHTML',$node->parseHTML,1);
  214. tripal_analysis_update_property($node->analysis_id,'analysis_interpro_query_re',$node->query_re,1);
  215. tripal_analysis_update_property($node->analysis_id,'analysis_interpro_query_type',$node->query_type,1);
  216. tripal_analysis_update_property($node->analysis_id,'analysis_interpro_query_uniquename',$node->query_uniquename,1);
  217. // if this analysis uses the old style settings cvterm then remove that term
  218. $old = tripal_analysis_get_property($node->analysis_id,'analysis_interpro_settings');
  219. if(count($old) > 0){
  220. tripal_analysis_delete_property($node->analysis_id,'analysis_interpro_settings');
  221. }
  222. // submit the parsing jobs
  223. chado_analysis_interpro_submit_job($node);
  224. }
  225. /*******************************************************************************
  226. * Delete interpro anlysis
  227. */
  228. function chado_analysis_interpro_delete($node){
  229. chado_analysis_delete($node);
  230. }
  231. /**
  232. *
  233. */
  234. function chado_analysis_interpro_submit_job($node){
  235. global $user;
  236. // Add a job if the user wants to parse the html output
  237. if($node->interprojob) {
  238. $job_args[0] = $node->analysis_id;
  239. $job_args[1] = $node->interprofile;
  240. if ($node->parsego) {
  241. $job_args[2] = 1;
  242. } else {
  243. $job_args[2] = 0;
  244. }
  245. if (is_readable($node->interprofile)) {
  246. $fname = preg_replace("/.*\/(.*)/", "$1", $node->interprofile);
  247. if($node->parseHTML){
  248. tripal_add_job("Parse HTML interpro: $fname",'tripal_analysis_interpro',
  249. 'tripal_analysis_interpro_parseHTMLFile', $job_args, $user->uid);
  250. } else {
  251. $job_args[3] = $node->query_re;
  252. $job_args[4] = $node->query_type;
  253. $job_args[5] = $node->query_uniquename;;
  254. tripal_add_job("Parse XML interpro: $fname",'tripal_analysis_interpro',
  255. 'tripal_analysis_interpro_parseXMLFile', $job_args, $user->uid);
  256. }
  257. } else {
  258. drupal_set_message("Can not open interpro output file. Job not scheduled.");
  259. }
  260. }
  261. // Add a job if the user wants to the keywords from the HTML output
  262. if ($node->interprokeywordjob) {
  263. $analysis_id = chado_get_id_for_node('analysis', $node);
  264. $job_args[0] = $analysis_id;
  265. tripal_add_job("Extract keywords for search: $node->analysisname",'tripal_analysis_interpro',
  266. 'tripal_analysis_interpro_extract_keywords', $job_args, $user->uid);
  267. }
  268. }
  269. /*******************************************************************************
  270. * This function customizes the view of the chado_analysis node. It allows
  271. * us to generate the markup.
  272. */
  273. function chado_analysis_interpro_view ($node, $teaser = FALSE, $page = FALSE) {
  274. // use drupal's default node view:
  275. if (!$teaser) {
  276. $node = node_prepare($node, $teaser);
  277. // When previewing a node submitting form, it shows 'Array' instead of
  278. // correct date format. We need to format the date here
  279. $time = $node->timeexecuted;
  280. if(is_array($time)){
  281. $month = $time['month'];
  282. $day = $time['day'];
  283. $year = $time['year'];
  284. $timestamp = $year.'-'.$month.'-'.$day;
  285. $node->timeexecuted = $timestamp;
  286. }
  287. // When viewing a node, we need to reformat the analysisprop since we
  288. // separate each value with a bar |
  289. if (preg_match("/.*\|.*/",$node->interprofile)) {
  290. $prop_values = explode("|", $node->interprofile);
  291. $node->interprofile = $prop_values[0];
  292. $node->interproparameters = $prop_values[1];
  293. }
  294. }
  295. return $node;
  296. }
  297. /*******************************************************************************
  298. * tripal_analysis_interpro_nodeapi()
  299. * HOOK: Implementation of hook_nodeapi()
  300. * Display interpro results for allowed node types
  301. */
  302. function tripal_analysis_interpro_nodeapi(&$node, $op, $teaser, $page) {
  303. switch ($op) {
  304. case 'view':
  305. // Find out which node types for showing the interpro
  306. $types_to_show = variable_get('tripal_analysis_interpro_setting',
  307. array('chado_feature'));
  308. // Abort if this node is not one of the types we should show.
  309. if (!in_array($node->type, $types_to_show, TRUE)) {
  310. break;
  311. }
  312. // Add interpro to the content item if it's not a teaser
  313. if (!$teaser && $node->feature->feature_id) {
  314. if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
  315. $node->content['tripal_analysis_interpro_index_version'] = array(
  316. '#value' => theme('parse_EBI_Interpro_XML_index_version',$node),
  317. '#weight' => 7,
  318. );
  319. } else {
  320. // Show interpro result if not at teaser view
  321. $node->content['tripal_feature_interpro_results'] = array(
  322. '#value' => theme('tripal_feature_interpro_results', $node),
  323. '#weight' => 7
  324. );
  325. }
  326. }
  327. }
  328. }
  329. /************************************************************************
  330. * We need to let drupal know about our theme functions and their arguments.
  331. * We create theme functions to allow users of the module to customize the
  332. * look and feel of the output generated in this module
  333. */
  334. function tripal_analysis_interpro_theme () {
  335. return array(
  336. 'parse_EBI_Interpro_XML_index_version' => array (
  337. 'arguments' => array('node'),
  338. ),
  339. 'tripal_feature_interpro_results' => array (
  340. 'arguments' => array('node'=> null),
  341. 'template' => 'tripal_feature_interpro_results',
  342. )
  343. );
  344. }
  345. /*******************************************************************************
  346. * Prepare interpro result for the feature shown on the page
  347. */
  348. //function theme_tripal_analysis_interpro_results ($node) {
  349. // $feature = $node->feature;
  350. // $content = tripal_get_interpro_results($feature->feature_id);
  351. // return $content;
  352. //}
  353. function tripal_analysis_interpro_preprocess_tripal_feature_interpro_results(&$variables){
  354. $feature = $variables['node']->feature;
  355. // we don't know how many analysis are the old style HTML version and how many are the newer
  356. // XML format. So, to be backwards compatible we should get both.
  357. $variables['tripal_analysis_interpro']['results']['html'] = tripal_get_interpro_HTML_results($feature->feature_id);
  358. $variables['tripal_analysis_interpro']['results']['xml'] = tripal_get_interpro_XML_results($feature->feature_id);
  359. }
  360. /*******************************************************************************
  361. * Prepare interpro result for the feature shown on the page
  362. */
  363. function theme_parse_EBI_Interpro_XML_index_version ($node) {
  364. $feature = $node->feature;
  365. $content = tripal_get_interpro_results_index_version($feature->feature_id);
  366. return $content;
  367. }
  368. /**
  369. *
  370. */
  371. function tripal_get_interpro_XML_results($feature_id){
  372. // Get the blast results stored as XML from the analysisfeatureprop table
  373. // the type for the property is named 'analysis_blast_output_iteration_hits'
  374. // and is found in the 'tripal' controlled vocabulary. This CV term was
  375. // added by this module.
  376. $select = array(
  377. 'analysisfeature_id' => array(
  378. 'feature_id' => $feature_id,
  379. ),
  380. 'type_id' => array(
  381. 'name' => 'analysis_interpro_xmloutput_hit',
  382. 'cv_id' => array(
  383. 'name' => 'tripal'
  384. ),
  385. ),
  386. );
  387. $afeatureprops = tripal_core_chado_select('analysisfeatureprop',array('*'),$select);
  388. // iterate through all of the interpro XML properties for this feature
  389. $results = array ();
  390. foreach ($afeatureprops as $index => $afeatureprop) {
  391. // get the analysis feature record
  392. $analysisfeature_arr = tripal_core_chado_select('analysisfeature',array('analysis_id'),
  393. array('analysisfeature_id' => $afeatureprop->analysisfeature_id));
  394. $analysisfeature = $analysisfeature_arr[0];
  395. // get the analysis record and the analysis_id
  396. $analysis = tripal_core_generate_chado_var('analysis',
  397. array('analysis_id' => $analysisfeature->analysis_id));
  398. $analysis_id = $analysis->analysis_id;
  399. // parse the XML and add it to the array of blast results to be returned
  400. $interpro_xml = $afeatureprop->value;
  401. $orf = tripal_analysis_interpro_get_result_object($interpro_xml,$feature_id);
  402. $results[$analysis->analysis_id]['protein_ORFs'][] = $orf;
  403. $results[$analysis->analysis_id]['analysis'] = $analysis;
  404. // iterate through all of the protein ORFs and combine the terms into one large list
  405. if(!is_array($results[$analysis->analysis_id]['allterms'])){
  406. $results[$analysis->analysis_id]['allterms'] = array();
  407. }
  408. if(!is_array($results[$analysis->analysis_id]['goterms'])){
  409. $results[$analysis->analysis_id]['goterms'] = array();
  410. }
  411. $results[$analysis->analysis_id]['allterms'] = array_merge($results[$analysis->analysis_id]['allterms'],$orf['iprterms']);
  412. $results[$analysis->analysis_id]['goterms'] = array_merge($results[$analysis->analysis_id]['goterms'],$orf['goterms']);
  413. $i++;
  414. }
  415. return $results;
  416. }
  417. /*******************************************************************************
  418. * tripal_get_interpro_results()
  419. * Get interpro result from featureprop table for the feature
  420. */
  421. function tripal_get_interpro_HTML_results($feature_id){
  422. // Get cvterm_id for 'analysis_interpro_output_hit' which is required
  423. // for inserting into the analysisfeatureprop table
  424. $previous_db = tripal_db_set_active('chado');
  425. $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT
  426. INNER JOIN cv ON cv.cv_id = CVT.cv_id
  427. WHERE CVT.name = 'analysis_interpro_output_hit'
  428. AND CV.name = 'tripal'";
  429. $type_id = db_result(db_query($sql));
  430. // Get analysis times for the feature
  431. $sql = "SELECT A.analysis_id AS aid
  432. FROM {analysis} A
  433. INNER JOIN analysisfeature AF ON A.analysis_id = AF.analysis_id
  434. INNER JOIN analysisfeatureprop AFP ON AF.analysisfeature_id = AFP.analysisfeature_id
  435. WHERE feature_id = %d
  436. AND AFP.type_id = %d
  437. GROUP BY A.analysis_id
  438. ";
  439. $hasResult = db_result(db_query($sql, $feature_id, $type_id));
  440. $result = db_query($sql, $feature_id, $type_id);
  441. // Show interpro result ORDER BY time
  442. if ($hasResult) { // If there is any result, show expandable box
  443. $content .= "<table class=\"tripal_interpro_results_table\">
  444. <tr><td>";
  445. while ($ana = db_fetch_object($result)) {
  446. // Show analysis date
  447. $sql = "SELECT name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
  448. FROM {analysis}
  449. WHERE analysis_id = %d";
  450. $ana_details = db_fetch_object(db_query($sql, $ana->aid));
  451. // Find node id for the analysis
  452. tripal_db_set_active($previous_db);
  453. $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $ana->aid));
  454. $ana_url = url("node/".$ana_nid);
  455. $previous_db = tripal_db_set_active('chado');
  456. // Show content
  457. $content .= "<strong>Analysis Date:</strong> $ana_details->time
  458. (<a href=$ana_url>$ana_details->name</a>)";
  459. // Show interpro results
  460. $sql = "SELECT AFP.value AS afpvalue
  461. FROM {analysisfeatureprop} AFP
  462. INNER JOIN analysisfeature AF on AF.analysisfeature_id = AFP.analysisfeature_id
  463. WHERE AF.analysis_id = %d
  464. AND AF.feature_id = %d
  465. ";
  466. $interpro_results = db_query($sql, $ana->aid, $feature_id);
  467. while ($afp = db_fetch_object($interpro_results)) {
  468. $content .= $afp->afpvalue;
  469. }
  470. }
  471. $content .= '</td></tr></table>';
  472. }
  473. tripal_db_set_active($previous_db);
  474. return $content;
  475. }
  476. /*******************************************************************************
  477. * tripal_get_interpro_results()
  478. * Get interpro result from featureprop table for the feature
  479. */
  480. function tripal_get_interpro_results_index_version($feature_id){
  481. // Get cvterm_id for 'analysis_interpro_output_hit' which is required
  482. // for inserting into the analysisfeatureprop table
  483. $previous_db = tripal_db_set_active('chado');
  484. $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
  485. "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
  486. "WHERE CVT.name = 'analysis_interpro_output_hit' ".
  487. "AND CV.name = 'tripal'";
  488. $type_id = db_result(db_query($sql));
  489. // Get xml string from analysisfeatureprop value column
  490. $sql = "SELECT AFP.value AS afpvalue FROM {analysisfeatureprop} AFP ".
  491. "INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id ".
  492. "INNER JOIN analysisprop AP ON AP.analysis_id = AF.analysis_id ".
  493. "WHERE feature_id = %d ".
  494. "AND AFP.type_id = %d ";
  495. $result = db_query($sql, $feature_id, $type_id);
  496. tripal_db_set_active($previous_db);
  497. if (db_result($result)) {
  498. // get the HTML content for viewing each of the XML file
  499. while ($analysisfeatureprop = db_fetch_object($result)) {
  500. $content .= $analysisfeatureprop->afpvalue;
  501. }
  502. }
  503. return $content;
  504. }
  505. /*******************************************************************************
  506. * Tripal Interpro administrative setting form. This function is called by
  507. * tripal_analysis module which asks for an admin form to show on the page
  508. */
  509. function tripal_analysis_interpro_get_settings() {
  510. // Get an array of node types with internal names as keys
  511. $options = node_get_types('names');
  512. // Add 'chado_feature' to allowed content types for showing interpro results
  513. $allowedoptions ['chado_feature'] = "Show Interpro results on feature pages";
  514. $form['description'] = array(
  515. '#type' => 'item',
  516. '#value' => t("Some chado features were analyzed using InterProScan. This option allows user to display the interpro analysis results. Please read user manual for storage and display of interpro files. Check the box to enable the analysis results. Uncheck to disable it."),
  517. '#weight' => 0,
  518. );
  519. $form['tripal_analysis_interpro_setting'] = array(
  520. '#type' => 'checkboxes',
  521. '#options' => $allowedoptions,
  522. '#default_value' => variable_get('tripal_analysis_interpro_setting',
  523. array('chado_feature')),
  524. );
  525. $settings->form = $form;
  526. $settings->title = "Tripal Interpro";
  527. return $settings;
  528. }
  529. /*******************************************************************************
  530. * Set the permission types that the chado module uses. Essentially we
  531. * want permissionis that protect creation, editing and deleting of chado
  532. * data objects
  533. */
  534. function tripal_analysis_interpro_perm(){
  535. return array(
  536. 'access chado_analysis_interpro content',
  537. 'create chado_analysis_interpro content',
  538. 'delete chado_analysis_interpro content',
  539. 'edit chado_analysis_interpro content',
  540. );
  541. }
  542. /*******************************************************************************
  543. * The following function proves access control for users trying to
  544. * perform actions on data managed by this module
  545. */
  546. function chado_analysis_interpro_access($op, $node, $account){
  547. if ($op == 'create') {
  548. return user_access('create chado_analysis_interpro content', $account);
  549. }
  550. if ($op == 'update') {
  551. if (user_access('edit chado_analysis_interpro content', $account)) {
  552. return TRUE;
  553. }
  554. }
  555. if ($op == 'delete') {
  556. if (user_access('delete chado_analysis_interpro content', $account)) {
  557. return TRUE;
  558. }
  559. }
  560. if ($op == 'view') {
  561. if (user_access('access chado_analysis_interpro content', $account)) {
  562. return TRUE;
  563. }
  564. }
  565. return FALSE;
  566. }
  567. /*******************************************************************************
  568. * Parsing Interpro HTML results that are stored in analysisfeatureprop for
  569. * searching
  570. * */
  571. function tripal_analysis_interpro_extract_keywords ($analysis_id) {
  572. print "Extracting keywords...\n";
  573. // Get all interpro output hits except for records with 'No hits reported', 'parent', 'children'.
  574. $output_type_id = tripal_get_cvterm_id('analysis_interpro_output_hit');
  575. $sql = "SELECT AFP.analysisfeature_id, AFP.value FROM {analysisfeatureprop} AFP
  576. INNER JOIN {analysisfeature} AF ON AF.analysisfeature_id = AFP.analysisfeature_id
  577. WHERE type_id = $output_type_id
  578. AND AF.analysis_id = $analysis_id
  579. AND value NOT like '%No hits reported.%'
  580. AND value NOT like '%parent%'
  581. AND value NOT like '%children%'";
  582. $results = chado_query($sql);
  583. $keyword_type_id = tripal_get_cvterm_id('analysis_interpro_output_keywords');
  584. // Define what to be extracted in the array
  585. $search = array (
  586. "'SEQUENCE:.*'",
  587. "'CRC64:.*'",
  588. "'LENGTH:.*'",
  589. "'<b>InterPro<br/>'",
  590. "'<br/>Domain|Family\n'",
  591. "'<td>no description</td>'",
  592. "'<[/!]*?[^<>]*?>'si", // replace HTML tags with a space
  593. "'\n'", // replace newlines with a space
  594. );
  595. $replace = array (
  596. "",
  597. "",
  598. "",
  599. "",
  600. "",
  601. "",
  602. " ",
  603. " ",
  604. );
  605. while ($record = db_fetch_object($results)) {
  606. $af_id = $record->analysisfeature_id;
  607. $value = $record->value;
  608. // Retrive keywords for this analysisfeature_id if there is any
  609. $sql = "SELECT value FROM {analysisfeatureprop} WHERE analysisfeature_id =$af_id AND type_id = $keyword_type_id";
  610. $keywords = db_result(chado_query($sql));
  611. // Extract new keywords from the interpro html output
  612. $text = preg_replace($search, $replace, $value);
  613. $new_keywords = trim(ereg_replace(' +', ' ', $text)); // remove extra spaces
  614. // Append the new keywords
  615. if ($keywords) {
  616. $new_keywords = "$keywords $new_keywords";
  617. $sql = "UPDATE {analysisfeatureprop} SET value = '$new_keywords' WHERE analysisfeature_id =$af_id AND type_id = $keyword_type_id ";
  618. } else {
  619. // Insert the keyword into the analysisfeatureprop table
  620. $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank) VALUES ($af_id, $keyword_type_id, '$new_keywords', 0)";
  621. }
  622. chado_query($sql);
  623. }
  624. print "Finished.\n";
  625. }