Skip to content

Commit

Permalink
refactor rename path variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
ReiHashimoto committed Jun 28, 2023
1 parent 4b8d401 commit 17801d9
Show file tree
Hide file tree
Showing 24 changed files with 53 additions and 55 deletions.
5 changes: 3 additions & 2 deletions run_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ def main(args):
# copy config file
if args.config is not None:
shutil.copyfile(
args.config, join_filepath([DIRPATH.ROOT_DIR, DIRPATH.SNAKEMAKE_CONFIG_YML])
args.config,
join_filepath([DIRPATH.STUDIO_DIR, DIRPATH.SNAKEMAKE_CONFIG_YML]),
)

snakemake(
DIRPATH.SNAKEMAKE_FILEPATH,
forceall=args.forceall,
cores=args.cores,
use_conda=args.use_conda,
workdir=f"{os.path.dirname(DIRPATH.ROOT_DIR)}",
workdir=f"{os.path.dirname(DIRPATH.STUDIO_DIR)}",
)


Expand Down
8 changes: 4 additions & 4 deletions studio/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ from studio.core.models import FILETYPE
from studio.core.snakemake.smk_utils import SmkUtils
from studio.core.utils.filepath_creater import join_filepath

configfile: join_filepath([DIRPATH.ROOT_DIR, 'config.yaml'])
configfile: join_filepath([DIRPATH.STUDIO_DIR, 'config.yaml'])

if config.get('type') == ACTION.EDIT_ROI:
rule edit_ROI:
conda:
EditRoiUtils.conda(config)
script:
f"{DIRPATH.ROOT_DIR}/core/rules/edit_ROI.py"
f"{DIRPATH.STUDIO_DIR}/core/rules/edit_ROI.py"
else:
rule all:
input: [join_filepath([DIRPATH.OUTPUT_DIR, x]) for x in config["last_output"]]
Expand All @@ -27,7 +27,7 @@ else:
params:
name = details
script:
f"{DIRPATH.ROOT_DIR}/core/rules/data.py"
f"{DIRPATH.STUDIO_DIR}/core/rules/data.py"
else:
rule:
input:
Expand All @@ -39,4 +39,4 @@ else:
conda:
SmkUtils.conda(details)
script:
f"{DIRPATH.ROOT_DIR}/core/rules/func.py"
f"{DIRPATH.STUDIO_DIR}/core/rules/func.py"
2 changes: 1 addition & 1 deletion studio/__main_unit__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
allow_headers=["*"],
)

FRONTEND_DIRPATH = DIRPATH.PKG_DIR + "/frontend"
FRONTEND_DIRPATH = DIRPATH.ROOT_DIR + "/frontend"

app.mount(
"/static",
Expand Down
21 changes: 11 additions & 10 deletions studio/core/dir_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@


class DIRPATH:
OPTINIST_DIR = _DEFAULT_DIR if _ENV_DIR is None else _ENV_DIR
INPUT_DIR = f"{OPTINIST_DIR}/input"
OUTPUT_DIR = f"{OPTINIST_DIR}/output"
DATA_DIR = _DEFAULT_DIR if _ENV_DIR is None else _ENV_DIR

CONDAENV_DIR = (
f"{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/conda"
)

PKG_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
ROOT_DIR = os.path.dirname(os.path.dirname(__file__))
INPUT_DIR = f"{DATA_DIR}/input"
OUTPUT_DIR = f"{DATA_DIR}/output"

if not os.path.exists(INPUT_DIR):
os.makedirs(INPUT_DIR)
Expand All @@ -24,6 +18,13 @@ class DIRPATH:
os.makedirs(OUTPUT_DIR)
assert os.path.exists(OUTPUT_DIR)

SNAKEMAKE_FILEPATH = f"{ROOT_DIR}/Snakefile"
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
STUDIO_DIR = os.path.dirname(os.path.dirname(__file__))

CONDAENV_DIR = (
f"{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/conda"
)

SNAKEMAKE_FILEPATH = f"{STUDIO_DIR}/Snakefile"
EXPERIMENT_YML = "experiment.yaml"
SNAKEMAKE_CONFIG_YML = "config.yaml"
7 changes: 3 additions & 4 deletions studio/core/edit_ROI/edit_ROI.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def get_algo(self):

if (
not os.path.exists(filepath)
and os.path.commonpath([DIRPATH.OPTINIST_DIR, filepath])
!= DIRPATH.OPTINIST_DIR
and os.path.commonpath([DIRPATH.DATA_DIR, filepath]) != DIRPATH.DATA_DIR
):
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
if os.path.basename(filepath) != "cell_roi.json":
Expand All @@ -61,7 +60,7 @@ def excute(self):
DIRPATH.SNAKEMAKE_FILEPATH,
use_conda=True,
cores=2,
workdir=f"{os.path.dirname(DIRPATH.ROOT_DIR)}",
workdir=f"{os.path.dirname(DIRPATH.STUDIO_DIR)}",
)

