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 the possibility to split multi-run physiological recordings #206

Merged
merged 210 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from 183 commits
Commits
Show all changes
210 commits
Select commit Hold shift + click to select a range
88f12a1
[ENHANC] intializing split utility
sangfrois Apr 7, 2020
ee685c2
[ENHANC] adding elements of the plan
sangfrois Apr 7, 2020
3215022
ephemeral issue_36.md added in root for planif. Linter Revisions
sangfrois Apr 8, 2020
e494d3e
updating step two, specified ways2integrate PR and possible names
sangfrois Apr 8, 2020
cd0c0a9
fixed typos and syntax error
sangfrois Apr 8, 2020
1d3c45b
Merge branch 'master' of https://github.com/physiopy/phys2bids into s…
sangfrois Apr 8, 2020
7759012
fixed typos and updated 2nd part of plan
sangfrois Apr 8, 2020
1168258
Add trig_idx as BlueprintInput attribute
Apr 9, 2020
e1b7e37
General reordering, comments and corrections
Apr 9, 2020
0ff1b24
Merge pull request #2 from smoia/enh/split4phys
sangfrois Apr 9, 2020
5610ec9
Finish adding trig_idx attribute
Apr 9, 2020
232dea9
implementing comments from stefano - corrections
sangfrois Apr 9, 2020
ba8b233
trimming and detailed comments
sangfrois Apr 9, 2020
de4e8f6
trimming and detailed comments - additions
sangfrois Apr 9, 2020
80c43f2
lintering
sangfrois Apr 9, 2020
c454c68
Merge remote-tracking branch 'sangfrois/split_utility' into enh/split…
Apr 10, 2020
3165b4d
Add start index to dictionary making it a dictionary of tuples
Apr 10, 2020
b13daea
typos and error raising
sangfrois Apr 10, 2020
66b15c2
define exceptions
sangfrois Apr 10, 2020
cbe40d0
Merge branch 'split_utility' of github.com:sangfrois/phys2bids into e…
Apr 10, 2020
6d449f5
opting for indexes by updating object in loop
sangfrois Apr 11, 2020
22677cb
redefining plan and minor fixes in split
sangfrois Apr 17, 2020
872038f
Merge branch 'master' of https://github.com/physiopy/phys2bids into s…
sangfrois Apr 17, 2020
3e6880c
fixing rendering in md
sangfrois Apr 17, 2020
ce0d1ed
fixing rendering in md
sangfrois Apr 17, 2020
9f00c4b
fixing rendering in md
sangfrois Apr 17, 2020
817f100
reverting to previous split2phys
sangfrois Apr 18, 2020
a7de9fb
Merge remote-tracking branch 'sangfrois/split_utility' into enh/split…
Apr 18, 2020
d30f419
Add comments and structure of if statements to call split function
Apr 18, 2020
c04f227
Merge pull request #3 from smoia/enh/split4phys
sangfrois Apr 18, 2020
84fca59
erase duplicate in split, regorg phys2bids, changes types in CLI
sangfrois Apr 18, 2020
e512921
updating
sangfrois Apr 28, 2020
e49f554
updating
sangfrois Apr 28, 2020
4356fab
adding smoia changes
sangfrois Apr 28, 2020
f8d9863
adjusting split and main workflow to smoia changes
sangfrois Apr 28, 2020
d6e3e1e
reformatting run definition with indexes
sangfrois Apr 30, 2020
80546a1
renaming function
sangfrois Apr 30, 2020
4754d50
merging smoia changes and restruc multirun sec in phys2bids
sangfrois May 8, 2020
6d445ae
adding plot for runs
sangfrois May 8, 2020
885708d
Merge branch 'master' of https://github.com/physiopy/phys2bids into s…
sangfrois May 8, 2020
5198840
lintering
sangfrois May 8, 2020
d7fd362
minor comment
sangfrois May 19, 2020
1bf7905
Reorganising some code
May 22, 2020
e535845
Adding back info stop
May 22, 2020
c018571
Change dictionary loop
May 22, 2020
ff0d992
Correct dictionary enumeration
May 22, 2020
bfe07a2
Code review
May 22, 2020
422b4d1
removing parralel workflow
sangfrois May 24, 2020
45d27b7
comments and doc string
sangfrois May 24, 2020
2420294
linter and multi-run section
sangfrois May 24, 2020
67248e6
merge conflicts
sangfrois May 24, 2020
0b21fad
changing argument name for chtrig
sangfrois May 24, 2020
632d404
merging smoia improvements
sangfrois May 24, 2020
16e8598
redefining first run_start - is not idx 0
sangfrois May 24, 2020
3fd4241
Merge branch 'master' of https://github.com/physiopy/phys2bids into s…
sangfrois May 24, 2020
09bda51
using where method to find values in array
sangfrois May 26, 2020
11e7ba4
Revert "removing parralel workflow"
May 27, 2020
689cf2c
Delete alternative workflow CLI
May 27, 2020
ef6657b
Add chtrig in BlueprintInput initialisation
May 27, 2020
b2cc386
Add split4phys and ones import
May 27, 2020
9e0798e
Move comments to right place
May 27, 2020
deb5c93
Init new function
May 27, 2020
7c7ddb4
ob2split
sangfrois May 27, 2020
1d81d5b
Merge remote-tracking branch 'sangfrois/split_utility' into enh/split…
May 27, 2020
350581c
Remove duplicate info
May 27, 2020
e1faeaa
last changes
sangfrois May 27, 2020
d1abe50
Merge pull request #6 from smoia/enh/split4phys
sangfrois May 27, 2020
fb9bea2
Update after gitpod
May 27, 2020
d5aa6da
Marked function parts
May 27, 2020
dad2b7f
Merge remote-tracking branch 'sangfrois/split_utility' into enh/split…
May 27, 2020
83dbc29
Solve merge
May 27, 2020
a6f4904
Merge pull request #7 from smoia/enh/split4phys
sangfrois May 27, 2020
da63d39
redefining run_start for padding problem + comments
sangfrois May 27, 2020
a7a60a0
redefining run_start for padding problem - last commit is comment
sangfrois May 27, 2020
9961afd
end_index definition and general reformatting
sangfrois May 27, 2020
876df71
initializing main function that will return sliced obj
sangfrois May 27, 2020
ad281d1
renaming function and outputs so it's more intuitive
sangfrois May 27, 2020
c169e14
renaming file also
sangfrois May 27, 2020
be278af
iterate through timestamps dict, slice and overwrite attributes
sangfrois May 27, 2020
7f62879
restructuring docstring and function order
sangfrois May 29, 2020
c6377a7
minimizing repetition in phys2bids for viz.plot_trigger
sangfrois May 29, 2020
966c593
Add comments and some suggestions
May 29, 2020
b386f67
Correct function import in main workflow
May 29, 2020
51fb2ce
Merge pull request #8 from smoia/enh/split4phys
sangfrois May 29, 2020
07f98e7
fixing conflicts
sangfrois May 29, 2020
c474ab0
reorder slice4phys
sangfrois May 29, 2020
31fa00c
viz.save_plot docstring and comment its use in main workflow
sangfrois May 29, 2020
bda8edf
implementing smoia comments - run counter
sangfrois May 29, 2020
ad16b5a
make sure phys_in update in find_runs dont extend to next run
sangfrois May 29, 2020
55d956c
minor fixes in comments/doctsrings and lintering
sangfrois May 29, 2020
c80fd9b
minor change to docstring
sangfrois May 29, 2020
e1128ed
minor fix in docstring
sangfrois May 29, 2020
91459e2
slice4phys - adding arguments in docstrings
sangfrois May 29, 2020
02b097d
slice4phys - adding notes in docstrings
sangfrois May 29, 2020
50afdb4
slice4phys - adding notes in docstrings
sangfrois May 29, 2020
e102c81
some more docstring info
sangfrois Jun 2, 2020
7ba1593
Merge branch 'master' of https://github.com/physiopy/phys2bids into s…
sangfrois Jun 2, 2020
0f8a919
initializing change in docs for split
sangfrois Jun 2, 2020
44d9f5b
Merge remote-tracking branch 'upstream/master' into enh/split4phys
Jun 2, 2020
6b26e58
merging conflict in phys2bids module import
sangfrois Jun 2, 2020
35a6eea
changing type in cli for -ntp, -tr - list doesn't work
sangfrois Jun 2, 2020
bfdb07c
adding microsiemens for eda
sangfrois Jun 2, 2020
2229c1c
changing argumets for check_trigger, slice4phys
sangfrois Jun 2, 2020
b6fbb05
adding argument and changing run_end definition
sangfrois Jun 2, 2020
5742434
Merge remote-tracking branch 'sangfrois/split_utility' into enh/split…
Jun 2, 2020
3c43e52
Merge remote-tracking branch 'upstream/master' into enh/split4phys
Jun 2, 2020
a21196c
Reorder imports
Jun 2, 2020
b736b03
Following general style
Jun 2, 2020
32db15b
Convert dict keys to number for easier integration
Jun 2, 2020
37a8724
Transform phys_in in dictionary for multirun support, adapt phys_out …
Jun 2, 2020
11cbfd7
Add filename property to BlueprintOutput class
Jun 2, 2020
e3e6fad
Add output filename as object property
Jun 2, 2020
0c17117
Add run as an optional variable in use_heuristic
Jun 2, 2020
e6be352
Rename bids_unit.py as bids.py
Jun 2, 2020
6310cf1
Move use_heuristic from phys2bids.py to bids.py
Jun 2, 2020
5240241
Adapt call to use_heuristic for possible multirun and multifreq
Jun 3, 2020
90681a4
Avoid overwriting
Jun 3, 2020
1a2d1b9
Change warning
Jun 3, 2020
d687147
Pass the run information to heuristics
Jun 3, 2020
6a35b3b
minor changes for troubleshooting multirun workflow
sangfrois Jun 3, 2020
e98eb91
Merge remote-tracking branch 'sangfrois/split_utility' into enh/split…
Jun 3, 2020
66fe785
Make run_idx human readable in print and in dictionary. Reformat docs…
Jun 3, 2020
fc39899
Change " into '
Jun 3, 2020
9aa8706
Flake the docstring
Jun 3, 2020
4ddf4fe
Solve a merge conflict, more 'flaking' for docstrings
Jun 3, 2020
a41efe2
Add ### comment
Jun 3, 2020
e40ae20
More ### comment and remove nonexistent defaults
Jun 3, 2020
1a8469b
More ### comments
Jun 3, 2020
aa5f687
Change viz.save_plot call loop for readability, also more ### comments
Jun 3, 2020
baee891
More ### comments, add defaults and parameters.
Jun 3, 2020
733098f
Deal with slices like [:i] and [i:], more ### comments
Jun 3, 2020
8d6db53
Merge remote-tracking branch 'upstream/master' into enh/split4phys
Jun 3, 2020
d0cca22
Merge branch 'master' of https://github.com/physiopy/phys2bids into s…
sangfrois Jun 4, 2020
d807cb3
Merge branch 'enh/split4phys' of https://github.com/smoia/phys2bids i…
sangfrois Jun 4, 2020
dd7eaa5
applying changes from smoia comments
sangfrois Jun 5, 2020
83de39c
adding statement to deal with single channel rec fo viz
sangfrois Jun 5, 2020
1770fc5
reverting some changes made for testing
sangfrois Jun 5, 2020
3e411d8
changing filename with run
sangfrois Jun 5, 2020
96b80f0
reverting filename
sangfrois Jun 5, 2020
6d9d8b1
reverting filename
sangfrois Jun 5, 2020
a897c15
documentation
sangfrois Jun 5, 2020
8953278
adding logger info and improve readability of run
sangfrois Jun 5, 2020
12341c2
erasing print for tests, idx.start still not working
sangfrois Jun 5, 2020
a1200e4
uncommenting section
sangfrois Jun 7, 2020
06af0a8
linting
sangfrois Jun 7, 2020
09ed5d9
adding last element to docs
sangfrois Jun 7, 2020
e4d72b6
linting on phys2bids
sangfrois Jun 7, 2020
6d73743
changing -ntp and -tr types for integration
sangfrois Jun 7, 2020
5916cdd
fixing types and error for CI
sangfrois Jun 7, 2020
6183d19
changing types for integration
sangfrois Jun 7, 2020
0a700d0
fixing integration errors
sangfrois Jun 7, 2020
9fa664c
reverting phys2bids test arguments
sangfrois Jun 7, 2020
6da16df
changing run_amount definition
sangfrois Jun 7, 2020
e146162
Update phys2bids/bids.py
Jun 9, 2020
2a29ac6
Update phys2bids/phys2bids.py
Jun 9, 2020
0b98410
Update phys2bids/phys2bids.py
Jun 9, 2020
9c01088
Update phys2bids/phys2bids.py
Jun 9, 2020
8ad2ba9
Update phys2bids/phys2bids.py
Jun 9, 2020
52964d4
Update phys2bids/phys2bids.py
Jun 9, 2020
7901296
Update phys2bids/viz.py
Jun 9, 2020
75b01db
Update phys2bids/viz.py
Jun 9, 2020
0542863
Update phys2bids/viz.py
Jun 9, 2020
2c9a9f8
Update phys2bids/phys2bids.py
sangfrois Jun 9, 2020
bd14f6c
Update phys2bids/phys2bids.py
sangfrois Jun 9, 2020
13df1c5
Update phys2bids/tests/test_integration.py
sangfrois Jun 9, 2020
f0917a1
Fix multirun errors
rmarkello Jun 9, 2020
2e65f28
Fixes final multifreq error
rmarkello Jun 10, 2020
4a14d93
Add padding as optional argument, correct split4phys call
Jun 11, 2020
1f178bd
Revert "Add filename property to BlueprintOutput class"
Jun 11, 2020
a0b68f8
Add filename to docstring
Jun 11, 2020
0c6cca7
Use import numpy as np syntax
rmarkello Jun 11, 2020
67b7a86
Correct documentation and short rephrasing
Jun 11, 2020
32a84cf
Update phys2bids/phys2bids.py
sangfrois Jun 11, 2020
366e2e8
Update phys2bids/cli/run.py
sangfrois Jun 11, 2020
3a86684
Update docs/howto.rst
Jun 12, 2020
1e3d9b1
Make things personal
Jun 12, 2020
be52689
Update docs/howto.rst
Jun 12, 2020
6396e67
Check tr ntp length earlier
Jun 12, 2020
80554b8
Bug fix on threshold entry
Jun 12, 2020
d2d2e97
Run keys start from 1
Jun 12, 2020
8e61577
Change plot filename
Jun 12, 2020
dd94f83
Merge remote-tracking branch 'sangfrois/split_utility' into enh/split…
Jun 12, 2020
4178b8a
Correct plot printing
Jun 12, 2020
68508fa
Moving back run_amount
Jun 12, 2020
3cdaf2c
Update pytest to make travis work
Jun 12, 2020
8858fed
Correct fileprefix name
Jun 12, 2020
01b5975
Deepcopy the object, then run again check_trigger_amount
Jun 16, 2020
6885cdc
Merge branch 'master' of github.com:physiopy/phys2bids into enh/split…
Jun 16, 2020
d7c5bd2
redef of run start
sangfrois Jun 16, 2020
174d4de
Add tr in test call
Jun 17, 2020
187f262
fix paddings
Jun 17, 2020
1c88981
Linter
Jun 17, 2020
cc7bacf
empty commit
sangfrois Jun 17, 2020
68a77da
Merge remote-tracking branch 'upstream/master' into enh/split4phys
Jun 18, 2020
ec3bc0d
Fix paths
Jun 18, 2020
dff0b14
Merge branch 'master' into enh/split4phys
Jun 21, 2020
c62a1be
Adapt use_heuristic call to new heuristic call, remove unused library
Jun 21, 2020
5da8f09
Add "run" as argument in new heuristic
Jun 21, 2020
797401f
Format filename frequency as integer
Jun 21, 2020
4595150
Format frequency as integer for heuristic
Jun 21, 2020
747e9bb
Optimise run_amount
Jun 21, 2020
30e3f14
Optimise metadata creation
Jun 21, 2020
c379fc7
Fix paths
Jun 21, 2020
c59c40b
Fix log name
Jun 21, 2020
5aedebb
Rename multifreq files as {freq}Hz
Jun 21, 2020
4d2d15d
Adapt names
Jun 21, 2020
aaf8624
Lint
Jun 21, 2020
bf943eb
Force pip to skip release candidates
Jun 21, 2020
4694d4d
Force pip to skip release candidates
Jun 22, 2020
2d56fd3
Force pip to skip matplotlib 3.3.0rc1
Jun 22, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ dmypy.json
.pyre/

