<commit_before>#! /usr/bin/perl -w


use strict;
use CGI;
use CoGeX;
use DBI;

use Data::Dumper;
use CoGe::Accessory::LogUser;
use CoGe::Accessory::Web;
use HTML::Template;
use URI::Escape;
use Spreadsheet::WriteExcel;
use Benchmark;
use DBIxProfiler;
use File::Path;
no warnings 'redefine';


use vars qw($P $DBNAME $DBHOST $DBPORT $DBUSER $DBPASS $connstr $PAGE_NAME $TEMPDIR $USER $DATE $BASEFILE $COGEDIR $coge $cogeweb $FORM $URL $HISTOGRAM $TEMPURL);
$P = CoGe::Accessory::Web::get_defaults($ENV{HOME}.'coge.conf');
$ENV{PATH} = $P->{COGEDIR};
$COGEDIR = $P->{COGEDIR};
$URL = $P->{URL};
$DATE = sprintf( "%04d-%02d-%02d %02d:%02d:%02d",
		sub { ($_[5]+1900, $_[4]+1, $_[3]),$_[2],$_[1],$_[0] }->(localtime));
$PAGE_NAME = "GenomeList.pl";
$HISTOGRAM = $P->{HISTOGRAM};	
($USER) = CoGe::Accessory::LogUser->get_user();
$TEMPDIR = $P->{TEMPDIR}."GenomeList/";
mkpath ($TEMPDIR, 0,0777) unless -d $TEMPDIR;
$TEMPURL = $P->{TEMPURL}."GenomeList/";
$FORM = new CGI;
$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);



$SIG{'__WARN__'} = sub { }; #silence warnings

my %FUNCTION = (
		gen_html=>\&gen_html,
		get_feature_counts=>\&get_feature_counts,
		get_gc=>\&get_gc,
		get_aa_usage=>\&get_aa_usage,
		get_codon_usage=>\&get_codon_usage,
	 	get_fasta_seqs=>\&get_fasta_seqs,
	 	generate_excel_file=>\&generate_excel_file,
	 	generate_csv_file=>\&generate_csv_file,
	 	gc_content=>\&gc_content,
	 	gen_data=>\&gen_data,
	 	send_to_msa=>\&send_to_msa,
	 	send_to_SynFind=>\&send_to_SynFind,
	 	send_to_CoGeBlast=>\&send_to_CoGeBlast,
	 	send_to_GenomeList=>\&send_to_GenomeList,
	 	send_to_SynFind=>\&send_to_SynFind,
	 	get_wobble_gc=>\&get_wobble_gc,
	 	save_FeatList_settings=>\&save_FeatList_settings,
	 	add_to_user_history=>\&add_to_user_history,
		cds_wgc_hist=>\&cds_wgc_hist,
		get_gc_for_feature_type=>\&get_gc_for_feature_type,
    );
#my $pj = new CGI::Ajax(%FUNCTION);
#$pj->js_encode_function('escape');
#my $t1 = new Benchmark;
if ($FORM->param('jquery_ajax'))
  {
    dispatch();
  }
else
  {
    print $FORM->header,"\n",gen_html();
  }
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);
	}
    }
}
sub gen_html
{
    my $html;    
    unless ($USER)
    {
	$html = login();
      }
    else
     {
       my ($body) = gen_body();
       my $template = HTML::Template->new(filename=>$P->{TMPLDIR}.'generic_page.tmpl');
       $template->param(PAGE_TITLE=>'GenomeList');
       $template->param(HELP=>'/wiki/index.php?title=GenomeList');
       # print STDERR "user is: ",$USER,"\n";
       #add_to_user_history() unless $USER->user_name eq "public";
       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(LOGO_PNG=>"GenomeList-logo.png");
       $template->param(LOGON=>1) unless $USER->user_name eq "public";
       $template->param(DATE=>$DATE);
       my $list_name = $FORM->param('list_name') || $FORM->param('ln');
       my $box_name = "Genome List:";
       $box_name .= " $list_name" if $list_name;
       $template->param(BOX_NAME=>$box_name);
       $template->param(BODY=>$body);
       $template->param(ADJUST_BOX=>1);
       $html .= $template->output;
   }
 }
 




