123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955 |
- <?php
- function tripal_analysis_interpro_init(){
-
- drupal_add_css(drupal_get_path('theme', 'tripal').
- '/css/tripal_analysis_interpro.css');
-
- drupal_add_js(drupal_get_path('theme', 'tripal').
- '/js/tripal_analysis_interpro.js');
- }
- 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;
- }
- function chado_analysis_interpro_form ($node){
- $type = node_get_types('type', $node);
- $form = array();
- $form['title']= array(
- '#type' => 'hidden',
- '#default_value' => $node->title,
- );
- $form['analysisname']= array(
- '#type' => 'textfield',
- '#title' => t('Analysis Name'),
- '#required' => FALSE,
- '#default_value' => $node->analysisname,
- '#weight' => 1
- );
- $form['program']= array(
- '#type' => 'textfield',
- '#title' => t('Program'),
- '#required' => TRUE,
- '#default_value' => $node->program,
- '#weight' => 2
- );
- $form['programversion']= array(
- '#type' => 'textfield',
- '#title' => t('Program Version'),
- '#required' => TRUE,
- '#default_value' => $node->programversion,
- '#weight' => 3
- );
- $form['algorithm']= array(
- '#type' => 'textfield',
- '#title' => t('Algorithm'),
- '#required' => FALSE,
- '#default_value' => $node->algorithm,
- '#weight' => 4
- );
- $form['sourcename']= array(
- '#type' => 'textfield',
- '#title' => t('Source Name'),
- '#required' => FALSE,
- '#default_value' => $node->sourcename,
- '#weight' => 5
- );
- $form['sourceversion']= array(
- '#type' => 'textfield',
- '#title' => t('Source Version'),
- '#required' => FALSE,
- '#default_value' => $node->sourceversion,
- '#weight' => 6
- );
- $form['sourceuri']= array(
- '#type' => 'textfield',
- '#title' => t('Source URI'),
- '#required' => FALSE,
- '#default_value' => $node->sourceuri,
- '#weight' => 7
- );
-
- $default_time = $node->timeexecuted;
- $year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
- $month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
- $day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
-
- if (!$default_time) {
- $default_time = time();
- $year = format_date($default_time, 'custom', 'Y');
- $month = format_date($default_time, 'custom', 'n');
- $day = format_date($default_time, 'custom', 'j');
- }
- $form['timeexecuted']= array(
- '#type' => 'date',
- '#title' => t('Time Executed'),
- '#required' => TRUE,
- '#default_value' => array(
- 'year' => $year,
- 'month' => $month,
- 'day' => $day,
- ),
- '#weight' => 8
- );
- $form['description']= array(
- '#type' => 'textarea',
- '#rows' => 15,
- '#title' => t('Description and/or Program Settings'),
- '#required' => FALSE,
- '#default_value' => check_plain($node->description),
- '#weight' => 9
- );
-
- if (preg_match("/.*\|.*/",$node->interprofile)) {
- $prop_values = explode("|", $node->interprofile);
- $node->interprofile = $prop_values[0];
- $node->interproparameters = $prop_values[1];
- }
- $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 Output File (in html format)'),
- '#type' => 'textfield',
- '#description' => t('The html output file generated by Interproscan in full path.'),
- '#default_value' => $node->interprofile,
- );
- $form['interpro']['interprojob'] = array(
- '#type' => 'checkbox',
- '#title' => t('Submit a job to parse the Interpro html output'),
- '#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 be '.
- 'discarded. Also, Triapl Interpro module needs to be enabled.'),
- '#default_value' => $node->interprojob,
- '#attributes' => array(
- 'onclick' => 'return isSubmittingJob(this)'
- )
- );
- $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' => $node->parsego
- );
- $form['interpro']['interproparameters'] = array(
- '#title' => t('Parameters'),
- '#type' => 'textfield',
- '#description' => t('The parameters for running the interpro analysis.'),
- '#default_value' => $node->interproparameters,
- );
- return $form;
- }
- function chado_analysis_interpro_insert($node){
- global $user;
-
- $time = $node->timeexecuted;
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $month.'/'.$day.'/'.$year;
-
- $analysis_id = $node->analysis_id;
- if ($analysis_id) {
- $sql = "SELECT analysis_id ".
- "FROM {Analysis} ".
- "WHERE analysis_id = %d ";
- $previous_db = tripal_db_set_active('chado');
- $analysis = db_fetch_object(db_query($sql, $node->analysis_id));
- tripal_db_set_active($previous_db);
- }
-
- if(!$analysis){
-
- $sql = "INSERT INTO {analysis} ".
- " (name, description, program, programversion, algorithm, ".
- " sourcename, sourceversion, sourceuri, timeexecuted) ".
- "VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')";
- $previous_db = tripal_db_set_active('chado');
- db_query($sql,$node->analysisname, $node->description,
- $node->program,$node->programversion,$node->algorithm,
- $node->sourcename, $node->sourceversion, $node->sourceuri,
- $timestamp);
-
- $sql = "SELECT analysis_id ".
- "FROM {Analysis} ".
- "WHERE program='%s'".
- "AND programversion='%s'".
- "AND sourcename='%s'";
- $analysis_id = db_result(db_query($sql, $node->program,
- $node->programversion, $node->sourcename));
-
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_interpro_settings' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
- $sql = "INSERT INTO {analysisprop} (analysis_id, type_id, value) ".
- "VALUES (%d, %d, '%s')";
- $interprosettings = $node->interprofile."|".$node->interproparameters;
- db_query($sql, $analysis_id, $type_id, $interprosettings);
- tripal_db_set_active($previous_db);
-
- if($node->interprojob) {
- $job_args[0] = $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);
- tripal_add_job("Parse interpro: $fname",'tripal_analysis_interpro',
- 'tripal_analysis_interpro_parseHTMLFile', $job_args, $user->uid);
- } else {
- drupal_set_message("Can not open interpro output file. Job not scheduled.");
- }
- }
- }
-
-
- $node_check_sql = "SELECT * FROM {chado_analysis} ".
- "WHERE analysis_id = %d";
- $node_check = db_fetch_object(db_query($node_check_sql, $analysis_id));
- if(!$node_check){
-
- $sql = "INSERT INTO {chado_analysis} (nid, vid, analysis_id) ".
- "VALUES (%d, %d, %d)";
- db_query($sql,$node->nid,$node->vid,$analysis_id);
-
-
- $record = new stdClass();
-
-
- if ($node->analysisname) {
- $record->title = $node->analysisname;
- } else {
-
- $record->title = "$node->program ($node->programversion)";
- }
- $record->nid = $node->nid;
- drupal_write_record('node',$record,'nid');
- drupal_write_record('node_revisions',$record,'nid');
- }
- }
- function chado_analysis_interpro_delete($node){
-
-
- $sql_drupal = "SELECT analysis_id ".
- "FROM {chado_analysis} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- $analysis_id = db_result(db_query($sql_drupal, $node->nid, $node->vid));
-
- $sql_del = "DELETE FROM {chado_analysis} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node_revisions} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
-
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE analysis_id=%d";
- $results = db_query($sql, $analysis_id);
- while ($af = db_fetch_object($results)) {
- db_query("DELETE FROM {analysisfeatureprop} WHERE analysisfeature_id = %d", $af->analysisfeature_id);
- }
- db_query("DELETE FROM {analysisfeature} WHERE analysis_id = %d", $analysis_id);
- db_query("DELETE FROM {analysisprop} WHERE analysis_id = %d", $analysis_id);
- db_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
- tripal_db_set_active($previous_db);
- }
- function chado_analysis_interpro_update($node){
- global $user;
- if($node->revision){
-
- } else {
-
- $time = $node->timeexecuted;
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $month.'/'.$day.'/'.$year;
-
- $sql = "SELECT analysis_id ".
- "FROM {chado_analysis} ".
- "WHERE vid = %d";
- $analysis_id = db_fetch_object(db_query($sql, $node->vid))->analysis_id;
- $sql = "UPDATE {analysis} ".
- "SET name = '%s', ".
- " description = '%s', ".
- " program = '%s', ".
- " programversion = '%s', ".
- " algorithm = '%s', ".
- " sourcename = '%s', ".
- " sourceversion = '%s', ".
- " sourceuri = '%s', ".
- " timeexecuted = '%s' ".
- "WHERE analysis_id = %d ";
- $previous_db = tripal_db_set_active('chado');
- db_query($sql, $node->analysisname, $node->description, $node->program,
- $node->programversion,$node->algorithm,$node->sourcename,
- $node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
-
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv CV ON CV.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_interpro_settings' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
- $sql = "UPDATE {analysisprop} ".
- "SET value = '%s' ".
- "WHERE analysis_id = %d AND type_id = %d";
- $interprosettings = $node->interprofile."|".$node->interproparameters;
- db_query($sql, $interprosettings, $analysis_id, $type_id);
- tripal_db_set_active($previous_db);
-
- if($node->interprojob) {
- $job_args[0] = $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);
- tripal_add_job("Parse interpro: $fname",'tripal_analysis_interpro',
- 'tripal_analysis_interpro_parseHTMLFile', $job_args, $user->uid);
- } else {
- drupal_set_message("Can not open interpro output file. Job not scheduled.");
- }
- }
-
-
- $record = new stdClass();
-
-
- if ($node->analysisname) {
- $record->title = $node->analysisname;
- } else {
-
- $record->title = "$node->program ($node->programversion)";
- }
- $record->nid = $node->nid;
- drupal_write_record('node',$record,'nid');
- drupal_write_record('node_revisions',$record,'nid');
- }
- }
- function chado_analysis_interpro_load($node){
-
- $sql = "SELECT analysis_id FROM {chado_analysis} WHERE vid = %d";
- $ana_node = db_fetch_object(db_query($sql, $node->vid));
- $additions = new stdClass();
- if ($ana_node) {
-
- $sql = "SELECT Analysis_id, name AS analysisname, description, program, ".
- " programversion, algorithm, sourcename, sourceversion, ".
- " sourceuri, timeexecuted ".
- "FROM {Analysis} ".
- "WHERE Analysis_id = $ana_node->analysis_id";
- $previous_db = tripal_db_set_active('chado');
- $additions = db_fetch_object(db_query($sql));
-
- $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
- "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
- "WHERE CVT.name = 'analysis_interpro_settings' ".
- "AND CV.name = 'tripal'";
- $type_id = db_result(db_query($sql));
-
- $sql = "SELECT value FROM {analysisprop} ".
- "WHERE analysis_id = %d ".
- "AND type_id = %d";
- $analysisprop = db_result(db_query($sql, $ana_node->analysis_id, $type_id));
- $prop_values = explode ("|", $analysisprop, 1);
- $additions->interprofile = $prop_values[0];
- $additions->interproparameters = $prop_values[1];
- tripal_db_set_active($previous_db);
- }
-
-
- if ($additions->analysisname) {
- $additions->title = $additions->analysisname;
- } else {
-
- $additions->title = "$additions->program ($additions->programversion)";
- }
- return $additions;
- }
- function chado_analysis_interpro_view ($node, $teaser = FALSE, $page = FALSE) {
-
- if (!$teaser) {
- $node = node_prepare($node, $teaser);
-
-
- $time = $node->timeexecuted;
- if(is_array($time)){
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $year.'-'.$month.'-'.$day;
- $node->timeexecuted = $timestamp;
- }
-
-
- if (preg_match("/.*\|.*/",$node->interprofile)) {
- $prop_values = explode("|", $node->interprofile);
- $node->interprofile = $prop_values[0];
- $node->interproparameters = $prop_values[1];
- }
- }
- return $node;
- }
- function tripal_analysis_interpro_parseHTMLFile ($analysis_id, $interprofile, $parsego, $job_id) {
-
- $filename = preg_replace("/.*\/(.*)/", "$1", $interprofile);
- $logfile = file_directory_path() . "/tripal/tripal_analysis_interpro/load_$filename.log";
- $log = fopen($logfile, 'a');
-
- print "Parsing File:".$interprofile." ...\n";
- fwrite($log, date("D M j G:i:s Y").". Loading $interprofile\n");
-
-
- $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));
- print "cvterm_id for analysis_interpro_output_iteration_hits is $type_id\n";
-
- $dom = new domDocument;
- $dom->loadHTMLFile($interprofile);
- $xml = $dom->saveXML();
- $interproput = simplexml_load_string($xml);
-
- $tables = $interproput->children()->children();
-
- $no_iterations = 0;
- foreach($tables as $tmp) {
- if ($tmp->getName() == 'table') {
- $no_iterations ++;
- }
- }
- print "$no_iterations html tables to be processed.\n";
- $interval = intval($no_iterations * 0.01);
- $idx_iterations = 0;
-
- foreach ($tables as $table) {
-
-
-
-
- if ($table->getName() == 'table' && !preg_match('/No hits reported/', $table->asXML()) ) {
- $idx_iterations ++;
- if ($idx_iterations % $interval == 0) {
- $percentage = (int) ($idx_iterations / $no_iterations * 100);
- tripal_db_set_active($previous_db);
- tripal_job_set_progress($job_id, $percentage);
- $previous_db = tripal_db_set_active('chado');
- print $percentage."% ";
- }
-
-
- $firsttd = $table->children()->children()->children();
- $feature_id = 0;
- foreach($firsttd as $b) {
- foreach($b->children() as $a) {
- if ($a->getName() == 'a') {
-
- $seqname = preg_replace('/^(.+?)_\d_.+/', "$1", $a);
- print "seqname is $seqname\n";
-
-
- $sql = "SELECT count(feature_id) FROM {feature} ".
- "WHERE uniquename = '%s' ";
- $no_features = db_result(db_query($sql, $seqname));
-
-
- if ($no_features == 1) {
- $sql = "SELECT feature_id FROM {feature} ".
- "WHERE uniquename = '%s' ";
- $feature_id = db_result(db_query($sql, $seqname));
- print "\tfeature id is $feature_id\n";
-
-
- } else if ($no_features > 1) {
- fwrite($log, "Ambiguous: ".$seqname." matches more than one feature and is not processed.\n");
- continue;
-
-
- } else {
- fwrite($log, "Failed: ".$seqname."\n");
- }
-
- }
- }
- }
-
-
- if ($feature_id) {
-
-
-
- $parent_row = "/<tr><td valign=\"top\"><b>Parent<\/b><\/td>\s*<td valign=\"top\">\s*no.*?parent<\/td>\s*<\/tr>/";
- $children_row = "/<tr><td valign=\"top\"><b>Children<\/b><\/td>\s*<td valign=\"top\">\s*no.*?children<\/td>\s*<\/tr>/";
- $found_row = "/<tr><td valign=\"top\"><b>Found.*?in<\/b><\/td>\s*<td valign=\"top\">\s*no.*?entries<\/td>\s*<\/tr>/";
- $contains_row = "/<tr><td valign=\"top\"><b>Contains<\/b><\/td>\s*<td valign=\"top\">\s*no.*?entries<\/td>\s*<\/tr>/";
- $go_row = "/<tr><td valign=\"top\"><b>GO.*?terms<\/b><\/td>\s*<td valign=\"top\">\s*none<\/td>\s*<\/tr>/";
-
- $table_txt = $table->asXML();
- $table_txt = preg_replace($parent_row, "", $table_txt);
- $table_txt = preg_replace($children_row, "", $table_txt);
- $table_txt = preg_replace($found_row, "", $table_txt);
- $table_txt = preg_replace($contains_row, "", $table_txt);
- $table_txt = preg_replace($go_row, "", $table_txt);
-
-
-
- $orf_link = "/<b><a href=\"\/iprscan\/wget.*?\">(.*?)<\/a><\/b>/";
- $table_txt = preg_replace($orf_link, "$1", $table_txt);
-
-
-
-
-
-
-
-
-
- $sql = "Select analysisfeature_id as id from {analysisfeature} where feature_id = %d and analysis_id = %d";
- $analysisfeature = db_fetch_object(db_query($sql, $feature_id, $analysis_id));
- if($analysisfeature){ $analysisfeature_id = $analysisfeature->id; }
- if(!$analysisfeature_id){
- print "inserting analysisfeature\n";
- $sql = "INSERT INTO {analysisfeature} (feature_id, analysis_id) ".
- "VALUES (%d, %d)";
- db_query ($sql, $feature_id, $analysis_id);
- $sql = "Select analysisfeature_id from {analysisfeature} where feature_id = %d and analysis_id = %d";
- $analysisfeature = db_fetch_object(db_query($sql, $feature_id, $analysis_id));
- $analysisfeature_id = $analysisfeature->id;
- }
- print "analysisfeature_id is $analysisfeature_id (analysis_id = $analysis_id; feature_id = $feature_id)\n";
-
-
-
- $sql = "SELECT MAX(rank) FROM {analysisfeatureprop} AFP ".
- "INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id ".
- "WHERE feature_id=%d ".
- "AND analysis_id=%d ".
- "AND type_id=%d ";
- $afp = db_fetch_object(db_query($sql, $feature_id, $analysis_id, $type_id));
- $hi_rank = 0;
- if ($afp) {
- $hi_rank = $afp->max + 1;
- }
-
-
-
-
-
- $sql = "SELECT value FROM {analysisfeatureprop} WHERE analysisfeature_id = %d AND type_id = %d";
- $result = db_query($sql, $analysisfeature_id, $type_id);
- $duplicate = 0;
- while ($afp_value = db_fetch_object($result)) {
- if ($table_txt == $afp_value->value) {
- $duplicate = 1;
- }
- }
- if (!$duplicate) {
- $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank)".
- "VALUES (%d, %d, '%s', %d)";
- db_query($sql, $analysisfeature_id, $type_id, $table_txt, $hi_rank);
- fwrite($log, " (Insert)\n");
- print "\twriting table\n";
- } else {
- fwrite($log, " (Skipped)\n");
- print "\tskipping table - dup\n";
- }
-
-
- $go_db_id = db_result(db_query("SELECT db_id FROM {db} WHERE name='GO'"));
- if (!$go_db_id) {
- print 'GO schema not installed in chado. GO terms are not processed.';
- }
- if ($go_db_id && $parsego) {
- $trs = $table->children();
- foreach ($trs as $tr) {
- $tds = $tr->children();
- foreach($tds as $td) {
- $gotags = $td->children();
- foreach ($gotags as $gotag) {
-
- if (preg_match("/^.*?GO:(\d+).*$/", $gotag, $matches)) {
-
-
- $sql = "SELECT cvterm_id FROM {cvterm} CVT
- INNER JOIN dbxref DBX ON CVT.dbxref_id = DBX.dbxref_id
- WHERE DBX.accession = '%s' AND DBX.db_id = %d";
- $goterm_id = db_result(db_query($sql, $matches[1], $go_db_id));
-
-
-
-
-
- $sql = "INSERT INTO {feature_cvterm} (feature_id, cvterm_id, pub_id)
- VALUES (%d, %d, 1)";
- db_query($sql, $feature_id, $goterm_id);
-
-
-
- $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank) ".
- "VALUES (%d, %d, '%s', 0)";
- db_query($sql, $analysisfeature_id, $goterm_id, $matches[1]);
- }
- }
- }
- }
- }
- }
- }
- }
- tripal_db_set_active ($previous_db);
- print "Done.\nSuccessful and failed entries have been saved in the log file:\n $logfile\n";
-
- fwrite($log, "\n");
- fclose($log);
- return;
- }
- function tripal_analysis_interpro_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
- case 'view':
-
- $types_to_show = variable_get('tripal_analysis_interpro_setting',
- array('chado_feature'));
-
- if (!in_array($node->type, $types_to_show, TRUE)) {
- break;
- }
-
- 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 {
-
- $node->content['tripal_analysis_interpro_form'] = array(
- '#value' => theme('tripal_analysis_interpro_results', $node),
- '#weight' => 7
- );
- }
- }
- }
- }
- function tripal_analysis_interpro_theme () {
- return array(
- 'parse_EBI_Interpro_XML_index_version' => array (
- 'arguments' => array('node'),
- ),
- 'tripal_analysis_interpro_results' => array (
- 'arguments' => array('node'),
- )
- );
- }
- function theme_tripal_analysis_interpro_results ($node) {
- $feature = $node->feature;
- $content = tripal_get_interpro_results($feature->feature_id);
- return $content;
- }
- 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_results($feature_id){
-
-
- $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));
-
-
- $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
- GROUP BY A.analysis_id
- ";
- $hasResult = db_result(db_query($sql, $feature_id, $type_id));
- $result = db_query($sql, $feature_id, $type_id);
-
- if ($hasResult) {
- $content .= "<div id=\"interpro-hits\" class=\"tripal_interpro-info-box\">
- <div class=\"tripal_expandableBox\">
- <h3>InterProScan Analysis</h3>
- </div>
- <div class=\"tripal_expandableBoxContent\">
- <span>
- <table class=\"tripal_interpro_results_table\">
- <tr><td>";
- while ($ana = db_fetch_object($result)) {
-
- $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));
-
- 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');
-
-
- $content .= "<strong>Analysis Date:</strong> $ana_details->time
- (<a href=$ana_url>$ana_details->name</a>)";
-
-
- $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
- ";
- $interpro_results = db_query($sql, $ana->aid, $feature_id);
- while ($afp = db_fetch_object($interpro_results)) {
- $content .= $afp->afpvalue;
- }
- }
- $content .= '</td></tr></table></span></div></div>';
- }
-
- tripal_db_set_active($previous_db);
- return $content;
- }
- function tripal_get_interpro_results_index_version($feature_id){
-
-
- $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));
-
- $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)) {
-
- while ($analysisfeatureprop = db_fetch_object($result)) {
- $content .= $analysisfeatureprop->afpvalue;
- }
- }
- return $content;
- }
- function tripal_analysis_interpro_get_settings() {
-
- $options = node_get_types('names');
-
- $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;
- }
- 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',
- );
- }
- function chado_analysis_interpro_access($op, $node, $account){
- if ($op == 'create') {
- return user_access('create chado_analysis_interpro content', $account);
- }
- if ($op == 'update') {
- if (user_access('edit chado_analysis_interpro content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'delete') {
- if (user_access('delete chado_analysis_interpro content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'view') {
- if (user_access('access chado_analysis_interpro content', $account)) {
- return TRUE;
- }
- }
- return FALSE;
- }
|