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

[Moose] ConfigOB - grepping the boolean config settings using ConfigOB #500

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions batch_uploads_imageuploader.pl
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,7 @@ =head2 Methods
my $data_dir = $configOB->getDataDirPath();
my $mail_user = $configOB->getMailUser();
my $bin_dir = $configOB->getMriCodePath();


# -----------------------------------------------------------------
## Get config setting using the old database calls
# -----------------------------------------------------------------

my $is_qsub = &NeuroDB::DBI::getConfigSetting(\$dbh, 'is_qsub');
my $is_qsub = $configOB->getIsQsub();



Expand Down
7 changes: 1 addition & 6 deletions batch_uploads_tarchive.pl
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,9 @@ =head1 AUTHORS
my $data_dir = $configOB->getDataDirPath();
my $tarchiveLibraryDir = $configOB->getTarchiveLibraryDir();
my $mail_user = $configOB->getMailUser();
my $is_qsub = $configOB->getIsQsub();


# -----------------------------------------------------------------
## Get config setting using the old database calls
# -----------------------------------------------------------------

my $is_qsub = &NeuroDB::DBI::getConfigSetting(\$dbh, 'is_qsub');


# define project space
my ($debug) = (0);
Expand Down
8 changes: 1 addition & 7 deletions tools/batch_run_defacing_script.pl
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,7 @@ =head1 AUTHORS
my $data_dir = $configOB->getDataDirPath();
my $mail_user = $configOB->getMailUser();
my $bin_dir = $configOB->getMriCodePath();


# -----------------------------------------------------------------
## Get config setting using the old database calls
# -----------------------------------------------------------------

my $is_qsub = &NeuroDB::DBI::getConfigSetting(\$dbh, 'is_qsub');
my $is_qsub = $configOB->getIsQsub();



Expand Down
8 changes: 1 addition & 7 deletions tools/batch_run_pipeline_qc_face_script.pl
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,7 @@ =head1 AUTHORS
my $data_dir = $configOB->getDataDirPath();
my $mail_user = $configOB->getMailUser();
my $bin_dir = $configOB->getMriCodePath();


# -----------------------------------------------------------------
## Get config setting using the old database calls
# -----------------------------------------------------------------

my $is_qsub = &NeuroDB::DBI::getConfigSetting(\$dbh, 'is_qsub');
my $is_qsub = $configOB->getIsQsub();



Expand Down
9 changes: 2 additions & 7 deletions tools/create_nifti_bval_bvec.pl
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,10 @@ =head1 AUTHORS

my $configOB = NeuroDB::objectBroker::ConfigOB->new(db => $db);

my $data_dir = $configOB->getDataDirPath();
my $data_dir = $configOB->getDataDirPath();
my $create_nii = $configOB->getCreateNii();


# -----------------------------------------------------------------
## Get config setting using the old database calls
# -----------------------------------------------------------------

my $create_nii = NeuroDB::DBI::getConfigSetting(\$dbh, 'create_nii');