sub cds_wgc_hist
  {
    my %opts = @_;
    my $dsid = $opts{dsid};
    my $dsgid = $opts{dsgid};
    my $chr = $opts{chr};
    my $gstid = $opts{gstid}; #genomic sequence type id
    my $min = $opts{min}; #limit results with gc values greater than $min;
    my $max = $opts{max}; #limit results with gc values smaller than $max;
    my $hist_type = $opts{hist_type};<commit_msg>Added tinyurl link to regen GenomeList<commit_after>#! /usr/bin/perl -w


use strict;
use CGI;
use CoGeX;
use DBI;

use Data::Dumper;
use CoGe::Accessory::LogUser;
use CoGe::Accessory::Web;
use HTML::Template;
use URI::Escape;
use Spreadsheet::WriteExcel;
use Benchmark;
use DBIxProfiler;
use File::Path;
no warnings 'redefine';


use vars qw($P $DBNAME $DBHOST $DBPORT $DBUSER $DBPASS $connstr $PAGE_NAME $TEMPDIR $USER $DATE $BASEFILE $COGEDIR $coge $cogeweb $FORM $URL $HISTOGRAM $TEMPURL);
$P = CoGe::Accessory::Web::get_defaults($ENV{HOME}.'coge.conf');
$ENV{PATH} = $P->{COGEDIR};
$COGEDIR = $P->{COGEDIR};
$URL = $P->{URL};
$DATE = sprintf( "%04d-%02d-%02d %02d:%02d:%02d",
		sub { ($_[5]+1900, $_[4]+1, $_[3]),$_[2],$_[1],$_[0] }->(localtime));
$PAGE_NAME = "GenomeList.pl";
$HISTOGRAM = $P->{HISTOGRAM};	
($USER) = CoGe::Accessory::LogUser->get_user();
$TEMPDIR = $P->{TEMPDIR}."GenomeList/";
mkpath ($TEMPDIR, 0,0777) unless -d $TEMPDIR;
$TEMPURL = $P->{TEMPURL}."GenomeList/";
$FORM = new CGI;
$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);



$SIG{'__WARN__'} = sub { }; #silence warnings

my %FUNCTION = (
		gen_html=>\&gen_html,
		get_feature_counts=>\&get_feature_counts,
		get_gc=>\&get_gc,
		get_aa_usage=>\&get_aa_usage,
		get_codon_usage=>\&get_codon_usage,
	 	get_fasta_seqs=>\&get_fasta_seqs,
	 	generate_excel_file=>\&generate_excel_file,
	 	generate_csv_file=>\&generate_csv_file,
	 	gc_content=>\&gc_content,
	 	gen_data=>\&gen_data,
	 	send_to_msa=>\&send_to_msa,
	 	send_to_SynFind=>\&send_to_SynFind,
	 	send_to_CoGeBlast=>\&send_to_CoGeBlast,
	 	send_to_GenomeList=>\&send_to_GenomeList,
	 	send_to_SynFind=>\&send_to_SynFind,
	 	get_wobble_gc=>\&get_wobble_gc,
	 	save_FeatList_settings=>\&save_FeatList_settings,
	 	add_to_user_history=>\&add_to_user_history,
		cds_wgc_hist=>\&cds_wgc_hist,
		get_gc_for_feature_type=>\&get_gc_for_feature_type,
    );
#my $pj = new CGI::Ajax(%FUNCTION);
#$pj->js_encode_function('escape');
#my $t1 = new Benchmark;
if ($FORM->param('jquery_ajax'))
  {
    dispatch();
  }
else
  {
    print $FORM->header,"\n",gen_html();
  }
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);
	}
    }
}
sub gen_html
{
    my $html;    
    unless ($USER)
    {
	$html = login();
      }
    else
     {
       my ($body) = gen_body();
       my $template = HTML::Template->new(filename=>$P->{TMPLDIR}.'generic_page.tmpl');
       $template->param(PAGE_TITLE=>'GenomeList');
       $template->param(HELP=>'/wiki/index.php?title=GenomeList');
       # print STDERR "user is: ",$USER,"\n";
       #add_to_user_history() unless $USER->user_name eq "public";
       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(LOGO_PNG=>"GenomeList-logo.png");
       $template->param(LOGON=>1) unless $USER->user_name eq "public";
       $template->param(DATE=>$DATE);
       my $link = "http://".$ENV{SERVER_NAME}.$ENV{REQUEST_URI};
       $link = CoGe::Accessory::Web::get_tiny_link(url=>$link);
       my $box_name = "Genome List: ";
       my $list_name = $FORM->param('list_name') || $FORM->param('ln');
       $box_name .= " $list_name" if $list_name;
       $box_name .= "<span class=link onclick=window.open('$link');>$link</span>";
       $template->param(BOX_NAME=>$box_name);
       $template->param(BODY=>$body);
       $template->param(ADJUST_BOX=>1);
       $html .= $template->output;
   }
 }
 




sub cds_wgc_hist
  {
    my %opts = @_;
    my $dsid = $opts{dsid};
    my $dsgid = $opts{dsgid};
    my $chr = $opts{chr};
    my $gstid = $opts{gstid}; #genomic sequence type id
    my $min = $opts{min}; #limit results with gc values greater than $min;
    my $max = $opts{max}; #limit results with gc values smaller than $max;
    my $hist_type = $opts{hist_type};
{'fraction_non_alphanumeric': 0.2009442653155228, 'fraction_numerical': 0.007369875633348687, 'mean_word_length': 4.191273161984459, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 164, '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': '1602557', 'n_tokens_mistral': 3683, 'n_tokens_neox': 3569, 'n_words': 585}