From be742ab9d2e1642881a576ec7e97405f2b041d2d Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 9 Aug 2023 13:53:35 -0400 Subject: [PATCH] ENH: Add support for _desc- entity to label different processings of a file --- dandi/consts.py | 1 + dandi/organize.py | 2 +- dandi/tests/test_organize.py | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/dandi/consts.py b/dandi/consts.py index 34391185a..7c0691daf 100644 --- a/dandi/consts.py +++ b/dandi/consts.py @@ -194,6 +194,7 @@ def urls(self) -> Iterator[str]: "slice_id": {"format": "_slice-{}"}, "cell_id": {"format": "_cell-{}"}, # disambiguation ones + "description": {"format": "_desc-{}", "type": "disambiguation"}, "probe_ids": {"format": "_probe-{}", "type": "disambiguation"}, "obj_id": { "format": "_obj-{}", diff --git a/dandi/organize.py b/dandi/organize.py index 85625f723..84010336d 100644 --- a/dandi/organize.py +++ b/dandi/organize.py @@ -1032,7 +1032,7 @@ def msg_(msg, n, cond=None): ORGANIZED_FILENAME_REGEX = ( rf"sub-{LABELREGEX}" rf"(_ses-{LABELREGEX})?" - rf"(_(tis|slice|cell|probe|obj)-{LABELREGEX})*" + rf"(_(tis|slice|cell|desc|probe|obj)-{LABELREGEX})*" r"(_[a-z]+(\+[a-z]+)*)?" r"\.nwb" ) diff --git a/dandi/tests/test_organize.py b/dandi/tests/test_organize.py index 990157e99..804b992ad 100644 --- a/dandi/tests/test_organize.py +++ b/dandi/tests/test_organize.py @@ -237,6 +237,21 @@ def test_ambiguous_probe1() -> None: ] +def test_ambiguous_desc() -> None: + base = dict(subject_id="1", session="2", modalities=["mod"], extension="nwb") + # fake filenames should be ok since we never should get to reading them for object_id + metadata = [ + dict(path="1.nwb", **base), + dict(path="2.nwb", description="ms5", **base), + ] + metadata_ = create_unique_filenames_from_metadata(metadata) + assert metadata_ != metadata + assert [m["dandi_path"] for m in metadata_] == [ + op.join("sub-1", "sub-1_mod.nwb"), + op.join("sub-1", "sub-1_desc-ms5_mod.nwb"), + ] + + @pytest.mark.parametrize( "sym_success,hard_success,result", [ @@ -332,6 +347,11 @@ def test_video_organize_common(video_mode, nwbfiles_video_common): [ ("XCaMPgf/XCaMPgf_ANM471996_cell01.dat", []), ("sub-RAT123/sub-RAT123.nwb", []), + ("sub-RAT123/sub-RAT123_desc-label.nwb", []), # _desc- is supported now + ( + "sub-RAT123/sub-RAT123_notsupported-irrelevant.nwb", + ["DANDI.NON_DANDI_FILENAME"], + ), ("sub-RAT123/sub-RAT124.nwb", ["DANDI.METADATA_MISMATCH_SUBJECT"]), ("sub-RAT124.nwb", ["DANDI.NON_DANDI_FOLDERNAME"]), ("foo/sub-RAT124.nwb", ["DANDI.NON_DANDI_FOLDERNAME"]),