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

use strict;
use CGI;
use CoGeX;
use CoGeX::Result::Genome qw(ERROR LOADING);
use CoGe::JEX::Jex;
use CoGe::Accessory::Web;
use CoGe::Accessory::Utils qw(sanitize_name get_unique_id commify execute);
use CoGe::Accessory::IRODS qw(irods_iput irods_imeta_add);
use CoGe::Core::Chromosomes;
use CoGe::Core::Genome;
use CoGe::Core::Metadata;
use CoGe::Core::Experiment qw(experimentcmp);
use CoGe::Core::Storage;
use CoGe::Core::Favorites;
use CoGe::Builder::CommonTasks;

use HTML::Template;
use JSON::XS;
use Sort::Versions;
use File::Basename qw(basename);
use File::Path qw(mkpath);
use File::Spec::Functions;
use File::Copy;
use POSIX qw(floor);
use Data::Dumper;

no warnings 'redefine';

use vars qw(
  $P $PAGE_TITLE $TEMPDIR $SECTEMPDIR $LOAD_ID $USER $config $DB $FORM %FUNCTION
  $MAX_SEARCH_RESULTS $LINK $node_types $ERROR $HISTOGRAM $TEMPURL $SERVER $JEX
  $JOB_ID $EMBED
);

$PAGE_TITLE = 'GenomeInfo';

$node_types = CoGeX::node_types();

use constant MAX_TITLE_LENGTH => 150;

$FORM = new CGI;
( $DB, $USER, $config, $LINK ) = CoGe::Accessory::Web->init(
    cgi => $FORM,
    page_title => $PAGE_TITLE
);

$JEX = CoGe::JEX::Jex->new( host => $config->{JOBSERVER}, port => $config->{JOBPORT} );
$JOB_ID  = $FORM->Vars->{'job_id'};
$LOAD_ID = ( defined $FORM->Vars->{'load_id'} ? $FORM->Vars->{'load_id'} : get_unique_id() );
$SECTEMPDIR = $config->{SECTEMPDIR} . $PAGE_TITLE . '/' . $USER->name . '/' . $LOAD_ID . '/';
$TEMPDIR   = $config->{TEMPDIR} . "/$PAGE_TITLE";
$TEMPURL   = $config->{TEMPURL} . "/$PAGE_TITLE";
$HISTOGRAM = $config->{HISTOGRAM};
$SERVER    = $config->{SERVER};

$MAX_SEARCH_RESULTS = 100;
$ERROR = encode_json({ error => 1 });

my %ajax = CoGe::Accessory::Web::ajax_func();

%FUNCTION = (
    get_genome_info            => \&get_genome_info,
    get_genome_data            => \&get_genome_data,
    edit_genome_info           => \&edit_genome_info,
    update_genome_info         => \&update_genome_info,
    update_owner               => \&update_owner,
    update_certified           => \&update_certified,
    toggle_favorite            => \&toggle_favorite,
    search_organisms           => \&search_organisms,
    search_users               => \&search_users,
    delete_genome              => \&delete_genome,
#    delete_dataset             => \&delete_dataset,
    check_login                => \&check_login,
    copy_genome                => \&copy_genome,
    export_fasta		       => \&export_fasta,
    export_file_chr		       => \&export_file_chr,
    annotate                   => \&annotate,
    get_datasets               => \&get_datasets,
    get_bed                    => \&get_bed,
    get_gff                    => \&get_gff,
    get_tbl                    => \&get_tbl,
    get_load_log               => \&get_load_log,
    get_progress_log           => \&get_progress_log,
    export_bed                 => \&export_bed,
    export_gff                 => \&export_gff,
    export_tbl                 => \&export_tbl,
    export_features            => \&export_features,
    get_genome_info_details    => \&get_genome_info_details,
    get_features               => \&get_features,
    gen_data                   => \&gen_data,
    get_gc_for_genome          => \&get_gc_for_genome,
    get_gc_for_noncoding       => \&get_gc_for_noncoding,
    get_gc_for_feature_type    => \&get_gc_for_feature_type,
    get_chr_length_hist        => \&get_chr_length_hist,
    get_chromosomes            => \&get_chromosomes,
    cache_chr_fasta			   => \&cache_chr_fasta,
    get_aa_usage               => \&get_aa_usage,
    get_wobble_gc              => \&get_wobble_gc,
    get_wobble_gc_diff         => \&get_wobble_gc_diff,
    get_codon_usage            => \&get_codon_usage,
    get_experiments            => \&get_experiments,
    recommend_certification    => \&recommend_certification,
    %ajax
);

CoGe::Accessory::Web->dispatch( $FORM, \%FUNCTION, \&generate_html );

