Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

registration quoting patch #271

Merged
merged 21 commits into from

3 participants

Tobias Paczian Travis Harrison Jared Bischof
Tobias Paczian
Owner

No description provided.

Travis Harrison and others added some commits
Travis Harrison Merge branch 'develop' of github.com:MG-RAST/MG-RAST into develop a913aba
Travis Harrison teharrison Merge pull request #265 from MG-RAST/master
Hot fix 3.3.2.1
92e63d4
Jared Bischof jaredbischof Added user resource to new API. d3616f6
Travis Harrison teharrison Merge pull request #266 from jaredbischof/develop
Added user resource to new API.
bcbd707
Travis Harrison added support for 'represtative hit' and 'lca hit' in organism matrix 7f014bc
Travis Harrison Merge branch 'develop' of git@github.com:MG-RAST/MG-RAST into develop 4339229
Jared Bischof jaredbischof Fixing some spacing and text and other minor stuff. ead4cde
Jared Bischof jaredbischof Added inbox resource to new API. d3ebcc1
Jared Bischof jaredbischof Merge branch 'develop' of https://github.com/MG-RAST/MG-RAST into dev…
…elop
5f9979e
Travis Harrison teharrison Merge pull request #268 from jaredbischof/develop
Added inbox resource to new API.
a643a13
Jared Bischof jaredbischof Merge pull request #267 from teharrison/develop
added support for 'represtative hit' and 'lca hit' in organism matrix
cfd0826
Travis Harrison fixed missing output attribute 6f916bf
Travis Harrison teharrison Merge pull request #269 from teharrison/develop
fixed missing output attribute
3971ff7
Jared Bischof jaredbischof Disabling 'Sequence Length Histogram' on Metagenome Overview page whe…
…n all sequences are the same length, $len_min == $len_max
dfc466c
Jared Bischof jaredbischof Merge branch 'develop' of https://github.com/MG-RAST/MG-RAST into dev…
…elop
ff76a21
Jared Bischof jaredbischof Fixed axis on PCoA plot when min == max. The axis had no range and th…
…us was being displayed incorrectly in this case.
d8f73dc
Jared Bischof jaredbischof Fixing path to index file for pairend joining. a0014a5
Jared Bischof jaredbischof Fixed bug in source field on Analysis page. Was preventing users from…
… downloading sequences from the workbench when they used "Representative Hit" to do their Analysis.
1492c89
Travis Harrison teharrison Merge pull request #270 from jaredbischof/develop
These changes require a version release.
63ee592
Tobias Paczian paczian updated the login / email validity check 12b33df
Tobias Paczian paczian fixed login name quoting issue cc93df5
Travis Harrison
Owner

should this be a production update? we have other develop branch stuff to roll in also.

Jared Bischof jaredbischof was assigned
Jared Bischof jaredbischof merged commit e8c9b9b into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 28, 2013
  1. Travis Harrison

    Merge pull request #265 from MG-RAST/master

    teharrison authored
    Hot fix 3.3.2.1
  2. Jared Bischof
  3. Travis Harrison

    Merge pull request #266 from jaredbischof/develop

    teharrison authored
    Added user resource to new API.
Commits on Mar 1, 2013
  1. Jared Bischof
  2. Jared Bischof
  3. Jared Bischof
  4. Travis Harrison

    Merge pull request #268 from jaredbischof/develop

    teharrison authored
    Added inbox resource to new API.
  5. Jared Bischof

    Merge pull request #267 from teharrison/develop

    jaredbischof authored
    added support for 'represtative hit' and 'lca hit' in organism matrix
Commits on Mar 3, 2013
  1. fixed missing output attribute

    Travis Harrison authored
  2. Travis Harrison

    Merge pull request #269 from teharrison/develop

    teharrison authored
    fixed missing output attribute
Commits on Mar 12, 2013
  1. Jared Bischof

    Disabling 'Sequence Length Histogram' on Metagenome Overview page whe…

    jaredbischof authored
    …n all sequences are the same length, $len_min == $len_max
  2. Jared Bischof
Commits on Mar 13, 2013
  1. Jared Bischof

    Fixed axis on PCoA plot when min == max. The axis had no range and th…

    jaredbischof authored
    …us was being displayed incorrectly in this case.
Commits on Mar 25, 2013
  1. Jared Bischof
  2. Jared Bischof

    Fixed bug in source field on Analysis page. Was preventing users from…

    jaredbischof authored
    … downloading sequences from the workbench when they used "Representative Hit" to do their Analysis.
  3. Travis Harrison

    Merge pull request #270 from jaredbischof/develop

    teharrison authored
    These changes require a version release.
Commits on Mar 28, 2013
  1. Tobias Paczian
  2. Tobias Paczian

    fixed login name quoting issue

    paczian authored
