tripal_analysis_interpro.module 29 KB

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