<commit_before>package resources::compute;

use strict;
use warnings;
no warnings('once');

use MGRAST::Analysis;
use List::MoreUtils qw(any uniq);
use File::Temp qw(tempfile tempdir);

use Conf;
use parent qw(resources::resource);

# 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} = "compute";
    $self->{example} = '"columns": ["mgm4441619.3","mgm4441656.4","mgm4441680.3","mgm4441681.3"], "rows": ["Eukaryota","Bacteria","Archaea"], "data": [[135,410,848,1243],[4397,6529,71423,204413],[1422,2156,874,1138]]';
    $self->{attributes} = { alphadiversity => { "id"   => [ "string", "unique metagenome identifier" ],
                                                "url"  => [ "string", "resource location of this object instance" ],
                                                "data" => [ 'float', 'alpha diversity value' ] },
                            normalize => { 'data' => ['list', ['list', ['float', 'normalized value']]],
                                           'rows' => ['list', ['string', 'row id']],
                                           'columns' => ['list', ['string', 'column id']] },
                            significance => { 'data' => ['list', ['list', ['float', 'significance value']]],
                                              'rows' => ['list', ['string', 'row name']],
                                              'columns' => ['list', ['string', 'column name']] },
                            heatmap => { 'data' => ['list', ['list', ['float', 'normalized value']]],
                                         'rows' => ['list', ['string', 'row id']],
                                         'columns' => ['list', ['string', 'column id']],
                                         'colindex' => ['list', ['float', 'column id index']],
                                         'rowindex' => ['list', ['float', 'row id index']],
                                         'coldend' => ['object', 'dendogram object for columns'],
                                         'rowdend' => ['object', 'dendogram object for rows'] },
                            pcoa => { 'data' => [ 'list', ['object', [
                                                            {'id' => ['string', 'column id'], 'pco' => ['list', ['float', 'principal component value']]},
                                                            "pcoa object" ]
                                                          ] ],
      				                  'pco' => ['list', ['float', 'average principal component value']] }
      				      };
    $self->{distance} = ["bray-curtis", "euclidean", "maximum", "manhattan", "canberra", "minkowski", "difference"];
    $self->{cluster} = ["ward", "single", "complete", "mcquitty", "median", "centroid"];
    $self->{significance} = ["Kruskal-Wallis", "t-test-paired", "Wilcoxon-paired", "t-test-unpaired", "Mann-Whitney-unpaired-Wilcoxon", "ANOVA-one-way"];
    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' => "Calculate various statistics for given input data.",
		            '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'        => "alphadiversity",
				          'request'     => $self->cgi->url."/".$self->name."/alphadiversity/{ID}",
				          'description' => "Calculate alpha diversity value for given ID and taxon level.",
				          'example'     => [ $self->cgi->url."/".$self->name."/alphadiversity/mgm4447943.3?level=order",
             				                 "retrieve alpha diversity for order taxon" ],
				          'method'      => "GET",
				          'type'        => "synchronous",
				          'attributes'  => $self->{attributes}{alphadiversity},
				          'parameters'  => { 'options'  => { 'level' => [ 'cv', $self->hierarchy->{organism} ],
				                                             'source' => [ 'cv', [@{$self->source->{protein}}, @{$self->source->{rna}}] ] },
							                 'required' => {},
							                 'body'     => {} }
						},
				        { 'name'        => "normalize",
				          'request'     => $self->cgi->url."/".$self->name."/normalize",
				          'description' => "Calculate normalized values for given input data.",
				          'example'     => [ 'curl -X POST -d \'{'.$self->{example}.'}\' "'.$self->cgi->url."/".$self->name.'/normalize"',
             				                 "retrieve normalized values for inputed abundances" ],
				          'method'      => "POST",
				          'type'        => "synchronous",
				          'attributes'  => $self->{attributes}{normalize},
				          'parameters'  => { 'options'  => {},
							                 'required' => {},
							                 'body'     => { "data" => ['list', ['list', ['int', 'raw value']]],
          							                         "rows" => ['list', ['string', 'row id']],
          							                         "columns" => ['list', ['string', 'column id']] } }
						},
						{ 'name'        => "significance",
				          'request'     => $self->cgi->url."/".$self->name."/significance",
				          'description' => "Calculate significance values for given input data.",
				          'example'     => [ 'curl -X POST -d \'{"test":"Kruskal-Wallis","groups":["whale","whale","cow","cow"],'.$self->{example}.'}\' "'.$self->cgi->url."/".$self->name.'/significance"',
             				                 "retrieve significance values for inputed abundances and groups using the 'Kruskal-Wallis' significance test" ],
				          'method'      => "POST",
				          'type'        => "synchronous",
				          'attributes'  => $self->{attributes}{significance},
				          'parameters'  => { 'options'  => {},
							                 'required' => {},<commit_msg>api: add required id to doc<commit_after>package resources::compute;

use strict;
use warnings;
no warnings('once');

use MGRAST::Analysis;
use List::MoreUtils qw(any uniq);
use File::Temp qw(tempfile tempdir);

use Conf;
use parent qw(resources::resource);

# 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} = "compute";
    $self->{example} = '"columns": ["mgm4441619.3","mgm4441656.4","mgm4441680.3","mgm4441681.3"], "rows": ["Eukaryota","Bacteria","Archaea"], "data": [[135,410,848,1243],[4397,6529,71423,204413],[1422,2156,874,1138]]';
    $self->{attributes} = { alphadiversity => { "id"   => [ "string", "unique metagenome identifier" ],
                                                "url"  => [ "string", "resource location of this object instance" ],
                                                "data" => [ 'float', 'alpha diversity value' ] },
                            normalize => { 'data' => ['list', ['list', ['float', 'normalized value']]],
                                           'rows' => ['list', ['string', 'row id']],
                                           'columns' => ['list', ['string', 'column id']] },
                            significance => { 'data' => ['list', ['list', ['float', 'significance value']]],
                                              'rows' => ['list', ['string', 'row name']],
                                              'columns' => ['list', ['string', 'column name']] },
                            heatmap => { 'data' => ['list', ['list', ['float', 'normalized value']]],
                                         'rows' => ['list', ['string', 'row id']],
                                         'columns' => ['list', ['string', 'column id']],
                                         'colindex' => ['list', ['float', 'column id index']],
                                         'rowindex' => ['list', ['float', 'row id index']],
                                         'coldend' => ['object', 'dendogram object for columns'],
                                         'rowdend' => ['object', 'dendogram object for rows'] },
                            pcoa => { 'data' => [ 'list', ['object', [
                                                            {'id' => ['string', 'column id'], 'pco' => ['list', ['float', 'principal component value']]},
                                                            "pcoa object" ]
                                                          ] ],
      				                  'pco' => ['list', ['float', 'average principal component value']] }
      				      };
    $self->{distance} = ["bray-curtis", "euclidean", "maximum", "manhattan", "canberra", "minkowski", "difference"];
    $self->{cluster} = ["ward", "single", "complete", "mcquitty", "median", "centroid"];
    $self->{significance} = ["Kruskal-Wallis", "t-test-paired", "Wilcoxon-paired", "t-test-unpaired", "Mann-Whitney-unpaired-Wilcoxon", "ANOVA-one-way"];
    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' => "Calculate various statistics for given input data.",
		            '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'        => "alphadiversity",
				          'request'     => $self->cgi->url."/".$self->name."/alphadiversity/{ID}",
				          'description' => "Calculate alpha diversity value for given ID and taxon level.",
				          'example'     => [ $self->cgi->url."/".$self->name."/alphadiversity/mgm4447943.3?level=order",
             				                 "retrieve alpha diversity for order taxon" ],
				          'method'      => "GET",
				          'type'        => "synchronous",
				          'attributes'  => $self->{attributes}{alphadiversity},
				          'parameters'  => { 'options'  => { 'level' => [ 'cv', $self->hierarchy->{organism} ],
				                                             'source' => [ 'cv', [@{$self->source->{protein}}, @{$self->source->{rna}}] ] },
							                 'required' => { 'id' => ["string", "unique object identifier"] },
							                 'body'     => {} }
						},
				        { 'name'        => "normalize",
				          'request'     => $self->cgi->url."/".$self->name."/normalize",
				          'description' => "Calculate normalized values for given input data.",
				          'example'     => [ 'curl -X POST -d \'{'.$self->{example}.'}\' "'.$self->cgi->url."/".$self->name.'/normalize"',
             				                 "retrieve normalized values for inputed abundances" ],
				          'method'      => "POST",
				          'type'        => "synchronous",
				          'attributes'  => $self->{attributes}{normalize},
				          'parameters'  => { 'options'  => {},
							                 'required' => {},
							                 'body'     => { "data" => ['list', ['list', ['int', 'raw value']]],
          							                         "rows" => ['list', ['string', 'row id']],
          							                         "columns" => ['list', ['string', 'column id']] } }
						},
						{ 'name'        => "significance",
				          'request'     => $self->cgi->url."/".$self->name."/significance",
				          'description' => "Calculate significance values for given input data.",
				          'example'     => [ 'curl -X POST -d \'{"test":"Kruskal-Wallis","groups":["whale","whale","cow","cow"],'.$self->{example}.'}\' "'.$self->cgi->url."/".$self->name.'/significance"',
             				                 "retrieve significance values for inputed abundances and groups using the 'Kruskal-Wallis' significance test" ],
				          'method'      => "POST",
				          'type'        => "synchronous",
				          'attributes'  => $self->{attributes}{significance},
				          'parameters'  => { 'options'  => {},
							                 'required' => {},
{'fraction_non_alphanumeric': 0.19205397301349325, 'fraction_numerical': 0.013043478260869565, 'mean_word_length': 1.5262260935428895, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 252, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 64, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3611537', 'n_tokens_mistral': 4126, 'n_tokens_neox': 3469, 'n_words': 782}