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

Add codespell workflow, config and fix some typos #126

Merged
merged 7 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[codespell]
skip = .git,*.pdf,*.svg,venvs
#
# ignore-words-list =
22 changes: 22 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Codespell

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
contents: read

jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Codespell
uses: codespell-project/actions-codespell@v2
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ repos:
hooks:
- id: black
language_version: python3.7

- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
- id: codespell
4 changes: 2 additions & 2 deletions bep028spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ Each Entity (as a record or a top-level entity) has the following fields:
<tr>
<td><code>wasGeneratedBy</code>
</td>
<td>OPTIONAL. UUID. Identifier of the activity which generated this entity (the corresponding Activity must be defined with its own Activty record).
<td>OPTIONAL. UUID. Identifier of the activity which generated this entity (the corresponding Activity must be defined with its own Activity record).
</td>
</tr>
<tr>
Expand Down Expand Up @@ -555,7 +555,7 @@ An example of this can be [fMRIPrep](https://fmriprep.org/en/stable/index.html),

The most simplistic way you can think of is to have this container "black-boxed" in your workflow. You basically record the calling of this container (`command` section) and the output (see the outputs section from fMRIPrep)

"prov:Activty": [
"prov:Activity": [

{

Expand Down
78 changes: 39 additions & 39 deletions bids_prov/afni/afni_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def find_param(cmd_args_remain: list) -> dict:
for arg_remain in cmd_args_remain:
if arg_remain.startswith("-"):
if arg_remain != cmd_args_remain[-1]:
succesor = cmd_args_remain[cmd_args_remain.index(arg_remain) + 1]
if not succesor.startswith("-"):
param_dic[arg_remain] = succesor
cmd_args_remain.remove(succesor)
successor = cmd_args_remain[cmd_args_remain.index(arg_remain) + 1]
if not successor.startswith("-"):
param_dic[arg_remain] = successor
cmd_args_remain.remove(successor)
else:
param_dic[arg_remain] = True
else:
Expand All @@ -88,15 +88,15 @@ def find_param(cmd_args_remain: list) -> dict:
return param_dic


def build_records(commands_bloc: list, agent_id: str, verbose: bool = False):
def build_records(commands_block: list, agent_id: str, verbose: bool = False):
"""
Build the `records` field for the final .jsonld file,
from commands lines grouped by stage (e.g. `Registration`, `Post-stats`)

Parameters
----------

commands_bloc : list of str
commands_block : list of str
all commands extracted from afni file
agent_id : int
random uuid for software agent (here afni)
Expand All @@ -115,7 +115,7 @@ def build_records(commands_bloc: list, agent_id: str, verbose: bool = False):

bloc_act = []

for (bloc, cmd) in commands_bloc:
for (block, cmd) in commands_block:
cmd_s = re.split(" |=", cmd)
a_name = cmd_s[0]
cmd_args_remain = cmd_s[1:]
Expand Down Expand Up @@ -232,7 +232,7 @@ def build_records(commands_bloc: list, agent_id: str, verbose: bool = False):
# "derivedFrom": input_id,
}
)
bloc_act.append((bloc, activity["@id"]))
bloc_act.append((block, activity["@id"]))

records["Activities"].append(activity)
if verbose:
Expand Down Expand Up @@ -294,23 +294,23 @@ def readlines(input_file: str) -> list:

# commands = [cmd for cmd in commands if not any(
# cmd.startswith(begin) for begin in dropline_begin)]
regex_bloc = re.compile(r'# =+ ([^=]+) =+')
commands_bloc = []
bloc = ""
regex_block = re.compile(r'# =+ ([^=]+) =+')
commands_block = []
block = ""
for cmd in commands:
if cmd.startswith("# ==="):
bloc = regex_bloc.match(cmd).groups()[0] if regex_bloc.match(cmd) is not None else "bloc ..."
block = regex_block.match(cmd).groups()[0] if regex_block.match(cmd) is not None else "block ..."

if not any(cmd.startswith(begin) for begin in dropline_begin):
commands_bloc.append((bloc, cmd))
commands_block.append((block, cmd))

commands_bloc = [(bloc, re.sub(r"\s+", " ", cmd))
for (bloc, cmd) in commands_bloc] # drop multiple space between args
commands_block = [(block, re.sub(r"\s+", " ", cmd))
for (block, cmd) in commands_block] # drop multiple space between args

commands_bloc = [(bloc, cmd)
for (bloc, cmd) in commands_bloc if cmd] # drop empty commands
commands_block = [(block, cmd)
for (block, cmd) in commands_block if cmd] # drop empty commands

return commands_bloc
return commands_block


def get_activities_by_ids(graph, ids):
Expand Down Expand Up @@ -425,7 +425,7 @@ def get_extern_entities_from_activities(graph, activities, id_fusion_activity):


def afni_to_bids_prov(filename: str, context_url=CONTEXT_URL, output_file=None,
soft_ver='afni24', indent=2, verbose=True, with_blocs=True) -> bool:
soft_ver='afni24', indent=2, verbose=True, with_blocks=True) -> bool:
"""
afni parser

Expand All @@ -438,55 +438,55 @@ def afni_to_bids_prov(filename: str, context_url=CONTEXT_URL, output_file=None,
output_file : str
name of output parsed file with extension json.ld
soft_ver:str
version of sofware afni
version of software afni
indent : int
number of indentation in jsonld
verbose : bool
True to have more verbosity
with_blocs : bool
with_blocks : bool
To retrieve or not the results of the parser in block mode and not only for each command

Returns
-------
bool
Write the json-ld to the location indicated in output_file.
If `with_blocs` is True, it generates the file to the location indicated in output_file.
If `with_blocks` is True, it generates the file to the location indicated in output_file.
"""
commands_bloc = readlines(filename)
commands_block = readlines(filename)

graph, agent_id = get_default_graph(label="AFNI", context_url=context_url, soft_ver=soft_ver)
records, bloc_act = build_records(commands_bloc, agent_id, verbose=verbose)
records, bloc_act = build_records(commands_block, agent_id, verbose=verbose)

graph["Records"].update(records)
compute_sha_256_entity(graph["Records"]["Entities"])

if with_blocs:
if with_blocks:
bl_name = list(OrderedDict.fromkeys(bl for (bl, id) in bloc_act))
blocs = [{
blocks = [{
"bloc_name": bl,
"act_ids": [id_ for (b, id_) in bloc_act if b == bl]} for bl in bl_name]

graph_bloc = copy.deepcopy(graph)
activities_blocs = []
entities_blocs = []
for bloc in blocs:
activities = get_activities_by_ids(graph_bloc, bloc["act_ids"])
fus_activities = fusion_activities(activities, bloc["bloc_name"])
graph_block = copy.deepcopy(graph)
activities_blocks = []
entities_blocks = []
for block in blocks:
activities = get_activities_by_ids(graph_block, block["act_ids"])
fus_activities = fusion_activities(activities, block["bloc_name"])
ext_entities = get_extern_entities_from_activities(
graph_bloc, activities, fus_activities["@id"])
graph_block, activities, fus_activities["@id"])
for ent in ext_entities:
if ent["@id"] not in entities_blocs:
entities_blocs.append(ent)
if ent["@id"] not in entities_blocks:
entities_blocks.append(ent)

for ent_used in fus_activities["Used"]:
if ent_used not in [id_["@id"] for id_ in ext_entities]:
fus_activities["Used"].remove(ent_used)
activities_blocs.append(fus_activities)
activities_blocks.append(fus_activities)

graph_bloc["Records"]["Activities"] = activities_blocs
graph_bloc["Records"]["Entities"] = entities_blocs
graph_block["Records"]["Activities"] = activities_blocks
graph_block["Records"]["Entities"] = entities_blocks

return writing_jsonld(graph_bloc, indent, output_file)
return writing_jsonld(graph_block, indent, output_file)

return writing_jsonld(graph, indent, output_file)

Expand Down
18 changes: 9 additions & 9 deletions bids_prov/fsl/fsl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
]
)

# tags used to detect outputs from cammand lines
# tags used to detect outputs from command lines
# eg. convert_xfm -inverse -omat highres2example_func.mat example_func2highres.mat
OUTPUT_TAGS = frozenset(
[
Expand Down Expand Up @@ -141,14 +141,14 @@ def readlines(filename: str) -> Mapping[str, List[str]]:
# return None


def _get_kwarg(serie, with_value=True):
def _get_kwarg(series, with_value=True):
"""
Get the named arguments (kwarg) from a column ("Used", "GeneratedBy", "ParametersValue" or "ParametersNoValue" ) of the dataframe coming frome in description_functions.json
Get the named arguments (kwarg) from a column ("Used", "GeneratedBy", "ParametersValue" or "ParametersNoValue" ) of the dataframe coming from in description_functions.json

Parameters
----------

serie : pandas series
series : pandas series
A list of the command arguments description.
with_value : boolean
A bool to specify if values are expected or not, in order to dicrimine "ParametersValue" (with_value=True), and "ParametersNoValue" (with_value=False)
Expand All @@ -162,7 +162,7 @@ def _get_kwarg(serie, with_value=True):
arg_list = []

add_argument_list = []
for u_arg in serie:
for u_arg in series:
if type(u_arg) == dict:
# parser.add_argument(u_arg["name"], nargs='+', action='append')
if "Nargs" in u_arg:
Expand Down Expand Up @@ -199,14 +199,14 @@ def _get_kwarg(serie, with_value=True):
return add_argument_list, arg_list


def _get_arg(serie, arg_rest):
def _get_arg(series, 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 should be used when all named arguments are removed from the initial command.

Parameters
----------

serie : pandas series
series : pandas series
A list of the command arguments description.
arg_rest : string of the command, (without all the named argument used in description_functions.json)

Expand All @@ -217,7 +217,7 @@ def _get_arg(serie, arg_rest):

arg_list = []
arg_purge = [arg for arg in arg_rest if not arg.startswith("-")]
for u_arg in serie:
for u_arg in series:
if type(u_arg) == int:
# print("arg_purge", type(arg_purge), arg_purge, u_arg)
if u_arg < len(arg_purge):
Expand Down
2 changes: 1 addition & 1 deletion bids_prov/tests/test_afni_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_readlines():
"3dTcat -prefix $output_dir/pb00.$subj.r01.tcat ./afni_voxelwise_p0001/sub-01_task-tonecounting_bold.nii.gz'[0..$]'",
"3dToutcount -automask -fraction -polort 2 -legendre pb00.$subj.r$run.tcat+orig > outcount.r$run.1D"
]
commands = [cmd.strip() for (bloc, cmd) in commands]
commands = [cmd.strip() for (block, cmd) in commands]
# Replace multi (>=2 ) blank space to one
commands = [re.sub(r"\s{2,}", " ", cmd) for cmd in commands]
expected_commands = [cmd.strip() for cmd in expected_commands]
Expand Down
2 changes: 1 addition & 1 deletion code_of_conduct.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
identity and expression, level of experience, education, socioeconomic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

Expand Down
Loading