[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.12, Wed Jun 11 20:52:32 2008 UTC revision 1.13, Wed Jun 11 21:17:56 2008 UTC
# Line 7  Line 7 
7    
8  use FIG_Config;  use FIG_Config;
9  use DBI;  use DBI;
10    use Data::Dumper;
11    
12  1;  1;
13    
# Line 65  Line 66 
66                 dbh => $dbh,                 dbh => $dbh,
67                 key2taxa => undef,                 key2taxa => undef,
68                 query => {},                 query => {},
69                       dbid_cache => {},
70               };               };
71    bless $self, $class;    bless $self, $class;
72    
# Line 149  Line 151 
151  }  }
152    
153    
154    #
155    # Determine the correct dbid for this job. Use sims.database_list
156    # to find the version that the analysis was run with.
157    #
158  sub get_dataset_id {  sub get_dataset_id {
159    # mapping contained in table db_type      my($self, $dataset) = @_;
160    # unstable, changes every time  
161    my $db_ids = { 'SEED' => 2,      my $id = $self->{dbid_cache}->{$dataset};
162                   'Greengenes' => 3,      return $id if defined($id);
163                   'RDP' => 1,  
164                   'LSU' => 4,      my($dbname, $type) = split(/:/, $dataset);
165                   'SSU' => 5,  
166                   'Subsystem' => 6,      my $dbs = $self->job->metaxml->get_metadata('sims.database_list');
167                 };  
168    return $db_ids->{ $_[1] } || undef;      my @this = grep { $_->{name} eq $dbname } @$dbs;
169  }      if (@this)
170        {
171            my $vers = $this[0]->{version};
172    
173            #
174            # Now we can find the dbid ni the database.
175            #
176            my $res = $self->dbh->selectcol_arrayref(qq(SELECT dbid
177                                                        FROM seq_db
178                                                        WHERE name = ? AND version = ?
179                                                            AND tax_db_name = ?), undef,
180                                                     $dbname, $vers, $type);
181            if (@$res)
182            {
183                print STDERR "Found @$res for $dbname $type $vers\n";
184                $id = $res->[0];
185                $self->{dbid_cache}->{$dataset} = $id;
186                return $id;
187            }
188            print STDERR "Did not find anything for dataset='$dataset' '$dbname' '$type' '$vers'\n";
189        }
190        print STDERR "did not find a vers for dataset='$dataset' $dbname $type\n" . Dumper($dbs);
191    }
192    
193  #******************************************************************************  #******************************************************************************
194  #* MANAGING QUERY CRITERIA  #* MANAGING QUERY CRITERIA
# Line 424  Line 451 
451    $sth->execute;    $sth->execute;
452    my $result = $sth->fetchall_arrayref();    my $result = $sth->fetchall_arrayref();
453    
454      print STDERR "get_group_counts: ds=$dataset group=$group filter1=$filter1 filter2=$filter2\n";
455      print STDERR Dumper($result);
456    return $result;    return $result;
457    
458  }  }
# Line 526  Line 555 
555    my ($self, $genome) = @_;    my ($self, $genome) = @_;
556    
557    my $table = $self->dbtable_best_psc;    my $table = $self->dbtable_best_psc;
558    my $dbid  = $self->get_dataset_id("SEED");    my $dbid  = $self->get_dataset_id("SEED:seed_genome_tax");
559    my $where = $self->get_where_clause();    my $where = $self->get_where_clause();
560    $where = ($where) ? "and $where" : '';    $where = ($where) ? "and $where" : '';
561    
562    my ($tax_id) = $self->dbh->selectrow_array("select tax_str from rdp_to_tax where seq_num='". $genome . "'");    my ($tax_id) = $self->dbh->selectrow_array(qq(SELECT tax_str
563                                                    FROM rdp_to_tax
564                                                    WHERE seq_num= ?), undef, $genome);
565    
566    if($tax_id =~ /(\S+)\s/){    if($tax_id =~ /(\S+)\s/){
567      $tax_id = $1;      $tax_id = $1;
568    }    }
   my $sth = $self->dbh->prepare("select id1, id2, b2, e2, logpsc from $table where dbid=$dbid $where and tax_str='$tax_id'");  
569    
570    $sth->execute;    my $sth = $self->dbh->prepare(qq(SELECT id1, id2, b2, e2, logpsc
571                                       FROM $table
572                                       WHERE dbid=? $where and tax_str=?));
573    
574    
575      $sth->execute($dbid, $tax_id);
576    my $result = $sth->fetchall_arrayref();    my $result = $sth->fetchall_arrayref();
577    
578    return $result;    return $result;
# Line 566  Line 601 
601    my $dbid  = $self->get_dataset_id($dataset);    my $dbid  = $self->get_dataset_id($dataset);
602    $limit = 10 unless ($limit);    $limit = 10 unless ($limit);
603    
604    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;");    my $sth = $self->dbh->prepare(qq(SELECT id2, tax_str, logpsc, bsc, ali_ln,
605    $sth->execute;                                          iden, b1, e1
606                                       FROM $table
607                                       WHERE id1=? AND dbid=? AND rank_psc < ?));
608      $sth->execute($id, $dbid, $limit);
609    my $result = $sth->fetchall_arrayref();    my $result = $sth->fetchall_arrayref();
610    
611    return $result;    return $result;

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3