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 Run label #32

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions fnirsapp_qr.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
"list": true,
"value-key": "[SessionLabel]"
},
{
"command-line-flag": "--run-label",
"description": "The label(s) of the run(s) that should be analyzed. The label corresponds to run-<session_label> from the BIDS spec (so it does not include \"run-\"). If this parameter is not provided all sessions should be analyzed. Multiple runs can be specified with a space separated list.",
"id": "run_label",
"name": "run-label",
"optional": true,
"type": "String",
"list": true,
"value-key": "[RunLabel]"
},
{
"command-line-flag": "--task-label",
"description": "The label(s) of the tasks(s) that should be analyzed. The label corresponds to task-<subject_label> from the BIDS spec. If this parameter is not provided all tasks should be analyzed. Multiple tasks can be specified with a space separated list.",
Expand Down
83 changes: 60 additions & 23 deletions fnirsapp_qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def fnirsapp_qr(command, env={}):
'all sessions should be analyzed. Multiple sessions '
'can be specified with a space separated list.',
nargs="+")
parser.add_argument('--run-label',
help='The label(s) of the run(s) that should be '
'analyzed. The label corresponds to '
'run-<run-label> from the BIDS spec (so it does '
'not include "run-"). If this parameter is not provided '
'all runs should be analyzed. Multiple runs '
'can be specified with a space separated list.',
nargs="+")
parser.add_argument('--sci-threshold', type=float, default=0.0,
help='Threshold below which a channel is marked as bad.')
parser.add_argument('--pp-threshold', type=float, default=0.0,
Expand Down Expand Up @@ -125,6 +133,19 @@ def create_report(app_name=None, pargs=None):
logger.info(f" Sessions: {sess}")


logger.info("Extracting run metadata.")
sess = []
if args.session_label:
logger.info(" Run data provided as input argument.")
runs = args.session_label
else:
logger.info(" Run data will be extracted from data.")
runs = get_entity_vals(args.input_datasets, 'run')
if len(runs) == 0:
runs = [None]
logger.info(f" Runs: {runs}")


logger.info("Extracting tasks metadata.")
tasks = []
if args.task_label:
Expand Down Expand Up @@ -294,29 +315,45 @@ def run_report(path, path_out):
for sub in subs:
for task in tasks:
for ses in sess:

logger.info(f"Processing: sub-{sub}/ses-{ses}/task-{task}")
exec_files[f"sub-{sub}_ses-{ses}_task-{task}"] = dict()

in_path = BIDSPath(subject=sub, task=task, session=ses,
root=f"{args.input_datasets}",
datatype="nirs", suffix="nirs",
extension=".snirf")

exec_files[f"sub-{sub}_ses-{ses}_task-{task}"]["FileName"] = str(in_path.fpath)
exec_files[f"sub-{sub}_ses-{ses}_task-{task}"]["FileHash"] = hashlib.md5(open(in_path.fpath, 'rb').read()).hexdigest()

out_path = BIDSPath(subject=sub, task=task, session=ses,
root=f"{args.output_location}",
datatype="nirs", suffix="qualityReport",
extension=".html", check=False)

if op.exists(in_path):
logger.info(f" Found file: {in_path}")
out_path.fpath.parent.mkdir(exist_ok=True, parents=True)
run_report(in_path, out_path)
else:
logger.info(f" No file exists: {in_path}")
for run in runs:
if len(runs) > 1 :
logger.info(f"Processing: sub-{sub}/ses-{ses}/run-{run}/task-{task}")
exec_files[f"sub-{sub}_ses-{ses}_task-{task}_run-{run}"] = dict()

in_path = BIDSPath(subject=sub, task=task, session=ses, run = rub,
root=f"{args.input_datasets}",
datatype="nirs", suffix="nirs",
extension=".snirf")
exec_files[f"sub-{sub}_ses-{ses}_task-{task}_run-{run}"]["FileName"] = str(in_path.fpath)
exec_files[f"sub-{sub}_ses-{ses}_task-{task}_run-{run}"]["FileHash"] = hashlib.md5(open(in_path.fpath, 'rb').read()).hexdigest()
out_path = BIDSPath(subject=sub, task=task, session=ses,run=run,
root=f"{args.output_location}",
datatype="nirs", suffix="qualityReport",
extension=".html", check=False)
else
logger.info(f"Processing: sub-{sub}/ses-{ses}/task-{task}")
exec_files[f"sub-{sub}_ses-{ses}_task-{task}"] = dict()

in_path = BIDSPath(subject=sub, task=task, session=ses,
root=f"{args.input_datasets}",
datatype="nirs", suffix="nirs",
extension=".snirf")

exec_files[f"sub-{sub}_ses-{ses}_task-{task}"]["FileName"] = str(in_path.fpath)
exec_files[f"sub-{sub}_ses-{ses}_task-{task}"]["FileHash"] = hashlib.md5(open(in_path.fpath, 'rb').read()).hexdigest()

out_path = BIDSPath(subject=sub, task=task, session=ses,
root=f"{args.output_location}",
datatype="nirs", suffix="qualityReport",
extension=".html", check=False)

if op.exists(in_path):
logger.info(f" Found file: {in_path}")
out_path.fpath.parent.mkdir(exist_ok=True, parents=True)
run_report(in_path, out_path)
else:
logger.info(f" No file exists: {in_path}")


exec_rep["Files"] = exec_files
exec_path = f"{args.input_datasets}/execution"
Expand Down