Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/MGRAST/lib/WebPage/DownloadMetagenome.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use LWP::UserAgent;
use JSON;

use Conf;
use Auth;
use MGRAST::Metadata;

1;
Expand Down Expand Up @@ -57,9 +58,7 @@ sub init {
'440' => { name => 'RNA Clustering 97%', link => "rna_clust" },
'450' => { name => 'M5 RNA Search', link => "rna_sim" },
'550' => { name => 'Protein Clustering 90%', link => "aa_clust" },
'650' => { name => 'M5 Protein Search', link => "aa_sim" },
'700' => { name => 'Annotation of Sims', link => "ann_sim" }
'999' => { name => 'Metagenome Statistics', link => "mg_stats" }
'650' => { name => 'M5 Protein Search', link => "aa_sim" }
};
$self->data('stages', $stages);

Expand Down Expand Up @@ -172,7 +171,8 @@ my $css_tmp = qq~
~;

my $content = $css_tmp;
my $job = $self->{job};
my $job = $self->{job};
my $user = $self->application->session->user;

unless ($job) {
$self->title("Data sets available");
Expand Down Expand Up @@ -244,7 +244,7 @@ my $css_tmp = qq~
# group by ID
my $stages = {};
foreach my $set (@{$response->{data}}) {
push @{ $stages->{$set->{id}} }, $set;
push @{ $stages->{$set->{stage_id}} }, $set;
}

# prep output for every stage
Expand Down Expand Up @@ -285,6 +285,10 @@ if (this.innerHTML == "show stats") {
sub stage_download_info {
my ($self, $sid, $stages) = @_;

unless (exists $self->data('stages')->{$sid}) {
return "";
}

my $name = $self->data('stages')->{$sid}->{name};
my $link = $self->data('stages')->{$sid}->{link};
my $content = "<a name='$link'><h3>$name</h3></a>\n";
Expand All @@ -295,6 +299,10 @@ sub stage_download_info {
my $file_count = 0;

foreach my $info (@$stages) {
unless (exists($info->{file_size}) && $info->{file_size}) {
continue;
}

my $stats = exists($info->{statistics}) ? $info->{statistics} : {};
my $count = exists($stats->{bp_count}) ? format_number($stats->{bp_count})." reads" : '';
my $size = exists($info->{file_size}) ? sprintf("%.2f", ($info->{file_size} / (1024 * 1024)))."MB" : '';
Expand Down Expand Up @@ -385,7 +393,7 @@ sub download {
eval {
my $url = $Conf::shock_url.'/node/'.$node.'?download_raw';
my @args = (
$mgrast_token ? ('Authorization', "OAuth $auth") : (),
$mgrast_token ? ('Authorization', "OAuth $mgrast_token") : (),
':read_size_hint', 8192,
':content_cb', sub{ my ($chunk) = @_; print $chunk; }
);
Expand All @@ -401,7 +409,9 @@ sub download {

sub format_number {
my ($val) = @_;
while ($val =~ s/(\d+)(\d{3})+/$1,$2/) {}
unless ($val =~ /\./) {
while ($val =~ s/(\d+)(\d{3})+/$1,$2/) {}
}
return $val;
}

Expand Down
2 changes: 1 addition & 1 deletion src/MGRAST/lib/resources/resource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ sub get_download_set {
my ($self, $mgid, $auth, $seq_only) = @_;

my %seen = ();
my %subset = {'preprocess' => 1, 'dereplication' => 1, 'screen' => 1, 'rna.filter' => 1}
my %subset = ('preprocess' => 1, 'dereplication' => 1, 'screen' => 1);
my $stages = [];
my $mgdata = $self->get_shock_query({'type' => 'metagenome', 'id' => 'mgm'.$mgid}, $auth);
@$mgdata = grep { exists($_->{attributes}{stage_id}) && exists($_->{attributes}{data_type}) } @$mgdata;
Expand Down