Skip to content
Merged
9 changes: 3 additions & 6 deletions src/MGRAST/html/js/FileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ function start_upload () {
document.getElementById('progress_display').style.display = "";

if (start < SIZE) {
if ('mozSlice' in blob) {
chunk = blob.mozSlice(start, end);
} else {
chunk = blob.webkitSlice(start, end);
}

var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
chunk = blobSlice.call(blob, start, end);

document.getElementById("upload_progress").style.display = "";
document.querySelector("#upload_status").innerHTML = "<b>current file</b> " + blob.name + "<br><b>file</b> " + (fu_curr_file+1) + " of " + fu_curr_files.length + "<br><b>size</b> " + pretty_size(blob.size) + "<br><b>type</b> " + pretty_type(blob.type);
fu_curr_offset = end;
Expand Down
4 changes: 3 additions & 1 deletion src/MGRAST/html/js/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function init_all () {
auth = user.auth;
init_uploader();
update_inbox();
document.getElementById('new_project').addEventListener('keydown', function (event) { window.lastP = this.value; });
document.getElementById('new_project').addEventListener('keyup', function (event) { if (! this.value.match(/^[\w+\-\(\)\@\; \:]*$/)) { this.value = window.lastP; alert('invalid character'); } });
}
}

Expand All @@ -33,7 +35,7 @@ function stop(e){

function validateTextFields() {
var boxes = { "deviation": "positive_float",
"max_ambig": "positive_int",
"max_ambig": "int",
"max_lqb": "int",
"min_qual": "int" };

Expand Down
1 change: 1 addition & 0 deletions src/MGRAST/lib/WebPage/Analysis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4607,6 +4607,7 @@ sub metabolism_visual {
$content .= "'>";
close(D);
unlink $infile;
$cdata =~ s/'/\&\#39\;/g;

$content .= "<form method=post action='download.cgi'><input type='hidden' name='filename' value='data.csv'><input type='hidden' name='content' value='$cdata'><input type='submit' value='download values used to generate this figure'></form>";

Expand Down
44 changes: 24 additions & 20 deletions src/MGRAST/lib/resources/matrix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,30 @@ sub new {
$self->{org2tid} = {};
$self->{max_mgs} = 100;
$self->{cutoffs} = { evalue => '5', identity => '60', length => '15' };
$self->{attributes} = { "id" => [ 'string', 'unique object identifier' ],
"url" => [ 'uri', 'resource location of this object instance' ],
"format" => [ 'string', 'format specification name' ],
"format_url" => [ 'string', 'url to the format specification' ],
"type" => [ 'string', 'type of the data in the return table (taxon, function or gene)' ],
"generated_by" => [ 'string', 'identifier of the data generator' ],
"date" => [ 'date', 'time the output data was generated' ],
"matrix_type" => [ 'string', 'type of the data encoding matrix (dense or sparse)' ],
"matrix_element_type" => [ 'string', 'data type of the elements in the return matrix' ],
"matrix_element_value" => [ 'string', 'result_type of the elements in the return matrix' ],
"shape" => [ 'list', ['integer', 'list of the dimension sizes of the return matrix'] ],
"rows" => [ 'list', ['object', [{'id' => ['string', 'unique annotation text'],
'metadata' => ['hash', 'key value pairs describing metadata']}, "rows object"]] ],
"columns" => [ 'list', ['object', [{'id' => ['string', 'unique metagenome identifier'],
'metadata' => ['hash', 'key value pairs describing metadata']}, "columns object"]] ],
"data" => [ 'list', ['list', ['float', 'the matrix values']] ]
};
$self->{sources} = { organism => [ $self->source->{m5nr}, $self->source->{m5rna} ],
ontology => $self->source->{ontology}
};
$self->{attributes} = {
"id" => [ 'string', 'unique object identifier' ],
"url" => [ 'uri', 'resource location of this object instance' ],
"format" => [ 'string', 'format specification name' ],
"format_url" => [ 'string', 'url to the format specification' ],
"type" => [ 'string', 'type of the data in the return table (taxon, function or gene)' ],
"generated_by" => [ 'string', 'identifier of the data generator' ],
"date" => [ 'date', 'time the output data was generated' ],
"matrix_type" => [ 'string', 'type of the data encoding matrix (dense or sparse)' ],
"matrix_element_type" => [ 'string', 'data type of the elements in the return matrix' ],
"matrix_element_value" => [ 'string', 'result_type of the elements in the return matrix' ],
"shape" => [ 'list', ['integer', 'list of the dimension sizes of the return matrix'] ],
"rows" => [ 'list', ['object', [{'id' => ['string', 'unique annotation text'],
'metadata' => ['hash', 'key value pairs describing metadata']}, "rows object"]]
],
"columns" => [ 'list', ['object', [{'id' => ['string', 'unique metagenome identifier'],
'metadata' => ['hash', 'key value pairs describing metadata']}, "columns object"]]
],
"data" => [ 'list', ['list', ['float', 'the matrix values']] ]
};
$self->{sources} = {
organism => [ $self->source->{m5nr}, $self->source->{m5rna} ],
ontology => $self->source->{ontology}
};
map { push @{$self->{sources}{organism}}, $_ } @{$self->source->{protein}};
map { push @{$self->{sources}{organism}}, $_ } @{$self->source->{rna}};
return $self;
Expand Down
159 changes: 101 additions & 58 deletions src/MGRAST/lib/resources/profile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,63 +21,82 @@ sub new {
$self->{name} = "profile";
$self->{rights} = \%rights;
$self->{cutoffs} = { evalue => '5', identity => '60', length => '15' };
$self->{sources} = [ $self->source->{m5nr}[0], @{$self->source->{protein}}, $self->source->{m5rna}[0], @{$self->source->{rna}}, @{$self->source->{ontology}} ];
$self->{attributes} = { "id" => [ 'string', 'unique object identifier' ],
"format" => [ 'string', 'format specification name' ],
"format_url" => [ 'string', 'url to the format specification' ],
"type" => [ 'string', 'type of the data in the return table (taxon, function or gene)' ],
"generated_by" => [ 'string', 'identifier of the data generator' ],
"date" => [ 'date', 'time the output data was generated' ],
"matrix_type" => [ 'string', 'type of the data encoding matrix (dense or sparse)' ],
"matrix_element_type" => [ 'string', 'data type of the elements in the return matrix' ],
"shape" => [ 'list', [ 'integer', 'list of the dimension sizes of the return matrix' ] ],
"rows" => [ 'list', [ 'object', [ { 'id' => [ 'string', 'unique identifier' ],
'metadata' => [ 'hash', 'key value pairs describing metadata' ] }, "rows object" ] ] ],
"columns" => [ 'list', [ 'object', [ { 'id' => [ 'string', 'unique identifier' ],
'metadata' => [ 'hash', 'list of metadata, contains the metagenome' ] }, "columns object" ] ] ],
"data" => [ 'list', [ 'list', [ 'float', 'the matrix values' ] ] ]
};
$self->{sources} = [
$self->source->{m5nr}[0],
@{$self->source->{protein}},
$self->source->{m5rna}[0],
@{$self->source->{rna}},
@{$self->source->{ontology}}
];
$self->{attributes} = {
"id" => [ 'string', 'unique object identifier' ],
"format" => [ 'string', 'format specification name' ],
"format_url" => [ 'string', 'url to the format specification' ],
"type" => [ 'string', 'type of the data in the return table (taxon, function or gene)' ],
"generated_by" => [ 'string', 'identifier of the data generator' ],
"date" => [ 'date', 'time the output data was generated' ],
"matrix_type" => [ 'string', 'type of the data encoding matrix (dense or sparse)' ],
"matrix_element_type" => [ 'string', 'data type of the elements in the return matrix' ],
"shape" => [ 'list', [ 'integer', 'list of the dimension sizes of the return matrix' ] ],
"rows" => [ 'list', [ 'object', [ { 'id' => [ 'string', 'unique identifier' ],
'metadata' => [ 'hash', 'key value pairs describing metadata' ] }, "rows object" ] ]
],
"columns" => [ 'list', [ 'object', [ { 'id' => [ 'string', 'unique identifier' ],
'metadata' => [ 'hash', 'list of metadata, contains the metagenome' ] }, "columns object" ] ]
],
"data" => [ 'list', [ 'list', [ 'float', 'the matrix values' ] ] ]
};
return $self;
}

# resource is called without any parameters
# this method must return a description of the resource
sub info {
my ($self) = @_;
my $content = { 'name' => $self->name,
'url' => $self->cgi->url."/".$self->name,
'description' => "A profile in biom format that contains abundance and similarity values",
'type' => 'object',
'documentation' => $self->cgi->url.'/api.html#'.$self->name,
'requests' => [ { 'name' => "info",
'request' => $self->cgi->url."/".$self->name,
'description' => "Returns description of parameters and attributes.",
'method' => "GET" ,
'type' => "synchronous" ,
'attributes' => "self",
'parameters' => { 'options' => {},
'required' => {},
'body' => {} } },
{ 'name' => "instance",
'request' => $self->cgi->url."/".$self->name."/{ID}",
'description' => "Returns a single data object in BIOM format",
'method' => "GET" ,
'type' => "synchronous" ,
'attributes' => $self->attributes,
'parameters' => { 'options' => {
'evalue' => ['int', 'negative exponent value for maximum e-value cutoff: default is '.$self->{cutoffs}{evalue}],
'identity' => ['int', 'percent value for minimum % identity cutoff: default is '.$self->{cutoffs}{identity}],
'length' => ['int', 'value for minimum alignment length cutoff: default is '.$self->{cutoffs}{length}],
'type' => [ 'cv', [ ['organism', 'return organism data'],
['function', 'return functional data'],
['feature', 'return feature data'] ] ],
'source' => [ 'cv', $self->{sources} ]
},
'required' => { "id" => [ "string", "unique object identifier" ] },
'body' => {} } }
]
};
$self->return_data($content);
my ($self) = @_;
my $content = {
'name' => $self->name,
'url' => $self->cgi->url."/".$self->name,
'description' => "A profile in biom format that contains abundance and similarity values",
'type' => 'object',
'documentation' => $self->cgi->url.'/api.html#'.$self->name,
'requests' => [
{ 'name' => "info",
'request' => $self->cgi->url."/".$self->name,
'description' => "Returns description of parameters and attributes.",
'method' => "GET" ,
'type' => "synchronous" ,
'attributes' => "self",
'parameters' => {
'options' => {},
'required' => {},
'body' => {} }
},
{ 'name' => "instance",
'description' => "Returns a single data object in BIOM format",
'method' => "GET" ,
'type' => "synchronous" ,
'attributes' => $self->attributes,
'parameters' => {
'options' => {
'evalue' => ['int', 'negative exponent value for maximum e-value cutoff: default is '.$self->{cutoffs}{evalue}],
'identity' => ['int', 'percent value for minimum % identity cutoff: default is '.$self->{cutoffs}{identity}],
'length' => ['int', 'value for minimum alignment length cutoff: default is '.$self->{cutoffs}{length}],
'source' => ['cv', $self->{sources}],
'type' => ['cv', [ ['organism', 'return organism data'],
['function', 'return functional data'],
['feature', 'return feature data'] ]
],
'hit_type' => ['cv', [ ['all', 'returns results based on all organisms that map to top hit per read-feature'],
['single', 'returns results based on a single organism for top hit per read-feature'],
['lca', 'returns results based on the Least Common Ancestor for all organisms (M5NR+M5RNA only) that map to hits from a read-feature']]
]
},
'required' => { "id" => ["string", "unique object identifier"] },
'body' => {} }
}
]
};
$self->return_data($content);
}

# the resource is called with an id parameter
Expand Down Expand Up @@ -124,6 +143,7 @@ sub prepare_data {
my $params = {};
my $cgi = $self->cgi;
$params->{type} = $cgi->param('type') ? $cgi->param('type') : 'organism';
$params->{hit_type} = $cgi->param('hit_type') ? $cgi->param('hit_type') : 'all';
$params->{source} = $cgi->param('source') ? $cgi->param('source') : (($params->{type} eq 'organism') ? 'M5NR' : (($params->{type} eq 'function') ? 'Subsystems': 'RefSeq'));
$params->{evalue} = defined($cgi->param('evalue')) ? $cgi->param('evalue') : $self->{cutoffs}{evalue};
$params->{identity} = defined($cgi->param('identity')) ? $cgi->param('identity') : $self->{cutoffs}{identity};
Expand Down Expand Up @@ -180,20 +200,43 @@ sub prepare_data {
# get data
if ($params->{type} eq 'organism') {
$ttype = 'Taxon';
# my ($self, $sources, $eval, $ident, $alen, $with_taxid) = @_;
my ($md5_abund, $result) = $mgdb->get_organisms_for_sources([$params->{source}], int($params->{evalue}), int($params->{identity}), int($params->{length}), 1);
# mgid, source, tax_domain, tax_phylum, tax_class, tax_order, tax_family, tax_genus, tax_species, name, abundance, sub_abundance, exp_avg, exp_stdv, ident_avg, ident_stdv, len_avg, len_stdv, md5s, taxid
my $result = [];
if ($params->{hit_type} eq 'all') {
# my ($self, $sources, $eval, $ident, $alen, $with_taxid) = @_;
(undef, $result) = $mgdb->get_organisms_for_sources([$params->{source}], int($params->{evalue}), int($params->{identity}), int($params->{length}), 1);
# mgid, source, tax_domain, tax_phylum, tax_class, tax_order, tax_family, tax_genus, tax_species, name, abundance, sub_abundance, exp_avg, exp_stdv, ident_avg, ident_stdv, len_avg, len_stdv, md5s, taxid
} elsif ($params->{hit_type} eq 'single') {
# my ($self, $source, $eval, $ident, $alen, $with_taxid) = @_;
$result = $mgdb->get_organisms_unique_for_source($params->{source}, int($params->{evalue}), int($params->{identity}), int($params->{length}), 1);
# mgid, tax_domain, tax_phylum, tax_class, tax_order, tax_family, tax_genus, tax_species, name, abundance, exp_avg, exp_stdv, ident_avg, ident_stdv, len_avg, len_stdv, md5s, taxid
} elsif ($params->{hit_type} eq 'lca') {
# my ($self, $eval, $ident, $alen) = @_;
$result = $mgdb->get_lca_data(int($params->{evalue}), int($params->{identity}), int($params->{length}));
# mgid, tax_domain, tax_phylum, tax_class, tax_order, tax_family, tax_genus, tax_species, name, abundance, exp_avg, exp_stdv, ident_avg, ident_stdv, len_avg, len_stdv
}
foreach my $row (@$result) {
my $tax_str = [ $row->[2], $row->[3], $row->[4], $row->[5], $row->[6], $row->[7], $row->[9] ];
push(@$rows, { "id" => $row->[19], "metadata" => { "taxonomy" => $tax_str } });
push(@$values, [ $self->toFloat($row->[10]), $self->toFloat($row->[12]), $self->toFloat($row->[14]), $self->toFloat($row->[16]) ]);
if ($params->{hit_type} eq 'all') {
my $rmd = {
taxonomy => [$row->[2], $row->[3], $row->[4], $row->[5], $row->[6], $row->[7], $row->[8]],
tax_id => $row->[19]
};
push(@$rows, { "id" => $row->[9], "metadata" => $rmd });
push(@$values, [ $self->toFloat($row->[10]), $self->toFloat($row->[12]), $self->toFloat($row->[14]), $self->toFloat($row->[16]) ]);
} else {
my $rmd = { taxonomy => [$row->[1], $row->[2], $row->[3], $row->[4], $row->[5], $row->[6], $row->[7]] };
if ($params->{hit_type} eq 'single') {
$rmd->{tax_id} = $row->[17];
}
push(@$rows, { "id" => $row->[8], "metadata" => $rmd });
push(@$values, [ $self->toFloat($row->[9]), $self->toFloat($row->[10]), $self->toFloat($row->[12]), $self->toFloat($row->[14]) ]);
}
}
}
elsif ($params->{type} eq 'function') {
$ttype = 'Function';
my $function2ont = $mgdb->get_hierarchy('ontology', $params->{source});
# my ($self, $source, $eval, $ident, $alen) = @_;
my ($md5_abund, $result) = $mgdb->get_ontology_for_source($params->{source}, int($params->{evalue}), int($params->{identity}), int($params->{length}));
my (undef, $result) = $mgdb->get_ontology_for_source($params->{source}, int($params->{evalue}), int($params->{identity}), int($params->{length}));
# mgid, id, annotation, abundance, sub_abundance, exp_avg, exp_stdv, ident_avg, ident_stdv, len_avg, len_stdv, md5s
foreach my $row (@$result) {
next unless (exists $function2ont->{$row->[1]});
Expand Down
Loading