.vscode/
phys2bids/tests/data/*
68 changes: 68 additions & 0 deletions docs/howto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,74 @@ By looking at this figure, we can work out that we need a smaller threshold in o
Tip: Time 0 is the time of first trigger
------------------------------------------------

Splitting your input file into multiple run output files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If your file contains more than one (f)MRI acquisition (or runs), you can provide multiple values to ``-ntp`` in order to get multiple ``.tsv.gz`` outputs. If the TR of the entire session is consistent (i.e. all your acquisitions have the same TR), then you can specify one value after ``-tr``.

By specifying the number of timepoints in each acquisition, ``phys2bids`` will recursively cut the input file by detecting the first trigger of the entire session and the ones after the number of timepoints you specified.

.. code-block:: shell

phys2bids -in two_scans_samefreq_all.txt -chtrig 2 -ntp 536 398 -tr 1.2 -thr 2

Now, instead of counting the trigger timepoints once, ``physbids`` will check the trigger channel recursively with all the values listed in ``-ntp``. The logger will inform you about the number of timepoints left at each iteration.

.. code-block:: shell

INFO:phys2bids.physio_obj:Counting trigger points
INFO:phys2bids.physio_obj:The trigger is in channel 2
INFO:phys2bids.physio_obj:The number of timepoints found with the manual threshold of 2.0000 is 934
INFO:phys2bids.physio_obj:Checking number of timepoints
INFO:phys2bids.physio_obj:Found just the right amount of timepoints!
WARNING:phys2bids.slice4phys:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
phys2bids will split the input file according to the given -tr and -ntp arguments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
INFO:phys2bids.physio_obj:Counting trigger points
INFO:phys2bids.physio_obj:The trigger is in channel 2
INFO:phys2bids.physio_obj:The number of timepoints found with the manual threshold of 2.0000 is 934
INFO:phys2bids.physio_obj:Checking number of timepoints
WARNING:phys2bids.physio_obj:Found 398 timepoints more than expected!
Assuming extra timepoints are at the end (try again with a more liberal thr)
INFO:phys2bids.slice4phys:
--------------------------------------------------------------
Slicing between 0.0 seconds and 961.381 seconds
--------------------------------------------------------------
INFO:phys2bids.physio_obj:Counting trigger points
INFO:phys2bids.physio_obj:The trigger is in channel 2
INFO:phys2bids.physio_obj:The number of timepoints found with the manual threshold of 2.0000 is 400
INFO:phys2bids.physio_obj:Checking number of timepoints
WARNING:phys2bids.physio_obj:Found 2 timepoints more than expected!
Assuming extra timepoints are at the end (try again with a more liberal thr)
INFO:phys2bids.slice4phys:
--------------------------------------------------------------
Slicing between 952.381 seconds and 1817.96 seconds
--------------------------------------------------------------
INFO:phys2bids.viz:Plot trigger
INFO:phys2bids.viz:Plot trigger
INFO:phys2bids.phys2bids:Preparing 2 output files.
INFO:phys2bids.phys2bids:Exporting files for run 1 freq 1000.0

The logger also notifies you about the slicing points used (the first always being from the beginning of session, until the specified number of timepoints after the first trigger). The user can also check the resulting slice by looking at the plot of the trigger channel for each run. Each slice is adjusted with a padding after the last trigger. Such padding can be specified while calling ``phys2bids`` with ``-pad``. If nothing is specified, the default value of 9 seconds will be used. This padding is also applied at the beginning (before the first trigger of the run) of the 2nd to last run.

What if I have multiple acquisition types ?
*******************************************

The user can also benefit from this utility when dealing with multiple **acquisition types** such as different functional scans with different TRs. Like ``-ntp``, ``-tr`` can take multiple values. **Though, if more than one value is specified, they require the same amount of values**. The idea is simple: if you only have one acquisition type, the one ``-tr`` input you gave will be broadcast through all runs, but if you have different acquisition types, you have to list all of them in order.

.. warning::
There are currently no ``multi-run tutorial files`` available along with the package (under ``phys2bids/tests/data``). Although, you can visit `phys2bids OSF <https://osf.io/3txqr/files/>`_ storage to access a LabChart physiological recording with multiple fMRI acquisitions. Find it under ``labchart/chicago``.

.. note::
**Why would I have more than one fMRI acquisition in the physiological recording?**

The idea is to reduce human error and have a good padding around your fMRI scan!

Synchronization between start of both fMRI and physiological acquisitions can be difficult, so it is safer to have as few physiological recordings as possible, with multiple imaging sequences.

Moreover, if you want to correct for recording/physiological delays, you will love *that bit of recorded information* around your fMRI scan!

Generating outputs in BIDs format
#################################

Expand Down
85 changes: 85 additions & 0 deletions phys2bids/bids_units.py → phys2bids/bids.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import logging
import os
from pathlib import Path

from phys2bids import utils

LGR = logging.getLogger(__name__)

Expand All @@ -18,6 +22,9 @@
# ampere: electric current
'ampere': 'A', 'amp': 'A', 'amps': 'A',
# second: time and hertzs: frequency
# siemens: electric conductance (e.g. EDA)
'siemens': 'S',
# second: time and hertzs
'1/hz': 's', '1/hertz': 's', 'hz': 'Hz',
'1/s': 'Hz', '1/second': 'Hz', '1/seconds': 'Hz',
'1/sec': 'Hz', '1/secs': 'Hz', 'hertz': 'Hz',
Expand Down Expand Up @@ -87,3 +94,81 @@ def bidsify_units(orig_unit):
LGR.warning(f'The given unit {orig_unit} does not have aliases, '
f'passing it as is')
return orig_unit


def use_heuristic(heur_file, sub, ses, filename, outdir, run='', record_label=''):
"""
Import and use the heuristic specified by the user to rename the file.

Parameters
----------
heur_file: path
Fullpath to heuristic file.
sub: str or int
Name of subject.
ses: str or int or None
Name of session.
filename: path
Name of the input of phys2bids.
outdir: str or path
Path to the directory that will become the "site" folder
("root" folder of BIDS database).
record_label: str
Optional label for the "record" entry of BIDS.

Returns
-------
heurpath: str or path
Returned fullpath to tsv.gz new file (post BIDS formatting).

Raises
------
KeyError
if `bids_keys['task']` is empty
"""
utils.check_file_exists(heur_file)

# Initialise a dictionary of bids_keys that has already "recording"
bids_keys = {'sub': '', 'ses': '', 'task': '', 'acq': '', 'ce': '',
'dir': '', 'rec': '', 'run': run, 'recording': record_label}

# Start filling bids_keys dictionary and path with subject and session
if sub.startswith('sub-'):
bids_keys['sub'] = sub[4:]
fldr = os.path.join(outdir, sub)
else:
bids_keys['sub'] = sub
fldr = os.path.join(outdir, f'sub-{sub}')

if ses:
if ses.startswith('ses-'):
bids_keys['ses'] = ses[4:]
fldr = os.path.join(fldr, ses)
else:
bids_keys['ses'] = ses
fldr = os.path.join(fldr, f'ses-{ses}')

# Load heuristic and use it to fill dictionary
heur = utils.load_heuristic(heur_file)
bids_keys.update(heur.heur(Path(filename).stem, run))

# If bids_keys['task'] is still empty, stop the program
if not bids_keys['task']:
LGR.warning(f'The heuristic {heur_file} could not deal with'
f'{Path(filename).stem}')
raise KeyError('No "task" attribute found')

# Compose name by looping in the bids_keys dictionary
# and adding nonempty keys
name = ''
for key in bids_keys:
if bids_keys[key] != '':
name = f'{name}{key}-{bids_keys[key]}_'

# Finish path, create it, add filename, export
fldr = os.path.join(fldr, 'func')
utils.path_exists_or_make_it(fldr)

heurpath = os.path.join(fldr, f'{name}physio')

return heurpath
51 changes: 29 additions & 22 deletions phys2bids/cli/run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""
Parser for phys2bids
"""
"""Parser for phys2bids."""


import argparse

Expand All @@ -10,7 +9,7 @@

def _get_parser():
"""
Parses command line inputs for this function
Parse command line inputs for this function.

Returns
-------
Expand All @@ -27,8 +26,8 @@ def _get_parser():
required.add_argument('-in', '--input-file',
dest='filename',
type=str,
help='The name of the file containing physiological data, with or '
'without extension.',
help='The name of the file containing physiological '
'data, with or without extension.',
required=True)
optional.add_argument('-info', '--info',
dest='info',
Expand Down Expand Up @@ -61,11 +60,6 @@ def _get_parser():
'in the current folder. Edit the heur_ex.py file in '
'heuristics folder.',
default=None)
# optional.add_argument('-hdir', '--heur-dir',
# dest='heurdir',
# type=str,
# help='Folder containing heuristic file.',
# default='.')
optional.add_argument('-sub', '--subject',
dest='sub',
type=str,
Expand Down Expand Up @@ -94,26 +88,39 @@ def _get_parser():
default=None)
optional.add_argument('-ntp', '--numtps',
dest='num_timepoints_expected',
nargs='*',
type=int,
help='Number of expected timepoints (TRs). '
'Default is 0. Note: the estimation of when the '
'neuroimaging acquisition started cannot take place '
'with this default.',
default=0)
help='Number of expected trigger timepoints (TRs). '
'Default is None. Note: the estimation of beggining of '
'neuroimaging acquisition cannot take place with this default. '
'If you\'re running phys2bids on a multi-run recording, '
'give a list of each expected ntp for each run.',
default=None)
optional.add_argument('-tr', '--tr',
dest='tr',
nargs='*',
type=float,
help='TR of sequence in seconds. '
'Default is 0 second.',
default=0)
'If you\'re running phys2bids on a multi-run recording, '
'you can give a list of each expected ntp for each run, '
'or just one TR if it is consistent throughout the session.',
default=None)
optional.add_argument('-thr', '--threshold',
dest='thr',
type=float,
help='Threshold to use for trigger detection. '
'If "ntp" and "TR" are specified, phys2bids automatically computes '
'a threshold to detect the triggers. Use this parameter to set it '
'manually',
default=None)
'If "ntp" and "TR" are specified, phys2bids '
'automatically computes a threshold to detect '
'the triggers. Use this parameter to set it manually. '
'This parameter is necessary for multi-run recordings. ',
default=None)
optional.add_argument('-pad', '--padding',
dest='pad',
type=float,
help='Padding in seconds used around a single run '
'when separating multi-run session files. '
'Default is 9 seconds.',
Comment on lines +120 to +122
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something like 'Padding between multi-run session files (in seconds). Default is 9 seconds.'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in love with this suggestion, for one main reason. This argument sets the amount of recording you have before or after a run, no matter how much time is there between runs (i.e. you might end up having part of an earlier run into this file, if you set enough padding). If you formulate it like the "between runs in a multi-run session", then it looks like you're asking the user how much time they recorded in between - which is a different concept.

default=9)
optional.add_argument('-chnames', '--channel-names',
dest='ch_name',
nargs='*',
Expand Down
2 changes: 1 addition & 1 deletion phys2bids/heuristics/heur_euskalibur.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fnmatch


def heur(physinfo):
def heur(physinfo, run=''):
"""
Set of if .. elif statements to fill BIDS names.

Expand Down
2 changes: 1 addition & 1 deletion phys2bids/heuristics/heur_test_acq.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fnmatch


def heur(physinfo):
def heur(physinfo, run=''):
"""
Set of if .. elif statements to fill BIDS names.

Expand Down
2 changes: 1 addition & 1 deletion phys2bids/heuristics/heur_tutorial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fnmatch


def heur(physinfo):
def heur(physinfo, run=''):
"""
Set of if .. elif statements to fill BIDS names.

Expand Down
4 changes: 1 addition & 3 deletions phys2bids/interfaces/acq.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
phys2bids interface for acqknowledge files.
"""
"""phys2bids interface for acqknowledge files."""
import logging
import warnings

Expand Down
4 changes: 1 addition & 3 deletions phys2bids/interfaces/txt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
phys2bids interface for txt files.
"""
"""phys2bids interface for txt files."""

import logging
from collections import Counter
Expand Down
Loading