def set_smk_config(self):
Expand All @@ -73,7 +72,7 @@ def set_smk_config(self):
"params": self.params,
}
ConfigWriter.write(
dirname=DIRPATH.ROOT_DIR,
dirname=DIRPATH.STUDIO_DIR,
filename=DIRPATH.SNAKEMAKE_CONFIG_YML,
config=config,
)
Expand Down
7 changes: 2 additions & 5 deletions studio/core/rules/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import os
from os.path import abspath, dirname

optinist_dirname = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
)
OPTINIST_DIRPATH = f"{optinist_dirname}"
ROOT_DIRPATH = dirname(dirname(dirname(dirname(abspath(__file__)))))
4 changes: 2 additions & 2 deletions studio/core/rules/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# - F821: do not import snakemake
import sys

from const import OPTINIST_DIRPATH
from const import ROOT_DIRPATH

sys.path.append(OPTINIST_DIRPATH)
sys.path.append(ROOT_DIRPATH)

from studio.core.models import FILETYPE
from studio.core.rules.file_writer import FileWriter
Expand Down
4 changes: 2 additions & 2 deletions studio/core/rules/edit_ROI.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# - F821: do not import snakemake
import sys

from const import OPTINIST_DIRPATH
from const import ROOT_DIRPATH

sys.path.append(OPTINIST_DIRPATH)
sys.path.append(ROOT_DIRPATH)

from studio.core.edit_ROI import EditRoiUtils

Expand Down
4 changes: 2 additions & 2 deletions studio/core/rules/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# - F821: do not import snakemake
import sys

from const import OPTINIST_DIRPATH
from const import ROOT_DIRPATH

sys.path.append(OPTINIST_DIRPATH)
sys.path.append(ROOT_DIRPATH)

from studio.core.dir_path import DIRPATH
from studio.core.rules.runner import Runner
Expand Down
2 changes: 1 addition & 1 deletion studio/core/snakemake/snakemake_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def snakemake_execute(unique_id: str, params: SmkParam):
forceall=params.forceall,
cores=params.cores,
use_conda=params.use_conda,
workdir=f"{os.path.dirname(DIRPATH.ROOT_DIR)}",
workdir=f"{os.path.dirname(DIRPATH.STUDIO_DIR)}",
log_handler=[Logger(unique_id).smk_logger],
)

Expand Down
2 changes: 1 addition & 1 deletion studio/core/snakemake/snakemake_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class SmkConfigWriter:
@classmethod
def write(cls, unique_id, flow_config):
ConfigWriter.write(
dirname=DIRPATH.ROOT_DIR,
dirname=DIRPATH.STUDIO_DIR,
filename=DIRPATH.SNAKEMAKE_CONFIG_YML,
config=flow_config,
)
Expand Down
4 changes: 2 additions & 2 deletions studio/core/utils/filepath_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def find_filepath(name, category) -> Optional[str]:
name, _ = os.path.splitext(name)

filepaths = glob(
join_filepath([DIRPATH.ROOT_DIR, "wrappers", "**", category, f"{name}.yaml"]),
join_filepath([DIRPATH.STUDIO_DIR, "wrappers", "**", category, f"{name}.yaml"]),
recursive=True,
)
return filepaths[0] if len(filepaths) > 0 else None


def find_param_filepath(name: str):
if name in ["snakemake", "nwb"]:
return join_filepath([DIRPATH.ROOT_DIR, "core", name, f"{name}.yaml"])
return join_filepath([DIRPATH.STUDIO_DIR, "core", name, f"{name}.yaml"])
else:
return find_filepath(name, "params")

Expand Down
2 changes: 1 addition & 1 deletion studio/tests/core/experiment/test_expt_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from studio.core.experiment.experiment_reader import ExptConfigReader
from studio.core.workflow.workflow import Edge, Node, NodeData, NodePosition, Style

expt_filepath = f"{DIRPATH.OPTINIST_DIR}/output_test/0123/experiment.yaml"
expt_filepath = f"{DIRPATH.DATA_DIR}/output_test/0123/experiment.yaml"


def test_read():
Expand Down
2 changes: 1 addition & 1 deletion studio/tests/core/experiment/test_expt_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
)
}

dirpath = f"{DIRPATH.OPTINIST_DIR}/output/unique_id"
dirpath = f"{DIRPATH.DATA_DIR}/output/unique_id"


def test_create_config() -> ExptConfig:
Expand Down
6 changes: 3 additions & 3 deletions studio/tests/core/snakemake/test_snakemake_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
)

shutil.copyfile(
f"{DIRPATH.OPTINIST_DIR}/config.yaml",
f"{DIRPATH.ROOT_DIR}/config.yaml",
f"{DIRPATH.DATA_DIR}/config.yaml",
f"{DIRPATH.STUDIO_DIR}/config.yaml",
)


Expand Down Expand Up @@ -84,7 +84,7 @@ def test_snakemake_execute():
),
}

output_dirpath = f"{DIRPATH.OPTINIST_DIR}/output/snakemake"
output_dirpath = f"{DIRPATH.DATA_DIR}/output/snakemake"


