tripal_analysis_interpro.module 29 KB

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