This page is out of date. Refresh to see the latest.
4 src/MGRAST/cgi/upload.cgi
View
@@ -297,13 +297,13 @@ if (scalar(@rest) && $rest[0] eq 'user_inbox') {
if($seqfile3 eq "") {
$command = "echo \"$fix_files_str $Conf::pairend_join -j -m 8 -p 10 -t $udir/.tmp -o $udir/$joinfile $udir/$seqfile1 $udir/$seqfile2 2>&1 | tee -a $udir/$seqfile1.error_log > $udir/$seqfile2.error_log; rm $lock_file1 $lock_file2 $lock_file3;\" | /usr/local/bin/qsub -q fast -j oe -N $jobid -l walltime=60:00:00 -m n -o $udir/.tmp";
} else {
- $command = "echo \"$fix_files_str $Conf::pairend_join -j -r -i $seqfile3 -m 8 -p 10 -t $udir/.tmp -o $udir/$joinfile $udir/$seqfile1 $udir/$seqfile2 2>&1 | tee -a $udir/$seqfile1.error_log > $udir/$seqfile2.error_log; rm $lock_file1 $lock_file2 $lock_file3;\" | /usr/local/bin/qsub -q fast -j oe -N $jobid -l walltime=60:00:00 -m n -o $udir/.tmp";
+ $command = "echo \"$fix_files_str $Conf::pairend_join -j -r -i $udir/$seqfile3 -m 8 -p 10 -t $udir/.tmp -o $udir/$joinfile $udir/$seqfile1 $udir/$seqfile2 2>&1 | tee -a $udir/$seqfile1.error_log > $udir/$seqfile2.error_log; rm $lock_file1 $lock_file2 $lock_file3;\" | /usr/local/bin/qsub -q fast -j oe -N $jobid -l walltime=60:00:00 -m n -o $udir/.tmp";
}
} else {
if($seqfile3 eq "") {
$command = "echo \"$fix_files_str $Conf::pairend_join -m 8 -p 10 -t $udir/.tmp -o $udir/$joinfile $udir/$seqfile1 $udir/$seqfile2 2>&1 | tee -a $udir/$seqfile1.error_log > $udir/$seqfile2.error_log; rm $lock_file1 $lock_file2 $lock_file3;\" | /usr/local/bin/qsub -q fast -j oe -N $jobid -l walltime=60:00:00 -m n -o $udir/.tmp";
} else {
- $command = "echo \"$fix_files_str $Conf::pairend_join -r -i $seqfile3 -m 8 -p 10 -t $udir/.tmp -o $udir/$joinfile $udir/$seqfile1 $udir/$seqfile2 2>&1 | tee -a $udir/$seqfile1.error_log > $udir/$seqfile2.error_log; rm $lock_file1 $lock_file2 $lock_file3;\" | /usr/local/bin/qsub -q fast -j oe -N $jobid -l walltime=60:00:00 -m n -o $udir/.tmp";
+ $command = "echo \"$fix_files_str $Conf::pairend_join -r -i $udir/$seqfile3 -m 8 -p 10 -t $udir/.tmp -o $udir/$joinfile $udir/$seqfile1 $udir/$seqfile2 2>&1 | tee -a $udir/$seqfile1.error_log > $udir/$seqfile2.error_log; rm $lock_file1 $lock_file2 $lock_file3;\" | /usr/local/bin/qsub -q fast -j oe -N $jobid -l walltime=60:00:00 -m n -o $udir/.tmp";
}
}
$jnum = `$command`;
12 src/MGRAST/html/js/pca.js
View
@@ -177,7 +177,17 @@ function min_max(items, c1, c2){
c1_max = (c1_max && c1_max > items[i][c1]) ? c1_max : items[i][c1];
c2_min = (c2_min && c2_min < items[i][c2]) ? c2_min : items[i][c2];
c2_max = (c2_max && c2_max > items[i][c2]) ? c2_max : items[i][c2];
- }
+ }
+ // If min == max for either axis, we want to artificially create a gap between
+ // them so that the axis has some span, otherwise the plot is messed up.
+ if(c1_min == c1_max) {
+ c1_min = c1_min - 0.5;
+ c1_max = c1_max + 0.5;
+ }
+ if(c2_min == c2_max) {
+ c2_min = c2_min - 0.5;
+ c2_max = c2_max + 0.5;
+ }
var c1_diff = Math.abs(c1_min - c1_max);
var c2_diff = Math.abs(c2_min - c2_max);
return [(c1_min-(c1_diff*0.1)),(c1_max+(c1_diff*0.1)), Math.abs((c1_max+(c1_diff*0.1))-(c1_min-(c1_diff*0.1))),(c2_min-(c2_diff*0.1)),(c2_max+(c2_diff*0.1)), Math.abs((c2_max+(c2_diff*0.1))-(c2_min-(c2_diff*0.1)))];
20 src/MGRAST/lib/WebPage/Analysis.pm
View
@@ -1914,17 +1914,9 @@ sub single_visual {
} else {
$mgs .= "metagenome ".$mgnames->[0];
}
- my $sorcs = "";
- my @sources = $cgi->param('source');
- foreach my $source (@sources) {
- $settings_preserve .= "<input type='hidden' name='source' value='".$source."'>";
- }
- if (scalar(@sources) > 1) {
- my $last = pop(@sources);
- $sorcs = join(", ", @sources)." and $last";
- } else {
- $sorcs = $sources[0];
- }
+ my $source = $cgi->param('source');
+ $settings_preserve .= "<input type='hidden' name='source' value='".$source."'>";
+
my $cutoffs = "a maximum e-value of 1e-" . ($cgi->param('evalue') || '0') . ", ";
$cutoffs .= "a minimum identity of " . ($cgi->param('identity') || '0') . " %, ";
$cutoffs .= "and a minimum alignment length of " . ($cgi->param('alength') || '1') . ' measured in aa for protein and bp for RNA databases';
@@ -1946,7 +1938,7 @@ sub single_visual {
$settings_preserve .= "<input type='hidden' name='alength' value='" . ($cgi->param('alength') || '1') . "'>";
my $fid = $cgi->param('fid') || int(rand(1000000));
- my $settings = "<i>This data was calculated for $mgs. The data was compared to $sorcs using $cutoffs.$pset</i><br/>";
+ my $settings = "<i>This data was calculated for $mgs. The data was compared to $source using $cutoffs.$pset</i><br/>";
## determine if any metagenomes missing from results
my $missing_txt = "";
@@ -2014,7 +2006,7 @@ sub single_visual {
{ name => 'align len std dev', visible => 0, sortable => 1, tooltip => 'standard deviation of<br>the alignment length of the hits' },
{ name => 'md5s', visible => 0 },
{ name => '# hits', visible => 1, sortable => 1, filter => 1, operators => ['less','more'], tooltip => 'number of unique hits in protein or rna database' },
- { name => "<input type='button' onclick='buffer_data(\"table\", \"".$t->id."\", \"18\", \"16\", \"0\", \"-\", \"9\");' value='to workbench'>", input_type => 'checkbox', tooltip => 'check to select features<br>to add to workbench' } ];
+ { name => "<input type='button' onclick='buffer_data(\"table\", \"".$t->id."\", \"18\", \"16\", \"0\", \"".$source."\", \"9\");' value='to workbench'>", input_type => 'checkbox', tooltip => 'check to select features<br>to add to workbench' } ];
#### do the pivoting
unless (defined $cgi->param('group_by')) {
@@ -2297,7 +2289,7 @@ sub single_visual {
}
}
}
- return clear_progress_image()."<h3 style='margin-top: 0px;'>".$header_names->{$level}." Distribution (".$cgi->param('single_bar_sel').") <input type='button' value='download' title='click to download tabular data' onclick='myWindow=window.open(\"\",\"\",\"width=600,height=500\");myWindow.document.write(\"<pre>$download_data_string</pre>\");myWindow.focus();'> <input type='button' value='to workbench' onclick='buffer_data(\"barchart\", \"$level$fid\", \"$sorcs phylogenetic\", \"".$cgi->param('single_bar_sel')."\", \"0\", \"".join(";",$cgi->param('source'))."\");'></h3></a>".$dom_v->output."<br><input type='hidden' id='$level$fid\_md5s' value='".join(";", keys(%$md5s))."'><input type='hidden' id='$level$fid\_mgids' value='".join(";", @comp_mgs)."'><div id='".(int($level)+1)."_$fid'></div>";
+ return clear_progress_image()."<h3 style='margin-top: 0px;'>".$header_names->{$level}." Distribution (".$cgi->param('single_bar_sel').") <input type='button' value='download' title='click to download tabular data' onclick='myWindow=window.open(\"\",\"\",\"width=600,height=500\");myWindow.document.write(\"<pre>$download_data_string</pre>\");myWindow.focus();'> <input type='button' value='to workbench' onclick='buffer_data(\"barchart\", \"$level$fid\", \"$source phylogenetic\", \"".$cgi->param('single_bar_sel')."\", \"0\", \"".join(";",$cgi->param('source'))."\");'></h3></a>".$dom_v->output."<br><input type='hidden' id='$level$fid\_md5s' value='".join(";", keys(%$md5s))."'><input type='hidden' id='$level$fid\_mgids' value='".join(";", @comp_mgs)."'><div id='".(int($level)+1)."_$fid'></div>";
}
}
53 src/MGRAST/lib/WebPage/MetagenomeOverview.pm
View
@@ -383,7 +383,18 @@ sub output {
if ($source_chart) {
$html .= "<li><a href='#source_ref'>Source Distribution</a></li>";
}
- $html .= "<li><a href='#len_ref'>Sequence Length Histogram</a></li>";
+
+ # sequence length histogram
+ my @len_raw_hist = sort {$a->[0] <=> $b->[0]} @{ $mgdb->get_histogram_nums($job->job_id, 'len', 'raw') };
+ my @len_qc_hist = sort {$a->[0] <=> $b->[0]} @{ $mgdb->get_histogram_nums($job->job_id, 'len', 'qc') };
+ my $len_min = (@len_raw_hist && @len_qc_hist) ? min($len_raw_hist[0][0], $len_qc_hist[0][0]) : (@len_raw_hist ? $len_raw_hist[0][0] : (@len_qc_hist ? $len_qc_hist[0][0] : 0));
+ my $len_max = (@len_raw_hist && @len_qc_hist) ? max($len_raw_hist[-1][0], $len_qc_hist[-1][0]) : (@len_raw_hist ? $len_raw_hist[-1][0] : (@len_qc_hist ? $len_qc_hist[-1][0] : 0));
+ my $len_raw_bins = @len_raw_hist ? &get_bin_set(\@len_raw_hist, $len_min, $len_max, $self->data('bin_size')) : [];
+ my $len_qc_bins = @len_qc_hist ? &get_bin_set(\@len_qc_hist, $len_min, $len_max, $self->data('bin_size')) : [];
+
+ unless($len_max == $len_min) {
+ $html .= "<li><a href='#len_ref'>Sequence Length Histogram</a></li>";
+ }
$html .= "<li><a href='#gc_ref'>Sequence GC Distribution</a></li>";
$html .= "</ul></ul></div></td></tr></table><br>";
@@ -666,15 +677,8 @@ $drisee_boilerplate
<div id='alpha_div'></div>
</div>~;
- # sequence length histogram
- my @len_raw_hist = sort {$a->[0] <=> $b->[0]} @{ $mgdb->get_histogram_nums($job->job_id, 'len', 'raw') };
- my @len_qc_hist = sort {$a->[0] <=> $b->[0]} @{ $mgdb->get_histogram_nums($job->job_id, 'len', 'qc') };
- my $len_min = (@len_raw_hist && @len_qc_hist) ? min($len_raw_hist[0][0], $len_qc_hist[0][0]) : (@len_raw_hist ? $len_raw_hist[0][0] : (@len_qc_hist ? $len_qc_hist[0][0] : 0));
- my $len_max = (@len_raw_hist && @len_qc_hist) ? max($len_raw_hist[-1][0], $len_qc_hist[-1][0]) : (@len_raw_hist ? $len_raw_hist[-1][0] : (@len_qc_hist ? $len_qc_hist[-1][0] : 0));
- my $len_raw_bins = @len_raw_hist ? &get_bin_set(\@len_raw_hist, $len_min, $len_max, $self->data('bin_size')) : [];
- my $len_qc_bins = @len_qc_hist ? &get_bin_set(\@len_qc_hist, $len_min, $len_max, $self->data('bin_size')) : [];
-
- $html .= qq~<a name='len_ref'></a>
+ unless($len_max == $len_min) {
+ $html .= qq~<a name='len_ref'></a>
<h3>Sequence Length Histogram
<a style='cursor:pointer;clear:both;font-size:small;padding-left:10px;' onclick='
if (this.innerHTML=="show") {
@@ -687,10 +691,10 @@ $drisee_boilerplate
<div id='len_show'>
<p>The histograms below show the distribution of sequence lengths in basepairs for this metagenome. Each position represents the number of sequences within a length bp range.</p><p>The data used in these graphs are based on raw upload and post QC sequences.</p>~;
- if (@$len_raw_bins > 1) {
- my $len_raw_data = join("~", map { $_->[0] .";;" . $_->[1] } @$len_raw_bins);
- my $len_raw_link = $self->chart_export_link($len_raw_bins, 'upload_len_hist');
- $html .= qq~<p>$len_raw_link</p>
+ if (@$len_raw_bins > 1) {
+ my $len_raw_data = join("~", map { $_->[0] .";;" . $_->[1] } @$len_raw_bins);
+ my $len_raw_link = $self->chart_export_link($len_raw_bins, 'upload_len_hist');
+ $html .= qq~<p>$len_raw_link</p>
<div id='static2'>
The image is currently dynamic. To be able to right-click/save the image, please click the static button
<input type='button' value='static' onclick='
@@ -710,13 +714,13 @@ The image is currently dynamic. To be able to right-click/save the image, please
<div><div id='length_hist_raw'></div></div>
<input type='hidden' id='len_data_raw' value='$len_raw_data'>
<img src='./Html/clear.gif' onload='draw_histogram_plot("len_data_raw", "length_hist_raw", "bps", "Number of Reads Uploaded");'>~;
- } else {
- $html .= "<p><em>Raw sequence length histogram " . (@$len_raw_bins ? "has insufficient data" : "not yet computed") . ".</em></p>";
- }
- if (@$len_qc_bins > 1) {
- my $len_qc_data = join("~", map { $_->[0] .";;" . $_->[1] } @$len_qc_bins);
- my $len_qc_link = $self->chart_export_link($len_qc_bins, 'postqc_len_hist');
- $html .= qq~<p>$len_qc_link</p>
+ } else {
+ $html .= "<p><em>Raw sequence length histogram " . (@$len_raw_bins ? "has insufficient data" : "not yet computed") . ".</em></p>";
+ }
+ if (@$len_qc_bins > 1) {
+ my $len_qc_data = join("~", map { $_->[0] .";;" . $_->[1] } @$len_qc_bins);
+ my $len_qc_link = $self->chart_export_link($len_qc_bins, 'postqc_len_hist');
+ $html .= qq~<p>$len_qc_link</p>
<div id='static3'>
The image is currently dynamic. To be able to right-click/save the image, please click the static button
<input type='button' value='static' onclick='
@@ -736,10 +740,11 @@ The image is currently dynamic. To be able to right-click/save the image, please
<div><div id='length_hist_qc'></div></div>
<input type='hidden' id='len_data_qc' value='$len_qc_data'>
<img src='./Html/clear.gif' onload='draw_histogram_plot("len_data_qc", "length_hist_qc", "bps", "Number of Reads Post QC");'>~;
- } else {
- $html .= "<p><em>QC sequence length histogram " . (@$len_qc_bins ? "has insufficient data" : "not yet computed") . ".</em></p>";
+ } else {
+ $html .= "<p><em>QC sequence length histogram " . (@$len_qc_bins ? "has insufficient data" : "not yet computed") . ".</em></p>";
+ }
+ $html .= "</div>";
}
- $html .= "</div>";
# sequence gc distribution
my @gc_raw_hist = sort {$a->[0] <=> $b->[0]} @{ $mgdb->get_histogram_nums($job->job_id, 'gc', 'raw') };
180 src/MGRAST/lib/resources2/inbox.pm
View
@@ -0,0 +1,180 @@
+package resources2::inbox;
+
+use strict;
+use warnings;
+no warnings('once');
+
+use Data::Dumper;
+use Conf;
+use parent qw(resources2::resource);
+
+# Override parent constructor
+sub new {
+ my ($class, @args) = @_;
+
+ # Call the constructor of the parent class
+ my $self = $class->SUPER::new(@args);
+
+ # Add name
+ $self->{name} = "inbox";
+ 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' => "inbox receives user inbox data upload, requires authentication, see http://blog.metagenomics.anl.gov/mg-rast-v3-2-faq/#api_submission for details",
+ 'type' => 'object',
+ 'documentation' => $Conf::cgi_url.'/Html/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' => "view",
+ 'request' => $self->cgi->url."/".$self->name."/view",
+ 'description' => "lists the contents of the user inbox",
+ 'method' => "GET",
+ 'type' => "synchronous",
+ 'attributes' => { 'id' => [ 'string', "user login" ],
+ 'timestamp' => [ 'string', "timestamp for return of this query" ],
+ 'files' => [ 'list', [ 'object', [ { 'filename' => [ 'string', "path of file from within user inbox" ],
+ 'filesize' => [ 'string', "disk size of file in bytes" ],
+ 'timestamp' => [ 'string', "timestamp of file" ]
+ }, "list of file objects"] ] ],
+ 'url' => [ 'uri', "resource location of this object instance" ] },
+ 'parameters' => { 'options' => {},
+ 'required' => { "auth" => [ "string", "unique string of text generated by MG-RAST for your account" ] },
+ 'body' => {} } },
+ { 'name' => "upload",
+ 'request' => $self->cgi->url."/".$self->name."/upload",
+ 'description' => "receives user inbox data upload",
+ 'method' => "POST",
+ 'type' => "synchronous",
+ 'attributes' => { 'id' => [ 'string', "user login" ],
+ 'status' => [ 'string', "status message" ],
+ 'timestamp' => [ 'string', "timestamp for return of this query" ]
+ },
+ 'parameters' => { 'options' => {},
+ 'required' => { "auth" => [ "string", "unique string of text generated by MG-RAST for your account" ] },
+ 'body' => {} } }
+ ]
+ };
+
+ $self->return_data($content);
+}
+
+sub instance {
+ my ($self) = @_;
+
+ if (($self->rest->[0] eq 'upload') && ($self->method eq 'POST')) {
+ $self->upload_file();
+ } elsif ($self->rest->[0] eq 'view') {
+ $self->view_inbox();
+ } else {
+ $self->info();
+ }
+}
+
+sub view_inbox {
+ my ($self) = @_;
+
+ my $black_list = "USER";
+ my $black_list_seq_ext = "stats_info|error_log|lock|";
+ if($self->user) {
+ use Digest::MD5 qw(md5_hex);
+ my $base_dir = "$Conf::incoming";
+ my $udir = $base_dir."/".md5_hex($self->user->login);
+ my @files = ();
+ foreach my $file (`ls $udir`) {
+ chomp $file;
+ if(-d "$udir/$file") {
+ my $subdir = $file;
+ foreach my $subfile (`ls $udir/$subdir`) {
+ chomp $subfile;
+ unless($subfile =~ /^$black_list$/ || $subfile =~ /^\S+\.($black_list_seq_ext)$/) {
+ my $filesize = -s "$udir/$subdir/$subfile";
+ my $timestamp = scalar localtime((stat("$udir/$subdir/$subfile"))[9]);
+ push @files, { 'filename' => "$subdir/$subfile",
+ 'filesize', => $filesize." bytes",
+ 'timestamp', => $timestamp };
+ }
+ }
+ } else {
+ unless($file =~ /^$black_list$/ || $file =~ /^\S+\.($black_list_seq_ext)$/) {
+ my $filesize = -s "$udir/$file";
+ my $timestamp = scalar localtime((stat("$udir/$file"))[9]);
+ push @files, { 'filename' => $file,
+ 'filesize', => $filesize." bytes",
+ 'timestamp', => $timestamp };
+ }
+ }
+ }
+ $self->return_data( { 'id' => $self->user->login,
+ 'timestamp' => scalar localtime,
+ 'files' => \@files,
+ 'url' => $self->cgi->url."/".$self->name."/view" } );
+ } else {
+ $self->return_data( {"ERROR" => "authentication failed"}, 401 );
+ }
+}
+
+sub upload_file {
+ my ($self) = @_;
+
+ if($self->user) {
+ use Digest::MD5 qw(md5_hex);
+ my $base_dir = "$Conf::incoming";
+ my $udir = $base_dir."/".md5_hex($self->user->login);
+ my $fn = $self->cgi->param('upload');
+
+ if ($fn) {
+
+ if ($fn =~ /\.\./) {
+ $self->return_data( {"ERROR" => "invalid parameters, trying to change directory with filename, aborting"}, 400 );
+ }
+
+ if ($fn !~ /^[\w\d_\.\-\:\, ]+$/) {
+ $self->return_data({"ERROR" => "Invalid parameters, filename allows only word, underscore, dash, colon, comma, dot (.), space, and number characters"}, 400);
+ }
+
+ if (-f "$udir/$fn") {
+ $self->return_data( {"ERROR" => "the file already exists"}, 400 );
+ }
+
+ my $fh = $self->cgi->upload('upload');
+ if (defined $fh) {
+ my $io_handle = $fh->handle;
+ if (open FH, ">$udir/$fn") {
+ my ($bytesread, $buffer);
+ while ($bytesread = $io_handle->read($buffer,4096)) {
+ print FH $buffer;
+ }
+ close FH;
+ $self->return_data( { 'id' => $self->user->login,
+ 'status' => "data received successfully",
+ 'timestamp' => scalar localtime } );
+ } else {
+ $self->return_data( {"ERROR" => "storing object failed - could not open target file"}, 507 );
+ }
+ } else {
+ $self->return_data( {"ERROR" => "storing object failed - could not obtain filehandle"}, 507 );
+ }
+
+ } else {
+ $self->return_data( {"ERROR" => "invalid parameters, requires filename and data"}, 400 );
+ }
+
+ } else {
+ $self->return_data( {"ERROR" => "authentication failed"}, 401 );
+ }
+}
+
+1;
210 src/MGRAST/lib/resources2/matrix.pm
View
@@ -8,8 +8,9 @@ use POSIX qw(strftime);
use Conf;
use MGRAST::Metadata;
use MGRAST::Analysis;
-use Babel::lib::Babel;
use Data::Dumper;
+use URI::Escape;
+use List::Util qw(max min sum first);
use Digest::MD5 qw(md5_hex md5_base64);
use parent qw(resources2::resource);
@@ -25,52 +26,53 @@ sub new {
$self->{org2tax} = {};
$self->{cutoffs} = { evalue => '5', identity => '60', length => '15' };
$self->{hierarchy} = { organism => [ ['strain', 'bottom organism taxanomic level'],
- ['species', 'organism type level'],
- ['genus', 'organism taxanomic level'],
- ['family', 'organism taxanomic level'],
- ['order', 'organism taxanomic level'],
- ['class', 'organism taxanomic level'],
- ['phylum', 'organism taxanomic level'],
- ['domain', 'top organism taxanomic level'] ],
- ontology => [ ['function', 'bottom function ontology level'],
+ ['species', 'organism type level'],
+ ['genus', 'organism taxanomic level'],
+ ['family', 'organism taxanomic level'],
+ ['order', 'organism taxanomic level'],
+ ['class', 'organism taxanomic level'],
+ ['phylum', 'organism taxanomic level'],
+ ['domain', 'top organism taxanomic level'] ],
+ ontology => [ ['function', 'bottom function ontology level'],
['level3', 'function ontology level' ],
['level2', 'function ontology level' ],
- ['level1', 'top function ontology level'] ]
+ ['level1', 'top function ontology level'] ]
};
$self->{sources} = { organism => [ ["M5NR", "comprehensive protein database"],
["RefSeq", "protein database"],
- ["SwissProt", "protein database"],
- ["GenBank", "protein database"],
- ["IMG", "protein database"],
- ["SEED", "protein database"],
- ["TrEMBL", "protein database"],
- ["PATRIC", "protein database"],
- ["KEGG", "protein database"],
- ["M5RNA", "comprehensive RNA database"],
- ["RDP", "RNA database"],
- ["Greengenes", "RNA database"],
- ["LSU", "RNA database"],
- ["SSU", "RNA database"] ],
- ontology => [ ["Subsystems", "ontology database, type function only"],
- ["NOG", "ontology database, type function only"],
- ["COG", "ontology database, type function only"],
- ["KO", "ontology database, type function only"] ]
+ ["SwissProt", "protein database"],
+ ["GenBank", "protein database"],
+ ["IMG", "protein database"],
+ ["SEED", "protein database"],
+ ["TrEMBL", "protein database"],
+ ["PATRIC", "protein database"],
+ ["KEGG", "protein database"],
+ ["M5RNA", "comprehensive RNA database"],
+ ["RDP", "RNA database"],
+ ["Greengenes", "RNA database"],
+ ["LSU", "RNA database"],
+ ["SSU", "RNA database"] ],
+ ontology => [ ["Subsystems", "ontology database, type function only"],
+ ["NOG", "ontology database, type function only"],
+ ["COG", "ontology database, type function only"],
+ ["KO", "ontology database, type function only"] ]
};
$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' ],
- "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']] ]
+ "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']] ]
};
return $self;
}
@@ -107,6 +109,9 @@ sub info {
['evalue', 'average e-value exponent of hits in annotation'],
['identity', 'average percent identity of hits in annotation'],
['length', 'average alignment length of hits in annotation']] ],
+ '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']] ],
'source' => [ 'cv', $self->{sources}{organism} ],
'group_level' => [ 'cv', $self->{hierarchy}{organism} ],
'filter' => [ 'string', 'filter the return results to only include abundances based on genes with this function' ],
@@ -274,18 +279,27 @@ sub prepare_data {
my $cgi = $self->cgi;
my $source = $cgi->param('source') ? $cgi->param('source') : (($type eq 'organism') ? 'M5NR' : (($type eq 'function') ? 'Subsystems': 'RefSeq'));
my $rtype = $cgi->param('result_type') ? $cgi->param('result_type') : 'abundance';
+ my $htype = $cgi->param('hit_type') ? $cgi->param('hit_type') : 'all';
my $glvl = $cgi->param('group_level') ? $cgi->param('group_level') : (($type eq 'organism') ? 'strain' : 'function');
my $eval = defined($cgi->param('evalue')) ? $cgi->param('evalue') : $self->{cutoffs}{evalue};
my $ident = defined($cgi->param('identity')) ? $cgi->param('identity') : $self->{cutoffs}{identity};
my $alen = defined($cgi->param('length')) ? $cgi->param('length') : $self->{cutoffs}{length};
my $fsrc = $cgi->param('filter_source') ? $cgi->param('filter_source') : (($type eq 'organism') ? 'Subsystems' : 'M5NR');
my @filter = $cgi->param('filter') ? $cgi->param('filter') : ();
- my $hide_md = $cgi->param('hide_metadata') ? 1 : 0;
+ my $hide_md = $cgi->param('hide_metadata') ? 1 : 0;
my $all_srcs = {};
my $leaf_node = 0;
- my $matrix_id = join("_", map {'mgm'.$_} sort @$data).'_'.join("_", ($type, $glvl, $source, $rtype, $eval, $ident, $alen));
+ my $group_level = $glvl;
+ my $matrix_id = join("_", map {'mgm'.$_} sort @$data).'_'.join("_", ($type, $glvl, $source, $htype, $rtype, $eval, $ident, $alen));
+ my $matrix_url = $self->cgi->url.'/matrix/'.$type.'?id='.join('&id=', map {'mgm'.$_} sort @$data).'&group_level='.$glvl.
+ '&source='.$source.'&hit_type='.$htype.'&result_type='.$rtype.'&evalue='.$eval.'&identity='.$ident.'&length='.$alen;
+ if ($hide_md) {
+ $matrix_id .= '_'.$hide_md;
+ $matrix_url .= '&hide_metadata='.$hide_md;
+ }
if (@filter > 0) {
- $matrix_id .= md5_hex( join("_", sort map { s/\s+/_/g } @filter) )."_".$fsrc;
+ $matrix_id .= md5_hex( join("_", sort map { s/\s+/_/g } @filter) )."_".$fsrc;
+ $matrix_url .= '&filter='.join('&filter=', sort map { uri_escape($_) } @filter).'&filter_source='.$fsrc;
}
# initialize analysis obj with mgids
@@ -308,11 +322,11 @@ sub prepare_data {
}
# controlled vocabulary set
- my $result_idx = { abundance => {function => 3, organism => 10, feature => 2},
- evalue => {function => 5, organism => 12, feature => 3},
- length => {function => 7, organism => 14, feature => 5},
- identity => {function => 9, organism => 16, feature => 7}
- };
+ my $result_idx = { abundance => {function => 3, organism => {all => 10, single => 9, lca => 9}, feature => 2},
+ evalue => {function => 5, organism => {all => 12, single => 10, lca => 10}, feature => 3},
+ length => {function => 7, organism => {all => 14, single => 12, lca => 12}, feature => 5},
+ identity => {function => 9, organism => {all => 16, single => 14, lca => 14}, feature => 7}
+ };
my $result_map = {abundance => 'abundance', evalue => 'exp_avg', length => 'len_avg', identity => 'ident_avg'};
my @func_hier = map { $_->[0] } @{$self->{hierarchy}{ontology}};
my @org_hier = map { $_->[0] } @{$self->{hierarchy}{organism}};
@@ -332,7 +346,7 @@ sub prepare_data {
$leaf_node = 1;
}
} else {
- $self->return_data({"ERROR" => "invalid group_level for matrix call of type ".$type.": ".$glvl." - valid types are [".join(", ", @org_hier)."]"}, 500);
+ $self->return_data({"ERROR" => "invalid group_level for matrix call of type ".$type.": ".$group_level." - valid types are [".join(", ", @org_hier)."]"}, 500);
}
} elsif ($type eq 'function') {
map { $all_srcs->{$_->[0]} = 1 } grep { $_->[0] !~ /^GO/ } @{$mgdb->sources_for_type('ontology')};
@@ -345,7 +359,7 @@ sub prepare_data {
$leaf_node = 1;
}
} else {
- $self->return_data({"ERROR" => "invalid group_level for matrix call of type ".$type.": ".$glvl." - valid types are [".join(", ", @func_hier)."]"}, 500);
+ $self->return_data({"ERROR" => "invalid group_level for matrix call of type ".$type.": ".$group_level." - valid types are [".join(", ", @func_hier)."]"}, 500);
}
} elsif ($type eq 'feature') {
map { $all_srcs->{$_->[0]} = 1 } @{$mgdb->sources_for_type('protein')};
@@ -368,20 +382,71 @@ sub prepare_data {
if ($type eq 'organism') {
$ttype = 'Taxon';
$mtype = 'taxonomy';
+ $col_idx = $result_idx->{$rtype}{$type}{$htype};
if (@filter > 0) {
$umd5s = $mgdb->get_md5s_for_ontology(\@filter, $fsrc);
}
unless ((@filter > 0) && (@$umd5s == 0)) {
- if ($leaf_node) {
- # my ($self, $md5s, $sources, $eval, $ident, $alen, $with_taxid) = @_;
- my (undef, $info) = $mgdb->get_organisms_for_md5s($umd5s, [$source], int($eval), int($ident), int($alen));
- # 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
- @$matrix = map {[ $_->[9], $_->[0], $self->toNum($_->[$col_idx], $rtype) ]} @$info;
- map { $self->{org2tax}->{$_->[9]} = [ @$_[2..9] ] } @$info;
+ if ($htype eq 'all') {
+ if ($leaf_node) {
+ # my ($self, $md5s, $sources, $eval, $ident, $alen, $with_taxid) = @_;
+ my (undef, $info) = $mgdb->get_organisms_for_md5s($umd5s, [$source], int($eval), int($ident), int($alen));
+ # 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
+ @$matrix = map {[ $_->[9], $_->[0], $self->toNum($_->[$col_idx], $rtype) ]} grep {$_->[9] !~ /^(\-|unclassified)/} @$info;
+ map { $self->{org2tax}->{$_->[9]} = [ @$_[2..9] ] } @$info;
+ } else {
+ # my ($self, $level, $names, $srcs, $value, $md5s, $eval, $ident, $alen) = @_;
+ @$matrix = map {[ $_->[1], $_->[0], $self->toNum($_->[2], $rtype) ]} grep {$_->[1] !~ /^(\-|unclassified)/} @{$mgdb->get_abundance_for_tax_level($glvl, undef, [$source], $result_map->{$rtype}, $umd5s, int($eval), int($ident), int($alen))};
+ # mgid, hier_annotation, value
+ }
+ } elsif ($htype eq 'single') {
+ # my ($self, $source, $eval, $ident, $alen) = @_;
+ my $info = $mgdb->get_organisms_unique_for_source($source, int($eval), int($ident), int($alen));
+ # 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
+ my @levels = reverse @org_hier;
+ my $lvl_idx = first { $levels[$_] eq $group_level } 0..$#levels;
+ $lvl_idx += 1;
+ my $merged = {};
+ foreach my $set (@$info) {
+ next if ($set->[$lvl_idx] =~ /^(\-|unclassified)/);
+ if (! exists($merged->{$set->[0]}{$set->[$lvl_idx]})) {
+ $merged->{$set->[0]}{$set->[$lvl_idx]} = [ $self->toNum($set->[$col_idx], $rtype), 1 ];
+ } else {
+ $merged->{$set->[0]}{$set->[$lvl_idx]}[0] += $self->toNum($set->[$col_idx], $rtype);
+ $merged->{$set->[0]}{$set->[$lvl_idx]}[1] += 1;
+ }
+ }
+ foreach my $m (keys %$merged) {
+ foreach my $a (keys %{$merged->{$m}}) {
+ my $val = ($rtype eq 'abundance') ? $merged->{$m}{$a}[0] : $merged->{$m}{$a}[0] / $merged->{$m}{$a}[1];
+ push @$matrix, [ $a, $m, $val ];
+ }
+ }
+ } elsif ($htype eq 'lca') {
+ # my ($self, $eval, $ident, $alen) = @_;
+ my $info = $mgdb->get_lca_data(int($eval), int($ident), int($alen));
+ # 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
+ my @levels = reverse @org_hier;
+ my $lvl_idx = first { $levels[$_] eq $group_level } 0..$#levels;
+ $lvl_idx += 1;
+ my $merged = {};
+ foreach my $set (@$info) {
+ next if ($set->[$lvl_idx] =~ /^(\-|unclassified)/);
+ if (! exists($merged->{$set->[0]}{$set->[$lvl_idx]})) {
+ $merged->{$set->[0]}{$set->[$lvl_idx]} = [ $self->toNum($set->[$col_idx], $rtype), 1 ];
+ } else {
+ $merged->{$set->[0]}{$set->[$lvl_idx]}[0] += $self->toNum($set->[$col_idx], $rtype);
+ $merged->{$set->[0]}{$set->[$lvl_idx]}[1] += 1;
+ }
+ }
+ foreach my $m (keys %$merged) {
+ foreach my $a (keys %{$merged->{$m}}) {
+ my $val = ($rtype eq 'abundance') ? $merged->{$m}{$a}[0] : $merged->{$m}{$a}[0] / $merged->{$m}{$a}[1];
+ push @$matrix, [ $a, $m, $val ];
+ }
+ }
} else {
- # my ($self, $level, $names, $srcs, $value, $md5s, $eval, $ident, $alen) = @_;
- @$matrix = map {[ $_->[1], $_->[0], $self->toNum($_->[2], $rtype) ]} @{$mgdb->get_abundance_for_tax_level($glvl, undef, [$source], $result_map->{$rtype}, $umd5s, int($eval), int($ident), int($alen))};
- # mgid, hier_annotation, value
+ $self->return_data({"ERROR" => "invalid hit_type for matrix call: ".$htype." - valid types are ['all', 'single', 'lca']"}, 500);
}
}
} elsif ($type eq 'function') {
@@ -436,19 +501,20 @@ sub prepare_data {
}
my $obj = { "id" => $matrix_id,
- "format" => "Biological Observation Matrix 1.0",
- "format_url" => "http://biom-format.org",
- "type" => $ttype." table",
- "generated_by" => "MG-RAST revision ".$Conf::server_version,
- "date" => strftime("%Y-%m-%dT%H:%M:%S", localtime),
- "matrix_type" => "sparse",
- "matrix_element_type" => ($rtype eq 'abundance') ? "int" : "float",
- "matrix_element_value" => $rtype,
- "shape" => [ scalar(keys %$row_ids), scalar(keys %$col_ids) ],
- "rows" => $brows,
- "columns" => $bcols,
- "data" => $self->index_sparse_matrix($matrix, $row_ids, $col_ids)
- };
+ "url" => $matrix_url,
+ "format" => "Biological Observation Matrix 1.0",
+ "format_url" => "http://biom-format.org",
+ "type" => $ttype." table",
+ "generated_by" => "MG-RAST revision ".$Conf::server_version,
+ "date" => strftime("%Y-%m-%dT%H:%M:%S", localtime),
+ "matrix_type" => "sparse",
+ "matrix_element_type" => ($rtype eq 'abundance') ? "int" : "float",
+ "matrix_element_value" => $rtype,
+ "shape" => [ scalar(keys %$row_ids), scalar(keys %$col_ids) ],
+ "rows" => $brows,
+ "columns" => $bcols,
+ "data" => $self->index_sparse_matrix($matrix, $row_ids, $col_ids)
+ };
return $obj;
}
28 src/MGRAST/lib/resources2/project.pm
View
@@ -182,23 +182,23 @@ sub prepare_data {
if ($self->cgi->param('verbosity')) {
if ($self->cgi->param('verbosity') eq 'full') {
- my @jobs = map { ["mgm".$_, $url.'/metagenome/mgm'.$_] } @{ $project->all_metagenome_ids };
- my @colls = @{ $project->collections };
- my @samples = map { ["mgs".$_->{ID}, $url."/sample/mgs".$_->{ID}] } grep { $_ && ref($_) && ($_->{type} eq 'sample') } @colls;
- my @libraries = map { ["mgl".$_->{ID}, $url."/library/mgl".$_->{ID}] } grep { $_ && ref($_) && ($_->{type} eq 'library') } @colls;
- $obj->{analyzed} = \@jobs;
- $obj->{samples} = \@samples;
- $obj->{libraries} = \@libraries;
+ my @jobs = map { ["mgm".$_, $url.'/metagenome/mgm'.$_] } @{ $project->all_metagenome_ids };
+ my @colls = @{ $project->collections };
+ my @samples = map { ["mgs".$_->{ID}, $url."/sample/mgs".$_->{ID}] } grep { $_ && ref($_) && ($_->{type} eq 'sample') } @colls;
+ my @libraries = map { ["mgl".$_->{ID}, $url."/library/mgl".$_->{ID}] } grep { $_ && ref($_) && ($_->{type} eq 'library') } @colls;
+ $obj->{analyzed} = \@jobs;
+ $obj->{samples} = \@samples;
+ $obj->{libraries} = \@libraries;
}
if (($self->cgi->param('verbosity') eq 'verbose') || ($self->cgi->param('verbosity') eq 'full')) {
- my $metadata = $project->data();
- my $desc = $metadata->{project_description} || $metadata->{study_abstract} || " - ";
- my $fund = $metadata->{project_funding} || " - ";
- $obj->{metadata} = $metadata;
- $obj->{description} = $desc;
- $obj->{funding_source} = $fund;
+ my $metadata = $project->data();
+ my $desc = $metadata->{project_description} || $metadata->{study_abstract} || " - ";
+ my $fund = $metadata->{project_funding} || " - ";
+ $obj->{metadata} = $metadata;
+ $obj->{description} = $desc;
+ $obj->{funding_source} = $fund;
} elsif ($self->cgi->param('verbosity') ne 'minimal') {
- $self->return_data( {"ERROR" => "invalid value for option verbosity"}, 400 );
+ $self->return_data( {"ERROR" => "invalid value for option verbosity"}, 400 );
}
}
push @$objects, $obj;
12 src/MGRAST/lib/resources2/status.pm
View
@@ -17,6 +17,12 @@ sub new {
# Add name / attributes
$self->{name} = "status";
+ $self->{attributes} = { "id" => [ 'integer', 'process id' ],
+ "status" => [ 'string', 'cv', [ ['processing', 'process is still computing'],
+ ['done', 'process is done computing'] ] ],
+ "url" => [ 'url', 'resource location of this object instance'],
+ "data" => [ 'hash', 'if status is done, data holds the result, otherwise data is not present']
+ };
return $self;
}
@@ -95,15 +101,15 @@ sub prepare_data {
my $obj = {};
if ($process_status ne "") {
$obj->{id} = $id;
- $obj->{status} = "Processing";
+ $obj->{status} = "processing";
$obj->{url} = $self->cgi->url."/".$self->name."/".$id;
} elsif ($process_status eq "" && $self->cgi->param('verbosity') && ($self->cgi->param('verbosity') eq 'minimal')) {
$obj->{id} = $id;
- $obj->{status} = "Done";
+ $obj->{status} = "done";
$obj->{url} = $self->cgi->url."/".$self->name."/".$id;
} else {
$obj->{id} = $id;
- $obj->{status} = "Done";
+ $obj->{status} = "done";
$obj->{url} = $self->cgi->url."/".$self->name."/".$id;
local $/;
open my $fh, "<", $fname;
120 src/MGRAST/lib/resources2/user.pm
View
@@ -0,0 +1,120 @@
+package resources2::user;
+
+use strict;
+use warnings;
+no warnings('once');
+
+use Conf;
+use Data::Dumper;
+use parent qw(resources2::resource);
+use WebApplicationDBHandle;
+use DBMaster;
+
+
+# Override parent constructor
+sub new {
+ my ($class, @args) = @_;
+
+ # Call the constructor of the parent class
+ my $self = $class->SUPER::new(@args);
+
+ # Add name / attributes
+ $self->{name} = "user";
+ $self->{attributes} = { "id" => [ 'string', 'user login' ],
+ "email" => [ 'string', 'user e-mail' ],
+ "firstname" => [ 'string', 'first name of user' ],
+ "lastname" => [ 'string', 'last name of user' ],
+ "entry_date" => [ 'date', 'date of user creation' ],
+ "active" => [ 'boolean', '' ],
+ "comment" => [ 'string', 'any comment about the user account' ],
+ "url" => [ 'uri', 'resource location of this object instance' ]
+ };
+ 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' => "The user resource returns information about a user.",
+ 'type' => 'object',
+ 'documentation' => $Conf::cgi_url.'/Html/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 user object.",
+ 'method' => "GET" ,
+ 'type' => "synchronous" ,
+ 'attributes' => $self->attributes,
+ 'parameters' => { 'options' => {},
+ 'required' => { "id" => [ "string", "unique user login" ] },
+ 'body' => {} } },
+ ]
+ };
+
+ $self->return_data($content);
+}
+
+# the resource is called with an id parameter
+sub instance {
+ my ($self) = @_;
+
+ # check id format
+ my $rest = $self->rest;
+ my $id = $rest->[0];
+
+ if ($rest && scalar(@$rest) == 1) {
+ unless ($self->user && $self->user->has_right(undef, 'edit', 'user', $self->user->{_id})) {
+ $self->return_data( {"ERROR" => "insufficient permissions for user call"}, 400 );
+ }
+ }
+
+ use WebApplicationDBHandle;
+ use DBMaster;
+
+ my ($dbmaster, $error) = WebApplicationDBHandle->new();
+ if ($error) {
+ $self->return_data( {"ERROR" => "could not connect to user database - $error"}, 500 );
+ }
+
+ # get data
+ my $user = $dbmaster->User->get_objects( { "login" => $id } );
+
+ unless (scalar(@$user)) {
+ $self->return_data( {"ERROR" => "login $id does not exists"}, 404 );
+ }
+
+ # prepare data
+ my $data = $self->prepare_data($user->[0]);
+ $self->return_data($data);
+}
+
+# reformat the data into the requested output format
+sub prepare_data {
+ my ($self, $user) = @_;
+
+ my $url = $self->cgi->url;
+ my $obj = {};
+ $obj->{id} = $user->login;
+ $obj->{email} = $user->email;
+ $obj->{firstname} = $user->firstname;
+ $obj->{lastname} = $user->lastname;
+ $obj->{entry_date} = $user->entry_date;
+ $obj->{active} = $user->active;
+ $obj->{comment} = $user->comment;
+ $obj->{url} = $url.'/user/'.$obj->{id};
+
+ return $obj;
+}
+
+1;
4 src/WebApplication/WebComponent/Register.pm
View
@@ -212,7 +212,7 @@ sub perform_registration {
}
# check if email address is valid
- unless ($cgi->param('email') =~ /[\d\w\.-]+\@[\d\w\.-]+\.[\w+]/) {
+ unless ($cgi->param('email') =~ /^[\d\w\.-\']+\@[\d\w\.-]+\.[\w+]$/) {
$application->add_message('warning', 'You must enter a valid eMail address.');
return 0;
}
@@ -224,7 +224,7 @@ sub perform_registration {
}
# check if the login is valid
- unless ($cgi->param('login') =~ /[\d\w]+/) {
+ unless ($cgi->param('login') =~ /^[\d\w]+$/) {
$application->add_message('warning', 'Login may only consist of alphanumeric characters.');
return 0;
}
2  src/WebApplication/WebPage/AccountManagement.pm
View
@@ -170,7 +170,7 @@ sub output {
my $i=0;
foreach my $request (@$user_requests) {
my $request_text = $request->{user}->firstname() . " " . $request->{user}->lastname() . " is requesting access to the " . $request->{type} . " " . $request->{group}->name();
- $html .= "<tr><td>$request_text<input type='hidden' name='group_$i' value='" . $request->{group}->name() . "'><input type='hidden' name='type_$i' value='" . $request->{type} . "'><input type='hidden' name='login_$i' value='".$request->{user}->login()."'></td><td><input type='Radio' name='handling_$i' value='accept'></td><td><input type='radio' name='handling_$i' value='reject'></td><td><input type='radio' name='handling_$i' value='defer' checked='checked'></td><td><input type='text' name='reason_$i' value='-'></td></tr>";
+ $html .= "<tr><td>$request_text<input type='hidden' name='group_$i' value='" . $request->{group}->name() . "'><input type='hidden' name='type_$i' value='" . $request->{type} . "'><input type='hidden' name='login_$i' value=\"".$request->{user}->login()."\"></td><td><input type='Radio' name='handling_$i' value='accept'></td><td><input type='radio' name='handling_$i' value='reject'></td><td><input type='radio' name='handling_$i' value='defer' checked='checked'></td><td><input type='text' name='reason_$i' value='-'></td></tr>";
$i++;
}
$html .= "</table><input type='submit' value='submit'>";
Something went wrong with that request. Please try again.