[Bio] / SeedViewer / MetagenomeAnalysis.pm Repository:
ViewVC logotype

Diff of /SeedViewer/MetagenomeAnalysis.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4, Tue Apr 22 19:56:18 2008 UTC revision 1.9, Tue Jun 10 20:07:34 2008 UTC
# Line 10  Line 10 
10    
11  1;  1;
12    
   
   
13  use constant QUERY_DEFAULTS =>  use constant QUERY_DEFAULTS =>
14    { 1 => { evalue => '1e-05', align_len => 50 }, # RDP    { 1 => { evalue => '1e-05', align_len => 50 }, # RDP
15      2 => { evalue => '0.01' }, # SEED      2 => { evalue => '0.01' }, # SEED
# Line 21  Line 19 
19      6 => { evalue => '0.01' }, # Subsystem      6 => { evalue => '0.01' }, # Subsystem
20    };    };
21    
   
   
   
22  sub new {  sub new {
23    my ($class, $job) = @_;    my ($class, $job) = @_;
24    
# Line 36  Line 31 
31    my $dbh;    my $dbh;
32    eval {    eval {
33    
34        my $dbms     = $FIG_Config::mgrast_dbms;
35      my $host     = $FIG_Config::mgrast_dbhost;      my $host     = $FIG_Config::mgrast_dbhost;
36      my $database = $FIG_Config::mgrast_db;      my $database = $FIG_Config::mgrast_db;
37      my $user     = $FIG_Config::mgrast_dbuser;      my $user     = $FIG_Config::mgrast_dbuser;
38      my $password = '';      my $password = '';
39    
40        if ($dbms eq 'Pg')
41        {
42            $dbh = DBI->connect("DBI:Pg:dbname=$database;host=$host", $user, $password,
43                            { RaiseError => 1, AutoCommit => 0, PrintError => 0 }) ||
44                                die "database connect error.";
45        }
46        elsif ($dbms eq 'mysql' or $dbms eq '') # Default to mysql
47        {
48      $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $password,      $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $password,
49                          { RaiseError => 1, AutoCommit => 0, PrintError => 0 }) ||                          { RaiseError => 1, AutoCommit => 0, PrintError => 0 }) ||
50                                            die "database connect error.";                                            die "database connect error.";
51        }
52        else
53        {
54            die "MetagenomeAnalysis: unknown dbms '$dbms'";
55        }
56    
57    };    };
58    if ($@) {    if ($@) {
59      warn "Unable to connect to metagenomics database: $@\n";      warn "Unable to connect to metagenomics database: $@\n";
# Line 65  Line 75 
75    
76  }  }
77    
   
   
   
