Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix Entity Table Order #157

Merged
merged 14 commits into from
Apr 16, 2022
37 changes: 32 additions & 5 deletions dcm2bids/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""k"""


import logging
from os.path import join as opj
from future.utils import iteritems
from .utils import DEFAULT
Expand Down Expand Up @@ -132,6 +132,8 @@ def __init__(
self.customLabels = customLabels
self.srcSidecar = srcSidecar

self.logger = logging.getLogger(__name__)

if sidecarChanges is None:
self.sidecarChanges = {}
else:
Expand Down Expand Up @@ -207,7 +209,7 @@ def dstRoot(self):
return opj(
self.participant.directory,
self.dataType,
self.participant.prefix + self.suffix,
self.set_order_entity_table(),
)

@property
Expand All @@ -219,9 +221,36 @@ def dstIntendedFor(self):
return opj(
self.participant.session,
self.dataType,
self.participant.prefix + self.suffix,
self.set_order_entity_table(),
)

def set_order_entity_table(self):
"""
Return:
The destination filename formated following BIDS entity key table
https://bids-specification.readthedocs.io/en/latest/99-appendices/04-entity-table.html#appendix-iv-entity-table
arnaudbore marked this conversation as resolved.
Show resolved Hide resolved
"""
curr_name = self.participant.prefix + self.suffix
new_name = ''
curr_dict = dict(x.split("-") for x in curr_name.split("_") if len(x.split('-')) == 2)
ext = [x for x in curr_name.split("_") if len(x.split('-')) == 1]

for curr_key in DEFAULT.entityTableKeys:
if curr_key in curr_dict.keys():
new_name = '_'.join([new_name, curr_key + '-' +
curr_dict[curr_key]])
curr_dict.pop(curr_key, None)

for curr_key in curr_dict.keys():
self.logger.warning(
"Entity \"%s\" is not a valid BIDS entity.", curr_key
)
new_name = '_'.join([new_name, curr_key + '-' +
curr_dict[curr_key]])
new_name = new_name[1:]
new_name = '_'.join([new_name, ext[0]])
arnaudbore marked this conversation as resolved.
Show resolved Hide resolved
return new_name

@property
def intendedFor(self):
return self._intendedFor
Expand Down Expand Up @@ -249,14 +278,12 @@ def indexSidecar(self, value):
"""
self._indexSidecar = value


def dstSidecarData(self, descriptions, intendedForList):
"""
"""
data = self.srcSidecar.origData
data["Dcm2bidsVersion"] = __version__


# intendedFor key
if self.intendedFor != [None]:
intendedValue = []
Expand Down
6 changes: 6 additions & 0 deletions dcm2bids/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class DEFAULT(object):
runTpl = "_run-{:02d}"
caseSensitive = True

# Entity table:
# https://bids-specification.readthedocs.io/en/latest/99-appendices/04-entity-table.html#appendix-iv-entity-table
arnaudbore marked this conversation as resolved.
Show resolved Hide resolved
entityTableKeys = ["sub", "ses", "task", "acq", "ce", "rec", "dir",
"run", "mod", "echo", "flip", "inv", "mt", "part",
"recording"]

# misc
tmpDirName = "tmp_dcm2bids"
helperDir = "helper"
Expand Down