From 2ad0f92030ce99a11b172f4c84f5e9b6ada44c4f Mon Sep 17 00:00:00 2001 From: cmadjar Date: Wed, 16 Mar 2022 15:54:27 -0400 Subject: [PATCH 01/11] use configOB for array configs --- tools/delete_imaging_upload.pl | 4 +- tools/run_defacing_script.pl | 24 +++--- uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm | 12 +-- .../NeuroDB/objectBroker/ConfigOB.pm | 73 +++++++++++++------ uploadNeuroDB/tarchiveLoader.pl | 16 +--- 5 files changed, 73 insertions(+), 56 deletions(-) diff --git a/tools/delete_imaging_upload.pl b/tools/delete_imaging_upload.pl index 89ad90a9d..e511cde68 100755 --- a/tools/delete_imaging_upload.pl +++ b/tools/delete_imaging_upload.pl @@ -2002,8 +2002,8 @@ sub getScanTypesToDelete { return () if !defined $scanTypeList && !$keepDefaced; if($keepDefaced) { - my $scanTypesRef = &NeuroDB::DBI::getConfigSetting(\$dbh, 'modalities_to_deface'); - return defined $scanTypesRef ? (map { $_ => 1 } @$scanTypesRef) : (); + my @scanTypes = $configOB->getModalitiesToDeface(); + return defined @scanTypes ? (map { $_ => 1 } @scanTypes) : (); } my %types = map { $_=> 1 } split(/,/, $scanTypeList); diff --git a/tools/run_defacing_script.pl b/tools/run_defacing_script.pl index 04922d6d9..f0644dd12 100755 --- a/tools/run_defacing_script.pl +++ b/tools/run_defacing_script.pl @@ -184,14 +184,14 @@ =head1 METHODS my $data_dir = $configOB->getDataDirPath(); my $ref_scan_type = $configOB->getDefacingRefScanType(); +my @to_deface = $configOB->getModalitiesToDeface(); # ----------------------------------------------------------------- ## Get config setting using the old database calls # ----------------------------------------------------------------- -my $to_deface = &NeuroDB::DBI::getConfigSetting(\$dbh, 'modalities_to_deface'); -unless ($ref_scan_type && $to_deface) { +unless ($ref_scan_type && @to_deface) { print STDERR "\n==> ERROR: you need to configure both the " . "reference_scan_type_for_defacing & modalities_to_deface config " . "settings in the imaging pipeline section of the Config module.\n" @@ -235,14 +235,14 @@ =head1 METHODS print "\n==> Fetching all FileIDs to deface.\n" if $verbose; my @session_ids = defined $session_ids ? split(",", $session_ids) : (); -unless ($to_deface) { +unless (@to_deface) { print "\nNo modalities were set to be defaced in the Config module. Ensure" . " to select modalities to deface in the Config module under the imaging" . " pipeline section (setting called modalities_to_deface. \n\n"; exit $NeuroDB::ExitCodes::SUCCESS; } -my %files_hash = grep_FileIDs_to_deface(\@session_ids, $to_deface); +my %files_hash = grep_FileIDs_to_deface(\@session_ids, @to_deface); @@ -293,7 +293,7 @@ =head1 METHODS =pod -=head3 grep_FileIDs_to_deface($session_id_arr, $modalities_to_deface_arr) +=head3 grep_FileIDs_to_deface($session_id_arr, @modalities_to_deface_arr) Queries the database for the list of acquisitions' FileID to be used to run the defacing algorithm based on the provided list of SessionID and Scan_type to @@ -301,7 +301,7 @@ =head3 grep_FileIDs_to_deface($session_id_arr, $modalities_to_deface_arr) INPUTS: - $session_id_arr : array of SessionIDs to use when grepping FileIDs - - $modalities_to_deface_arr: array of Scan_type to use when grepping FileIDs + - @modalities_to_deface_arr: array of Scan_type to use when grepping FileIDs RETURNS: hash of matching FileIDs to be used to run the defacing algorithm organized in a hash as follows: @@ -318,7 +318,7 @@ =head3 grep_FileIDs_to_deface($session_id_arr, $modalities_to_deface_arr) =cut sub grep_FileIDs_to_deface { - my ($session_id_arr, $modalities_to_deface_arr) = @_; + my ($session_id_arr, @modalities_to_deface_arr) = @_; # separate the special modalities specified in %SPECIAL_ACQUISITIONS from the # standard scan types @@ -326,10 +326,10 @@ sub grep_FileIDs_to_deface { my @special_cases; foreach my $special (@special_scan_types) { # push the special modalities to a new array @special_cases - push @special_cases, grep(/$special/, @$modalities_to_deface_arr); + push @special_cases, grep(/$special/, @modalities_to_deface_arr); # remove the special modalities from the modalities array as they will be # dealt with differently than standard modalities - @$modalities_to_deface_arr = grep(! /$special/, @$modalities_to_deface_arr); + @modalities_to_deface_arr = grep(! /$special/, @modalities_to_deface_arr); } # base query @@ -342,8 +342,8 @@ sub grep_FileIDs_to_deface { # add where clause for the different standard scan types to deface my @where; - if (@$modalities_to_deface_arr) { - @where = map { "mst.Scan_type = ?" } @$modalities_to_deface_arr; + if (@modalities_to_deface_arr) { + @where = map { "mst.Scan_type = ?" } @modalities_to_deface_arr; $query .= sprintf(" %s ", join(" OR ", @where)); } @@ -366,7 +366,7 @@ sub grep_FileIDs_to_deface { my $sth = $dbh->prepare($query); # create array of parameters - my @bind_param = @$modalities_to_deface_arr; + my @bind_param = @modalities_to_deface_arr; foreach my $special_scan_type (@special_cases) { push @bind_param, $special_scan_type; push @bind_param, $SPECIAL_ACQUISITIONS_FILTER{$special_scan_type}; diff --git a/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm b/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm index 0331a042c..b3f759bf0 100755 --- a/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm +++ b/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm @@ -1390,7 +1390,7 @@ sub registerScanIntoDB { =pod -=head3 dicom_to_minc($study_dir, $converter, $get_dicom_info, $exclude, $mail_user, $upload_id) +=head3 dicom_to_minc($study_dir, $converter, $get_dicom_info, @exclude, $mail_user, $upload_id) Converts a DICOM study into MINC files. @@ -1398,7 +1398,7 @@ INPUTS: - $study_dir : DICOM study directory to convert - $converter : converter to be used - $get_dicom_info : get DICOM information setting from the C table - - $exclude : which files to exclude from the C command + - @exclude : which files to exclude from the C command - $mail_user : mail of the user - $upload_id : upload ID of the study @@ -1406,7 +1406,7 @@ INPUTS: sub dicom_to_minc { my $this = shift; - my ($study_dir, $converter, $get_dicom_info, $exclude,$mail_user, $upload_id) = @_; + my ($study_dir, $converter, $get_dicom_info, @exclude,$mail_user, $upload_id) = @_; my ($d2m_cmd, $d2m_log, $exit_code, $excluded_regex); my $message = ''; @@ -1415,11 +1415,7 @@ sub dicom_to_minc { # series description specified in the Config Setting excluded_series_description # # If there are no series to exclude, $excluded_regex remains undef # #--------------------------------------------------------------------------------# - if ($exclude && ref($exclude) eq 'ARRAY') { - $excluded_regex = join('|', map { quotemeta($_) } @$exclude); - } elsif ($exclude) { - $excluded_regex = $exclude; - } + $excluded_regex = join('|', map { quotemeta($_) } @exclude) if (@exclude); #-----------------------------------------------------------------------------------# # Run get_dicom_info on all the DICOM files and build the set of all the distinct # diff --git a/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm b/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm index e8d231382..5c4ef5ab5 100644 --- a/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm +++ b/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm @@ -65,28 +65,30 @@ use NeuroDB::objectBroker::ObjectBrokerException; use TryCatch; -use constant TARCHIVE_LIBRARY_DIR => 'tarchiveLibraryDir'; -use constant DATA_DIR_BASE_PATH => 'dataDirBasepath'; -use constant MAIL_USER => 'mail_user'; -use constant MRI_CODE_PATH => 'MRICodePath'; -use constant PREFIX => 'prefix'; -use constant DTI_VOLUMES => 'DTI_volumes'; -use constant T1_SCAN_TYPE => 't1_scan_type'; -use constant REJECT_THRESHOLD => 'reject_thresh'; -use constant NIAK_PATH => 'niak_path'; -use constant QCED2_STEP => 'QCed2_step'; -use constant GET_DICOM_INFO => 'get_dicom_info'; -use constant CONVERTER => 'converter'; -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'; -use constant PYTHON_CONFIG_FILE => 'MriPythonConfigFile'; -use constant COMPUTE_SNR_MODALITIES => 'compute_snr_modalities'; +use constant TARCHIVE_LIBRARY_DIR => 'tarchiveLibraryDir'; +use constant DATA_DIR_BASE_PATH => 'dataDirBasepath'; +use constant MAIL_USER => 'mail_user'; +use constant MRI_CODE_PATH => 'MRICodePath'; +use constant PREFIX => 'prefix'; +use constant DTI_VOLUMES => 'DTI_volumes'; +use constant T1_SCAN_TYPE => 't1_scan_type'; +use constant REJECT_THRESHOLD => 'reject_thresh'; +use constant NIAK_PATH => 'niak_path'; +use constant QCED2_STEP => 'QCed2_step'; +use constant GET_DICOM_INFO => 'get_dicom_info'; +use constant CONVERTER => 'converter'; +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'; +use constant PYTHON_CONFIG_FILE => 'MriPythonConfigFile'; +use constant COMPUTE_SNR_MODALITIES => 'compute_snr_modalities'; +use constant EXCLUDED_SERIES_DESCRIPTION => 'excluded_series_description'; +use constant MODALITIES_TO_DEFACE => 'modalities_to_deface'; =pod @@ -467,6 +469,33 @@ sub getComputeSnrModalities { } +=head3 getExcludedSeriesDescription() + +Get the excluded_series_description Config setting + +RETURN: an array (possibly empty) of the series description to exclude from import + +=cut +sub getExcludedSeriesDescription { + my $self = shift; + + return &$getConfigSettingRef($self, EXCLUDED_SERIES_DESCRIPTION); +} + + +=head3 getModalitiesToDeface() + +Get the modalities_to_deface Config setting + +RETURN: an array (possibly empty) of the series description to exclude from import + +=cut +sub getModalitiesToDeface { + my $self = shift; + + return &$getConfigSettingRef($self, MODALITIES_TO_DEFACE); +} + 1; diff --git a/uploadNeuroDB/tarchiveLoader.pl b/uploadNeuroDB/tarchiveLoader.pl index e1287459b..0e7bf69c3 100755 --- a/uploadNeuroDB/tarchiveLoader.pl +++ b/uploadNeuroDB/tarchiveLoader.pl @@ -247,13 +247,7 @@ =head2 Methods my $mail_user = $configOB->getMailUser(); my $get_dicom_info = $configOB->getDicomInfo(); my $converter = $configOB->getConverter(); - - -# ----------------------------------------------------------------- -## Get config setting using the old database calls -# ----------------------------------------------------------------- - -my $exclude = NeuroDB::DBI::getConfigSetting(\$dbh, 'excluded_series_description'); +my @exclude = $configOB->getExcludedSeriesDescription(); @@ -410,7 +404,7 @@ =head2 Methods ##################### convert the dicom data to minc ########### ################################################################ $utility->dicom_to_minc( - $study_dir, $converter, $get_dicom_info, $exclude, $mail_user, $upload_id + $study_dir, $converter, $get_dicom_info, @exclude, $mail_user, $upload_id ); @@ -433,11 +427,9 @@ =head2 Methods ################################################################ if ($mcount < 1) { $message = "\nNo data could be converted into valid MINC files.\n"; - if ($exclude && ref($exclude) eq 'ARRAY') { - my $excluded_series = join(', ', map {quotemeta($_)} @$exclude); + if (@exclude) { + my $excluded_series = join(', ', map {quotemeta($_)} @exclude); $message .= "$excluded_series will not be considered! \n" ; - } elsif ($exclude) { - $message .= "$exclude will not be considered! \n"; } $utility->writeErrorLog( $message, $NeuroDB::ExitCodes::NO_VALID_MINC_CREATED, $logfile From 5091233a8d57f06e8d6cf66fa0a516cc8a32f981 Mon Sep 17 00:00:00 2001 From: cmadjar Date: Wed, 16 Mar 2022 16:06:59 -0400 Subject: [PATCH 02/11] use configOB for minc_to_bids script --- tools/minc_to_bids_converter.pl | 24 ++++--- uploadNeuroDB/NeuroDB/DBI.pm | 41 ------------ .../NeuroDB/objectBroker/ConfigOB.pm | 63 ++++++++++++++++++- 3 files changed, 79 insertions(+), 49 deletions(-) diff --git a/tools/minc_to_bids_converter.pl b/tools/minc_to_bids_converter.pl index 1fdf43de0..1116e9c83 100755 --- a/tools/minc_to_bids_converter.pl +++ b/tools/minc_to_bids_converter.pl @@ -203,13 +203,23 @@ =head2 METHODS my $dbh = &NeuroDB::DBI::connect_to_db(@Settings::db); print "\n==> Successfully connected to database \n"; -# Get settings from the ConfigSettings table -my $data_dir = &NeuroDB::DBI::getConfigSetting(\$dbh,'dataDirBasepath'); -my $bin_dir = &NeuroDB::DBI::getConfigSetting(\$dbh,'MRICodePath'); -my $authors = &NeuroDB::DBI::getConfigSetting(\$dbh, 'bids_dataset_authors'); -my $acknowledgments = &NeuroDB::DBI::getConfigSetting(\$dbh, 'bids_acknowledgments_text'); -my $readme_content = &NeuroDB::DBI::getConfigSetting(\$dbh, 'bids_readme_text'); -my $validator_ignore_opts = &NeuroDB::DBI::getConfigSetting(\$dbh, 'bids_validator_options_to_ignore'); +# new Moose database connection +my $db = NeuroDB::Database->new( + databaseName => $Settings::db[0], + userName => $Settings::db[1], + password => $Settings::db[2], + hostName => $Settings::db[3] +); +$db->connect(); + +# Get settings from the Config table +my $configOB = NeuroDB::objectBroker::ConfigOB->new(db => $db); +my $data_dir = $configOB->getDataDirPath(); +my $bin_dir = $configOB->getMriCodePath(); +my $authors = $configOB->getBidsDatasetAuthors(); +my $acknowledgments = $configOB->getBidsAcknowledgmentsText(); +my $readme_content = $configOB->getBidsReadmeText(); +my $validator_ignore_opts = $configOB->getBidsValidatorOptionsToIgnore(); unless (defined $authors && defined $acknowledgments && defined $readme_content) { print STDERR "\n ERROR: Some 'MINC to BIDS Converter Tool Options' are not set in the configuration module." diff --git a/uploadNeuroDB/NeuroDB/DBI.pm b/uploadNeuroDB/NeuroDB/DBI.pm index 81f6faf16..a2eb3b171 100755 --- a/uploadNeuroDB/NeuroDB/DBI.pm +++ b/uploadNeuroDB/NeuroDB/DBI.pm @@ -72,47 +72,6 @@ sub connect_to_db return $dbh; } -=pod - -=head3 getConfigSetting($dbh, $name) - -This method fetches the value (C<$value>) stored in the C table for a -specific config setting (C<$name>) specified as an input. - -INPUTS: - - $dbh : database handler - - $name: name of the config setting - -RETURNS: value corresponding to the config setting in the C table - of LORIS - -=cut -sub getConfigSetting -{ - my ($dbh, $name) = @_; - my ($message, $query, $where) = ''; - my $value = undef; - - $where = " WHERE c.ConfigID=(Select cs.ID from ConfigSettings cs where cs.Name=?)"; - $query = " SELECT c.Value FROM Config c"; - $query = $query . $where; - my $sth = $$dbh->prepare($query); - $sth->execute($name); - - if ( $sth->rows > 1 ){ - # if more than one row returned, push data into an array that will be - # dereferenced into $value - my @values; - while (my $row = $sth->fetchrow_array()) { - push (@values, $row); - } - $value = \@values; - } elsif ( $sth->rows > 0 ) { - $value = $sth->fetchrow_array(); - } - return $value; -} - 1; =pod diff --git a/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm b/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm index 5c4ef5ab5..c427f007c 100644 --- a/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm +++ b/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm @@ -89,6 +89,10 @@ use constant PYTHON_CONFIG_FILE => 'MriPythonConfigFile'; use constant COMPUTE_SNR_MODALITIES => 'compute_snr_modalities'; use constant EXCLUDED_SERIES_DESCRIPTION => 'excluded_series_description'; use constant MODALITIES_TO_DEFACE => 'modalities_to_deface'; +use constant BIDS_DATASET_AUTHORS => 'bids_dataset_authors'; +use constant BIDS_ACKNOWLEDGMENTS_TEXT => 'bids_acknowledgments_text'; +use constant BIDS_README_TEXT => 'bids_readme_text'; +use constant BIDS_VALIDATOR_OPTIONS_TO_IGNORE => 'bids_validator_options_to_ignore'; =pod @@ -487,7 +491,7 @@ sub getExcludedSeriesDescription { Get the modalities_to_deface Config setting -RETURN: an array (possibly empty) of the series description to exclude from import +RETURN: an array (possibly empty) of the modalities to run the defacing pipeline on =cut sub getModalitiesToDeface { @@ -496,6 +500,63 @@ sub getModalitiesToDeface { return &$getConfigSettingRef($self, MODALITIES_TO_DEFACE); } + +=head3 getBidsDatasetAuthors() + +Get the bids_dataset_authors Config setting + +RETURN: an array (possibly empty) of the authors to use for a BIDS dataset + +=cut +sub getBidsDatasetAuthors { + my $self = shift; + + return &$getConfigSettingRef($self, BIDS_DATASET_AUTHORS); +} + + +=head3 getBidsAcknowledgmentsText() + +Get the bids_acknowledgments_text Config setting + +RETURN: an array (possibly empty) of the acknowledgment text to use for a BIDS dataset + +=cut +sub getBidsAcknowledgmentsText { + my $self = shift; + + return &$getConfigSettingRef($self, BIDS_ACKNOWLEDGMENTS_TEXT); +} + + +=head3 getBidsReadmeText() + +Get the bids_readme_text Config setting + +RETURN: an array (possibly empty) of the README text to use for a BIDS dataset + +=cut +sub getBidsReadmeText { + my $self = shift; + + return &$getConfigSettingRef($self, BIDS_README_TEXT); +} + + +=head3 getBidsValidatorOptionsToIgnore() + +Get the bids_validator_options_to_ignore Config setting + +RETURN: an array (possibly empty) of the BIDS validator options to ignore +to use when creating a BIDS dataset + +=cut +sub getBidsValidatorOptionsToIgnore { + my $self = shift; + + return &$getConfigSettingRef($self, BIDS_VALIDATOR_OPTIONS_TO_IGNORE); +} + 1; From 25aeffabe4a3ee42cbecf738f7e8a596d553291a Mon Sep 17 00:00:00 2001 From: cmadjar Date: Wed, 16 Mar 2022 16:48:21 -0400 Subject: [PATCH 03/11] fix bug in delete script --- tools/delete_imaging_upload.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/delete_imaging_upload.pl b/tools/delete_imaging_upload.pl index e511cde68..63ec8438d 100755 --- a/tools/delete_imaging_upload.pl +++ b/tools/delete_imaging_upload.pl @@ -2003,7 +2003,7 @@ sub getScanTypesToDelete { if($keepDefaced) { my @scanTypes = $configOB->getModalitiesToDeface(); - return defined @scanTypes ? (map { $_ => 1 } @scanTypes) : (); + return @scanTypes ? (map { $_ => 1 } @scanTypes) : (); } my %types = map { $_=> 1 } split(/,/, $scanTypeList); From 32f058b1ed06712a531762d81921b0314f0a9190 Mon Sep 17 00:00:00 2001 From: cmadjar Date: Wed, 16 Mar 2022 17:19:15 -0400 Subject: [PATCH 04/11] fix bugs with new perl --- tools/run_defacing_script.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/run_defacing_script.pl b/tools/run_defacing_script.pl index f0644dd12..c7dc5b68a 100755 --- a/tools/run_defacing_script.pl +++ b/tools/run_defacing_script.pl @@ -434,7 +434,7 @@ =head3 check_if_deface_files_already_in_db($session_files, $session_id) sub check_if_deface_files_already_in_db { my ($session_files, $session_id) = @_; - my @defaced_scan_types = map { $_ . '-defaced' } keys $session_files; + my @defaced_scan_types = map { $_ . '-defaced' } keys %{ $session_files }; # base query my $query = "SELECT COUNT(*) " @@ -554,7 +554,7 @@ sub deface_session { # add multi-constrast modalities to cmd line & remove them from $session_files foreach my $multi (@MULTI_CONTRAST_ACQUISITIONS_BASE_NAMES) { - my @scan_types = keys $session_files; + my @scan_types = keys %{ $session_files }; my @matching_types = grep (/$multi/i, @scan_types); my @non_matching_types = grep (!/$multi/i, @scan_types); my (@multi_files_list, @other_files); @@ -623,7 +623,7 @@ sub fetch_defaced_files { $defaced_images{$deface_ref}{Scan_type} = $$ref_file{Scan_type}; # for each files in $session_files, append the defaced images to the hash - foreach my $scan_type (keys $session_files) { + foreach my $scan_type (keys %{ $session_files }) { my %files = %{ $$session_files{$scan_type} }; foreach my $fileID (keys %files) { my $deface_file = $deface_dir . '/' . basename($files{$fileID}); @@ -663,7 +663,7 @@ sub register_defaced_files { . " -coordinateSpace native " . " -outputType defaced "; - foreach my $file (keys $defaced_images) { + foreach my $file (keys %{ $defaced_images }) { my $input_fileID = $$defaced_images{$file}{InputFileID}; my $scan_type = $$defaced_images{$file}{Scan_type} . "-defaced"; From ef362d3f6cad8b63439e6bd4379f21234e92e3a8 Mon Sep 17 00:00:00 2001 From: cmadjar Date: Wed, 16 Mar 2022 17:39:14 -0400 Subject: [PATCH 05/11] use array for some bids config --- tools/minc_to_bids_converter.pl | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tools/minc_to_bids_converter.pl b/tools/minc_to_bids_converter.pl index 1116e9c83..f2f4bfc1f 100755 --- a/tools/minc_to_bids_converter.pl +++ b/tools/minc_to_bids_converter.pl @@ -216,12 +216,12 @@ =head2 METHODS my $configOB = NeuroDB::objectBroker::ConfigOB->new(db => $db); my $data_dir = $configOB->getDataDirPath(); my $bin_dir = $configOB->getMriCodePath(); -my $authors = $configOB->getBidsDatasetAuthors(); +my @authors = $configOB->getBidsDatasetAuthors(); my $acknowledgments = $configOB->getBidsAcknowledgmentsText(); my $readme_content = $configOB->getBidsReadmeText(); -my $validator_ignore_opts = $configOB->getBidsValidatorOptionsToIgnore(); +my @validator_ignore_opts = $configOB->getBidsValidatorOptionsToIgnore(); -unless (defined $authors && defined $acknowledgments && defined $readme_content) { +unless (@authors && defined $acknowledgments && defined $readme_content) { print STDERR "\n ERROR: Some 'MINC to BIDS Converter Tool Options' are not set in the configuration module." . " 'BIDS Dataset Authors', 'BIDS Dataset Acknowledgments' and 'BIDS Dataset README' need to be" . " defined.\n\n"; @@ -269,7 +269,7 @@ =head2 METHODS 'BIDSVersion' => $BIDS_VERSION, 'Name' => $dataset_name, 'LORISScriptVersion' => $LORIS_SCRIPT_VERSION, - 'Authors' => $authors, + 'Authors' => @authors, 'HowToAcknowledge' => $acknowledgments, 'LORISReleaseVersion' => $loris_mri_version ); @@ -300,11 +300,9 @@ =head2 METHODS # specifications, not the same number of files per session etc...) # ============================================================================= my $bids_validator_config_file = $dest_dir . "/.bids-validator-config.json"; -if (!-e $bids_validator_config_file && defined $validator_ignore_opts) { +if (!-e $bids_validator_config_file && @validator_ignore_opts) { print "\n******* Creating the .bids-validator-config.json file $bids_validator_config_file *******\n"; - my $validator_ignore_string = ref($validator_ignore_opts) eq 'ARRAY' - ? join(", ", @$validator_ignore_opts) - : $validator_ignore_opts; + my $validator_ignore_string = join(", ", @validator_ignore_opts); my $bids_validator_config_content = < Date: Wed, 16 Mar 2022 17:41:18 -0400 Subject: [PATCH 06/11] bug fix --- tools/minc_to_bids_converter.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/minc_to_bids_converter.pl b/tools/minc_to_bids_converter.pl index f2f4bfc1f..4a20d3ee4 100755 --- a/tools/minc_to_bids_converter.pl +++ b/tools/minc_to_bids_converter.pl @@ -81,6 +81,7 @@ =head2 METHODS use NeuroDB::MRI; use NeuroDB::ExitCodes; use NeuroDB::File; +use NeuroDB::objectBroker::ConfigOB; # # Set script's constants here From b48bcde582321e699907f440e8877331caf09fbf Mon Sep 17 00:00:00 2001 From: cmadjar Date: Fri, 3 Jun 2022 09:29:36 -0400 Subject: [PATCH 07/11] fix pod error + Nic's comment --- docs/scripts_md/MRIProcessingUtility.md | 16 ++-------------- tools/delete_imaging_upload.pl | 2 +- uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm | 2 -- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/docs/scripts_md/MRIProcessingUtility.md b/docs/scripts_md/MRIProcessingUtility.md index b90d19911..feb43556f 100644 --- a/docs/scripts_md/MRIProcessingUtility.md +++ b/docs/scripts_md/MRIProcessingUtility.md @@ -329,7 +329,7 @@ INPUTS: RETURNS: acquisition protocol ID of the MINC file -### dicom\_to\_minc($study\_dir, $converter, $get\_dicom\_info, $exclude, $mail\_user, $upload\_id) +### dicom\_to\_minc($study\_dir, $converter, $get\_dicom\_info, @exclude, $mail\_user, $upload\_id) Converts a DICOM study into MINC files. @@ -337,7 +337,7 @@ INPUTS: - $study\_dir : DICOM study directory to convert - $converter : converter to be used - $get\_dicom\_info : get DICOM information setting from the `Config` table - - $exclude : which files to exclude from the `dcm2mnc` command + - @exclude : which files to exclude from the `dcm2mnc` command - $mail\_user : mail of the user - $upload\_id : upload ID of the study @@ -505,15 +505,3 @@ License: GPLv3 LORIS community and McGill Centre for Integrative Neuroscience - -# POD ERRORS - -Hey! **The above document had some coding errors, which are explained below:** - -- Around line 567: - - =cut found outside a pod block. Skipping to next block. - -- Around line 1880: - - =cut found outside a pod block. Skipping to next block. diff --git a/tools/delete_imaging_upload.pl b/tools/delete_imaging_upload.pl index 63ec8438d..a6a1c756c 100755 --- a/tools/delete_imaging_upload.pl +++ b/tools/delete_imaging_upload.pl @@ -2003,7 +2003,7 @@ sub getScanTypesToDelete { if($keepDefaced) { my @scanTypes = $configOB->getModalitiesToDeface(); - return @scanTypes ? (map { $_ => 1 } @scanTypes) : (); + return (map { $_ => 1 } @scanTypes); } my %types = map { $_=> 1 } split(/,/, $scanTypeList); diff --git a/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm b/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm index b3f759bf0..a89386a8f 100755 --- a/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm +++ b/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm @@ -564,7 +564,6 @@ sub createMriUploadArray { return %{ $mriUploadInfoRef->[0] }; } -=cut =pod @@ -1880,7 +1879,6 @@ sub validate_tarchive_id_against_upload_id { } } -=cut =pod From 8192a2e5336746333c81cd579a1fc846425687f5 Mon Sep 17 00:00:00 2001 From: cmadjar Date: Fri, 17 Jun 2022 14:19:36 -0400 Subject: [PATCH 08/11] take care of Nic's comments --- tools/run_defacing_script.pl | 18 +++++++++--------- uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm | 6 +++--- uploadNeuroDB/tarchiveLoader.pl | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/run_defacing_script.pl b/tools/run_defacing_script.pl index c7dc5b68a..5068c6493 100755 --- a/tools/run_defacing_script.pl +++ b/tools/run_defacing_script.pl @@ -318,7 +318,7 @@ =head3 grep_FileIDs_to_deface($session_id_arr, @modalities_to_deface_arr) =cut sub grep_FileIDs_to_deface { - my ($session_id_arr, @modalities_to_deface_arr) = @_; + my ($session_id_ref, @modalities_to_deface) = @_; # separate the special modalities specified in %SPECIAL_ACQUISITIONS from the # standard scan types @@ -326,10 +326,10 @@ sub grep_FileIDs_to_deface { my @special_cases; foreach my $special (@special_scan_types) { # push the special modalities to a new array @special_cases - push @special_cases, grep(/$special/, @modalities_to_deface_arr); + push @special_cases, grep(/$special/, @modalities_to_deface); # remove the special modalities from the modalities array as they will be # dealt with differently than standard modalities - @modalities_to_deface_arr = grep(! /$special/, @modalities_to_deface_arr); + @modalities_to_deface = grep(! /$special/, @modalities_to_deface); } # base query @@ -342,8 +342,8 @@ sub grep_FileIDs_to_deface { # add where clause for the different standard scan types to deface my @where; - if (@modalities_to_deface_arr) { - @where = map { "mst.Scan_type = ?" } @modalities_to_deface_arr; + if (@modalities_to_deface) { + @where = map { "mst.Scan_type = ?" } @modalities_to_deface; $query .= sprintf(" %s ", join(" OR ", @where)); } @@ -358,20 +358,20 @@ sub grep_FileIDs_to_deface { # add where clause for the session IDs specified to the script if -sessionIDs # was set - if ($session_id_arr) { - @where = map { "f.SessionID = ?" } @$session_id_arr; + if ($session_id_ref) { + @where = map { "f.SessionID = ?" } @$session_id_ref; $query .= sprintf(" AND (%s) ", join(" OR ", @where)); } my $sth = $dbh->prepare($query); # create array of parameters - my @bind_param = @modalities_to_deface_arr; + my @bind_param = @modalities_to_deface; foreach my $special_scan_type (@special_cases) { push @bind_param, $special_scan_type; push @bind_param, $SPECIAL_ACQUISITIONS_FILTER{$special_scan_type}; } - push @bind_param, @$session_id_arr; + push @bind_param, @$session_id_ref; # execute the query $sth->execute(@bind_param); diff --git a/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm b/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm index a89386a8f..c7edb66f4 100755 --- a/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm +++ b/uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm @@ -1389,7 +1389,7 @@ sub registerScanIntoDB { =pod -=head3 dicom_to_minc($study_dir, $converter, $get_dicom_info, @exclude, $mail_user, $upload_id) +=head3 dicom_to_minc($study_dir, $converter, $get_dicom_info, $mail_user, $upload_id, @exclude) Converts a DICOM study into MINC files. @@ -1397,15 +1397,15 @@ INPUTS: - $study_dir : DICOM study directory to convert - $converter : converter to be used - $get_dicom_info : get DICOM information setting from the C table - - @exclude : which files to exclude from the C command - $mail_user : mail of the user - $upload_id : upload ID of the study + - @exclude : which files to exclude from the C command =cut sub dicom_to_minc { my $this = shift; - my ($study_dir, $converter, $get_dicom_info, @exclude,$mail_user, $upload_id) = @_; + my ($study_dir, $converter, $get_dicom_info, $mail_user, $upload_id, @exclude) = @_; my ($d2m_cmd, $d2m_log, $exit_code, $excluded_regex); my $message = ''; diff --git a/uploadNeuroDB/tarchiveLoader.pl b/uploadNeuroDB/tarchiveLoader.pl index 0e7bf69c3..4d6dc072b 100755 --- a/uploadNeuroDB/tarchiveLoader.pl +++ b/uploadNeuroDB/tarchiveLoader.pl @@ -404,7 +404,7 @@ =head2 Methods ##################### convert the dicom data to minc ########### ################################################################ $utility->dicom_to_minc( - $study_dir, $converter, $get_dicom_info, @exclude, $mail_user, $upload_id + $study_dir, $converter, $get_dicom_info, $mail_user, $upload_id, @exclude ); From dcf70e6ec32eaf2c425ff5b13d1b1711cb4d52f9 Mon Sep 17 00:00:00 2001 From: cmadjar Date: Fri, 17 Jun 2022 14:23:46 -0400 Subject: [PATCH 09/11] recreate markdown files --- docs/scripts_md/ConfigOB.md | 37 +++++++++++++++++++++++++ docs/scripts_md/DBI.md | 12 -------- docs/scripts_md/MRIProcessingUtility.md | 4 +-- docs/scripts_md/run_defacing_script.md | 4 +-- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/docs/scripts_md/ConfigOB.md b/docs/scripts_md/ConfigOB.md index fe21eb2fb..a4beb3138 100644 --- a/docs/scripts_md/ConfigOB.md +++ b/docs/scripts_md/ConfigOB.md @@ -207,6 +207,43 @@ Get the compute\_snr\_modalities Config setting RETURN: an array (possibly empty) of the modality IDs (i.e t1w, etc..) for which to compute the SNR +### getExcludedSeriesDescription() + +Get the excluded\_series\_description Config setting + +RETURN: an array (possibly empty) of the series description to exclude from import + +### getModalitiesToDeface() + +Get the modalities\_to\_deface Config setting + +RETURN: an array (possibly empty) of the modalities to run the defacing pipeline on + +### getBidsDatasetAuthors() + +Get the bids\_dataset\_authors Config setting + +RETURN: an array (possibly empty) of the authors to use for a BIDS dataset + +### getBidsAcknowledgmentsText() + +Get the bids\_acknowledgments\_text Config setting + +RETURN: an array (possibly empty) of the acknowledgment text to use for a BIDS dataset + +### getBidsReadmeText() + +Get the bids\_readme\_text Config setting + +RETURN: an array (possibly empty) of the README text to use for a BIDS dataset + +### getBidsValidatorOptionsToIgnore() + +Get the bids\_validator\_options\_to\_ignore Config setting + +RETURN: an array (possibly empty) of the BIDS validator options to ignore +to use when creating a BIDS dataset + # TO DO Nothing planned. diff --git a/docs/scripts_md/DBI.md b/docs/scripts_md/DBI.md index ce1a61781..38fdfab22 100644 --- a/docs/scripts_md/DBI.md +++ b/docs/scripts_md/DBI.md @@ -35,18 +35,6 @@ INPUTS: RETURNS: DBI database handler when connection is successful -### getConfigSetting($dbh, $name) - -This method fetches the value (`$value`) stored in the `Config` table for a -specific config setting (`$name`) specified as an input. - -INPUTS: - - $dbh : database handler - - $name: name of the config setting - -RETURNS: value corresponding to the config setting in the `Config` table - of LORIS - # TO DO Expand the package with more functions. diff --git a/docs/scripts_md/MRIProcessingUtility.md b/docs/scripts_md/MRIProcessingUtility.md index feb43556f..55a380c51 100644 --- a/docs/scripts_md/MRIProcessingUtility.md +++ b/docs/scripts_md/MRIProcessingUtility.md @@ -329,7 +329,7 @@ INPUTS: RETURNS: acquisition protocol ID of the MINC file -### dicom\_to\_minc($study\_dir, $converter, $get\_dicom\_info, @exclude, $mail\_user, $upload\_id) +### dicom\_to\_minc($study\_dir, $converter, $get\_dicom\_info, $mail\_user, $upload\_id, @exclude) Converts a DICOM study into MINC files. @@ -337,9 +337,9 @@ INPUTS: - $study\_dir : DICOM study directory to convert - $converter : converter to be used - $get\_dicom\_info : get DICOM information setting from the `Config` table - - @exclude : which files to exclude from the `dcm2mnc` command - $mail\_user : mail of the user - $upload\_id : upload ID of the study + - @exclude : which files to exclude from the `dcm2mnc` command ### get\_mincs($minc\_files, $upload\_id) diff --git a/docs/scripts_md/run_defacing_script.md b/docs/scripts_md/run_defacing_script.md index 096350409..efbb2f16c 100644 --- a/docs/scripts_md/run_defacing_script.md +++ b/docs/scripts_md/run_defacing_script.md @@ -22,7 +22,7 @@ specified in the Config module of LORIS. # METHODS -### grep\_FileIDs\_to\_deface($session\_id\_arr, $modalities\_to\_deface\_arr) +### grep\_FileIDs\_to\_deface($session\_id\_arr, @modalities\_to\_deface\_arr) Queries the database for the list of acquisitions' FileID to be used to run the defacing algorithm based on the provided list of SessionID and Scan\_type to @@ -30,7 +30,7 @@ restrict the search. INPUTS: - $session\_id\_arr : array of SessionIDs to use when grepping FileIDs - - $modalities\_to\_deface\_arr: array of Scan\_type to use when grepping FileIDs + - @modalities\_to\_deface\_arr: array of Scan\_type to use when grepping FileIDs RETURNS: hash of matching FileIDs to be used to run the defacing algorithm organized in a hash as follows: From 4cd24477ef9e8b71ee74248c1baab1010f44d08d Mon Sep 17 00:00:00 2001 From: cmadjar Date: Fri, 17 Jun 2022 16:54:37 -0400 Subject: [PATCH 10/11] correct documentation of grep_FileIDs_to_deface in run_defacing_script --- docs/scripts_md/run_defacing_script.md | 6 +++--- tools/run_defacing_script.pl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/scripts_md/run_defacing_script.md b/docs/scripts_md/run_defacing_script.md index efbb2f16c..1d5bf225e 100644 --- a/docs/scripts_md/run_defacing_script.md +++ b/docs/scripts_md/run_defacing_script.md @@ -22,15 +22,15 @@ specified in the Config module of LORIS. # METHODS -### grep\_FileIDs\_to\_deface($session\_id\_arr, @modalities\_to\_deface\_arr) +### grep\_FileIDs\_to\_deface($session\_id\_ref, @modalities\_to\_deface) Queries the database for the list of acquisitions' FileID to be used to run the defacing algorithm based on the provided list of SessionID and Scan\_type to restrict the search. INPUTS: - - $session\_id\_arr : array of SessionIDs to use when grepping FileIDs - - @modalities\_to\_deface\_arr: array of Scan\_type to use when grepping FileIDs + - $session\_id\_ref : array of SessionIDs to use when grepping FileIDs + - @modalities\_to\_deface: array of Scan\_type to use when grepping FileIDs RETURNS: hash of matching FileIDs to be used to run the defacing algorithm organized in a hash as follows: diff --git a/tools/run_defacing_script.pl b/tools/run_defacing_script.pl index 5068c6493..89cc3783c 100755 --- a/tools/run_defacing_script.pl +++ b/tools/run_defacing_script.pl @@ -293,15 +293,15 @@ =head1 METHODS =pod -=head3 grep_FileIDs_to_deface($session_id_arr, @modalities_to_deface_arr) +=head3 grep_FileIDs_to_deface($session_id_ref, @modalities_to_deface) Queries the database for the list of acquisitions' FileID to be used to run the defacing algorithm based on the provided list of SessionID and Scan_type to restrict the search. INPUTS: - - $session_id_arr : array of SessionIDs to use when grepping FileIDs - - @modalities_to_deface_arr: array of Scan_type to use when grepping FileIDs + - $session_id_ref : array of SessionIDs to use when grepping FileIDs + - @modalities_to_deface: array of Scan_type to use when grepping FileIDs RETURNS: hash of matching FileIDs to be used to run the defacing algorithm organized in a hash as follows: From 30d2e2af7fecc7e6cb433619a93b2458b6e4f75d Mon Sep 17 00:00:00 2001 From: cmadjar Date: Tue, 14 Feb 2023 17:24:04 -0500 Subject: [PATCH 11/11] Nic's review --- docs/scripts_md/ConfigOB.md | 6 +++--- uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/scripts_md/ConfigOB.md b/docs/scripts_md/ConfigOB.md index a4beb3138..c241b855d 100644 --- a/docs/scripts_md/ConfigOB.md +++ b/docs/scripts_md/ConfigOB.md @@ -229,19 +229,19 @@ RETURN: an array (possibly empty) of the authors to use for a BIDS dataset Get the bids\_acknowledgments\_text Config setting -RETURN: an array (possibly empty) of the acknowledgment text to use for a BIDS dataset +RETURN: a string of the acknowledgment text to use for a BIDS dataset (or undef) ### getBidsReadmeText() Get the bids\_readme\_text Config setting -RETURN: an array (possibly empty) of the README text to use for a BIDS dataset +RETURN: a string of the README text to use for a BIDS dataset (or undef) ### getBidsValidatorOptionsToIgnore() Get the bids\_validator\_options\_to\_ignore Config setting -RETURN: an array (possibly empty) of the BIDS validator options to ignore +RETURN: an array of the BIDS validator options to ignore to use when creating a BIDS dataset # TO DO diff --git a/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm b/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm index c427f007c..00ddfffa5 100644 --- a/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm +++ b/uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm @@ -519,7 +519,7 @@ sub getBidsDatasetAuthors { Get the bids_acknowledgments_text Config setting -RETURN: an array (possibly empty) of the acknowledgment text to use for a BIDS dataset +RETURN: a string of the acknowledgment text to use for a BIDS dataset (or undef) =cut sub getBidsAcknowledgmentsText { @@ -533,7 +533,7 @@ sub getBidsAcknowledgmentsText { Get the bids_readme_text Config setting -RETURN: an array (possibly empty) of the README text to use for a BIDS dataset +RETURN: a string of the README text to use for a BIDS dataset (or undef) =cut sub getBidsReadmeText { @@ -547,7 +547,7 @@ sub getBidsReadmeText { Get the bids_validator_options_to_ignore Config setting -RETURN: an array (possibly empty) of the BIDS validator options to ignore +RETURN: an array of the BIDS validator options to ignore to use when creating a BIDS dataset =cut