78  sub job {  sub job {
79    return $_[0]->{job};    return $_[0]->{job};
80  }  }
# Line 85  Line 92 
92    return $_[0]->{dbtable};    return $_[0]->{dbtable};
93  }  }
94    
95    sub dbtable_best_psc {
96      unless (defined $_[0]->{dbtable}) {
97        $_[0]->{dbtable} = 'tax_sim_best_by_psc_'.$_[0]->job->id;
98      }
99      return $_[0]->{dbtable};
100    }
101    
102    sub dbtable_best_iden {
103      unless (defined $_[0]->{dbtable}) {
104        $_[0]->{dbtable} = 'tax_sim_best_by_iden_'.$_[0]->job->id;
105      }
106      return $_[0]->{dbtable};
107    }
108    
109  sub get_key2taxa_mapping {  sub get_key2taxa_mapping {
110    
# Line 149  Line 169 
169    
170  =pod  =pod
171    
172    =over 4
173    
174  =item * B<query_evalue> (I<evalue>)  =item * B<query_evalue> (I<evalue>)
175    
176  Set/get the expectation value which is currently used to query the database.  Set/get the expectation value which is currently used to query the database.
# Line 315  Line 337 
337  #******************************************************************************  #******************************************************************************
338    
339    
   
   
   
340  =pod  =pod
341    
342  =item * B<get_sequence> (I<sequence_id>)  =item * B<get_sequence> (I<sequence_id>)
# Line 422  Line 441 
441  sub get_taxa_counts {  sub get_taxa_counts {
442    my ($self, $dataset) = @_;    my ($self, $dataset) = @_;
443    
444    my $table = $self->dbtable;    my $table = $self->dbtable_best_psc;
445    my $dbid  = $self->get_dataset_id($dataset);    my $dbid  = $self->get_dataset_id($dataset);
446    my $where = $self->get_where_clause();    my $where = $self->get_where_clause();
447    $where = ($where) ? "and $where" : '';    $where = ($where) ? "and $where" : '';
448    
449    my $sth = $self->dbh->prepare("select s.tax_str as tax, count(*) as num from ( select id1, min(rank_psc) as rank from $table where dbid=$dbid $where group by id1) as b inner join $table as s on b.id1=s.id1 and b.rank=s.rank_psc where dbid=$dbid group by s.tax_str");    my $sth = $self->dbh->prepare("select tax_str as tax, count(*) from $table where dbid=$dbid group by tax");
450    
451    $sth->execute;    $sth->execute;
452    my $result = $sth->fetchall_arrayref();    my $result = $sth->fetchall_arrayref();
# Line 449  Line 468 
468  sub get_subsystem_counts {  sub get_subsystem_counts {
469    my ($self, $dataset) = @_;    my ($self, $dataset) = @_;
470    
471    my $table = $self->dbtable;    my $table = $self->dbtable_best_psc;
472    my $dbid  = $self->get_dataset_id($dataset);    my $dbid  = $self->get_dataset_id($dataset);
473    my $where = $self->get_where_clause();    my $where = $self->get_where_clause();
474    $where = ($where) ? "and $where" : '';    $where = ($where) ? "and $where" : '';
475    
476    #print STDERR "select s.tax_group_1, s.tax_group_2, s.tax_group_3, s.tax_str, count(*) as num from ( select id1, min(rank_psc) as rank from $table where dbid=$dbid $where group by id1) as b inner join $table as s on b.id1=s.id1 and b.rank=s.rank_psc where dbid=$dbid group by s.tax_group_1, s.tax_group_2, s.tax_group_3";    my $sth = $self->dbh->prepare("select tax_group_1, tax_group_2, tax_group_3, tax_str, count(*) as num from $table where dbid=$dbid group by tax_group_1, tax_group_2, tax_group_3, tax_str");
  #die;  
   my $sth = $self->dbh->prepare("select s.tax_group_1, s.tax_group_2, s.tax_group_3, s.tax_str, count(*) as num from ( select id1, min(rank_psc) as rank from $table where dbid=$dbid $where group by id1) as b inner join $table as s on b.id1=s.id1 and b.rank=s.rank_psc where dbid=$dbid group by s.tax_group_1, s.tax_group_2, s.tax_group_3");  
477    
478    $sth->execute;    $sth->execute;
479    my $result = $sth->fetchall_arrayref();    my $result = $sth->fetchall_arrayref();
# Line 497  Line 514 
514    
515  =pod  =pod
516    
517    =item * B<get_recruitment_plot_data> (I<genome>)
518    
519    Given a genome id (83333.1), this method returns all sequence ids,
520    the alignment length, the match id and the taxonomy string for all
521    sequences which match the criteria and have their tax_str start equal
522    the genome tax string I<filter>.
523    
524    =cut
525    
526    sub get_recruitment_plot_data {
527      my ($self, $genome) = @_;
528    
529      my $table = $self->dbtable_best_psc;
530      my $dbid  = $self->get_dataset_id("SEED");
531      my $where = $self->get_where_clause();
532      $where = ($where) ? "and $where" : '';
533    
534      my ($tax_id) = $self->dbh->selectrow_array("select tax_str from rdp_to_tax where seq_num='". $genome . "'");
535    
536      if($tax_id =~ /(\S+)\s/){
537        $tax_id = $1;
538      }
539    print STDERR "select id1, id2, b2, e2, logpsc from $table where dbid=$dbid $where and tax_str='$tax_id'";
540      my $sth = $self->dbh->prepare("select id1, id2, b2, e2, logpsc from $table where dbid=$dbid $where and tax_str='$tax_id'");
541    
542      $sth->execute;
543      my $result = $sth->fetchall_arrayref();
544    
545      return $result;
546    
547    }
548    
549    
550    
551    
552    =pod
553    
554  =item * B<get_hits_for_sequence> (I<seq_id>, I<dataset>, I<limit>)  =item * B<get_hits_for_sequence> (I<seq_id>, I<dataset>, I<limit>)
555    
556  Given a sequence id I<seq_id> (id1) and a dataset name (db_id), this method returns  Given a sequence id I<seq_id> (id1) and a dataset name (db_id), this method returns
# Line 546  Line 600 
600    
601  }  }
602    
603    =pod
604    
605    =back
606    
607    =cut

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.9

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3