From 33b5815d51c05d629ffa53e9adc2f2e78635720c Mon Sep 17 00:00:00 2001 From: Chenying Zhao Date: Wed, 5 Apr 2023 13:20:43 -0400 Subject: [PATCH 1/2] start to code babs-update-setup --- babs/babs.py | 33 ++++++++++++++++++++++ babs/cli.py | 48 +++++++++++++++++++++++++++++++- babs/merge_outputs_postscript.sh | 3 +- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/babs/babs.py b/babs/babs.py index e130d80b..1ba427da 100644 --- a/babs/babs.py +++ b/babs/babs.py @@ -991,6 +991,39 @@ def babs_check_setup(self, input_ds, flag_job_test): if flag_warning_output_ria: print("\nPlease check out the warning for output RIA!") + def babs_update_setup(self, input_ds, container_config_yaml_file): + """ + This is to update setup of jobs run in a BABS project. + + Parameters: + -------------- + input_ds: class `Input_ds` + information of input dataset(s) + container_config_yaml_file: str + Path to an updated container's configuration YAML file. + """ + + babs_proj_config = read_yaml(self.config_path, if_filelock=True) + + # Sanity check: if the user has changed `required_files` section in YAML file: + # if changed, throw out a warning. + # TODO^^ + + # ============================================================== + # Redo: Bootstrap scripts: + # ============================================================== + + # Re-generate `_zip.sh`: ---------------------------------- + # which is a bash script of singularity run + zip + # in folder: `analysis/code` + print("\nRe-generating a bash script for running container and zipping the outputs...") + print("This bash script will be named as `" + container_name + "_zip.sh`") + bash_path = op.join(self.analysis_path, "code", container_name + "_zip.sh") + container.generate_bash_run_bidsapp(bash_path, input_ds, self.type_session) + self.datalad_save(path="code/" + container_name + "_zip.sh", + message="Generate script of running container") + + def babs_submit(self, count=1, df_job_specified=None): """ This function submits jobs and prints out job status. diff --git a/babs/cli.py b/babs/cli.py index cefe2f84..45401eae 100644 --- a/babs/cli.py +++ b/babs/cli.py @@ -79,7 +79,8 @@ def babs_init_cli(): parser.add_argument( '--container_config_yaml_file', '--container-config-yaml-file', help="Path to a YAML file that contains the configurations" - " of how to run the BIDS App container") + " of how to run the BIDS App container", + required=True) parser.add_argument( "--type_session", "--type-session", choices=['single-ses', 'single_ses', 'single-session', 'single_session', @@ -295,6 +296,51 @@ def babs_check_setup_main(): # Call method `babs_check_setup()`: babs_proj.babs_check_setup(input_ds, args.job_test) +def babs_update_setup_cli(): + """ + CLI for: Update setups for job running in a BABS project, + e.g., cluster resources request, script preamble. + """ + + parser = argparse.ArgumentParser( + description="Update setups for running jobs.") + parser.add_argument( + "--project_root", "--project-root", + help="Absolute path to the root of BABS project." + " For example, '/path/to/my_BABS_project/'.", + required=True) + parser.add_argument( + '--container_config_yaml_file', '--container-config-yaml-file', + help="Path to an updated YAML file that contains the configurations" + " of how to run the BIDS App container", + required=True) + + return parser + +def babs_update_setup_main(): + """ + Update setups for job running in a BABS project, + e.g., cluster resources request, script preamble. + + Parameters: + -------------- + project_root: str + Absolute path to the root of BABS project. + container_config_yaml_file: str + Path to an updated container's configuration YAML file. + """ + + # Get arguments: + args = babs_check_setup_cli().parse_args() + project_root = args.project_root + + # Get class `BABS` based on saved `analysis/code/babs_proj_config.yaml`: + babs_proj, input_ds = get_existing_babs_proj(project_root) + + # Call `babs_update_setup()`: + babs_proj.babs_update_setup(input_ds, args.container_config_yaml_file) + + def babs_submit_cli(): """ Submit jobs. diff --git a/babs/merge_outputs_postscript.sh b/babs/merge_outputs_postscript.sh index 6cb7fbe9..f66efced 100644 --- a/babs/merge_outputs_postscript.sh +++ b/babs/merge_outputs_postscript.sh @@ -2,7 +2,8 @@ # The following should be pasted into the merge_outputs.sh script datalad clone ${outputsource} merge_ds cd merge_ds -NBRANCHES=$(git branch -a | grep job- | sort | wc -l) +# translate command below into python +NBRANCHES=$(git branch -a | grep job- | sort | wc -l) # no need `sort`, then count lines echo "Found $NBRANCHES branches to merge" # find the default branch's name: master or main: - added by Chenying From 3bd7fbbeee94c21c23a25c3fb1bda053dbcf7528 Mon Sep 17 00:00:00 2001 From: Chenying Zhao Date: Wed, 5 Apr 2023 14:55:39 -0400 Subject: [PATCH 2/2] remove notes for babs-merge --- babs/merge_outputs_postscript.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/babs/merge_outputs_postscript.sh b/babs/merge_outputs_postscript.sh index f66efced..6cb7fbe9 100644 --- a/babs/merge_outputs_postscript.sh +++ b/babs/merge_outputs_postscript.sh @@ -2,8 +2,7 @@ # The following should be pasted into the merge_outputs.sh script datalad clone ${outputsource} merge_ds cd merge_ds -# translate command below into python -NBRANCHES=$(git branch -a | grep job- | sort | wc -l) # no need `sort`, then count lines +NBRANCHES=$(git branch -a | grep job- | sort | wc -l) echo "Found $NBRANCHES branches to merge" # find the default branch's name: master or main: - added by Chenying