Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5c48319
add rat to bowtie2 index
teharrison Sep 29, 2014
d1e34a2
Merge pull request #623 from teharrison/develop
teharrison Sep 29, 2014
f1889bb
added support for deep nesting of parameters
Oct 7, 2014
15d4b60
updated api2html to catch more stuff
Oct 7, 2014
1822d27
fix broken ftp download links
teharrison Oct 8, 2014
4ef0bc3
perl syntax fix
teharrison Oct 8, 2014
2439c27
remove unneeded text
teharrison Oct 8, 2014
dc65c59
Merge pull request #626 from teharrison/develop
teharrison Oct 8, 2014
d2ce2f8
updated description
Oct 9, 2014
6031ec1
Merge branch 'develop' of github.com:MG-RAST/MG-RAST into develop
Oct 9, 2014
bc3cf07
removed shebang
Oct 9, 2014
03e7140
added more description parsing
Oct 9, 2014
cdf35f6
Merge pull request #625 from paczian/develop
Oct 9, 2014
83f0c3c
added secondary email address to user
Oct 9, 2014
e6d06d0
Merge pull request #628 from paczian/develop
Oct 9, 2014
bc83e82
added request_access to valid verbosities
Oct 9, 2014
24bf42b
fixed typo
Oct 9, 2014
b895205
added html formatting to the description
Oct 9, 2014
7013277
updated api2html parser to work with formatted description
Oct 9, 2014
ec0f904
added proper data return to request_access query
Oct 9, 2014
5e2903b
Merge pull request #629 from paczian/develop
Oct 10, 2014
a23968a
add more actions / workflows to inbox resource
teharrison Oct 15, 2014
6316e89
Merge branch 'develop' of github.com:MG-RAST/MG-RAST into develop
teharrison Oct 15, 2014
fe3598f
fix perl errors
teharrison Oct 15, 2014
1e32021
fix perl errors
teharrison Oct 15, 2014
06a8a91
change job_name
teharrison Oct 15, 2014
f681209
added authenticate request
Oct 16, 2014
bfb8a3b
Merge pull request #631 from paczian/develop
Oct 16, 2014
2c11d27
fixed request_access request
Oct 20, 2014
313a29c
Merge pull request #632 from paczian/develop
Oct 20, 2014
c46b073
fix file names
teharrison Oct 20, 2014
0cdf96d
syntax error
teharrison Oct 20, 2014
828ac91
Merge pull request #630 from teharrison/develop
teharrison Oct 20, 2014
cbdf915
fix workbench bl2seq bug
teharrison Oct 20, 2014
6818f78
Merge pull request #633 from teharrison/develop
teharrison Oct 20, 2014
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
Binary file added .swo
Binary file not shown.
Binary file added .swp
Binary file not shown.
246 changes: 136 additions & 110 deletions bin/api2html.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

use Getopt::Long;

use Data::Dumper;

use JSON;
use LWP::UserAgent;

Expand All @@ -23,18 +25,18 @@ sub usage {

GetOptions ( 'url=s' => \$url,
'site_name=s' => \$site_name,
'outfile=s' => \$outfile,
'help!' => \$help );
'outfile=s' => \$outfile,
'help!' => \$help );

if ($help) {
&usage();
exit 0;
&usage();
exit 0;
}

unless ($url and $outfile) {
print "missing required paramater\n";
&usage();
exit 1;
print "missing required paramater\n";
&usage();
exit 1;
}

