<commit_before>## no critic (ProhibitPostfixControls, ProhibitNegativeExpressionsInUnlessAndUntilConditions)
package CSG::Mapper::Sample;

use CSG::Base qw(file);
use CSG::Mapper::Config;
use CSG::Mapper::Exceptions;
use CSG::Storage::Slots;
use CSG::Types;

use Moose;
use Module::Load;

has '_conf' => (
  is      => 'ro',
  isa     => 'CSG::Mapper::Config',
  lazy    => 1,
  builder => '_build_conf',
);

has 'slot' => (
  is        => 'ro',
  isa       => 'Maybe[ValidSlotFSProject]',
  lazy      => 1,
  builder   => '_build_slot',
  predicate => 'has_slot',
);

has 'cluster' => (
  is       => 'ro',
  isa      => 'ValidCluster',
  required => 1,
);

has 'build' => (
  is       => 'ro',
  isa      => 'Int',
  required => 1,
);

has 'record' => (
  is       => 'ro',
  isa      => 'CSG::Mapper::DB::Schema::Result::Sample',
  required => 1,
);

has 'prefix' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_prefix',
);

has 'project' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_project',
);

has 'host' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_host',
);

has 'center' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_center',
);

has 'pi' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_pi',
);

has 'run_dir' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_run_dir',
);

has 'filename' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_filename',
);

has 'sample_id' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_sample_id',
);

has 'incoming_path' => (
  is        => 'ro',
  isa       => 'Str',
  lazy      => 1,
  builder   => '_build_incoming_path',
  predicate => 'has_incoming_path',
);

has 'result_path' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_result_path',
);

has 'build_str' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_build_str',
);

has 'log_dir' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_log_dir',
);

has 'cram' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_cram',
);

has 'crai' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_crai',
);

has 'state_dir' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_state_dir',
);

before [qw(incoming_path result_path)] => sub {
  shift->slot;
};

sub _build_conf {
  return CSG::Mapper::Config->new(project => 'topmed');
}

sub _build_slot {
  my ($self) = @_;

  my $project = ucfirst(lc($self->project));
  my $class   = "CSG::Storage::SlotFS::$project";
  my $slot    = undef;

  try {
    load $class;

    # XXX - this is not right
    $slot = $class->find(
      name   => $self->sample_id,
      prefix => $self->prefix,
    );
  }
  catch {
    CSG::Mapper::Exceptions::Sample::SlotFailed->throw($_);
  };

  return $slot;
}

sub _build_prefix {
  my ($self) = @_;
  return $self->_conf->get($self->cluster, 'prefix');
}<commit_msg>so in Moose undef still returns true for a predicate test, doh.<commit_after>## no critic (ProhibitPostfixControls, ProhibitNegativeExpressionsInUnlessAndUntilConditions)
package CSG::Mapper::Sample;

use CSG::Base qw(file);
use CSG::Mapper::Config;
use CSG::Mapper::Exceptions;
use CSG::Storage::Slots;
use CSG::Types;

use Moose;
use Module::Load;

has '_conf' => (
  is      => 'ro',
  isa     => 'CSG::Mapper::Config',
  lazy    => 1,
  builder => '_build_conf',
);

has 'slot' => (
  is        => 'ro',
  isa       => 'Maybe[ValidSlotFSProject]',
  lazy      => 1,
  builder   => '_build_slot',
  predicate => 'has_slot',
  clearer   => 'clear_slot',
);

has 'cluster' => (
  is       => 'ro',
  isa      => 'ValidCluster',
  required => 1,
);

has 'build' => (
  is       => 'ro',
  isa      => 'Int',
  required => 1,
);

has 'record' => (
  is       => 'ro',
  isa      => 'CSG::Mapper::DB::Schema::Result::Sample',
  required => 1,
);

has 'prefix' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_prefix',
);

has 'project' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_project',
);

has 'host' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_host',
);

has 'center' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_center',
);

has 'pi' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_pi',
);

has 'run_dir' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_run_dir',
);

has 'filename' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_filename',
);

has 'sample_id' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_sample_id',
);

has 'incoming_path' => (
  is        => 'ro',
  isa       => 'Str',
  lazy      => 1,
  builder   => '_build_incoming_path',
  predicate => 'has_incoming_path',
);

has 'result_path' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_result_path',
);

has 'build_str' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_build_str',
);

has 'log_dir' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_log_dir',
);

has 'cram' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_cram',
);

has 'crai' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_crai',
);

has 'state_dir' => (
  is      => 'ro',
  isa     => 'Str',
  lazy    => 1,
  builder => '_build_state_dir',
);

before [qw(incoming_path result_path)] => sub {
  shift->slot;
};

after 'slot' => sub {
  my ($self) = @_;

  unless (defined $self->{slot}) {
    $self->clear_slot;
  }
};

sub _build_conf {
  return CSG::Mapper::Config->new(project => 'topmed');
}

sub _build_slot {
  my ($self) = @_;

  my $project = ucfirst(lc($self->project));
  my $class   = "CSG::Storage::SlotFS::$project";
  my $slot    = undef;

  try {
    load $class;

    # XXX - this is not right
    $slot = $class->find(
      name   => $self->sample_id,
      prefix => $self->prefix,
    );
  }
  catch {
    CSG::Mapper::Exceptions::Sample::SlotFailed->throw(error => $_);
  };

  return $slot;
}

sub _build_prefix {
  my ($self) = @_;
  return $self->_conf->get($self->cluster, 'prefix');
}
{'fraction_non_alphanumeric': 0.21120558761008199, 'fraction_numerical': 0.0060734892195566355, 'mean_word_length': 2.3744877049180326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 234, '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': '337698', 'n_tokens_mistral': 2634, 'n_tokens_neox': 2565, 'n_words': 558}