123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795 |
- <?php
- require_once "includes/parseInterpro.inc";
- /*******************************************************************************
- * Tripal Interpro lets users show/hide iprscan results associated with a tripal
- * feature
- ******************************************************************************/
- function tripal_analysis_interpro_init(){
- // Add javascript and style sheet
- drupal_add_css(drupal_get_path('module', 'tripal_analysis_interpro').'/theme/css/tripal_analysis_interpro.css', 'theme');
- drupal_add_js( drupal_get_path('module', 'tripal_analysis_interpro').'/theme/js/tripal_analysis_interpro.js');
- }
- /*******************************************************************************
- * Provide information to drupal about the node types that we're creating
- * in this module
- */
- function tripal_analysis_interpro_node_info() {
- $nodes = array();
- $nodes['chado_analysis_interpro'] = array(
- 'name' => t('Analysis: Interpro'),
- 'module' => 'chado_analysis_interpro',
- 'description' => t('An interpro analysis from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Analysis: Interpro'),
- 'has_body' => FALSE,
- 'body_label' => t('Interpro Analysis Description'),
- 'locked' => TRUE
- );
- return $nodes;
- }
- /*******************************************************************************
- * Provide a Interpro Analysis form
- */
- function chado_analysis_interpro_form ($node){
- // add in the default fields for the analysis
- $form = chado_analysis_form($node);
- $analysis = $node->analysis;
- $interprofile = $analysis->tripal_analysis_interpro->interprofile;
- $interproparameters = $analysis->tripal_analysis_interpro->interproparameters;
- $parsego = $analysis->tripal_analysis_interpro->parsego;
- $parseHTML = $analysis->tripal_analysis_interpro->parseHTML;
- $query_re = $analysis->tripal_analysis_interpro->query_re;
- $query_type = $analysis->tripal_analysis_interpro->query_type;
- $query_uniquename = $analysis->tripal_analysis_interpro->query_uniquename;
- $moreSettings ['interpro'] = 'Interpro Settings';
- $form['interpro'] = array(
- '#title' => t('Interpro Settings'),
- '#type' => 'fieldset',
- '#description' => t('Specific Settings for Interpro Analysis.'),
- '#collapsible' => TRUE,
- '#attributes' => array('id' => 'interpro-extra-settings'),
- '#weight' => 11
- );
- $form['interpro']['interprofile'] = array(
- '#title' => t('InterProScan XML File/Directory: (if you input a directory without the tailing slash, all xml files in the directory will be loaded)'),
- '#type' => 'textfield',
- '#description' => t('Please provide the full path to the XML output file generated by InterProScan or a directory containing multiple XML files.'),
- '#default_value' => $interprofile,
- );
- $form['interpro']['interprojob'] = array(
- '#type' => 'checkbox',
- '#title' => t('Submit a job to parse the InterProScan XML file(s)'),
- '#description' => t('Note: features associated with the interpro results must '.
- 'exist in chado before parsing the file. Otherwise, interpro '.
- 'results that cannot be linked to a feature will not '.
- 'be imported. The feature name must be unique'),
- '#default_value' => $interprojob,
- '#attributes' => array(
- 'onclick' => 'return isSubmittingJob(this)'
- )
- );
- $form['interpro']['parseHTML'] = array(
- '#type' => 'checkbox',
- '#title' => t('The input file is in HTML format (deprecated, only provided for backwards compatibility)'),
- '#description' => t('Check the box to use the HTML parser.'),
- '#default_value' => $parseHTML
- );
- $form['interpro']['parsego'] = array(
- '#type' => 'checkbox',
- '#title' => t('Load GO terms to the database'),
- '#description' => t('Check the box to load GO terms to chado database'),
- '#default_value' => $parsego
- );
- // $form['interpro']['interprokeywordjob'] = array(
- // '#type' => 'checkbox',
- // '#title' => t('Submit a job to extract keywords from the Interpro html output'),
- // '#description' => t('Note: Interpro results are only searchable after keywords are extracted.'),/
- // );
- $form['interpro']['interproparameters'] = array(
- '#title' => t('Parameters'),
- '#type' => 'textfield',
- '#description' => t('The parameters used when running the InterProScan analysis.'),
- '#default_value' => $interproparameters,
- );
- $form['interpro']['query_re'] = array(
- '#title' => t('Query Name RE'),
- '#type' => 'textfield',
- '#description' => t('Enter the regular expression that will extract the '.
- 'feature name from the query line in the interpro results. This option is '.
- 'is only required when the query does not identically match a feature '.
- 'in the database. By default, the parser will try to match results to '.
- 'a feature in Chado using the feature name. Select the check box below'.
- 'to match against the unique name if needed.'),
- '#default_value' => $query_re,
- );
- $form['interpro']['query_uniquename'] = array(
- '#title' => t('Use Unique Name'),
- '#type' => 'checkbox',
- '#description' => t('Select this checboxk if the query name in the results file '.
- 'matches the unique name of the feature. '),
- '#default_value' => $query_uniquename,
- );
- $form['interpro']['query_type'] = array(
- '#title' => t('Query Type'),
- '#type' => 'textfield',
- '#description' => t('Please enter the Sequence Ontology term (e.g. contig, polypeptide, mRNA) that describes '.
- 'the query sequences in the interproscan XML results file(s). This is only necessary if two '.
- 'or more sequences have the same name.'),
- '#default_value' => $query_type,
- );
- return $form;
- }
- /**
- *
- */
- function chado_analysis_interpro_validate($node, &$form){
- // use the analysis parent to validate the node
- tripal_analysis_validate($node, $form);
- }
- /**
- *
- *
- */
- function chado_analysis_interpro_load($node){
- // load the default set of analysis fields
- $additions = chado_analysis_load($node);
- // create some variables for easier lookup
- $analysis = $additions->analysis;
- $analysis_id = $analysis->analysis_id;
- $intepro_settings = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_settings');
- $interprofile = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_interprofile');
- $interproparameters= tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_interproparameters');
- $parsego = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_parsego');
- $parseHTML = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_parseHTML');
- $query_re = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_query_re');
- $query_type = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_query_type');
- $query_uniquename = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_query_uniquename');
- $analysis->tripal_analysis_interpro->interprofile = $interprofile->value;
- $analysis->tripal_analysis_interpro->interproparameters= $interproparameters->value;
- $analysis->tripal_analysis_interpro->parsego = $parsego->value;
- $analysis->tripal_analysis_interpro->parseHTML = $parseHTML->value;
- $analysis->tripal_analysis_interpro->query_re = $query_re->value;
- $analysis->tripal_analysis_interpro->query_type = $query_type->value;
- $analysis->tripal_analysis_interpro->query_uniquename = $query_uniquename->value;
- // if there is an old style 'interpro_settings' array, then break these out for
- // use in the new format
- if(count($interpro_settings)>0){
- $prop_values = explode ("|", $interpro_settings->value);
- $analysis->tripal_analysis_interpro->interprofile = $prop_values[0];
- $analysis->tripal_analysis_interpro->interproparameters = $prop_values[1];
- }
- return $additions;
- }
- /**
- *
- */
- function chado_analysis_interpro_insert($node){
- // insert the analysistripal_core_generate_chado_var
- chado_analysis_insert($node);
- // set the type for this analysis
- tripal_analysis_insert_property($node->analysis_id,'analysis_type','tripal_analysis_interpro');
- // now add in the remaining settings as a single property but separated by bars
- tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_interprofile',$node->interprofile);
- tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_interproparameters',$node->interproparameters);
- tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_parsego',$node->parsego);
- tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_parseHTML',$node->parseHTML);
- tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_query_re',$node->query_re);
- tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_query_type',$node->query_type);
- tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_query_uniquename',$node->query_uniquename);
-
- // submit the parsing jobs
- chado_analysis_interpro_submit_job($node);
- }
- /**
- *
- */
- function chado_analysis_interpro_update($node){
- // insert the analysistripal_core_generate_chado_var
- chado_analysis_update($node);
- // set the type for this analysis
- tripal_analysis_update_property($node->analysis_id,'analysis_type','tripal_analysis_interpro',1);
- // now add in the remaining settings as a single property but separated by bars
- tripal_analysis_update_property($node->analysis_id,'analysis_interpro_interprofile',$node->interprofile,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_interpro_interproparameters',$node->interproparameters,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_interpro_parsego',$node->parsego,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_interpro_parseHTML',$node->parseHTML,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_interpro_query_re',$node->query_re,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_interpro_query_type',$node->query_type,1);
- tripal_analysis_update_property($node->analysis_id,'analysis_interpro_query_uniquename',$node->query_uniquename,1);
- // if this analysis uses the old style settings cvterm then remove that term
- $old = tripal_analysis_get_property($node->analysis_id,'analysis_interpro_settings');
- if(count($old) > 0){
- tripal_analysis_delete_property($node->analysis_id,'analysis_interpro_settings');
- }
-
- // submit the parsing jobs
- chado_analysis_interpro_submit_job($node);
- }
- /*******************************************************************************
- * Delete interpro anlysis
- */
- function chado_analysis_interpro_delete($node){
- chado_analysis_delete($node);
- }
- /**
- *
- */
- function chado_analysis_interpro_submit_job($node){
- global $user;
- // Add a job if the user wants to parse the html output
- if($node->interprojob) {
- $job_args[0] = $node->analysis_id;
- $job_args[1] = $node->interprofile;
- if ($node->parsego) {
- $job_args[2] = 1;
- } else {
- $job_args[2] = 0;
- }
- if (is_readable($node->interprofile)) {
- $fname = preg_replace("/.*\/(.*)/", "$1", $node->interprofile);
- if($node->parseHTML){
- tripal_add_job("Parse HTML interpro: $fname",'tripal_analysis_interpro',
- 'tripal_analysis_interpro_parseHTMLFile', $job_args, $user->uid);
- } else {
- $job_args[3] = $node->query_re;
- $job_args[4] = $node->query_type;
- $job_args[5] = $node->query_uniquename;;
- tripal_add_job("Parse XML interpro: $fname",'tripal_analysis_interpro',
- 'tripal_analysis_interpro_parseXMLFile', $job_args, $user->uid);
- }
- } else {
- drupal_set_message("Can not open interpro output file. Job not scheduled.");
- }
- }
-
- // Add a job if the user wants to the keywords from the HTML output
- if ($node->interprokeywordjob) {
- $analysis_id = chado_get_id_for_node('analysis', $node);
- $job_args[0] = $analysis_id;
- tripal_add_job("Extract keywords for search: $node->analysisname",'tripal_analysis_interpro',
- 'tripal_analysis_interpro_extract_keywords', $job_args, $user->uid);
- }
- }
- /*******************************************************************************
- * This function customizes the view of the chado_analysis node. It allows
- * us to generate the markup.
- */
- function chado_analysis_interpro_view ($node, $teaser = FALSE, $page = FALSE) {
- // use drupal's default node view:
- if (!$teaser) {
- $node = node_prepare($node, $teaser);
- // When previewing a node submitting form, it shows 'Array' instead of
- // correct date format. We need to format the date here
- $time = $node->timeexecuted;
- if(is_array($time)){
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $year.'-'.$month.'-'.$day;
- $node->timeexecuted = $timestamp;
- }
- // When viewing a node, we need to reformat the analysisprop since we
- // separate each value with a bar |
- if (preg_match("/.*\|.*/",$node->interprofile)) {
- $prop_values = explode("|", $node->interprofile);
- $node->interprofile = $prop_values[0];
- $node->interproparameters = $prop_values[1];
- }
- }
- return $node;
- }
- /**
- *
- *
- * @ingroup tripal_analysis_interpro
- */
- function tripal_analysis_interpro_block($op = 'list', $delta = 0, $edit=array()){
- switch($op) {
- case 'list':
- $blocks['ipr_base']['info'] = t('Analysis: Interpro Details');
- $blocks['ipr_base']['cache'] = BLOCK_NO_CACHE;
- $blocks['featureipr']['info'] = t('Tripal Feature Interpro Results');
- $blocks['featureipr']['cache'] = BLOCK_NO_CACHE;
-
- return $blocks;
- case 'view':
- if(user_access('access chado_analysis_interpro content') and arg(0) == 'node' and is_numeric(arg(1))) {
- $nid = arg(1);
- $node = node_load($nid);
-
- $block = array();
- switch($delta){
- case 'ipr_base':
- $block['subject'] = t('Interpro Details');
- $block['content'] = theme('tripal_analysis_interpro_base',$node);
- break;
- case 'featureipr':
- $block['subject'] = t('Interpro Results');
- $block['content'] = theme('tripal_feature_interpro_results',$node);
- break;
-
- default :
- }
- return $block;
- }
- }
- }
- /*******************************************************************************
- * tripal_analysis_interpro_nodeapi()
- * HOOK: Implementation of hook_nodeapi()
- * Display interpro results for allowed node types
- */
- function tripal_analysis_interpro_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
- case 'view':
- // Find out which node types for showing the interpro
- $types_to_show = variable_get('tripal_analysis_interpro_setting',
- array('chado_feature'));
- // Abort if this node is not one of the types we should show.
- if (!in_array($node->type, $types_to_show, TRUE)) {
- break;
- }
- // Add interpro to the content item if it's not a teaser
- if (!$teaser && $node->feature->feature_id) {
- if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
- $node->content['tripal_analysis_interpro_index_version'] = array(
- '#value' => theme('parse_EBI_Interpro_XML_index_version',$node),
- '#weight' => 7,
- );
- } else {
- // Show interpro result if not at teaser view
- $node->content['tripal_feature_interpro_results'] = array(
- '#value' => theme('tripal_feature_interpro_results', $node),
- '#weight' => 7
- );
- }
- }
- }
- }
- /**
- * Implements hook_theme_registry_alter().
- */
- function tripal_analysis_interpro_theme_registry_alter(&$info) {
- // Inject our module into the node theme registry as being an available theme
- // path so that we can override the node template for our content type.
- array_splice($info['node']['theme paths'], 1, 0, array(drupal_get_path('module', 'tripal_analysis_interpro')));
- }
- /************************************************************************
- * We need to let drupal know about our theme functions and their arguments.
- * We create theme functions to allow users of the module to customize the
- * look and feel of the output generated in this module
- */
- function tripal_analysis_interpro_theme () {
- $path = drupal_get_path('module' , 'tripal_analysis_interpro') . '/theme';
- return array(
- 'parse_EBI_Interpro_XML_index_version' => array (
- 'arguments' => array('node'),
- ),
- 'tripal_feature_interpro_results' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_feature_interpro_results',
- 'path' => $path . '/tripal_feature',
- ),
- 'tripal_analysis_interpro_base' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_analysis_interpro_base',
- 'path' => $path . '/tripal_analysis_interpro',
- )
- );
- }
- /*******************************************************************************
- * Prepare interpro result for the feature shown on the page
- */
- //function theme_tripal_analysis_interpro_results ($node) {
- // $feature = $node->feature;
- // $content = tripal_get_interpro_results($feature->feature_id);
- // return $content;
- //}
- function tripal_analysis_interpro_preprocess_tripal_feature_interpro_results(&$variables){
- $feature = $variables['node']->feature;
- // we don't know how many analysis are the old style HTML version and how many are the newer
- // XML format. So, to be backwards compatible we should get both.
- // $feature->tripal_analysis_interpro->results->html = tripal_get_interpro_HTML_results($feature->feature_id);
- $feature->tripal_analysis_interpro->results->xml = tripal_get_interpro_XML_results($feature->feature_id);
- }
- /*******************************************************************************
- * Prepare interpro result for the feature shown on the page
- */
- function theme_parse_EBI_Interpro_XML_index_version ($node) {
- $feature = $node->feature;
- $content = tripal_get_interpro_results_index_version($feature->feature_id);
- return $content;
- }
- /**
- *
- */
- function tripal_get_interpro_XML_results($feature_id){
- // Get the blast results stored as XML from the analysisfeatureprop table
- // the type for the property is named 'analysis_blast_output_iteration_hits'
- // and is found in the 'tripal' controlled vocabulary. This CV term was
- // added by this module.
- $select = array(
- 'analysisfeature_id' => array(
- 'feature_id' => $feature_id,
- ),
- 'type_id' => array(
- 'name' => 'analysis_interpro_xmloutput_hit',
- 'cv_id' => array(
- 'name' => 'tripal'
- ),
- ),
- );
- $afeatureprops = tripal_core_chado_select('analysisfeatureprop',array('*'),$select);
- // iterate through all of the interpro XML properties for this feature
- $results = array ();
- if($afeatureprops){
- foreach ($afeatureprops as $index => $afeatureprop) {
- // get the analysis feature record
- $analysisfeature_arr = tripal_core_chado_select('analysisfeature',array('analysis_id'),
- array('analysisfeature_id' => $afeatureprop->analysisfeature_id));
- $analysisfeature = $analysisfeature_arr[0];
- // get the analysis record and the analysis_id
- $analysis = tripal_core_generate_chado_var('analysis',
- array('analysis_id' => $analysisfeature->analysis_id));
- $analysis_id = $analysis->analysis_id;
- // parse the XML and add it to the array of blast results to be returned
- $interpro_xml = $afeatureprop->value;
- $orf = tripal_analysis_interpro_get_result_object($interpro_xml,$feature_id);
- $results[$analysis->analysis_id]['protein_ORFs'][] = $orf;
- $results[$analysis->analysis_id]['analysis'] = $analysis;
- // iterate through all of the protein ORFs and combine the terms into one large list
- if(!is_array($results[$analysis->analysis_id]['allterms'])){
- $results[$analysis->analysis_id]['allterms'] = array();
- }
- if(!is_array($results[$analysis->analysis_id]['goterms'])){
- $results[$analysis->analysis_id]['goterms'] = array();
- }
- $results[$analysis->analysis_id]['allterms'] = array_merge($results[$analysis->analysis_id]['allterms'],$orf['iprterms']);
- $results[$analysis->analysis_id]['goterms'] = array_merge($results[$analysis->analysis_id]['goterms'],$orf['goterms']);
- $i++;
- }
- }
- return $results;
- }
- /*******************************************************************************
- * tripal_get_interpro_results()
- * Get interpro result from featureprop table for the feature
- */
- function tripal_get_interpro_HTML_results($feature_id){
- // Get cvterm_id for 'analysis_interpro_output_hit' which is required
- // for inserting into the analysisfeatureprop table
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT
- INNER JOIN cv ON cv.cv_id = CVT.cv_id
- WHERE CVT.name = 'analysis_interpro_output_hit'
- AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
- // Get analysis times for the feature
- $sql = "SELECT A.analysis_id AS aid
- FROM {analysis} A
- INNER JOIN analysisfeature AF ON A.analysis_id = AF.analysis_id
- INNER JOIN analysisfeatureprop AFP ON AF.analysisfeature_id = AFP.analysisfeature_id
- WHERE feature_id = %d
- AND AFP.type_id = %d
- AND AFP.value NOT like '%No hits reported.%'
- AND AFP.value NOT like '%parent%'
- AND AFP.value NOT like '%children%'
- GROUP BY A.analysis_id
- ";
- $hasResult = db_result(db_query($sql, $feature_id, $type_id));
- $result = db_query($sql, $feature_id, $type_id);
- // Show interpro result ORDER BY time
- if ($hasResult) { // If there is any result, show expandable box
- $content .= "<table class=\"tripal_interpro_results_table\">
- <tr><td>";
- while ($ana = db_fetch_object($result)) {
- // Show analysis date
- $sql = "SELECT name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
- FROM {analysis}
- WHERE analysis_id = %d";
- $ana_details = db_fetch_object(db_query($sql, $ana->aid));
- // Find node id for the analysis
- tripal_db_set_active($previous_db);
- $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $ana->aid));
- $ana_url = url("node/".$ana_nid);
- $previous_db = tripal_db_set_active('chado');
-
- // Show content
- $content .= "<strong>Analysis Date:</strong> $ana_details->time
- (<a href=$ana_url>$ana_details->name</a>)";
-
- // Show interpro results
- $sql = "SELECT AFP.value AS afpvalue
- FROM {analysisfeatureprop} AFP
- INNER JOIN analysisfeature AF on AF.analysisfeature_id = AFP.analysisfeature_id
- WHERE AF.analysis_id = %d
- AND AF.feature_id = %d
- AND AFP.type_id = %d
- AND AFP.value NOT like '%No hits reported.%'
- AND AFP.value NOT like '%parent%'
- AND AFP.value NOT like '%children%'
- ";
- $interpro_results = db_query($sql, $ana->aid, $feature_id, $type_id);
- while ($afp = db_fetch_object($interpro_results)) {
- $content .= $afp->afpvalue;
- }
- }
- $content .= '</td></tr></table>';
- }
-
- tripal_db_set_active($previous_db);
- return $content;
- }
- /*******************************************************************************
- * tripal_get_interpro_results()
- * Get interpro result from featureprop table for the feature
- */
- function tripal_get_interpro_results_index_version($feature_id){
- // Get cvterm_id for 'analysis_interpro_output_hit' which is required
- // for inserting into the analysisfeatureprop table
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_interpro_output_hit' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
- // Get xml string from analysisfeatureprop value column
- $sql = "SELECT AFP.value AS afpvalue FROM {analysisfeatureprop} AFP ".
- "INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id ".
- "INNER JOIN analysisprop AP ON AP.analysis_id = AF.analysis_id ".
- "WHERE feature_id = %d ".
- "AND AFP.type_id = %d ";
- $result = db_query($sql, $feature_id, $type_id);
- tripal_db_set_active($previous_db);
- if (db_result($result)) {
- // get the HTML content for viewing each of the XML file
- while ($analysisfeatureprop = db_fetch_object($result)) {
- $content .= $analysisfeatureprop->afpvalue;
- }
- }
- return $content;
- }
- /*******************************************************************************
- * Tripal Interpro administrative setting form. This function is called by
- * tripal_analysis module which asks for an admin form to show on the page
- */
- function tripal_analysis_interpro_get_settings() {
- // Get an array of node types with internal names as keys
- $options = node_get_types('names');
- // Add 'chado_feature' to allowed content types for showing interpro results
- $allowedoptions ['chado_feature'] = "Show Interpro results on feature pages";
- $form['description'] = array(
- '#type' => 'item',
- '#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."),
- '#weight' => 0,
- );
- $form['tripal_analysis_interpro_setting'] = array(
- '#type' => 'checkboxes',
- '#options' => $allowedoptions,
- '#default_value' => variable_get('tripal_analysis_interpro_setting',
- array('chado_feature')),
- );
- $settings->form = $form;
- $settings->title = "Tripal Interpro";
- return $settings;
- }
- /*******************************************************************************
- * Set the permission types that the chado module uses. Essentially we
- * want permissionis that protect creation, editing and deleting of chado
- * data objects
- */
- function tripal_analysis_interpro_perm(){
- return array(
- 'access chado_analysis_interpro content',
- 'create chado_analysis_interpro content',
- 'delete chado_analysis_interpro content',
- 'edit chado_analysis_interpro content',
- );
- }
- /*******************************************************************************
- * The following function proves access control for users trying to
- * perform actions on data managed by this module
- */
- function chado_analysis_interpro_access($op, $node, $account){
- if ($op == 'create') {
- if(!user_access('create chado_analysis_interpro content', $account)){
- return FALSE;
- }
- }
- if ($op == 'update') {
- if (!user_access('edit chado_analysis_interpro content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_analysis_interpro content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'view') {
- if(!user_access('access chado_analysis_interpro content', $account)){
- return FALSE;
- }
- }
- return NULL;
- }
- /**
- *
- *
- * @ingroup tripal_analysis_interpro
- */
- function tripal_analysis_interpro_job_describe_args($callback,$args){
- $new_args = array();
- if($callback == 'tripal_analysis_interpro_parseXMLFile'){
- // add in the analysis
- if($args[0]){
- $analysis = tripal_core_chado_select('analysis',array('name'),array('analysis_id' => $args[0]));
- }
- $new_args['Analysis'] = $analysis[0]->name;
- $new_args['File or Directory Name'] = $args[1];
- if($args[2]){
- $new_args['Parse GO terms'] = 'Yes';
- } else {
- $new_args['Parse GO terms'] = 'No';
- }
- $new_args['Query name regular expression'] = $args[3];
- $new_args['Query type'] = $args[4];
- if($args[5] == 1){
- $new_args['Feature identifier'] = 'feature unique name';
- } else {
- $new_args['Feature identifier'] = 'feature name';
- }
- }
- return $new_args;
- }
- /*******************************************************************************
- * Parsing Interpro HTML results that are stored in analysisfeatureprop for
- * searching
- * */
- function tripal_analysis_interpro_extract_keywords ($analysis_id) {
-
- // Remove previously stored interpro keywords for this analysis
- print "Remove keywords previously stored...\n";
- $output_type_id = tripal_get_cvterm_id('analysis_interpro_output_hit');
- $sql = "SELECT distinct AFP.analysisfeature_id FROM {analysisfeatureprop} AFP
- INNER JOIN {analysisfeature} AF ON AF.analysisfeature_id = AFP.analysisfeature_id
- WHERE type_id = $output_type_id
- AND AF.analysis_id = $analysis_id";
- $results_remove = chado_query($sql);
- $keyword_type_id = tripal_get_cvterm_id('analysis_interpro_output_keywords');
- while ($record = db_fetch_object($results_remove)) {
- $af_id = $record->analysisfeature_id;
- $sql = "DELETE FROM {analysisfeatureprop} WHERE analysisfeature_id =$af_id AND type_id = $keyword_type_id";
- chado_query($sql);
- }
-
- print "Extracting keywords...\n";
- $sql = "SELECT AFP.analysisfeature_id, AFP.value FROM {analysisfeatureprop} AFP
- INNER JOIN {analysisfeature} AF ON AF.analysisfeature_id = AFP.analysisfeature_id
- WHERE type_id = $output_type_id
- AND AF.analysis_id = $analysis_id
- AND value NOT like '%No hits reported.%'
- AND value NOT like '%parent%'
- AND value NOT like '%children%'";
- $results = chado_query($sql);
- // Define what to be extracted in the array
- $search = array (
- "'SEQUENCE:.*'",
- "'CRC64:.*'",
- "'LENGTH:.*'",
- "'unintegrated'",
- "'noIPR'",
- "'<td>seg</td>'",
- "'<b>InterPro<br/>'",
- "'<br/>Domain|Family\n'",
- "'<td>no description</td>'",
- "'<[/!]*?[^<>]*?>'si", // replace HTML tags with a space
- "'\n'", // replace newlines with a space
- );
- $replace = array (
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- " ",
- " ",
- );
- while ($record = db_fetch_object($results)) {
- $af_id = $record->analysisfeature_id;
- $value = $record->value;
- // Retrive keywords for this analysisfeature_id if there is any
- $sql = "SELECT value FROM {analysisfeatureprop} WHERE analysisfeature_id =$af_id AND type_id = $keyword_type_id";
- $keywords = db_result(chado_query($sql));
-
- // Extract new keywords from the interpro html output
- $text = preg_replace($search, $replace, $value);
- $new_keywords = trim(ereg_replace(' +', ' ', $text)); // remove extra spaces
-
- // Append the new keywords
- if ($keywords) {
- $new_keywords = "$keywords $new_keywords";
- $sql = "UPDATE {analysisfeatureprop} SET value = '$new_keywords' WHERE analysisfeature_id =$af_id AND type_id = $keyword_type_id ";
- } else {
- // Insert the keyword into the analysisfeatureprop table
- $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank) VALUES ($af_id, $keyword_type_id, '$new_keywords', 0)";
- }
- chado_query($sql);
- }
-
- print "Finished.\n";
-
- }
|