<commit_before>#! /usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';
use CoGe::Accessory::LogUser;
use CoGe::Accessory::Web;
use HTML::Template;
use Data::Dumper;
use CGI::Ajax;
use CoGeX;
use Benchmark;
use File::Path;
use Benchmark qw(:all);
use Statistics::Basic::Mean;
no warnings 'redefine';


use vars qw($P $DBNAME $DBHOST $DBPORT $DBUSER $DBPASS $connstr $DATE $DEBUG $TEMPDIR $TEMPURL $USER $FORM $coge $HISTOGRAM %FUNCTION $P);
$P = CoGe::Accessory::Web::get_defaults("/opt/apache/CoGe/coge.conf");
$ENV{PATH} = $P->{COGEDIR};
$ENV{irodsEnvFile} = "/var/www/.irods/.irodsEnv";

# set this to 1 to print verbose messages to logs
$DEBUG = 0;
$TEMPDIR = $P->{TEMPDIR}."OrgView";
$TEMPURL = $P->{TEMPURL}."OrgView";

mkpath ($TEMPDIR, 0,0777) unless -d $TEMPDIR;

$HISTOGRAM = $P->{HISTOGRAM};

$| = 1; # turn off buffering
$DATE = sprintf( "%04d-%02d-%02d %02d:%02d:%02d",
		 sub { ($_[5]+1900, $_[4]+1, $_[3]),$_[2],$_[1],$_[0] }->(localtime));

$FORM = new CGI;
($USER) = CoGe::Accessory::LogUser->get_user();

$DBNAME = $P->{DBNAME};
$DBHOST = $P->{DBHOST};
$DBPORT = $P->{DBPORT};
$DBUSER = $P->{DBUSER};
$DBPASS = $P->{DBPASS};
$connstr = "dbi:mysql:dbname=".$DBNAME.";host=".$DBHOST.";port=".$DBPORT;
$coge = CoGeX->connect($connstr, $DBUSER, $DBPASS );
#$coge->storage->debugobj(new DBIxProfiler());
#$coge->storage->debug(1);



#my $pj = new CGI::Ajax(
%FUNCTION = (
	     get_dataset_groups=>\&get_dataset_groups,
	     get_dataset_group_info=>\&get_dataset_group_info,
	     get_dataset => \&get_dataset,
	     get_dataset_info => \&get_dataset_info,
	     get_dataset_chr_info => \&get_dataset_chr_info,
	     gen_data => \&gen_data,
	     get_orgs => \&get_orgs,
	     get_org_info=>\&get_org_info,
	     get_recent_orgs=>\&get_recent_orgs,
	     get_start_stop=>\&get_start_stop,
	     get_feature_counts => \&get_feature_counts,
	     get_gc_for_chromosome=> \&get_gc_for_chromosome,
	     get_gc_for_noncoding=> \&get_gc_for_noncoding,
	     get_gc_for_feature_type =>\&get_gc_for_feature_type,
	     get_codon_usage=>\&get_codon_usage,
	     get_aa_usage=>\&get_aa_usage,
	     get_wobble_gc=>\&get_wobble_gc,
	     get_wobble_gc_diff=>\&get_wobble_gc_diff,
	     get_total_length_for_ds=>\&get_total_length_for_ds,
	     update_genomelist=>\&update_genomelist,
	     parse_for_GenoList=>\&parse_for_GenoList,
		 get_genome_list_for_org=>\&get_genome_list_for_org,
		add_to_irods=>\&add_to_irods,
	    );
my $pj = new CGI::Ajax(%FUNCTION);
$pj->JSDEBUG(0);
$pj->DEBUG(0);
if ($FORM->param('jquery_ajax'))
  {
    dispatch();
  }
else
  {
    print $pj->build_html($FORM, \&gen_html);
  }
#print "Content-Type: text/html\n\n";print gen_html($FORM);

sub dispatch
{
    my %args = $FORM->Vars;
    my $fname = $args{'fname'};
    if($fname)
    {
	#my %args = $cgi->Vars;
	#print STDERR Dumper \%args;
	if($args{args}){
	    my @args_list = split( /,/, $args{args} );
	    print $FORM->header, $FUNCTION{$fname}->(@args_list);
       	}
	else{
	    print $FORM->header, $FUNCTION{$fname}->(%args);
	}
    }
#    else{
#	print $FORM->header, gen_html();
#    }
}

sub parse_for_GenoList
  {
	my $genomelist = shift;
	my $url = "GenomeList.pl?";
	foreach my $genomeid (split /,/,$genomelist)
	{
		next unless $genomeid;
		$url .="dsgid=$genomeid&";
	}
	$url =~ s/&$//;
	return $url;
 }

