<commit_before>package CoGe::Core::Genome;

use strict;
use warnings;

use File::Spec::Functions;
use Sort::Versions;

use CoGe::Accessory::TDS qw(write read);
use CoGe::Accessory::Utils;
use CoGe::Core::Storage qw(get_genome_path);

BEGIN {
    our ( @EXPORT, @EXPORT_OK, @ISA, $VERSION );
    require Exporter;

    $VERSION = 0.1;
    @ISA = qw ( Exporter );
    @EXPORT = qw ( has_statistic get_gc_stats get_noncoding_gc_stats
        get_wobble_histogram get_wobble_gc_diff_histogram get_feature_type_gc_histogram
        get_download_path);

    @EXPORT_OK = qw(genomecmp);
}

my @LOCATIONS_PREFETCH = (
    { "feature_type_id" => 3 },
    {
        join => [
            'locations',
            { 'dataset' => { 'dataset_connectors' => 'genome' } }
        ],
        prefetch => [
            'locations',
            { 'dataset' => { 'dataset_connectors' => 'genome' } }
        ]
    }
);

sub genomecmp($$) {
    my ($a, $b) = @_;

    $a->organism->name cmp $b->organism->name
      || versioncmp( $b->version, $a->version )
      || $a->type->id <=> $b->type->id
      || $a->name cmp $b->name
      || $b->id cmp $a->id;
}

sub get_wobble_histogram {
    my $genome = _get_genome_or_exit(@_);
    my $storage_path = _get_histogram_file($genome->id);

    my $data = read($storage_path);
    return $data->{wobble_histogram} if defined $data->{wobble_histogram};

    $data->{wobble_histogram} = _generate_wobble_content($genome);

    # Exit if generate failed
    unless(defined $data->{wobble_histogram}) {
        say STDERR "Genome::get_genome_wobble_content: generate wobble content failed!";
        exit;
    }

    say STDERR "Genome::get_genome_wobble_content: write failed!"
        unless write($storage_path, $data);

    # Return data
    return $data->{wobble_histogram};
}

sub get_download_path {
    return catfile(shift, "GenomeInfo/downloads", shift);
}

sub get_feature_type_gc_histogram {<commit_msg>fix uninitialized value in string comparision<commit_after>package CoGe::Core::Genome;

use strict;
use warnings;

use File::Spec::Functions;
use Sort::Versions;

use CoGe::Accessory::TDS qw(write read);
use CoGe::Accessory::Utils;
use CoGe::Core::Storage qw(get_genome_path);

BEGIN {
    our ( @EXPORT, @EXPORT_OK, @ISA, $VERSION );
    require Exporter;

    $VERSION = 0.1;
    @ISA = qw ( Exporter );
    @EXPORT = qw ( has_statistic get_gc_stats get_noncoding_gc_stats
        get_wobble_histogram get_wobble_gc_diff_histogram get_feature_type_gc_histogram
        get_download_path);

    @EXPORT_OK = qw(genomecmp);
}

my @LOCATIONS_PREFETCH = (
    { "feature_type_id" => 3 },
    {
        join => [
            'locations',
            { 'dataset' => { 'dataset_connectors' => 'genome' } }
        ],
        prefetch => [
            'locations',
            { 'dataset' => { 'dataset_connectors' => 'genome' } }
        ]
    }
);

sub genomecmp($$) {
    my ($a, $b) = @_;

    my $namea = $a->name ? $a->name :  "";
    my $nameb = $b->name ? $b->name :  "";

    $a->organism->name cmp $b->organism->name
      || versioncmp( $b->version, $a->version )
      || $a->type->id <=> $b->type->id
      || $namea cmp $nameb
      || $b->id cmp $a->id;
}

sub get_wobble_histogram {
    my $genome = _get_genome_or_exit(@_);
    my $storage_path = _get_histogram_file($genome->id);

    my $data = read($storage_path);
    return $data->{wobble_histogram} if defined $data->{wobble_histogram};

    $data->{wobble_histogram} = _generate_wobble_content($genome);

    # Exit if generate failed
    unless(defined $data->{wobble_histogram}) {
        say STDERR "Genome::get_genome_wobble_content: generate wobble content failed!";
        exit;
    }

    say STDERR "Genome::get_genome_wobble_content: write failed!"
        unless write($storage_path, $data);

    # Return data
    return $data->{wobble_histogram};
}

sub get_download_path {
    return catfile(shift, "GenomeInfo/downloads", shift);
}

sub get_feature_type_gc_histogram {
{'fraction_non_alphanumeric': 0.14798093804865814, 'fraction_numerical': 0.0015048908954100827, 'mean_word_length': 3.1584984358706985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4875002', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1416, 'n_words': 269}