[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.3, Fri Apr 18 20:09:19 2008 UTC revision 1.8, Wed May 7 20:31:19 2008 UTC
# Line 36  Line 36 
36    my $dbh;    my $dbh;
37    eval {    eval {
38    
39        my $dbms     = $FIG_Config::mgrast_dbms;
40      my $host     = $FIG_Config::mgrast_dbhost;      my $host     = $FIG_Config::mgrast_dbhost;
41      my $database = $FIG_Config::mgrast_db;      my $database = $FIG_Config::mgrast_db;
42      my $user     = $FIG_Config::mgrast_dbuser;      my $user     = $FIG_Config::mgrast_dbuser;
43      my $password = '';      my $password = '';
44    
45        if ($dbms eq 'Pg')
46        {
47            $dbh = DBI->connect("DBI:Pg:dbname=$database;host=$host", $user, $password,
48                            { RaiseError => 1, AutoCommit => 0, PrintError => 0 }) ||
49                                die "database connect error.";
50        }
51        elsif ($dbms eq 'mysql' or $dbms eq '') # Default to mysql
52        {
53      $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $password,      $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $password,
54                          { RaiseError => 1, AutoCommit => 0, PrintError => 0 }) ||                          { RaiseError => 1, AutoCommit => 0, PrintError => 0 }) ||
55                                            die "database connect error.";                                            die "database connect error.";
56        }
57        else
58        {
59            die "MetagenomeAnalysis: unknown dbms '$dbms'";
60        }
61    
62    };    };
63    if ($@) {    if ($@) {
64      warn "Unable to connect to metagenomics database: $@\n";      warn "Unable to connect to metagenomics database: $@\n";
# Line 149  Line 164 
164    
165  =pod  =pod
166    
167    =over 4
168    
169  =item * B<query_evalue> (I<evalue>)  =item * B<query_evalue> (I<evalue>)
170    
171  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 454  Line 471 
471    my $where = $self->get_where_clause();    my $where = $self->get_where_clause();
472    $where = ($where) ? "and $where" : '';    $where = ($where) ? "and $where" : '';
473    
474      #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";
475     #die;
476    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");    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;
# Line 495  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;
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      my $sth = $self->dbh->prepare("select s.id1, s.id2, s.b2, s.e2, s.logpsc 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 and s.tax_str='$tax_id'");
537    
538      $sth->execute;
539      my $result = $sth->fetchall_arrayref();
540    
541      return $result;
542    
543    }
544    
545    
546    
547    
548    =pod
549    
550    =item * B<get_hits_for_sequence> (I<seq_id>, I<dataset>, I<limit>)
551    
552    Given a sequence id I<seq_id> (id1) and a dataset name (db_id), this method returns
553    the first I<limit> rows of hit data for this sequence. If no I<limit> is provided, it
554    will default to 10.
555    It returns (match id, taxonomy string, log evalue, bitscore, alignment length,
556    percent identity, start1, end1) per hit.
557    
558    =cut
559    
560    sub get_hits_for_sequence {
561      my ($self, $id, $dataset, $limit) = @_;
562    
563      my $table = $self->dbtable;
564      my $dbid  = $self->get_dataset_id($dataset);
565      $limit = 10 unless ($limit);
566    
567      my $sth = $self->dbh->prepare("select id2, tax_str, logpsc, bsc, ali_ln, iden, b1, e1 from $table where id1=$id and dbid=$dbid and rank_psc<$limit;");
568      $sth->execute;
569      my $result = $sth->fetchall_arrayref();
570    
571      return $result;
572    
573    }
574    
575    
576    =pod
577    
578  =item * B<get_align_len_range> (I<dataset_name>)  =item * B<get_align_len_range> (I<dataset_name>)
579    
580  Given a dataset name (db_id), this method returns  Given a dataset name (db_id), this method returns
# Line 516  Line 596 
596    
597  }  }
598    
599    =pod
600    
601    =back
602    
603    =cut

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3