def test_snakemake_delete_dependencies():
Expand Down
2 changes: 1 addition & 1 deletion studio/tests/core/snakemake/test_snakemake_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from studio.core.snakemake.snakemake_writer import SmkConfigWriter

unique_id = "smk_test"
output_fileapth = f"{DIRPATH.OPTINIST_DIR}/output/{unique_id}/config.yaml"
output_fileapth = f"{DIRPATH.DATA_DIR}/output/{unique_id}/config.yaml"


def test():
Expand Down
4 changes: 2 additions & 2 deletions studio/tests/core/test_dir_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@


def test_dir_path():
assert os.path.exists(DIRPATH.OPTINIST_DIR)
assert os.path.exists(DIRPATH.ROOT_DIR)
assert os.path.exists(DIRPATH.DATA_DIR)
assert os.path.exists(DIRPATH.STUDIO_DIR)
2 changes: 1 addition & 1 deletion studio/tests/core/utils/test_config_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from studio.core.utils.filepath_creater import join_filepath
from studio.core.utils.filepath_finder import find_param_filepath

dirpath = f"{DIRPATH.OPTINIST_DIR}/output"
dirpath = f"{DIRPATH.DATA_DIR}/output"
filename = "test.yaml"


Expand Down
2 changes: 1 addition & 1 deletion studio/tests/core/utils/test_filepath_creater.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from studio.core.dir_path import DIRPATH

filepath = f"{DIRPATH.OPTINIST_DIR}/output/test.txt"
filepath = f"{DIRPATH.DATA_DIR}/output/test.txt"


def test_create_filepath():
Expand Down
4 changes: 2 additions & 2 deletions studio/tests/core/utils/test_pickle_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from studio.core.dir_path import DIRPATH
from studio.core.utils.pickle_handler import PickleReader, PickleWriter

filepath = f"{DIRPATH.OPTINIST_DIR}/output/0123/func2/func2.pkl"
filepath = f"{DIRPATH.DATA_DIR}/output/0123/func2/func2.pkl"


def test_PickleWriter():
Expand All @@ -15,7 +15,7 @@ def test_PickleWriter():
assert os.path.exists(filepath)


filepath = f"{DIRPATH.OPTINIST_DIR}/output_test/0123/func1/func1.pkl"
filepath = f"{DIRPATH.DATA_DIR}/output_test/0123/func1/func1.pkl"


def test_PickleReader():
Expand Down
6 changes: 3 additions & 3 deletions studio/tests/core/workflow/test_workflow_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
unique_id = "result_test"
node_id_list = ["func1", "func2"]

workflow_dirpath = f"{DIRPATH.OPTINIST_DIR}/output_test/{unique_id}"
pickle_path = f"{DIRPATH.OPTINIST_DIR}/output_test/{unique_id}/func1/func1.pkl"
workflow_dirpath = f"{DIRPATH.DATA_DIR}/output_test/{unique_id}"
pickle_path = f"{DIRPATH.DATA_DIR}/output_test/{unique_id}/func1/func1.pkl"


def test_WorkflowResult_get():
shutil.copytree(
workflow_dirpath,
f"{DIRPATH.OPTINIST_DIR}/output/{unique_id}",
f"{DIRPATH.DATA_DIR}/output/{unique_id}",
dirs_exist_ok=True,
)
output = WorkflowResult(unique_id=unique_id).get(node_id_list)
Expand Down
4 changes: 2 additions & 2 deletions studio/tests/routers/test_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

unique_id = "0123"

output_test_dir = f"{DIRPATH.OPTINIST_DIR}/output_test"
output_test_dir = f"{DIRPATH.DATA_DIR}/output_test"

shutil.copytree(
f"{output_test_dir}/{unique_id}",
Expand Down Expand Up @@ -39,7 +39,7 @@ def test_import():

def test_delete():
dirname = "delete_dir"
dirpath = join_filepath([f"{DIRPATH.OPTINIST_DIR}/output", dirname])
dirpath = join_filepath([f"{DIRPATH.DATA_DIR}/output", dirname])
os.makedirs(dirpath, exist_ok=True)
assert os.path.exists(dirpath)
response = client.delete(f"/experiments/{dirname}")
Expand Down
2 changes: 1 addition & 1 deletion studio/tests/routers/test_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_hdf5():


def test_HDF5Getter():
output = HDF5Getter.get(f"{DIRPATH.OPTINIST_DIR}/input/files/test.nwb")
output = HDF5Getter.get(f"{DIRPATH.DATA_DIR}/input/files/test.nwb")

assert isinstance(output, list)
assert isinstance(output[0], HDF5Node)
2 changes: 1 addition & 1 deletion studio/tests/routers/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

client = TestClient(router)

timeseries_dirpath = f"{DIRPATH.OPTINIST_DIR}/output/0123/func1/fluorescence.json"
timeseries_dirpath = f"{DIRPATH.DATA_DIR}/output/0123/func1/fluorescence.json"


def test_inittimedata():
Expand Down

0 comments on commit 17801d9

Please sign in to comment.