Skip to content

Commit

Permalink
Merge pull request #189 from teharrison/develop
Browse files Browse the repository at this point in the history
fixes and stuff
  • Loading branch information
jaredbischof committed Dec 12, 2012
2 parents 1745eac + 323d154 commit b211174
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
14 changes: 8 additions & 6 deletions src/Babel/lib/Babel.pm
Expand Up @@ -653,16 +653,18 @@ sub org2contig_data {
my ($self, $org, $get_func) = @_;

my $sql;
# org is index, return md5 as index
if ($org =~ /^\d+$/) {
if ($get_func) {
$sql = qq(select c.name, d.md5, d.id, f.name, ic.low, ic.high, ic.strand, c.length
from id2contig ic, contigs c, md5_protein d, functions f
where (ic.id=d.id) and (ic.contig=c._id) and (c.organism=$org) and (d.function=f._id) order by c.name, ic.low);
$sql = qq(select c.name, m._id, d.id, f.name, ic.low, ic.high, ic.strand, c.length
from id2contig ic, contigs c, md5_protein d, md5s m, functions f
where (ic.id=d.id) and (ic.contig=c._id) and (c.organism=$org) and (m.md5=d.md5) and (d.function=f._id) order by c.name, ic.low);
} else {
$sql = qq(select c.name, d.md5, d.id, ic.low, ic.high, ic.strand, c.length
from id2contig ic, contigs c, md5_protein d
where (ic.id=d.id) and (ic.contig=c._id) and (c.organism=$org) order by c.name, ic.low);
$sql = qq(select c.name, m._id, d.id, ic.low, ic.high, ic.strand, c.length
from id2contig ic, contigs c, md5_protein d, md5s m
where (ic.id=d.id) and (ic.contig=c._id) and (c.organism=$org) and (m.md5=d.md5) order by c.name, ic.low);
}
# org is text, return md5 as text
} else {
my $qorg = $self->dbh->quote($org);
if ($get_func) {
Expand Down
45 changes: 26 additions & 19 deletions src/MGRAST/lib/Analysis.pm
Expand Up @@ -984,18 +984,23 @@ sub get_md5_evals_for_organism_source {
my ($self, $org, $src) = @_;

my $data = {};
my $umd5 = {};
my $where = $self->_get_where_str(['j.'.$self->_qver, 'j.'.$self->_qjobs, "a.name=".$self->_dbh->quote($org), "j.source=".$self->_src_id->{$src}, "j.id = a._id"]);
my $md5s = $self->_dbh->selectcol_arrayref("SELECT j.md5s FROM ".$self->_jtbl->{organism}." j, ".$self->_atbl->{organism}." a".$where);
unless ($md5s && (@$md5s > 0)) {
return $data;
}
foreach my $m (@$md5s) {
map { $data->{$_} = [] } @$m;
map { $umd5->{$_} = 1 } @$m;
}
$where = $self->_get_where_str([$self->_qver, $self->_qjobs, "md5 IN (".join(",", keys %$data).")"]);
foreach my $row (@{ $self->_dbh->selectall_arrayref("SELECT md5, evals FROM ".$self->_jtbl->{md5}.$where) }) {
my ($md5, $evals) = @$row;
for (my $i=0; $i<@$evals; $i++) { $data->{$md5}->[$i] += $evals->[$i]; }

my $iter = natatime $self->_chunk, keys %$umd5;
while (my @curr = $iter->()) {
$where = $self->_get_where_str([$self->_qver, $self->_qjobs, "md5 IN (".join(",", @curr).")"]);
my $sql = "SELECT md5, evals FROM ".$self->_jtbl->{md5}.$where;
foreach my $row (@{ $self->_dbh->selectall_arrayref($sql) }) {
for (my $i=0; $i<@{$row->[1]}; $i++) { $data->{$row->[0]}->[$i] += $row->[1]->[$i]; }
}
}
# md5 => [ eval ]
return $data;
Expand All @@ -1004,24 +1009,26 @@ sub get_md5_evals_for_organism_source {
sub get_md5_data_for_organism_source {
my ($self, $org, $src, $eval) = @_;

my $data = {};
my $data = [];
my $umd5 = {};
my $where = $self->_get_where_str(['j.'.$self->_qver, 'j.'.$self->_qjobs, "a.name=".$self->_dbh->quote($org), "j.source=".$self->_src_id->{$src}, "j.id = a._id"]);
my $md5s = $self->_dbh->selectrow_arrayref("SELECT j.md5s FROM ".$self->_jtbl->{organism}." j, ".$self->_atbl->{organism}." a".$where);
my $md5s = $self->_dbh->selectcol_arrayref("SELECT j.md5s FROM ".$self->_jtbl->{organism}." j, ".$self->_atbl->{organism}." a".$where);
unless ($md5s && (@$md5s > 0)) {
return [];
}
foreach my $m (@$md5s) {
map { $data->{$_} = 1 } @$m;
map { $umd5->{$_} = 1 } @$m;
}
$where = $self->_get_where_str([$self->_qver, $self->_qjobs, "md5 IN (".join(",", keys %$data).")", "seek IS NOT NULL", "length IS NOT NULL"]);
my $sql = "SELECT DISTINCT job,md5,abundance,exp_avg,exp_stdv,ident_avg,ident_stdv,len_avg,len_stdv,seek,length FROM ".$self->_jtbl->{md5}.$where;
my $rows = $self->_dbh->selectall_arrayref($sql);
if ($rows && (@$rows > 0)) {
map { $_->[0] = $self->_mg_map->{$_->[0]} } @$rows;
return $rows;
} else {
return [];

my $iter = natatime $self->_chunk, keys %$umd5;
while (my @curr = $iter->()) {
$where = $self->_get_where_str([$self->_qver, $self->_qjobs, "md5 IN (".join(",", @curr).")", "seek IS NOT NULL", "length IS NOT NULL"]);
my $sql = "SELECT DISTINCT job,md5,abundance,exp_avg,exp_stdv,ident_avg,ident_stdv,len_avg,len_stdv,seek,length FROM ".$self->_jtbl->{md5}.$where;
foreach my $row (@{ $self->_dbh->selectall_arrayref($sql) }) {
push @$data, [ $self->_mg_map->{$row->[0]}, @$row[1..10] ];
}
}
return $data;
# [ mgid, md5, abund, exp_avg, exp_stdv, ident_avg, ident_stdv, len_avg, len_stdv, seek, length ]
}

Expand Down Expand Up @@ -1284,7 +1291,7 @@ sub get_organisms_unique_for_source {
"COALESCE(tax_order,'unassigned') AS txo,COALESCE(tax_family,'unassigned') AS txf,COALESCE(tax_genus,'unassigned') AS txg,".
"COALESCE(tax_species,'unassigned') AS txs,name FROM ".$self->_atbl->{organism}." WHERE _id IN (".join(',', keys %$all_orgs).")";
foreach my $row (@{ $self->_dbh->selectall_arrayref($sql) }) {
my $oid = pop @$row;
my $oid = shift @$row;
$tax->{$oid} = $row;
}

Expand Down Expand Up @@ -1602,8 +1609,8 @@ sub get_md5_data {
my $sql = "SELECT DISTINCT j.job,j.md5,j.abundance,j.exp_avg,j.exp_stdv,j.ident_avg,j.ident_stdv,j.len_avg,j.len_stdv${cseek}${crep} FROM ".
$self->_jtbl->{md5}." j".($rep_org_src ? ", md5_organism_unique r" : "").$where.($ignore_sk ? "" : " ORDER BY job, seek");

foreach my $row (@{ $self->_dbh->selectall_arrayref($sql) }) {
my $j = pop @$row;
foreach my $row (@{ $self->_dbh->selectall_arrayref($sql) }) {
my $j = shift @$row;
my $mg = $self->_mg_map->{$j};
push @{ $data->{$mg} }, [ $mg, @$row ];
}
Expand Down
11 changes: 6 additions & 5 deletions src/MGRAST/lib/WebPage/Analysis.pm
Expand Up @@ -1099,8 +1099,8 @@ sub recruitment_plot_data {

my @data = ();
my %uniq = ();
my $link = $mgdb->link_for_source($source);
my %md5_data = map { $_->[1], [ @$_[2..10] ] } @{ $mgdb->get_md5_data_for_organism_source($name, $source, $cutoff) };
my $link = $mgdb->link_for_source($source);

foreach ( @{ $mgdb->ach->org2contig_data($orgid, 1) } ) {
my ($ctg, $md5, $id, $func, $low, $high, $strand, $clen) = @$_;
Expand Down Expand Up @@ -1135,7 +1135,7 @@ sub recruitment_plot_graph {
@$evals = @$evals[$cutoff..4];
@$colors = @$colors[$cutoff..4];

my $unique_str = join('_', ( join("_", values %{$mgdb->jobs}), $orgid, $eval, $log ));
my $unique_str = join('_', ( join("_", @{$mgdb->_jobs}), $orgid, $eval, $log ));
my $circos_file = "circos_$unique_str";
my $config_file = "$Conf::temp/circos_$unique_str.conf";
my $karyotype_file = "$Conf::temp/karyotype_$unique_str.txt";
Expand Down Expand Up @@ -1163,7 +1163,7 @@ sub recruitment_plot_graph {

my @eval_sums = (0, 0, 0, 0, 0);
@eval_sums = @eval_sums[$cutoff..4];

my $md5_evals = $mgdb->get_md5_evals_for_organism_source($name, $source);
foreach my $md5 (keys %$md5_evals) {
my @e = @{ $md5_evals->{$md5} };
Expand Down Expand Up @@ -1325,9 +1325,10 @@ units_nounit = n
~;
close CFG;

my $c = system($Conf::circos_path." -conf $config_file -silent");
my $cmd = $Conf::circos_path." -conf ".$config_file." -silent 2>&1";
my $msg = `$cmd`;
for (my $j=0; $j<@eval_sums; $j++) { push @$eval_set, [ $evals->[$j], $eval_sums[$j], $colors->[$j] ]; }
return ($c == 0) ? [$circos_file, $eval_set, [$num_frag, $num_hit, $num_feat]] : ["Circos failed: $?", []];
return $msg ? ["ERROR: $msg", [], undef] : [$circos_file, $eval_set, [$num_frag, $num_hit, $num_feat]];
}

sub workbench_export {
Expand Down
2 changes: 1 addition & 1 deletion src/MGRAST/lib/resources2/resource.pm
Expand Up @@ -431,7 +431,7 @@ sub toFloat {
}

sub toNum {
my ($x, $type) = @_;
my ($self, $x, $type) = @_;
if ($type eq 'abundance') {
return int($x);
} else {
Expand Down

0 comments on commit b211174

Please sign in to comment.