<commit_before># $Id$

package EnsEMBL::Web::Controller::Genoverse;

use strict;

use JSON qw(to_json from_json);
use List::Util qw(min);

use EnsEMBL::Web::Hub;
use EnsEMBL::Web::Document::GenoverseImage;

use base qw(EnsEMBL::Web::Controller);

sub new {
  my ($class, $r, $args) = @_;
  
  my $hub = new EnsEMBL::Web::Hub({
    apache_handle  => $r,
    session_cookie => $args->{'session_cookie'},
    user_cookie    => $args->{'user_cookie'},
  });
  
  my $func = $hub->action;
  my $self = { hub => $hub };
  
  bless $self, $class;
  
  $r->content_type('text/plain');
  $self->$func if $self->can($func);
  
  return $self;
}

sub fetch_features {
  my $self         = shift;
  my $hub          = $self->hub;
  my $action       = $hub->action;
  my $function     = $hub->function;
  my $image_config = $hub->get_imageconfig($hub->param('config'));
  my $referer      = $hub->referer;
  my @loc          = split ':', $hub->param('r');
  my $adaptor      = $hub->get_adaptor('get_SliceAdaptor');
  my $slice        = $adaptor->fetch_by_region('toplevel', shift @loc, split('-', shift @loc), @loc);
  my $chr          = $slice->seq_region_name;
  my $node         = $image_config->get_node($hub->param('id'));
  my $genoverse    = $node->get('genoverse');
  my ($func)       = grep $self->can($_), "fetch_$function", "fetch$function", 'fetch_features_generic';
  my (@features, %extra, $cache_url, $get_features);
  
  $self->{'cache'} = $hub->cache unless $genoverse->{'cache'} eq 'no';
  $self->{'json'}  = new JSON;
  $self->{'json'}->allow_blessed;
  
  $self->set_cache_params($slice, $node);
  
  # Needed to ensure zmenu links are correct
  $hub->type     = $referer->{'ENSEMBL_TYPE'};
  $hub->action   = $referer->{'ENSEMBL_ACTION'};
  $hub->function = $referer->{'ENSEMBL_FUNCTION'};<commit_msg>sanity check for valid looking locations<commit_after># $Id$

package EnsEMBL::Web::Controller::Genoverse;

use strict;

use JSON qw(to_json from_json);
use List::Util qw(min);

use EnsEMBL::Web::Hub;
use EnsEMBL::Web::Document::GenoverseImage;

use base qw(EnsEMBL::Web::Controller);

sub new {
  my ($class, $r, $args) = @_;
  
  my $hub = new EnsEMBL::Web::Hub({
    apache_handle  => $r,
    session_cookie => $args->{'session_cookie'},
    user_cookie    => $args->{'user_cookie'},
  });
  
  my $func = $hub->action;
  my $self = { hub => $hub };
  
  bless $self, $class;
  
  $r->content_type('text/plain');
  $self->$func if $self->can($func);
  
  return $self;
}

sub fetch_features {
  my $self = shift;
  my $hub  = $self->hub;
  my @loc  = split ':', $hub->param('r');

  return print to_json({ error => 'Invalid location: ' . $hub->param('r') }) unless $loc[1] =~ /^\d+-\d+$/;
  
  my $action       = $hub->action;
  my $function     = $hub->function;
  my $image_config = $hub->get_imageconfig($hub->param('config'));
  my $referer      = $hub->referer;
  my $adaptor      = $hub->get_adaptor('get_SliceAdaptor');
  my $slice        = $adaptor->fetch_by_region('toplevel', shift @loc, split('-', shift @loc), @loc);
  my $chr          = $slice->seq_region_name;
  my $node         = $image_config->get_node($hub->param('id'));
  my $genoverse    = $node->get('genoverse');
  my ($func)       = grep $self->can($_), "fetch_$function", "fetch$function", 'fetch_features_generic';
  my (@features, %extra, $cache_url, $get_features);
  
  $self->{'cache'} = $hub->cache unless $genoverse->{'cache'} eq 'no';
  $self->{'json'}  = new JSON;
  $self->{'json'}->allow_blessed;
  
  $self->set_cache_params($slice, $node);
  
  # Needed to ensure zmenu links are correct
  $hub->type     = $referer->{'ENSEMBL_TYPE'};
  $hub->action   = $referer->{'ENSEMBL_ACTION'};
  $hub->function = $referer->{'ENSEMBL_FUNCTION'};
{'fraction_non_alphanumeric': 0.20455153949129853, 'fraction_numerical': 0.0002677376171352075, 'mean_word_length': 3.635235732009926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 79, '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': '4247456', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1404, 'n_words': 282}