## exit if create_nii is set to No
Expand Down
22 changes: 13 additions & 9 deletions uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ sub determinePSC {
# ----------------------------------------------------------------
## Get config settings using ConfigOB
# ----------------------------------------------------------------
my $configOB = $this->{configOB};
my $configOB = $this->{'configOB'};
my $lookupCenterNameUsing = $configOB->getLookupCenterNameUsing();


Expand Down Expand Up @@ -1175,7 +1175,7 @@ sub registerScanIntoDB {
# ----------------------------------------------------------------
## Get config settings using ConfigOB
# ----------------------------------------------------------------
my $configOB = $this->{configOB};
my $configOB = $this->{'configOB'};
my $data_dir = $configOB->getDataDirPath();
my $prefix = $configOB->getPrefix();

Expand Down Expand Up @@ -1506,7 +1506,7 @@ sub moveAndUpdateTarchive {
# ----------------------------------------------------------------
## Get config settings using ConfigOB
# ----------------------------------------------------------------
my $configOB = $this->{configOB};
my $configOB = $this->{'configOB'};
my $tarchivePath = $configOB->getTarchiveLibraryDir();


Expand Down Expand Up @@ -1579,6 +1579,12 @@ sub CreateMRICandidates {
my ($subjectIDsref,$sex,$tarchiveInfo,$User,$centerID, $upload_id) = @_;
my ($message);

# ----------------------------------------------------------------
## Get config settings using ConfigOB
# ----------------------------------------------------------------
my $configOB = $this->{'configOB'};
my $createCandidates = $configOB->getCreateCandidates();

if ($tarchiveInfo->{'PatientSex'} eq 'F') {
$sex = "Female";
} elsif ($tarchiveInfo->{'PatientSex'} eq 'M') {
Expand All @@ -1589,11 +1595,9 @@ sub CreateMRICandidates {
## Create non-existent candidate if the profile allows for #####
## Candidate creation ##########################################
################################################################
if (!NeuroDB::MRI::subjectIDExists(
$subjectIDsref->{'CandID'},
$this->{dbhr}
)
&& (NeuroDB::DBI::getConfigSetting($this->{dbhr},'createCandidates'))
my $configOB = $this->{'configOB'};
if (!NeuroDB::MRI::subjectIDExists($subjectIDsref->{'CandID'}, $this->{dbhr})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to instantiate $configOB again: it was already defined on line 1585. Also, the definition of $createCandidates should go here instead of further up.

&& ($createCandidates)
) {
chomp($User);
unless ($subjectIDsref->{'CandID'}) {
Expand Down Expand Up @@ -1888,7 +1892,7 @@ sub computeSNR {
# ----------------------------------------------------------------
## Get config settings using ConfigOB
# ----------------------------------------------------------------
my $configOB = $this->{configOB};
my $configOB = $this->{'configOB'};
my $data_dir = $configOB->getDataDirPath();

my $modalities = NeuroDB::DBI::getConfigSetting(
Expand Down
64 changes: 64 additions & 0 deletions uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ use constant LOOK_UP_CENTER_NAME_USING => 'lookupCenterNameUsing';
use constant DEFACING_REF_SCAN_TYPE => 'reference_scan_type_for_defacing';
use constant LEGO_PHANTOM_REGEX => 'LegoPhantomRegex';
use constant LIVING_PHANTOM_REGEX => 'LivingPhantomRegex';
use constant CREATE_NII => 'create_nii';
use constant HORIZONTAL_PICS => 'horizontalPics';
use constant IS_QSUB => 'is_qsub';
use constant CREATE_CANDIDATES => 'createCandidates';

=pod

Expand Down Expand Up @@ -348,6 +352,66 @@ sub getLivingPhantomRegex {
return &$getConfigSettingRef($self, LIVING_PHANTOM_REGEX);
}

=head3 getCreateNii()

Get the create_nii Config setting.

RETURN: (boolean) 1 if create_nii is set to Yes in the Config module, 0 otherwise

=cut
sub getCreateNii {
Copy link
Collaborator

@nicolasbrossard nicolasbrossard Oct 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a good idea to have a private function getBoolean that the other methods would call instead of "hardcoding" the logic inside each method. What do you think?

Oh and here's how you declare/used a private function:

my $privatePrintMethodRef = sub {
    my($arg) = @_;
    print "$arg.\n";
};
.
.
.
sub myPublicSayHelloMethod {
    $myPrivatePrintMethodRef->('Hello');
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree!

my $self = shift;

my $value = &$getConfigSettingRef($self, CREATE_NII);

return ($value eq "true" || $value == 1) ? 1 : 0;
}

=head3 getHorizontalPics()

Get the horizontalPics Config setting.

RETURN: (boolean) 1 if horizontalPics is set to Yes in the Config module, 0 otherwise

=cut
sub getHorizontalPics {
my $self = shift;

my $value = &$getConfigSettingRef($self, HORIZONTAL_PICS);

return ($value eq "true" || $value == 1) ? 1 : 0;
}

=head3 getIsQsub()

Get the is_qsub Config setting.

RETURN: (boolean) 1 if is_qsub is set to Yes in the Config module, 0 otherwise

=cut
sub getIsQsub {
my $self = shift;

my $value = &$getConfigSettingRef($self, IS_QSUB);

return ($value eq "true" || $value == 1) ? 1 : 0;
}

=head3 getCreateCandidates()

Get the createCandidates Config setting.

RETURN: (boolean) 1 if createCandidates is set to Yes in the Config module, 0 otherwise

=cut
sub getCreateCandidates {
my $self = shift;

my $value = &$getConfigSettingRef($self, IS_QSUB);

return ($value eq "true" || $value == 1) ? 1 : 0;
}

1;


Expand Down
10 changes: 2 additions & 8 deletions uploadNeuroDB/mass_pic.pl
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,8 @@ =head1 DESCRIPTION

my $configOB = NeuroDB::objectBroker::ConfigOB->new(db => $db);

my $data_dir = $configOB->getDataDirPath();


# -----------------------------------------------------------------
## Get config setting using the old database calls
# -----------------------------------------------------------------

my $horizontalPics = &NeuroDB::DBI::getConfigSetting(\$dbh, 'horizontalPics');
my $data_dir = $configOB->getDataDirPath();
my $horizontalPics = $configOB->getHorizontalPics();



Expand Down
10 changes: 2 additions & 8 deletions uploadNeuroDB/minc_insertion.pl
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,8 @@ =head2 Methods

my $data_dir = $configOB->getDataDirPath();
my $tarchiveLibraryDir = $configOB->getTarchiveLibraryDir();


# -----------------------------------------------------------------
## Get config setting using the old database calls
# -----------------------------------------------------------------

my $create_nii = NeuroDB::DBI::getConfigSetting(\$dbh, 'create_nii' );
my $horizontalPics = NeuroDB::DBI::getConfigSetting(\$dbh, 'horizontalPics');
my $create_nii = $configOB->getCreateNii();
my $horizontalPics = $configOB->getHorizontalPics();



Expand Down
7 changes: 1 addition & 6 deletions uploadNeuroDB/register_processed_data.pl
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,9 @@ =head2 Methods

my $data_dir = $configOB->getDataDirPath();
my $lookupCenterName = $configOB->getLookupCenterNameUsing();
my $horizontalPics = $configOB->getHorizontalPics();


# -----------------------------------------------------------------
## Get config setting using the old database calls
# -----------------------------------------------------------------

my $horizontalPics = &NeuroDB::DBI::getConfigSetting(\$dbh,'horizontalPics');




Expand Down