sub get_genome_info_details {
    my %opts  = @_;
    my $dsgid = $opts{dsgid};
    return " " unless $dsgid;
    my $dsg = $DB->resultset("Genome")->find($dsgid);
    return "Unable to get genome object for id: $dsgid" unless $dsg;
    my $html;

    #TABLE
    $html .= qq{<div class="left coge-table-header">Statistics</div>};
    $html .= qq{<table style="padding: 2px; margin-bottom: 5px;" class="border-top">};
    my $total_length = $dsg->length;<commit_msg>added check for genome file and return 'missing' message if not found<commit_after>#! /usr/bin/perl -w

use strict;
use CGI;
use CoGeX;
use CoGeX::Result::Genome qw(ERROR LOADING);
use CoGe::JEX::Jex;
use CoGe::Accessory::Web;
use CoGe::Accessory::Utils qw(sanitize_name get_unique_id commify execute);
use CoGe::Accessory::IRODS qw(irods_iput irods_imeta_add);
use CoGe::Core::Chromosomes;
use CoGe::Core::Genome;
use CoGe::Core::Metadata;
use CoGe::Core::Experiment qw(experimentcmp);
use CoGe::Core::Storage;
use CoGe::Core::Favorites;
use CoGe::Builder::CommonTasks;

use HTML::Template;
use JSON::XS;
use Sort::Versions;
use File::Basename qw(basename);
use File::Path qw(mkpath);
use File::Spec::Functions;
use File::Copy;
use POSIX qw(floor);
use Data::Dumper;

no warnings 'redefine';

use vars qw(
  $P $PAGE_TITLE $TEMPDIR $SECTEMPDIR $LOAD_ID $USER $config $DB $FORM %FUNCTION
  $MAX_SEARCH_RESULTS $LINK $node_types $ERROR $HISTOGRAM $TEMPURL $SERVER $JEX
  $JOB_ID $EMBED
);

$PAGE_TITLE = 'GenomeInfo';

$node_types = CoGeX::node_types();

use constant MAX_TITLE_LENGTH => 150;

$FORM = new CGI;
( $DB, $USER, $config, $LINK ) = CoGe::Accessory::Web->init(
    cgi => $FORM,
    page_title => $PAGE_TITLE
);

$JEX = CoGe::JEX::Jex->new( host => $config->{JOBSERVER}, port => $config->{JOBPORT} );
$JOB_ID  = $FORM->Vars->{'job_id'};
$LOAD_ID = ( defined $FORM->Vars->{'load_id'} ? $FORM->Vars->{'load_id'} : get_unique_id() );
$SECTEMPDIR = $config->{SECTEMPDIR} . $PAGE_TITLE . '/' . $USER->name . '/' . $LOAD_ID . '/';
$TEMPDIR   = $config->{TEMPDIR} . "/$PAGE_TITLE";
$TEMPURL   = $config->{TEMPURL} . "/$PAGE_TITLE";
$HISTOGRAM = $config->{HISTOGRAM};
$SERVER    = $config->{SERVER};

$MAX_SEARCH_RESULTS = 100;
$ERROR = encode_json({ error => 1 });

my %ajax = CoGe::Accessory::Web::ajax_func();

%FUNCTION = (
    get_genome_info            => \&get_genome_info,
    get_genome_data            => \&get_genome_data,
    edit_genome_info           => \&edit_genome_info,
    update_genome_info         => \&update_genome_info,
    update_owner               => \&update_owner,
    update_certified           => \&update_certified,
    toggle_favorite            => \&toggle_favorite,
    search_organisms           => \&search_organisms,
    search_users               => \&search_users,
    delete_genome              => \&delete_genome,
#    delete_dataset             => \&delete_dataset,
    check_login                => \&check_login,
    copy_genome                => \&copy_genome,
    export_fasta		       => \&export_fasta,
    export_file_chr		       => \&export_file_chr,
    annotate                   => \&annotate,
    get_datasets               => \&get_datasets,
    get_bed                    => \&get_bed,
    get_gff                    => \&get_gff,
    get_tbl                    => \&get_tbl,
    get_load_log               => \&get_load_log,
    get_progress_log           => \&get_progress_log,
    export_bed                 => \&export_bed,
    export_gff                 => \&export_gff,
    export_tbl                 => \&export_tbl,
    export_features            => \&export_features,
    get_genome_info_details    => \&get_genome_info_details,
    get_features               => \&get_features,
    gen_data                   => \&gen_data,
    get_gc_for_genome          => \&get_gc_for_genome,
    get_gc_for_noncoding       => \&get_gc_for_noncoding,
    get_gc_for_feature_type    => \&get_gc_for_feature_type,
    get_chr_length_hist        => \&get_chr_length_hist,
    get_chromosomes            => \&get_chromosomes,
    cache_chr_fasta			   => \&cache_chr_fasta,
    get_aa_usage               => \&get_aa_usage,
    get_wobble_gc              => \&get_wobble_gc,
    get_wobble_gc_diff         => \&get_wobble_gc_diff,
    get_codon_usage            => \&get_codon_usage,
    get_experiments            => \&get_experiments,
    recommend_certification    => \&recommend_certification,
    %ajax
);

CoGe::Accessory::Web->dispatch( $FORM, \%FUNCTION, \&generate_html );

sub get_genome_info_details {
    my %opts  = @_;
    my $dsgid = $opts{dsgid};
    return " " unless $dsgid;
    my $dsg = $DB->resultset("Genome")->find($dsgid);
    return "Unable to get genome object for id: $dsgid" unless $dsg;
    my $html;
    unless (-r get_genome_file($dsg->id)) { return "Genome file is missing for Genome ID: $dsgid";}
    
    #TABLE
    $html .= qq{<div class="left coge-table-header">Statistics</div>};
    $html .= qq{<table style="padding: 2px; margin-bottom: 5px;" class="border-top">};
    my $total_length = $dsg->length;
{'fraction_non_alphanumeric': 0.14604125083167, 'fraction_numerical': 0.001996007984031936, 'mean_word_length': 2.7594831179658192, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 144, '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': '1022909', 'n_tokens_mistral': 3338, 'n_tokens_neox': 3221, 'n_words': 572}