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 all 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
119 changes: 118 additions & 1 deletion docs/scripts_md/ConfigOB.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,129 @@ INPUT: name of the setting to fetch.
RETURN: the setting value (as a string). If the setting value is NULL, then this
method will return `undef`.

### &$getBoolean($value)

Private method. This methods returns 1 if a boolean value is set to either 'true'
or '1'; 0 otherwise. This ensures harmonization of the boolean settings.

INPUT: boolean value extracted from the Config table

RETURN: 1 if the value provided is 'true' or '1'; 0 otherwise

### getTarchiveLibraryDir()

Gets the tarchive library dir.

RETURN: value (string) of the tarchive library dir in the Config table.

### getDataDirPath()

Get the data directory path.

RETURN: value (sting) of the data directory path in the Config table.

### getMriCodePath()

Get the MRI code path.

RETURN: value (string) of the MRI code path in the Config table.

### getNiakPath()

Get the NIAK package path.

RETURN: value (string) of the NIAK package path in the Config table.

### getMailUser()

Get the mail user.

RETURN: value (string) of the mail user in the Config table.

### getPrefix()

Get the study prefix.

RETURN: value (string) of the study prefix in the Config table.

### getDtiVolumes()

Get the number of DTI volumes.

RETURN: value (string) of the number of DTI volumes in the Config table.

### getT1ScanType()

Get the T1 scan type.

RETURN: value (string) of the T1 scan type in the Config table.

### getQced2Step()

Get the QCed2 step dataset name.

RETURN: value (string) of the QCed2 step dataset name in the Config table.

### getDicomInfo()

Get the get\_dicom\_info.pl path.

RETURN: value (string) of the get\_dicom\_info.pl path in the Config table.

### getConverter()

Get the converter name.

RETURN: value (string) of the converter name in the Config table.

### getLookupCenterNameUsing()

Get the lookup center name using.

RETURN: value (string) of the lookup center name using in the Config table.

### getDefacingRefScanType()

Get the defacing reference scan type.

RETURN: value (string) of the defacing reference scan type in the Config table.

### getLegoPhantomRegex()

Get the lego phantom regular expression.

RETURN: value (string) of the lego phantom regular expression in the Config table.

### getLivingPhantomRegex()

Get the living phantom regular expression.

RETURN: value (string) of the living phantom regular expression in the Config table.

### getCreateNii()

Get the create\_nii Config setting.

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

### getHorizontalPics()

Get the horizontalPics Config setting.

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

### getIsQsub()

Get the is\_qsub Config setting.

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

### getCreateCandidates()

Get the createCandidates Config setting.

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

# TO DO

Nothing planned.
Expand All @@ -91,5 +208,5 @@ License: GPLv3

# AUTHORS

LORIS community <loris.info@mcin.ca> and McGill Centre for Integrative
LORIS community <loris.info@mcin.ca> and McGill Centre for Integrative
Neuroscience
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
21 changes: 12 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 @@ -1585,15 +1585,18 @@ sub CreateMRICandidates {
$sex = "Male";
}

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

################################################################
## 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'))
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 +1891,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
81 changes: 81 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 @@ -139,6 +143,23 @@ my $getConfigSettingRef = sub {
return $result->[0]->{'value'};
};


=head3 &$getBooleanRef($value)

Private method. This method returns 1 if a boolean value is set to either 'true'
or '1'; 0 otherwise. This ensures harmonization of the boolean settings.

INPUT: boolean value extracted from the Config table

RETURN: 1 if the value provided is 'true' or '1'; 0 otherwise

=cut
my $getBooleanRef = sub {
my ($value) = @_;

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

=head3 getTarchiveLibraryDir()

Gets the tarchive library dir.
Expand Down Expand Up @@ -348,6 +369,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 $getBooleanRef->($value);
}

=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 $getBooleanRef->($value);
}

=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 $getBooleanRef->($value);
}

=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 $getBooleanRef->($value);
}

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
Loading