Skip to content

Commit

Permalink
Reconstruct ecpac call for re-running; Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nx10 committed Dec 19, 2023
1 parent c7c0010 commit f01dc84
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 161 deletions.
34 changes: 34 additions & 0 deletions src/ecpac/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pathlib as pl
from typing import Optional

import click


def check_exist_file(path: pl.Path, label: str = "") -> bool:
"""Check if a file exists. Or print a message if it doesn't."""
if path.exists() and path.is_file():
return True
click.secho(f'Error: {label} file does not exist! "{path}"', fg="red")
return False


def check_exist_dir(path: pl.Path, label: str = "") -> bool:
"""Check if a directory exists. Or print a message if it doesn't."""
if path.exists() and path.is_dir():
return True
click.secho(f'Error: {label} directory does not exist! "{path}"', fg="red")
return False


def option_or_prompt(opt: Optional[str], prompt: str, default: Optional[str] = None) -> str:
"""Prompt the user for input if the option is not provided."""
if opt is not None:
return opt
return click.prompt(prompt, default=default, type=str)


def option_or_confirm(opt: Optional[bool], prompt: str, default: Optional[bool] = False) -> bool:
"""Prompt the user for input (confirmation boolean) if the option is not provided."""
if opt is not None:
return opt
return click.confirm(prompt, default=default)
72 changes: 72 additions & 0 deletions src/ecpac/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
import pathlib as pl

ID_PIPELINE_DEFAULT = "default"
FILENAME_JOB = "job.sh"
FOLDERNAME_OUTPUT = "output"

# Grab from $PROJECT, which is "/ocean/projects/{med000000p}/{username}"
ENV_PROJECT = os.environ.get("PROJECT", "")
PSC_PROJECT_USER = pl.Path(ENV_PROJECT)
PSC_OUTPUT_DEFAULT = PSC_PROJECT_USER / "ecpac_runs"
PSC_IMAGE_DEFAULT = PSC_PROJECT_USER / "images/cpac.sif"

CPAC_ANALYSIS_LEVELS = ("participant", "group", "test_config")
ANALYSIS_LEVEL_DEFAULT = "participant"
CPAC_PRECONFIGS = [
"abcd-options",
"abcd-prep",
"anat-only",
"benchmark-FNIRT",
"blank",
"ccs-options",
"default",
"default-deprecated",
"fmriprep-options",
"fx-options",
"monkey",
"ndmg",
"nhp-macaque",
"preproc",
"rbc-options",
"rodent",
]


BASH_TEMPLATE_JOB = """\
#!/usr/bin/bash
#SBATCH --job-name {job_name}
#SBATCH --output {stdout_file}
#SBATCH --nodes 1
#SBATCH --partition RM-shared
#SBATCH --time {duration_str}
#SBATCH --ntasks-per-node {threads}
#SBATCH --mem {memory_mb}
set -x
cd {wd}
singularity run \
--cleanenv \
{cpac_bin_opt} \
-B {path_input}:{path_input}:ro \
-B {path_output}:{path_output} \
{image} {path_input} {path_output} {analysis_level} \
--skip_bids_validator \
--n_cpus {cpac_threads} \
--mem_gb {cpac_memory_gb} \
--participant_label {subject} \
{pipeline} \
{extra_cpac_args}
"""

BASH_TEMPLATE_PIPELINE_PRECONFIG = "--preconfig {pipeline}"
BASH_TEMPLATE_PIPELINE_CONFIG_FILE = "--pipeline-file {pipeline}"


BASH_TEMPLATE_JOB_CPAC_BIN = """\
-B {cpac_bin}/CPAC:/code/CPAC \
-B {cpac_bin}/dev/docker_data/run.py:/code/run.py \
-B {cpac_bin}/dev/docker_data:/cpac_resources \
"""
Loading

0 comments on commit f01dc84

Please sign in to comment.