tripal_analysis_interpro.module 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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. if($afeatureprops){
  391. foreach ($afeatureprops as $index => $afeatureprop) {
  392. // get the analysis feature record
  393. $analysisfeature_arr = tripal_core_chado_select('analysisfeature',array('analysis_id'),
  394. array('analysisfeature_id' => $afeatureprop->analysisfeature_id));
  395. $analysisfeature = $analysisfeature_arr[0];
  396. // get the analysis record and the analysis_id
  397. $analysis = tripal_core_generate_chado_var('analysis',
  398. array('analysis_id' => $analysisfeature->analysis_id));
  399. $analysis_id = $analysis->analysis_id;
  400. // parse the XML and add it to the array of blast results to be returned
  401. $interpro_xml = $afeatureprop->value;
  402. $orf = tripal_analysis_interpro_get_result_object($interpro_xml,$feature_id);
  403. $results[$analysis->analysis_id]['protein_ORFs'][] = $orf;
  404. $results[$analysis->analysis_id]['analysis'] = $analysis;
  405. // iterate through all of the protein ORFs and combine the terms into one large list
  406. if(!is_array($results[$analysis->analysis_id]['allterms'])){
  407. $results[$analysis->analysis_id]['allterms'] = array();
  408. }
  409. if(!is_array($results[$analysis->analysis_id]['goterms'])){
  410. $results[$analysis->analysis_id]['goterms'] = array();
  411. }
  412. $results[$analysis->analysis_id]['allterms'] = array_merge($results[$analysis->analysis_id]['allterms'],$orf['iprterms']);
  413. $results[$analysis->analysis_id]['goterms'] = array_merge($results[$analysis->analysis_id]['goterms'],$orf['goterms']);
  414. $i++;
  415. }
  416. }
  417. return $results;
  418. }
  419. /*******************************************************************************
  420. * tripal_get_interpro_results()
  421. * Get interpro result from featureprop table for the feature
  422. */
  423. function tripal_get_interpro_HTML_results($feature_id){
  424. // Get cvterm_id for 'analysis_interpro_output_hit' which is required
  425. // for inserting into the analysisfeatureprop table
  426. $previous_db = tripal_db_set_active('chado');
  427. $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT
  428. INNER JOIN cv ON cv.cv_id = CVT.cv_id
  429. WHERE CVT.name = 'analysis_interpro_output_hit'
  430. AND CV.name = 'tripal'";
  431. $type_id = db_result(db_query($sql));
  432. // Get analysis times for the feature
  433. $sql = "SELECT A.analysis_id AS aid
  434. FROM {analysis} A
  435. INNER JOIN analysisfeature AF ON A.analysis_id = AF.analysis_id
  436. INNER JOIN analysisfeatureprop AFP ON AF.analysisfeature_id = AFP.analysisfeature_id
  437. WHERE feature_id = %d
  438. AND AFP.type_id = %d
  439. GROUP BY A.analysis_id
  440. ";
  441. $hasResult = db_result(db_query($sql, $feature_id, $type_id));
  442. $result = db_query($sql, $feature_id, $type_id);
  443. // Show interpro result ORDER BY time
  444. if ($hasResult) { // If there is any result, show expandable box
  445. $content .= "<table class=\"tripal_interpro_results_table\">
  446. <tr><td>";
  447. while ($ana = db_fetch_object($result)) {
  448. // Show analysis date
  449. $sql = "SELECT name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
  450. FROM {analysis}
  451. WHERE analysis_id = %d";
  452. $ana_details = db_fetch_object(db_query($sql, $ana->aid));
  453. // Find node id for the analysis
  454. tripal_db_set_active($previous_db);
  455. $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $ana->aid));
  456. $ana_url = url("node/".$ana_nid);
  457. $previous_db = tripal_db_set_active('chado');
  458. // Show content
  459. $content .= "<strong>Analysis Date:</strong> $ana_details->time
  460. (<a href=$ana_url>$ana_details->name</a>)";
  461. // Show interpro results
  462. $sql = "SELECT AFP.value AS afpvalue
  463. FROM {analysisfeatureprop} AFP
  464. INNER JOIN analysisfeature AF on AF.analysisfeature_id = AFP.analysisfeature_id
  465. WHERE AF.analysis_id = %d
  466. AND AF.feature_id = %d
  467. ";
  468. $interpro_results = db_query($sql, $ana->aid, $feature_id);
  469. while ($afp = db_fetch_object($interpro_results)) {
  470. $content .= $afp->afpvalue;
  471. }
  472. }
  473. $content .= '</td></tr></table>';
  474. }
  475. tripal_db_set_active($previous_db);
  476. return $content;
  477. }
  478. /*******************************************************************************
  479. * tripal_get_interpro_results()
  480. * Get interpro result from featureprop table for the feature
  481. */
  482. function tripal_get_interpro_results_index_version($feature_id){
  483. // Get cvterm_id for 'analysis_interpro_output_hit' which is required
  484. // for inserting into the analysisfeatureprop table
  485. $previous_db = tripal_db_set_active('chado');
  486. $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
  487. "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
  488. "WHERE CVT.name = 'analysis_interpro_output_hit' ".
  489. "AND CV.name = 'tripal'";
  490. $type_id = db_result(db_query($sql));
  491. // Get xml string from analysisfeatureprop value column
  492. $sql = "SELECT AFP.value AS afpvalue FROM {analysisfeatureprop} AFP ".
  493. "INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id ".
  494. "INNER JOIN analysisprop AP ON AP.analysis_id = AF.analysis_id ".
  495. "WHERE feature_id = %d ".
  496. "AND AFP.type_id = %d ";
  497. $result = db_query($sql, $feature_id, $type_id);
  498. tripal_db_set_active($previous_db);
  499. if (db_result($result)) {
  500. // get the HTML content for viewing each of the XML file
  501. while ($analysisfeatureprop = db_fetch_object($result)) {
  502. $content .= $analysisfeatureprop->afpvalue;
  503. }
  504. }
  505. return $content;
  506. }
  507. /*******************************************************************************
  508. * Tripal Interpro administrative setting form. This function is called by
  509. * tripal_analysis module which asks for an admin form to show on the page
  510. */
  511. function tripal_analysis_interpro_get_settings() {
  512. // Get an array of node types with internal names as keys
  513. $options = node_get_types('names');
  514. // Add 'chado_feature' to allowed content types for showing interpro results
  515. $allowedoptions ['chado_feature'] = "Show Interpro results on feature pages";
  516. $form['description'] = array(
  517. '#type' => 'item',
  518. '#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."),
  519. '#weight' => 0,
  520. );
  521. $form['tripal_analysis_interpro_setting'] = array(
  522. '#type' => 'checkboxes',
  523. '#options' => $allowedoptions,
  524. '#default_value' => variable_get('tripal_analysis_interpro_setting',
  525. array('chado_feature')),
  526. );
  527. $settings->form = $form;
  528. $settings->title = "Tripal Interpro";
  529. return $settings;
  530. }
  531. /*******************************************************************************
  532. * Set the permission types that the chado module uses. Essentially we
  533. * want permissionis that protect creation, editing and deleting of chado
  534. * data objects
  535. */
  536. function tripal_analysis_interpro_perm(){
  537. return array(
  538. 'access chado_analysis_interpro content',
  539. 'create chado_analysis_interpro content',
  540. 'delete chado_analysis_interpro content',
  541. 'edit chado_analysis_interpro content',
  542. );
  543. }
  544. /*******************************************************************************
  545. * The following function proves access control for users trying to
  546. * perform actions on data managed by this module
  547. */
  548. function chado_analysis_interpro_access($op, $node, $account){
  549. if ($op == 'create') {
  550. return user_access('create chado_analysis_interpro content', $account);
  551. }
  552. if ($op == 'update') {
  553. if (user_access('edit chado_analysis_interpro content', $account)) {
  554. return TRUE;
  555. }
  556. }
  557. if ($op == 'delete') {
  558. if (user_access('delete chado_analysis_interpro content', $account)) {
  559. return TRUE;
  560. }
  561. }
  562. if ($op == 'view') {
  563. if (user_access('access chado_analysis_interpro content', $account)) {
  564. return TRUE;
  565. }
  566. }
  567. return FALSE;
  568. }
  569. /*******************************************************************************
  570. * Parsing Interpro HTML results that are stored in analysisfeatureprop for
  571. * searching
  572. * */
  573. function tripal_analysis_interpro_extract_keywords ($analysis_id) {
  574. print "Extracting keywords...\n";
  575. // Get all interpro output hits except for records with 'No hits reported', 'parent', 'children'.
  576. $output_type_id = tripal_get_cvterm_id('analysis_interpro_output_hit');
  577. $sql = "SELECT AFP.analysisfeature_id, AFP.value FROM {analysisfeatureprop} AFP
  578. INNER JOIN {analysisfeature} AF ON AF.analysisfeature_id = AFP.analysisfeature_id
  579. WHERE type_id = $output_type_id
  580. AND AF.analysis_id = $analysis_id
  581. AND value NOT like '%No hits reported.%'
  582. AND value NOT like '%parent%'
  583. AND value NOT like '%children%'";
  584. $results = chado_query($sql);
  585. $keyword_type_id = tripal_get_cvterm_id('analysis_interpro_output_keywords');
  586. // Define what to be extracted in the array
  587. $search = array (
  588. "'SEQUENCE:.*'",
  589. "'CRC64:.*'",
  590. "'LENGTH:.*'",
  591. "'<b>InterPro<br/>'",
  592. "'<br/>Domain|Family\n'",
  593. "'<td>no description</td>'",
  594. "'<[/!]*?[^<>]*?>'si", // replace HTML tags with a space
  595. "'\n'", // replace newlines with a space
  596. );
  597. $replace = array (
  598. "",
  599. "",
  600. "",
  601. "",
  602. "",
  603. "",
  604. " ",
  605. " ",
  606. );
  607. while ($record = db_fetch_object($results)) {
  608. $af_id = $record->analysisfeature_id;
  609. $value = $record->value;
  610. // Retrive keywords for this analysisfeature_id if there is any
  611. $sql = "SELECT value FROM {analysisfeatureprop} WHERE analysisfeature_id =$af_id AND type_id = $keyword_type_id";
  612. $keywords = db_result(chado_query($sql));
  613. // Extract new keywords from the interpro html output
  614. $text = preg_replace($search, $replace, $value);
  615. $new_keywords = trim(ereg_replace(' +', ' ', $text)); // remove extra spaces
  616. // Append the new keywords
  617. if ($keywords) {
  618. $new_keywords = "$keywords $new_keywords";
  619. $sql = "UPDATE {analysisfeatureprop} SET value = '$new_keywords' WHERE analysisfeature_id =$af_id AND type_id = $keyword_type_id ";
  620. } else {
  621. // Insert the keyword into the analysisfeatureprop table
  622. $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank) VALUES ($af_id, $keyword_type_id, '$new_keywords', 0)";
  623. }
  624. chado_query($sql);
  625. }
  626. print "Finished.\n";
  627. }