<commit_before>package CoGe::Services::API::JBrowse::Experiment;

use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON;

use CoGeX;
use CoGe::Accessory::histogram;
use CoGe::Accessory::IRODS qw( irods_iput );
use CoGe::Services::Auth qw( init );
use CoGe::Core::Experiment qw( get_data );
use CoGe::Core::Storage qw( get_experiment_path get_upload_path get_experiment_metadata );
use CoGeDBI qw( get_dataset_ids feature_type_names_to_id );
use Data::Dumper;
use File::Path;
use File::Spec::Functions;
use File::Temp qw( tempfile tempdir );
use JSON::XS;
#TODO: use these from Storage.pm instead of redeclaring them
my $DATA_TYPE_QUANT  = 1; # Quantitative data
my $DATA_TYPE_POLY	 = 2; # Polymorphism data
my $DATA_TYPE_ALIGN  = 3; # Alignments
my $DATA_TYPE_MARKER = 4; # Markers

my $NUM_QUANT_COL   = 6;
my $NUM_VCF_COL     = 9;
my $NUM_GFF_COL     = 7;
my $MAX_EXPERIMENTS = 20;
my $MAX_WINDOW_SIZE = 1000000;#500000;

my $QUAL_ENCODING_OFFSET = 33;

my $log10 = log(10);

sub stats_global { # mdb rewritten 8/26/16 COGE-270
    my $self = shift;
    my $eid  = $self->stash('eid');
    my $nid  = $self->stash('nid');
    my $gid  = $self->stash('gid');
	print STDERR "JBrowse::Experiment::stats_global\n";
	
	# Authenticate user and connect to the database
    my ($db, $user) = CoGe::Services::Auth::init($self);
    
    # Get experiments
	my $experiments = _get_experiments($db, $user, $eid, $gid, $nid);
	
	# Determine min/max values from all experiments' metadata
	my ($globalMax, $globalMin) = (0, 0);
	foreach my $experiment (@$experiments) {
	    my ($min, $max);
	    my $md = get_experiment_metadata();
	    if (defined $md && defined $md->{max} && defined $md->{min}) {
	        $min = $md->{min};
	        $max = $md->{max};
	    }
	    else { # legacy default values
	        $min = -1;
	        $max = 1;
	    }
	    if ($max > $globalMax) {
	        $globalMax = $max;
	    }
	    if ($min < $globalMin) {
	        $globalMin = $min;
	    }
	}
	
    $self->render(json => {<commit_msg>Fix missing id in invocation of get_experiment_metadata<commit_after>package CoGe::Services::API::JBrowse::Experiment;

use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON;

use CoGeX;
use CoGe::Accessory::histogram;
use CoGe::Accessory::IRODS qw( irods_iput );
use CoGe::Services::Auth qw( init );
use CoGe::Core::Experiment qw( get_data );
use CoGe::Core::Storage qw( get_experiment_path get_upload_path get_experiment_metadata );
use CoGeDBI qw( get_dataset_ids feature_type_names_to_id );
use Data::Dumper;
use File::Path;
use File::Spec::Functions;
use File::Temp qw( tempfile tempdir );
use JSON::XS;
#TODO: use these from Storage.pm instead of redeclaring them
my $DATA_TYPE_QUANT  = 1; # Quantitative data
my $DATA_TYPE_POLY	 = 2; # Polymorphism data
my $DATA_TYPE_ALIGN  = 3; # Alignments
my $DATA_TYPE_MARKER = 4; # Markers

my $NUM_QUANT_COL   = 6;
my $NUM_VCF_COL     = 9;
my $NUM_GFF_COL     = 7;
my $MAX_EXPERIMENTS = 20;
my $MAX_WINDOW_SIZE = 1000000;#500000;

my $QUAL_ENCODING_OFFSET = 33;

my $log10 = log(10);

sub stats_global { # mdb rewritten 8/26/16 COGE-270
    my $self = shift;
    my $eid  = $self->stash('eid');
    my $nid  = $self->stash('nid');
    my $gid  = $self->stash('gid');
	print STDERR "JBrowse::Experiment::stats_global\n";
	
	# Authenticate user and connect to the database
    my ($db, $user) = CoGe::Services::Auth::init($self);
    
    # Get experiments
	my $experiments = _get_experiments($db, $user, $eid, $gid, $nid);
	
	# Determine min/max values from all experiments' metadata
	my ($globalMax, $globalMin) = (0, 0);
	foreach my $experiment (@$experiments) {
	    my ($min, $max);
	    my $md = get_experiment_metadata($experiment->id);
	    print STDERR Dumper $md, "\n";
	    if (defined $md && defined $md->{max} && defined $md->{min}) {
	        $min = $md->{min};
	        $max = $md->{max};
	    }
	    else { # legacy default values
	        $min = -1;
	        $max = 1;
	    }
	    if ($max > $globalMax) {
	        $globalMax = $max;
	    }
	    if ($min < $globalMin) {
	        $globalMin = $min;
	    }
	}
	
    $self->render(json => {
{'fraction_non_alphanumeric': 0.15049841964502797, 'fraction_numerical': 0.019450522732798445, 'mean_word_length': 3.669693530079455, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5105668', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1522, 'n_words': 387}