# initialize json object and user agent
Expand Down Expand Up @@ -71,7 +73,7 @@ sub usage {
my $html = template_start($site_name);

# build the navigation
$html .= '<li><a href="#overview">overview</a></li>';
$html .= '';
foreach my $res (sort { $a->{name} cmp $b->{name} } @{$structure->{resources}}) {
$html .= '<li><a href="#'.$res->{name}.'">'.$res->{name}.'</a></li>';
}
Expand All @@ -80,115 +82,138 @@ sub usage {
<div class="span12" style="margin-left: 270px;">
~;

$html .= "<h1><a name='overview' style='padding-top: 50px;'>".$site_name." Overview</a></h1><p>".$structure->{service}->{description}."</p><hr>";
$html .= "<h1><a name='overview' style='padding-top: 50px;'>$site_name API Overview</a></h1>".$structure->{service}->{description}."<hr>";

my %param_types = ( body => "<p>This parameter must be passed in the message body.</p>",
options => "<p>This is an optional parameter and may be passed in the query string.</p>",
required => "<p>This is a required parameter and must be passed as a REST parameter.</p>" );

# iterate over the resources
foreach my $res (sort { $a->{name} cmp $b->{name} } @{$structure->{resources}}) {
print $res->{name}."\n";
$html .= "<h1><a name='".$res->{name}."' style='padding-top: 50px;'>".$res->{name}."</a></h1><h2>Description</h2><p>".$res->{description}."</p>";
foreach my $req (@{$res->{requests}}) {
print "\t".$req->{name}."\n";
$html .= "<h2>".$req->{name}." - request</h2><h3>Description</h3><p>".$req->{description}."</p><p>This is a ".$req->{type}." ".$req->{method}." request.";
unless (ref($req->{attributes})) {
$html .= " This request has no parameters.";
next;
}
$html .= "</p><h3>Parameters</h3><ul>";
# iterate over paramaters
foreach my $ptype (sort keys %param_types) {
foreach my $param (sort keys(%{$req->{parameters}->{$ptype}})) {
my $pm = $req->{parameters}->{$ptype}->{$param};
$pm->[0] =~ s/cv/controlled vocabulary/;
$html .= "<li><b>$param</b> (".$pm->[0];
if (ref($pm->[1]) eq 'ARRAY') {
if (! ref($pm->[0]) && $pm->[0] eq 'list') {
$html .= " of ".$pm->[1]->[0].")</li><p>";
$html .= $pm->[1]->[1]."</p>";
} else {
$html .= ")</li><p>";
$html .= "This parameter value can be chosen from the following (the first being default):</p><ul style='list-style: none;'>";
foreach my $cvitem (@{$pm->[1]}) {
if (ref($cvitem)) {
$html .= "<li><b>".$cvitem->[0]."</b> - ".$cvitem->[1]."</li>";
} else {
$html .= "<li><b>".$cvitem."</b></li>";
}
}
$html .= "</ul><br>";
}
} else {
$html .= ")</p><p>".$pm->[1]."</p>";
}
$html .= $param_types{$ptype};
}
}
$html .= "</ul>";
if (exists $req->{example}) {
$html .= "<h3>Example</h3><ul>";
$html .= "<li>".$req->{example}[0]."<li>".$req->{example}[1]."</ul>";
}
$html .= "<h3>Return Attributes</h3><ul>";
# iterate over attributes
foreach my $param (sort keys(%{$req->{attributes}})) {
my ($att_obj, $att_hash);
my $att = $param;
my $att_type = $req->{attributes}->{$param}->[0];
my $att_desc = $req->{attributes}->{$param}->[1];
if ($att_type eq 'cv') {
$html .= "<li><b>$att</b> (controlled vocabulary)</li><p>";
$html .= "This parameter value can be chosen from the following (the first being default):</p><ul style='list-style: none;'>";
foreach my $cvitem (@$att_desc) {
$html .= "<li><b>".$cvitem->[0]."</b> - ".$cvitem->[1]."</li>";
}
$html .= "</ul><br>";
} else {
while (ref($att_desc) eq 'ARRAY') {
if ($att_type =~ /object/) {
$att_obj = $att_desc->[0];
} elsif (($att_type =~ /hash/) && ref($att_desc) eq 'ARRAY') {
$att_hash = $att_desc->[0];
} else {
$att_type .= " of ".$att_desc->[0]."s";
}
$att_desc = $att_desc->[1];
}
$html .= "<li><b>$att</b> ($att_type)</li><p>";
if ($att_obj) {
$html .= "This attribute has an object structure:</p><ul style='list-style: none;'>";
foreach my $key (sort keys(%$att_obj)) {
my $obj_type = $att_obj->{$key}->[0];
my $obj_att = $att_obj->{$key}->[1];
while (ref($obj_att) eq 'ARRAY') {
$obj_type .= " of ".$obj_att->[0]."s";
$obj_att = $obj_att->[1];
}
$html .= "<li><b>$key ($obj_type)</b> - ".$obj_att."</li>";
}
$html .= "</ul><br>";
} elsif ($att_hash) {
$html .= "This attribute has a hash structure:</p><ul style='list-style: none;'>";
foreach my $key (('key', 'value')) {
my $hash_type = $att_hash->{$key}->[0];
my $hash_att = $att_hash->{$key}->[1];
while (ref($hash_att) eq 'ARRAY') {
$hash_type .= " of ".$hash_att->[0]."s";
$hash_att = $hash_att->[1];
}
$html .= "<li><b>$key ($hash_type)</b> - ".$hash_att."</li>";
}
$html .= "</ul><br>";
} else {
$html .= $att_desc."</p>"
}
}
}
$html .= "</p></ul>";
print $res->{name}."\n";
$html .= "<h1><a name='".$res->{name}."' style='padding-top: 50px;'>".$res->{name}."</a></h1><h2>Description</h2><p>".$res->{description}."</p>";
foreach my $req (@{$res->{requests}}) {
print "\t".$req->{name}."\n";
$html .= "<h2>".$req->{name}." - request</h2><h3>Description</h3><p>".$req->{description}."</p><p>This is a ".$req->{type}." ".$req->{method}." request.";
unless (ref($req->{attributes})) {
$html .= " This request has no parameters.";
next;
}
$html .= "</p><h3>Parameters</h3><ul>";
# iterate over paramaters
foreach my $ptype (sort keys %param_types) {
foreach my $param (sort keys(%{$req->{parameters}->{$ptype}})) {
my $pm = $req->{parameters}->{$ptype}->{$param};
$pm->[0] =~ s/cv/controlled vocabulary/;
$html .= "<li><b>$param</b> (".$pm->[0];
if (ref($pm->[1]) eq 'ARRAY') {
if (! ref($pm->[0]) && $pm->[0] eq 'list') {
while (ref($pm->[1]->[1]) eq 'ARRAY') {
$html .= " of list";
$pm->[1] = $pm->[1]->[1];
}
$html .= " of ".$pm->[1]->[0].")</li><p>";
$html .= $pm->[1]->[1]."</p>";
} else {
$html .= ")</li><p>";
$html .= "This parameter value can be chosen from the following (the first being default):</p><ul style='list-style: none;'>";
foreach my $cvitem (@{$pm->[1]}) {
if (ref($cvitem)) {
$html .= "<li><b>".$cvitem->[0]."</b> - ".$cvitem->[1]."</li>";
} else {
$html .= "<li><b>".$cvitem."</b></li>";
}
}
$html .= "</ul><br>";
}
} else {
$html .= ")</p><p>".$pm->[1]."</p>";
}
$html .= $param_types{$ptype};
}
}
$html .= "</ul>";
if (exists $req->{example}) {
$html .= "<h3>Example</h3><ul>";
$html .= "<li>".$req->{example}[0]."<li>".$req->{example}[1]."</ul>";
}
$html .= "<h3>Return Attributes</h3><ul>";
# iterate over attributes
foreach my $param (sort keys(%{$req->{attributes}})) {
my ($att_obj, $att_hash);
my $att = $param;
my $att_type = $req->{attributes}->{$param}->[0];
my $att_desc = $req->{attributes}->{$param}->[1];
if ($att_type eq 'cv') {
$html .= "<li><b>$att</b> (controlled vocabulary)</li><p>";
$html .= "This parameter value can be chosen from the following (the first being default):</p><ul style='list-style: none;'>";
foreach my $cvitem (@$att_desc) {
$html .= "<li><b>".$cvitem->[0]."</b> - ".$cvitem->[1]."</li>";
}
$html .= "</ul><br>";
} else {
while (ref($att_desc) eq 'ARRAY') {
if ($att_type =~ /object/) {
$att_obj = $att_desc->[0];
} elsif (($att_type =~ /hash/) && ref($att_desc) eq 'ARRAY') {
$att_hash = $att_desc->[0];
} else {
my $att_plural = $att_desc->[0];
$att_plural =~ s/y$/ie/;
$att_type .= " of ".$att_plural."s";
}
$att_desc = $att_desc->[1];
}
$html .= "<li><b>$att</b> ($att_type)</li><p>";
if ($att_obj) {
$html .= "This attribute has an object structure:</p><ul style='list-style: none;'>";
foreach my $key (sort keys(%$att_obj)) {
my $obj_type = $att_obj->{$key}->[0];
my $obj_att = $att_obj->{$key}->[1];
my $obj_cv;
while (ref($obj_att) eq 'ARRAY') {
if ($obj_type eq 'cv') {
$obj_cv = $obj_att;
$obj_type = "controlled vocabulary";
$obj_att = "cv";
} else {
$obj_type .= " of ".$obj_att->[0]."s";
$obj_att = $obj_att->[1];
}
}
if ($obj_cv) {
$html .= "<li><b>$key ($obj_type)</b>";
$html .= "<p>This parameter value can be chosen from the following (the first being default):</p><ul style='list-style: none;'>";
foreach my $cvitem (@$obj_cv) {
$html .= "<li><b>".$cvitem->[0]."</b> - ".$cvitem->[1]."</li>";
}
$html .= "</ul><br>";
$html .= "</li>";
} else {
$html .= "<li><b>$key ($obj_type)</b> - ".$obj_att."</li>";
}
}
$html .= "</ul><br>";
} elsif ($att_hash) {
$html .= "This attribute has a hash structure:</p><ul style='list-style: none;'>";
foreach my $key (('key', 'value')) {
my $hash_type = $att_hash->{$key}->[0];
my $hash_att = $att_hash->{$key}->[1];
while (ref($hash_att) eq 'ARRAY') {
$hash_type .= " of ".$hash_att->[0]."s";
$hash_att = $hash_att->[1];
}
$html .= "<li><b>$key ($hash_type)</b> - ".$hash_att."</li>";
}
$html .= "</ul><br>";
} else {
$html .= $att_desc."</p>"
}
}
}
$html .= "<hr>";
$html .= "</p></ul>";
}
$html .= "<hr>";
}

$html .= template_end();
Expand Down Expand Up @@ -221,14 +246,15 @@ sub template_start {
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="./index.html">$site_name API documentation</a>
<a class="brand">RESTful $site_name object and resource API</a>
</div>
</div>
</div>

<div class="row" style="margin-top: 50px;">
<div name="index" class="span3" style="position: fixed; width: 130px;">
<ul class="nav nav-list">
<li><a href="#overview">back to top</a></li>
<li class="nav-header">Resources</li>
~;
}
Expand Down
1 change: 0 additions & 1 deletion src/MGRAST/Templates/pipeline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<input>The input sequence data for this step is in the file 299.screen.passed.fna.</input>
<description>Coding regions within the sequences are predicted using FragGeneScan, an ab-initio prokaryotic gene calling algorithm. Using a hidden Markov model for coding regions and non-coding regions, this step identifies the most likely reading frame and translates nucleotide sequences into amino acids sequences. The predicted genes, possibly more than one per fragment, are called features.</description>
<output><file>The amino acid sequence FASTA formatted file 350.genecalling.coding.faa contains the predicted coding regions.</file></output>
<output><file>The nucleotide sequence FASTA formatted file 350.genecalling.coding.fna contains the predicted coding regions.</file></output>
</stage>
<stage num='425'>
<input>The input sequence data for this step is in the file 100.preprocess.passed.fna.</input>
Expand Down
4 changes: 1 addition & 3 deletions src/MGRAST/cgi/api.cgi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/perl

use CGI;
use JSON;
use Conf;
Expand Down Expand Up @@ -236,7 +234,7 @@ else {
service => 'MG-RAST',
url => ($Conf::url_base || $cgi->url),
documentation => $cgi_url.'/api.html',
description => "RESTful Metagenomics RAST object and resource API\nFor usage note that required parameters need to be passed as path parameters, optional parameters need to be query parameters. If an optional parameter has a list of option values, the first displayed will be used as default.",
description => "<p>The MG-RAST API covers most of the functionality available through the MG-RAST website, with access to annotations, analyses, metadata and access to the MG-RAST user inbox to view contents as well as upload files. All sequence data and data products from intermediate stages in the analysis pipeline are available for download. Other resources provide services not available through the website, e.g. the m5nr resource lets you query the m5nr database.</p><p>Each query to the API is represented as a URI beginning with \"http://api.metagenomics.anl.gov/\" and has a defined structure to pass the requests and parameters to the API server.</p><p>The URI queries can be used from the command line, e.g. using curl, in a browser, or incorporated in a shell script or program.</p><p>Each URI has the form</p><pre>\"http://api.metagenomics.anl.gov/{version}/{resourcepath}?{querystring}\"</pre><p>The {version} value (currently '1') explicitly directs the request to a specific version of the API, if it is omitted the latest API version will be used.</p><p>The resource path is constructed from the path parameters listed below to define a specific resource and the optional query string is used to filter the results obtained for the resource. For example:</p><pre>http://api.metagenomics.anl.gov/1/annotation/sequence/mgm4447943.3?evalue=10&type=organism&source=SwissProt</pre><p>In this example the resource path \"annotation/sequence/mgm4447943.3\" defines a request for the annotated sequences for the MG-RAST job with ID 4447943.3.</p><p>The optional query string \"evalue=10&type=organism&source=SwissProt\" modifies the results by setting an evalue cutoff, annotation type and database source.</p><p>The API provides an authentication mechanism for access to private MG-RAST jobs and users' inbox. The 'auth_key' (or 'webkey') is a 25 character long string (e.g. 'j6FNL61ekNarTgqupMma6eMx5') which is used by the API to identify an MG-RAST user account and determine access rights to metagenomes. Note that the auth_key is valid for a limited time after which queries using the key will be rejected. You can create a new auth_key or view the expiration date and time of an existing auth_key on the MG-RAST website. An account can have only one valid auth_key and creating a new key will invalidate an existing key.</p><p>All public data in MG-RAST is available without an auth_key. All API queries for private data which either do not have an auth_key or use an invalid or expired auth_key will get a \"insufficient permissions to view this data\" response.</p><p>The auth_key can be included in the query string like:</p><pre>\nhttp://api.metagenomics.anl.gov/1/annotation/sequence/mgm4447943.3?evalue=10&type=organism&source=SwissProt&auth_key=j6FNL61ekNarTgqupMma6eMx5</pre><p>or in a request using curl like:</p><pre>curl -X GET -H \"auth: j6FNL61ekNarTgqupMma6eMx5\" \"http://api.metagenomics.anl.gov/1/annotation/sequence/mgm4447943.3?evalue=10&type=organism&source=SwissProt\"</pre><p>Note that for the curl command the quotes are necessary for the query to be passed to the API correctly.</p><p>If an optional parameter passed through the query string has a list of values only the first will be used. When multiple values are required, e.g. for multiple md5 checksum values, they can be passed to the API like:</p><pre>curl -X POST -d '{\"data\":[\"000821a2e2f63df1a3873e4b280002a8\",\"15bf1950bd9867099e72ea6516e3d602\"]}' \"http://api.metagenomics.anl.gov/m5nr/md5\"</pre><p>In some cases, the data requested is in the form of a list with a large number of entries. In these cases the limit and offset parameters can be used to step through the list, for example:</p><pre>http://api.metagenomics.anl.gov/1/project?order=name&limit=20&offset=100</pre><p>will limit the number of entries returned to 20 with an offset of 100. If these parameters are not provided default values of limit=10 and offset=0 are used. The returned JSON structure will contain the 'next' and 'prev' (previous) URIs to simplify stepping through the list.</p><p>The data returned may be plain text, compressed gzipped files or a JSON structure.</p><p>Most API queries are 'synchronous' and results are returned immediately. Some queries may require a substantial time to compute results, in these cases you can select the asynchronous option by adding '&asynchronous=1' to the end of the query string. This query will then return a URL which will return the query results when they are ready.</p>",
contact => 'mg-rast@mcs.anl.gov',
resources => \@res };
print $cgi->header(-type => 'application/json',
Expand Down
5 changes: 3 additions & 2 deletions src/MGRAST/lib/WebPage/Analysis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1674,10 +1674,11 @@ sub get_read_align {

$self->{mgdb}->set_jobs([$mgid]);
my $md5_map = $self->{mgdb}->decode_annotation('md5', [$md5]);
my $md5sum = $md5_map->{$md5};
my $seq_data = $self->{mgdb}->md5s_to_read_sequences([$md5]); # [ { 'md5' => md5, 'id' => id, 'sequence' => sequence } ]
my @md5_seq = split(/\n/, $self->{mgdb}->ach->md5s2sequences([ $md5_map->{$md5} ])); # fasta text
my @md5_seq = split(/\n/, $self->{mgdb}->ach->md5s2sequences([$md5sum])); # fasta text

if ((@md5_seq == 2) && ($md5_seq[0] =~ /$md5/)) {
if ((@md5_seq == 2) && ($md5_seq[0] =~ /$md5sum/)) {
my $md5_fasta = $Conf::temp."/".$md5."_".time.".faa";
open(MD5F, ">$md5_fasta") || return $html;
print MD5F join("\n", @md5_seq) . "\n";
Expand Down
Loading