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
9 changes: 7 additions & 2 deletions src/MGRAST/html/js/Analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,13 @@ function buffer_data (source, id, selector, dataloc, mgloc, srcloc, abuloc) {
for (h=0; h<selector; h++) {
if (table_visible_columns[data_index][h] && table_visible_columns[data_index][h] != "0") {
if (abuloc && h == abuloc) {
var fid = data_array[i][h].match(/abu\(this\, (\d+)/)[1];
inf += "<td><a style='cursor:pointer' onclick='abu(null, "+fid+", null, \""+data_array[i][srcloc]+"\",\""+data_array[i][dataloc]+"\");'>"+parseInt(data_array[i][abuloc].replace(HTML_REPLACE, ''))+"</a></td>";
var fid = data_array[i][h].match(/abu\(this\, (\d+)/);
if (fid) {
fid = fid[1];
inf += "<td><a style='cursor:pointer' onclick='abu(null, "+fid+", null, \""+data_array[i][srcloc]+"\",\""+data_array[i][dataloc]+"\");'>"+parseInt(data_array[i][abuloc].replace(HTML_REPLACE, ''))+"</a></td>";
} else {
inf += "<td>"+data_array[i][h] + "</td>";
}
} else {
inf += "<td>"+data_array[i][h] + "</td>";
}
Expand Down
62 changes: 57 additions & 5 deletions src/MGRAST/html/js/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,52 @@ function init_all () {
}
}

function stop(e){
e.stopPropagation();
}

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

var success = true;
for (var i in boxes) {
if (boxes.hasOwnProperty(i)) {
var box = document.getElementById(i);
switch (boxes[i]) {
case "positive_float":
if (box.value == 0 || (! box.value.match(/^\d+\.?(\d+)?$/))) {
box.setAttribute('style', "border: 1px solid red; box-shadow: 0 0 7px red;");
success = false;
} else {
box.setAttribute('style', "");
}
break;
case "positive_int":
if (box.value == 0 || (! box.value.match(/^\d+$/))) {
box.setAttribute('style', "border: 1px solid red; box-shadow: 0 0 7px red;");
success = false;
} else {
box.setAttribute('style', "");
}
break;
case "int":
if (! box.value.match(/^\d+$/)) {
box.setAttribute('style', "border: 1px solid red; box-shadow: 0 0 7px red;");
success = false;
} else {
box.setAttribute('style', "");
}
break;
};
}
}

return success;
}

function update_inbox (data, files, action) {
if (data) {
var flist = DataStore['user_inbox'][user.login].files;
Expand Down Expand Up @@ -605,10 +651,14 @@ function unselect_metadata_file () {
}

function accept_pipeline_options () {
document.getElementById("sel_pip_pill").className = "pill_complete";
document.getElementById("icon_step_4").style.display = "";
toggle("sel_pip_div");
check_submitable();
if (validateTextFields()) {
document.getElementById("sel_pip_pill").className = "pill_complete";
document.getElementById("icon_step_4").style.display = "";
toggle("sel_pip_div");
check_submitable();
} else {
alert("You have entered invalid values in the highlighted fields.");
}
}

function check_submitable () {
Expand Down Expand Up @@ -763,10 +813,12 @@ function delete_dir () {
}
}

function generate_webkey (get_new) {
function generate_webkey (get_new, reactivate) {
var get_new_param = "";
if (get_new) {
get_new_param = "&generate_new_key=1";
} else if (reactivate) {
get_new_param = "&reactivate_key=1";
}
$.get("?page=Upload&action=generate_webkey"+get_new_param, function (data) {
document.getElementById('generate_key').innerHTML = data;
Expand Down
55 changes: 26 additions & 29 deletions src/MGRAST/lib/WebPage/Analysis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3807,6 +3807,7 @@ sub metabolism_visual {
$tabnum--;

# mgid => md5 => abundance
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
# mgid, level1, level2, level3, annotation, id, abundance, sub_abundance, exp_avg, exp_stdv, ident_avg, ident_stdv, len_avg, len_stdv, md5s

unless (scalar(@$data)) {
Expand Down Expand Up @@ -4133,42 +4134,38 @@ sub metabolism_visual {
}
my $expanded_data = [];
if (scalar(@comp_mgs) > 1) {
$pt->sample_names( [ @comp_mgs[0..1] ] );

$pt->sample_names( [ @comp_mgs ] );
$pt->coloring_method('split');
my $exp_hash = {};
foreach my $row (@$data) {
next if ($row->[1] eq "-");
next if ($row->[1] eq "Clustering-based subsystems");
if ($row->[0] eq $comp_mgs[0]) {
$exp_hash->{$row->[4]} = $row;
}
my $anno_hash = {};
my $mg2num = {};

for (my $hh=0; $hh<scalar(@comp_mgs); $hh++) {
$mg2num->{$comp_mgs[$hh]} = $hh;
}

foreach my $row (@$data) {
next if ($row->[1] eq "-");
next if ($row->[1] eq "Clustering-based subsystems");
if ($row->[0] eq $comp_mgs[1]) {
my $other = 0;
if (exists($exp_hash->{$row->[4]})) {
$other = $exp_hash->{$row->[4]}->[6];
delete $exp_hash->{$row->[4]};
}
if ($row->[6] + $other > 0) {
if ($has_three) {
push(@$expanded_data, [ 'Metabolism', $row->[1], $row->[2], $row->[3], $row->[4], [ $row->[6], $other ] ] );
} else {
push(@$expanded_data, [ 'Metabolism', $row->[1], $row->[2], $row->[4], [ $row->[6], $other ] ] );
}
}
}
my $keystring = join("", @$row[1..4]);
$anno_hash->{$keystring} = [ @$row[1..4] ];
unless (exists($exp_hash->{$keystring})) {
$exp_hash->{$keystring} = [];
}
$exp_hash->{$keystring}->[$mg2num->{$row->[0]}] = $row->[6];
}
foreach my $key (keys(%$exp_hash)) {
my $row = $exp_hash->{$key};
if ($row->[6] > 0) {
if ($has_three) {
push(@$expanded_data, [ 'Metabolism', $row->[1], $row->[2], $row->[3], $row->[4], [ 0, $row->[6] ] ] );
} else {
push(@$expanded_data, [ 'Metabolism', $row->[1], $row->[2], $row->[4], [ 0, $row->[6] ] ] );
}

foreach my $key (sort(keys(%$exp_hash))) {
my $vals = [];
for (my $ii=0; $ii<scalar(@comp_mgs); $ii++) {
push(@$vals, $exp_hash->{$key}->[$ii] || 0);
}
my $row = $anno_hash->{$key};
if ($has_three) {
push(@$expanded_data, [ 'Metabolism', $row->[0], $row->[1], $row->[2], $row->[3], $vals ] );
} else {
push(@$expanded_data, [ 'Metabolism', $row->[0], $row->[1], $row->[3], $vals ] );
}
}
} else {
Expand Down
82 changes: 67 additions & 15 deletions src/MGRAST/lib/WebPage/Upload.pm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ sub output {
}
}

my $webkey = $self->current_webkey();

my $user_project_ids = $user->has_right_to(undef, "edit", "project");
my $projects = [];
foreach my $pid (@$user_project_ids) {
Expand Down Expand Up @@ -226,7 +228,7 @@ sub output {
<table>
<tr style='display: none;'><td width="125px"><b>ftp</b></td><td>ftp://incoming.metagenomics.anl.gov/<span id="ftp_webkey">YOUR_PRIVATE_WEBKEY</span></td></tr>
<tr><td>http://api.metagenomics.anl.gov/1/inbox</td></tr>
<tr><td colspan=2 style='padding-top: 10px; padding-bottom: 10px;'><div id='generate_key'><input type='button' class='btn' onclick='generate_webkey();' value='generate webkey'></div></td></tr>
<tr><td colspan=2 style='padding-top: 10px; padding-bottom: 10px;'><div id='generate_key'><input type='button' class='btn' onclick='generate_webkey();' value='~. ($webkey->{key} ? ($webkey->{valid} ? "view webkey" : "re-activate webkey") : "generate webkey") . qq~'></div></td></tr>
</table>
<p><b>Note:</b> The <a href='http://blog.metagenomics.anl.gov/mg-rast-v3-2-faq/#command_line_submission' target=_blank>Blog</a> lists a number of examples for data transfer.</p>

Expand Down Expand Up @@ -1051,6 +1053,33 @@ sub validate_metadata {
exit 0;
}

sub current_webkey {
my ($self) = @_;

my $application = $self->application();
my $master = $application->dbmaster();
my $user = $application->session->user();

my $existing_key = $master->Preferences->get_objects( { 'user' => $user, 'name' => 'WebServicesKey' } );
my $existing_date = $master->Preferences->get_objects( { 'user' => $user, 'name' => 'WebServiceKeyTdate' } );

my $valid = 0;
my $key = 0;
my $date = 0;

if (scalar(@$existing_key)) {
if ($existing_date->[0]->{value} > time) {
$valid = 1;
}
$key = $existing_key->[0]->{value};
$date = $existing_date->[0]->{value};
}

return { "key" => $key,
"date" => $date,
"valid" => $valid };
}

sub generate_webkey {
my ($self) = @_;

Expand All @@ -1059,13 +1088,27 @@ sub generate_webkey {
my $master = $application->dbmaster();
my $user = $application->session->user();

my $timeout = 60 * 60 * 24 * 7; # one week

my $generated = "";

my $webkey = { "key" => 0,
"date" => 0,
"valid" => 0 };

my $existing_key = $master->Preferences->get_objects( { 'user' => $user, 'name' => 'WebServicesKey' } );
my $existing_date = $master->Preferences->get_objects( { 'user' => $user, 'name' => 'WebServiceKeyTdate' } );
if (scalar(@$existing_key) && ! $cgi->param('generate_new_key')) {
$existing_key = $existing_key->[0]->{value};
$existing_date = $existing_date->[0]->{value};
$webkey->{key} = $existing_key->[0]->{value};
$webkey->{date} = $existing_date->[0]->{value};
if ($webkey->{date} > time) {
$webkey->{valid} = 1;
}

if ($cgi->param('reactivate_key')) {
my $tdate = time + $timeout;
$existing_date->[0]->value($tdate);
}
} else {
my $possible = 'abcdefghijkmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
while (length($generated) < 25) {
Expand All @@ -1080,7 +1123,6 @@ sub generate_webkey {
}
$preference = $master->Preferences->get_objects( { value => $generated } );
}
my $timeout = 60 * 60 * 24 * 7; # one week
my $tdate = time + $timeout;

my $pref = $master->Preferences->get_objects( { 'user' => $user, 'name' => 'WebServiceKeyTdate' } );
Expand All @@ -1098,20 +1140,30 @@ sub generate_webkey {
$pref = $master->Preferences->create( { 'user' => $user, 'name' => 'WebServicesKey' } );
}
$pref->value($generated);
$existing_key = $generated;
$existing_date = $tdate;

# create a symlink

$webkey->{key} = $generated;
$webkey->{date} = $tdate;
$webkey->{valid} = 1;
}

my $content = "<b>Your current WebKey:</b> <input type='text' readOnly=1 size=25 value='" . $existing_key . "'>";
my $content = "";

my ($sec,$min,$hour,$mday,$mon,$year) = localtime($existing_date);
my $tdate_readable = ($year + 1900)." ".sprintf("%02d", $mon + 1)."-".sprintf("%02d", $mday)." ".sprintf("%02d", $hour).":".sprintf("%02d", $min).".".sprintf("%02d", $sec);
$content .= " <b>valid until</b>: <input type='text' readOnly=1 size=20 value='" . $tdate_readable . "'>";
$content .= " <input type='button' class='btn' value='generate new key' onclick='generate_webkey(1);'>";
$content .= "<img src='./Html/clear.gif' onload='document.getElementById(\"ftp_webkey\").innerHTML=\"" . $existing_key . "\";document.getElementById(\"http_webkey\").innerHTML=\"" . $existing_key . "\";'>";
if ($webkey->{valid}) {

my ($sec,$min,$hour,$mday,$mon,$year) = localtime($webkey->{date});
my $tdate_readable = ($year + 1900)." ".sprintf("%02d", $mon + 1)."-".sprintf("%02d", $mday)." ".sprintf("%02d", $hour).":".sprintf("%02d", $min).".".sprintf("%02d", $sec);

$content .= "<b>Your current WebKey:</b> <input type='text' readOnly=1 size=25 value='" . $webkey->{key} . "'>";
$content .= " &nbsp;&nbsp;&nbsp;<b>valid until</b>: <input type='text' readOnly=1 size=20 value='" . $tdate_readable . "'>";
$content .= "<br><input type='button' class='btn' value='extend key validity date' onclick='generate_webkey(null, 1);' style='margin-top: 5px; margin-left: 130px;'>";

} else {
$content .= "<b>Your current WebKey:</b> " . $webkey->{key};
$content .= "<br><span style='font-weight: bold; color: red; margin-top: 3px;'>your current key has timed out and is no longer valid!</span>";
$content .= "<br><input type='button' class='btn' value='re-activate key' onclick='generate_webkey(null, 1);'>";
}

$content .= " <input type='button' class='btn' value='generate new key' onclick='generate_webkey(1);' style='margin-top: 5px; margin-left: 50px;'>";
# $content .= "<img src='./Html/clear.gif' onload='document.getElementById(\"ftp_webkey\").innerHTML=\"" . $webkey->{key} . "\";document.getElementById(\"http_webkey\").innerHTML=\"" . $webkey->{key} . "\";'>";

print $cgi->header;
print $content;
Expand Down
4 changes: 2 additions & 2 deletions src/WebApplication/WebComponent/PhyloTree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ sub output {
if ($self->{nodes}->{$n}->{value}) {
$percent = sprintf("%.2f", $self->{nodes}->{$n}->{value} / $dt * 100 );
}
$info .= "<tr><td style='background-color: rgb(".$pie->color_set->[$ii + 6]->[0].",".$pie->color_set->[$ii + 6]->[1].",".$pie->color_set->[$ii + 6]->[2].");'>&nbsp;</td><td>".$self->{nodes}->{$n}->{name}."</td><td>".$self->{nodes}->{$n}->{value}." (" . $percent . "\%)</td></tr>";
$info .= "<tr><td style='background-color: rgb(".($pie->color_set->[$ii + 6]->[0] || "0").",".($pie->color_set->[$ii + 6]->[1] || "0").",".($pie->color_set->[$ii + 6]->[2] || "0").");'>&nbsp;</td><td>".($self->{nodes}->{$n}->{name} || "" )."</td><td>".($self->{nodes}->{$n}->{value} || "")." (" . $percent . "\%)</td></tr>";
$ii++;
}
$info .= "</table></td></tr></table>";
Expand Down Expand Up @@ -566,7 +566,7 @@ sub output {
if ($self->{nodes}->{$n}->{value}) {
$percent = sprintf("%.2f", $self->{nodes}->{$n}->{value} / $dt * 100 );
}
$info .= "<tr><td style='background-color: rgb(".$pie->color_set->[$ii + 6]->[0].",".$pie->color_set->[$ii + 6]->[1].",".$pie->color_set->[$ii + 6]->[2].");'>&nbsp;</td><td>".$self->{nodes}->{$n}->{name}."</td><td>".$self->{nodes}->{$n}->{value}." (" . $percent . "\%)</td></tr>";
$info .= "<tr><td style='background-color: rgb(".($pie->color_set->[$ii + 6]->[0] || "0").",".($pie->color_set->[$ii + 6]->[1] || "0").",".($pie->color_set->[$ii + 6]->[2] || "0").");'>&nbsp;</td><td>".($self->{nodes}->{$n}->{name} || "")."</td><td>".($self->{nodes}->{$n}->{value} || "")." (" . $percent . "\%)</td></tr>";
$ii++;
}
$info .= "</table></td></tr></table>";
Expand Down