Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up bystro-utils #172

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
34 changes: 19 additions & 15 deletions bin/bystro-utils.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use lib './lib';

use Getopt::Long;
use Getopt::Long 'HelpMessage';
use Path::Tiny qw/path/;
use Pod::Usage;
use YAML::XS qw/LoadFile/;
Expand Down Expand Up @@ -37,17 +37,17 @@
GetOptions(
'c|config=s' => \$yaml_config,
'n|name=s' => \$names,
'h|help' => \$help,
'u|util=s' => \$utilName,
'm|maxThreads=i' => \$maxThreads,
'h|help' => \$help,
'd|debug=i' => \$debug,
'o|overwrite' => \$overwrite,
'v|verbose=i' => \$verbose,
'r|dryRun' => \$dryRunInsertions,
'm|maxThreads=i' => \$maxThreads,
);

if ($help || !$yaml_config) {
Pod::Usage::pod2usage();
HelpMessage(1);
}

if(!$names) {
Expand Down Expand Up @@ -112,9 +112,15 @@
# config may be mutated, by the last utility
$config = LoadFile($yaml_config);
my $utilConfig = $config->{tracks}{tracks}[$trackIdx]{utils}[$utilIdx];
my $trackName = $config->{tracks}{tracks}[$trackIdx]{name};

my $utilName = $utilConfig->{name};
say $utilName;

if (!$utilName) {
die "The `name` property must be specified for each utility; missing for track \`$trackName\`\'s utility at index $utilIdx";
}

say "Processing \`$trackName\` utility \`$utilName\`";

# Uppercase the first letter of the utility class name
# aka user may specify "fetch" and we grab Utils::Fetch
Expand All @@ -132,19 +138,17 @@

=head1 NAME

run_utils - Runs items in lib/Utils
bystro_utils - Runs items in lib/Utils

=head1 SYNOPSIS

run_utils
--config <yaml>
--name <track>
[--debug]
[--verbose]
[--maxThreads]
[--dryRun]
[--overwrite]
[--help]
bystro_utils.pl

-c|--config The configuration file path, e.g. "config/hg19.yml".
-n|--name (Optional) The track names you wish to run the utilities of. Comma separated. Example: "ref,refSeq,cadd". Defaults to all tracks if not specified.
-u|--util (Optional) A single utility name, e.g. "SortCadd". Defaults to all utils for the specified tracks if not specified.
-m|--maxThreads (Optional) The maximum number of threads to use. Defaults to the number of logical CPU cores on the machine.
--help (Optional) Display this help message and exit.

=head1 DESCRIPTION

Expand Down
5 changes: 4 additions & 1 deletion lib/Utils/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use List::MoreUtils qw/first_index/;
use YAML::XS qw/LoadFile Dump/;
use Path::Tiny qw/path/;
use Time::localtime;
use Sys::CpuAffinity;

############## Arguments accepted #############
# The track name that they want to use
Expand Down Expand Up @@ -69,7 +70,9 @@ has verbose => (is => 'ro');

has dryRun => (is => 'ro', isa => 'Bool', default => 0);

has maxThreads => (is => 'ro', isa => 'Int', default => 8);
has maxThreads => (is => 'ro', isa => 'Int', lazy => 1, default => sub {
return Sys::CpuAffinity::getNumCpus();
});

#########'Protected' vars (Meant to be used by child class only) ############
has _wantedTrack => ( is => 'ro', init_arg => undef, writer => '_setWantedTrack' );
Expand Down
2 changes: 2 additions & 0 deletions lib/Utils/FilterCadd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use Seq::Tracks::Score::Build;
# Exports: _localFilesDir, _decodedConfig, compress, _wantedTrack, _setConfig, logPath, use_absolute_path
extends 'Utils::Base';

has '+compress' => (default => 1);

my $localFilesHandler = Seq::Tracks::Build::LocalFilesPaths->new();

sub BUILD {
Expand Down