tripal_analysis_interpro.module 31 KB

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