Skip to content

Commit

Permalink
more fixes in compliance with updated context
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaumet committed Sep 4, 2023
1 parent 27b8075 commit 84e319c
Show file tree
Hide file tree
Showing 11 changed files with 401 additions and 401 deletions.
14 changes: 7 additions & 7 deletions bids_prov/afni/afni_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ def build_records(commands_bloc: list, agent_id: str, verbose: bool = False):

inputs, outputs, cmd_args_remain = get_entities(cmd_s[1:], df)

# if "used" in df:
# arg = df["used"]
# if "Used" in df:
# arg = df["Used"]
# entities, args_consumed_list = get_entities(cmd_s, arg)
# renamed_entities = [clean_label_suffix(
# os.path.split(ent)[1]) for ent in entities]
# inputs.extend(renamed_entities)
# for arg in args_consumed_list:
# cmd_args_remain.remove(arg)

# if "generatedBy" in df:
# arg = df["generatedBy"]
# if "GeneratedBy" in df:
# arg = df["GeneratedBy"]
# entities, args_consumed_list = get_entities(cmd_s, arg)
# renamed_entities = [clean_label_suffix(
# os.path.split(ent)[1]) for ent in entities]
Expand Down Expand Up @@ -362,7 +362,7 @@ def fusion_activities(activities, label):
return {
"@id": f"urn:{get_id()}",
"Label": label,
"AssociatedWith": activities[0]["associatedWith"],
"AssociatedWith": activities[0]["AssociatedWith"],
"Command": command,
"Used": used_entities,
}
Expand Down Expand Up @@ -411,8 +411,8 @@ def get_extern_entities_from_activities(graph, activities, id_fusion_activity):
generated_entities.append(ent)

# for ent in used_ents:
# if "generatedBy" in ent:
# ent["generatedBy"] = id_fusion_activity
# if "GeneratedBy" in ent:
# ent["GeneratedBy"] = id_fusion_activity

for ent in generated_entities:
if "GeneratedBy" in ent:
Expand Down
12 changes: 6 additions & 6 deletions bids_prov/fsl/fsl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def readlines(filename: str) -> Mapping[str, List[str]]:

def _get_kwarg(serie, with_value=True):
"""
Get the named arguments (kwarg) from a column ("used", "generatedBy", "parameters_value" or "parameters_no_value" ) of the dataframe coming frome in description_functions.json
Get the named arguments (kwarg) from a column ("Used", "GeneratedBy", "parameters_value" or "parameters_no_value" ) of the dataframe coming frome in description_functions.json
Parameters
----------
Expand Down Expand Up @@ -201,7 +201,7 @@ def _get_kwarg(serie, with_value=True):

def _get_arg(serie, arg_rest):
"""
Get the ordinal arguments from a column ("used", "generatedBy") of the dataframe coming from in description_functions.json. _get_arg shoud be used when all named arguments are removed from the initial command.
Get the ordinal arguments from a column ("Used", "GeneratedBy") of the dataframe coming from in description_functions.json. _get_arg shoud be used when all named arguments are removed from the initial command.
Parameters
----------
Expand Down Expand Up @@ -306,11 +306,11 @@ def get_entities(cmd_s, parameters):
-------
>>> df = {
"name": "command",
"used": [0, "-a"],
"generatedBy": [-1, "-b"]
"name": "Command",
"Used": [0, "-a"],
"GeneratedBy": [-1, "-b"]
}
>>> cmd_s = ["command", "-a", "kwarg_0", "arg_0", "arg_1", "-b", "kwarg_1"]
>>> cmd_s = ["Command", "-a", "kwarg_0", "arg_0", "arg_1", "-b", "kwarg_1"]
>>> inputs, outputs, parameters = get_entities(cmd_s[1:], df)
>>> (["kwarg_0", "arg_0"], ["kwarg_1", "arg_1"], [])
Expand Down
16 changes: 8 additions & 8 deletions bids_prov/spm/spm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_input_entity(right: str) -> List[dict]:
Returns
-------
dict[str, str]
else with key "@id", "label", "prov"
else with key "@id", "Label", "prov"
"""

Expand All @@ -62,8 +62,8 @@ def get_input_entity(right: str) -> List[dict]:
entity_label_short = "_".join(file_location.split("/")[-2:]) # Sub01_con_0001.nii
entity = {
"@id": "urn:" + get_id(),
"label": label_mapping(entity_label_short, "spm/spm_activity_labels.json"),
"prov:atLocation": file_location
"Label": label_mapping(entity_label_short, "spm/spm_activity_labels.json"),
"AtLocation": file_location
}

entities.append(entity)
Expand Down Expand Up @@ -159,7 +159,7 @@ def get_entities_from_ext_config(conf_dic: dict, activity_name: str, activity_id
Returns
-------
list[dict]
each element is an entity dict with key "@id", "label", "prov:atLocation", "wasGeneratedBy"
each element is an entity dict with key "@id", "Label", "AtLocation", "wasGeneratedBy"
"""

output_entities = list()
Expand Down Expand Up @@ -200,7 +200,7 @@ def find_closest_activity(activities: list, right: str) -> dict:
dep_number = re.search(r"{(\d+)}", right) # retrieve name of the output_entity
closest_activity = None
for act in activities:
if act["label"].endswith(dep_number.group(1)):
if act["Label"].endswith(dep_number.group(1)):
closest_activity = act
break

Expand All @@ -221,14 +221,14 @@ def find_output_id_from_closest(closest_activity: dict, records: dict) -> str:
"""
for entity in records["Entities"]:
if "GeneratedBy" in entity:
if entity["GeneratedBy"] == closest_activity["@id"]: # entity["label"] == parts[-1]
if entity["GeneratedBy"] == closest_activity["@id"]: # entity["Label"] == parts[-1]
output_id = entity["@id"]
break
else:
output_id = "urn:" + get_id()
# output_id = next(
# (entity["@id"] for entity in records["prov:Entity"]
# if parts[-1] == entity["label"] and entity["generatedBy"] == closest_activity["@id"]
# if parts[-1] == entity["Label"] and entity["GeneratedBy"] == closest_activity["@id"]
# ), "urn:" + get_id()
# ) # find entity id generated by closest activity, if None new get_id

Expand Down Expand Up @@ -365,7 +365,7 @@ def get_records(task_groups: dict, agent_id: str, verbose=False) -> dict:
output_entity = { # output for closest activity but input for current one
"@id": output_id,
"Label": out_label, # label_mapping(parts[-1], "spm/spm_labels.json"),
# "prov:atLocation": TODO
# "AtLocation": TODO
"GeneratedBy": closest_activity["@id"],
}
output_entities.append(output_entity)
Expand Down
Loading

0 comments on commit 84e319c

Please sign in to comment.