<commit_before>package CoGe::Builder::Load::Genome;

use Moose;
with qw(CoGe::Builder::Buildable);

use Data::Dumper qw(Dumper);
use File::Spec::Functions qw(catfile catdir);
use File::Basename qw(basename);
use String::ShellQuote qw(shell_quote);

use CoGe::Accessory::Utils qw(get_unique_id);
use CoGe::Accessory::Web qw(url_for);
use CoGe::Core::Storage qw(get_upload_path);
use CoGe::Builder::CommonTasks;
use CoGe::Builder::Common::DataRetrieval;

sub get_name {
    my $self = shift;
    my $metadata = $self->params->{metadata};
    my $info;
    $info .= $metadata->{organism} if $metadata->{organism};
    $info .= " (" . $metadata->{name} . ")"  if $metadata->{name};
    $info .= ": " . $metadata->{description} if $metadata->{description};
    $info .= " (v" . $metadata->{version} . ")";
    return "Load Genome \"$info\"";
}

sub get_site_url {
    my $self = shift;
    return url_for('LoadGenome.pl', wid => $self->workflow->id);
}

sub build {
    my $self = shift;
    
    # Validate inputs
    my $organism_id = $self->params->{organism_id};
    return unless $organism_id;
    my $data = $self->params->{source_data};
    return unless (defined $data && @$data);
    my $metadata = $self->params->{metadata};
    return unless $metadata;
    my $load_id = $self->params->{load_id} || get_unique_id();
    
    # mdb added 2/25/15 - convert from Mojolicious boolean: bless( do{\\(my $o = 1)}, 'Mojo::JSON::_Bool' )
    $metadata->{restricted} = $metadata->{restricted} ? 1 : 0;

    # Get organism
    my $organism = $self->db->resultset('Organism')->find($organism_id);
    return unless $organism;
    
    #
    # Build workflow
    #
    
    # Create tasks to retrieve files #TODO move to pre_build()
    my $dr = CoGe::Builder::Common::DataRetrieval->new({ #FIXME better way to pass these args? See Moose constructors
        params      => $self->params,
        db          => $self->db,
        user        => $self->user,
        conf        => $self->conf,
        workflow    => $self->workflow,
        staging_dir => $self->staging_dir,
        result_dr   => $self->result_dir,
        outputs     => $self->outputs
    });
    $dr->build();
    
    # Build steps to add genome
    my @ncbi_accns  = $dr->get_assets('ncbi_accn');
    if (@ncbi_accns) { # NCBI-based load
        $self->add_task(
            $self->load_genome_from_NCBI(
                ncbi_accns => \@ncbi_accns,
                metadata => $metadata,<commit_msg>Remove unused variable<commit_after>package CoGe::Builder::Load::Genome;

use Moose;
with qw(CoGe::Builder::Buildable);

use Data::Dumper qw(Dumper);
use File::Spec::Functions qw(catfile catdir);
use File::Basename qw(basename);
use String::ShellQuote qw(shell_quote);

use CoGe::Accessory::Utils qw(get_unique_id);
use CoGe::Accessory::Web qw(url_for);
use CoGe::Core::Storage qw(get_upload_path);
use CoGe::Builder::CommonTasks;
use CoGe::Builder::Common::DataRetrieval;

sub get_name {
    my $self = shift;
    my $metadata = $self->params->{metadata};
    my $info;
    $info .= $metadata->{organism} if $metadata->{organism};
    $info .= " (" . $metadata->{name} . ")"  if $metadata->{name};
    $info .= ": " . $metadata->{description} if $metadata->{description};
    $info .= " (v" . $metadata->{version} . ")";
    return "Load Genome \"$info\"";
}

sub get_site_url {
    my $self = shift;
    return url_for('LoadGenome.pl', wid => $self->workflow->id);
}

sub build {
    my $self = shift;
    
    # Validate inputs
    my $organism_id = $self->params->{organism_id};
    return unless $organism_id;
    my $data = $self->params->{source_data};
    return unless (defined $data && @$data);
    my $metadata = $self->params->{metadata};
    return unless $metadata;

    # mdb added 2/25/15 - convert from Mojolicious boolean: bless( do{\\(my $o = 1)}, 'Mojo::JSON::_Bool' )
    $metadata->{restricted} = $metadata->{restricted} ? 1 : 0;

    # Get organism
    my $organism = $self->db->resultset('Organism')->find($organism_id);
    return unless $organism;
    
    #
    # Build workflow
    #
    
    # Create tasks to retrieve files #TODO move to pre_build()
    my $dr = CoGe::Builder::Common::DataRetrieval->new({ #FIXME better way to pass these args? See Moose constructors
        params      => $self->params,
        db          => $self->db,
        user        => $self->user,
        conf        => $self->conf,
        workflow    => $self->workflow,
        staging_dir => $self->staging_dir,
        result_dr   => $self->result_dir,
        outputs     => $self->outputs
    });
    $dr->build();
    
    # Build steps to add genome
    my @ncbi_accns  = $dr->get_assets('ncbi_accn');
    if (@ncbi_accns) { # NCBI-based load
        $self->add_task(
            $self->load_genome_from_NCBI(
                ncbi_accns => \@ncbi_accns,
                metadata => $metadata,
{'fraction_non_alphanumeric': 0.16769167691676917, 'fraction_numerical': 0.003280032800328003, 'mean_word_length': 2.9506072874493925, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 97, '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': '4362297', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1629, 'n_words': 365}