sub gen_html
  {
    my $html;
    unless ($USER)
      {
	$html = login();
      }
    else
      {
	my ($body, $seq_names, $seqs) = gen_body();
	my $template = HTML::Template->new(filename=>$P->{TMPLDIR}.'generic_page.tmpl');
#	$template->param(TITLE=>'Organism Overview');
	$template->param(PAGE_TITLE=>'OrgView');
	$template->param(HEAD=>qq{});
	$template->param(HELP=>"/wiki/index.php?title=OrganismView");
	my $name = $USER->user_name;
        $name = $USER->first_name if $USER->first_name;
        $name .= " ".$USER->last_name if $USER->first_name && $USER->last_name;
        $template->param(USER=>$name);
	$template->param(BOX_NAME=>"Search for organisms and genomes");
	$template->param(LOGON=>1) unless $USER->user_name eq "public";
	$template->param(DATE=>$DATE);
	$template->param(LOGO_PNG=>"OrganismView-logo.png");<commit_msg>updated generation of link to GenomeList<commit_after>#! /usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';
use CoGe::Accessory::LogUser;
use CoGe::Accessory::Web;
use HTML::Template;
use Data::Dumper;
use CGI::Ajax;
use CoGeX;
use Benchmark;
use File::Path;
use Benchmark qw(:all);
use Statistics::Basic::Mean;
no warnings 'redefine';


use vars qw($P $DBNAME $DBHOST $DBPORT $DBUSER $DBPASS $connstr $DATE $DEBUG $TEMPDIR $TEMPURL $USER $FORM $coge $HISTOGRAM %FUNCTION $P);
$P = CoGe::Accessory::Web::get_defaults("/opt/apache/CoGe/coge.conf");
$ENV{PATH} = $P->{COGEDIR};
$ENV{irodsEnvFile} = "/var/www/.irods/.irodsEnv";

# set this to 1 to print verbose messages to logs
$DEBUG = 0;
$TEMPDIR = $P->{TEMPDIR}."OrgView";
$TEMPURL = $P->{TEMPURL}."OrgView";

mkpath ($TEMPDIR, 0,0777) unless -d $TEMPDIR;

$HISTOGRAM = $P->{HISTOGRAM};

$| = 1; # turn off buffering
$DATE = sprintf( "%04d-%02d-%02d %02d:%02d:%02d",
		 sub { ($_[5]+1900, $_[4]+1, $_[3]),$_[2],$_[1],$_[0] }->(localtime));

$FORM = new CGI;
($USER) = CoGe::Accessory::LogUser->get_user();

$DBNAME = $P->{DBNAME};
$DBHOST = $P->{DBHOST};
$DBPORT = $P->{DBPORT};
$DBUSER = $P->{DBUSER};
$DBPASS = $P->{DBPASS};
$connstr = "dbi:mysql:dbname=".$DBNAME.";host=".$DBHOST.";port=".$DBPORT;
$coge = CoGeX->connect($connstr, $DBUSER, $DBPASS );
#$coge->storage->debugobj(new DBIxProfiler());
#$coge->storage->debug(1);



#my $pj = new CGI::Ajax(
%FUNCTION = (
	     get_dataset_groups=>\&get_dataset_groups,
	     get_dataset_group_info=>\&get_dataset_group_info,
	     get_dataset => \&get_dataset,
	     get_dataset_info => \&get_dataset_info,
	     get_dataset_chr_info => \&get_dataset_chr_info,
	     gen_data => \&gen_data,
	     get_orgs => \&get_orgs,
	     get_org_info=>\&get_org_info,
	     get_recent_orgs=>\&get_recent_orgs,
	     get_start_stop=>\&get_start_stop,
	     get_feature_counts => \&get_feature_counts,
	     get_gc_for_chromosome=> \&get_gc_for_chromosome,
	     get_gc_for_noncoding=> \&get_gc_for_noncoding,
	     get_gc_for_feature_type =>\&get_gc_for_feature_type,
	     get_codon_usage=>\&get_codon_usage,
	     get_aa_usage=>\&get_aa_usage,
	     get_wobble_gc=>\&get_wobble_gc,
	     get_wobble_gc_diff=>\&get_wobble_gc_diff,
	     get_total_length_for_ds=>\&get_total_length_for_ds,
	     update_genomelist=>\&update_genomelist,
	     parse_for_GenoList=>\&parse_for_GenoList,
		 get_genome_list_for_org=>\&get_genome_list_for_org,
		add_to_irods=>\&add_to_irods,
	    );
my $pj = new CGI::Ajax(%FUNCTION);
$pj->JSDEBUG(0);
$pj->DEBUG(0);
if ($FORM->param('jquery_ajax'))
  {
    dispatch();
  }
else
  {
    print $pj->build_html($FORM, \&gen_html);
  }
#print "Content-Type: text/html\n\n";print gen_html($FORM);

sub dispatch
{
    my %args = $FORM->Vars;
    my $fname = $args{'fname'};
    if($fname)
    {
	#my %args = $cgi->Vars;
	#print STDERR Dumper \%args;
	if($args{args}){
	    my @args_list = split( /,/, $args{args} );
	    print $FORM->header, $FUNCTION{$fname}->(@args_list);
       	}
	else{
	    print $FORM->header, $FUNCTION{$fname}->(%args);
	}
    }
#    else{
#	print $FORM->header, gen_html();
#    }
}

sub parse_for_GenoList
  {
	my $genomelist = shift;
	my $url = "GenomeList.pl?dsgid=$genomelist";
	return $url;
 }

sub gen_html
  {
    my $html;
    unless ($USER)
      {
	$html = login();
      }
    else
      {
	my ($body, $seq_names, $seqs) = gen_body();
	my $template = HTML::Template->new(filename=>$P->{TMPLDIR}.'generic_page.tmpl');
#	$template->param(TITLE=>'Organism Overview');
	$template->param(PAGE_TITLE=>'OrgView');
	$template->param(HEAD=>qq{});
	$template->param(HELP=>"/wiki/index.php?title=OrganismView");
	my $name = $USER->user_name;
        $name = $USER->first_name if $USER->first_name;
        $name .= " ".$USER->last_name if $USER->first_name && $USER->last_name;
        $template->param(USER=>$name);
	$template->param(BOX_NAME=>"Search for organisms and genomes");
	$template->param(LOGON=>1) unless $USER->user_name eq "public";
	$template->param(DATE=>$DATE);
	$template->param(LOGO_PNG=>"OrganismView-logo.png");
{'fraction_non_alphanumeric': 0.19557061599903183, 'fraction_numerical': 0.008471499455403606, 'mean_word_length': 4.454785478547855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 159, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7088462', 'n_tokens_mistral': 3531, 'n_tokens_neox': 3399, 'n_words': 542}