-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use literalincludes almost exclusively within tutorial to make maintenance easier * Update non-tutorial documentation files to 1.0 syntax * Add more links to attributes like zip_lists and path * Update typing annotations within source code for more consistency, and to take advantage of auto-documentation. * Various formatting fixes
- Loading branch information
Showing
25 changed files
with
477 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
Workflows | ||
========= | ||
|
||
Snakebids workflows are constructed the same way as any other [Snakemake workflows](inv:snakemake#snakefiles/rules), but with a few additions that make it easier to work with BIDS datasets. | ||
|
||
To get access to these additions, the base Snakefile for a snakebids workflow should begin with the following boilerplate: | ||
|
||
```python | ||
import snakebids | ||
from snakebids import bids | ||
|
||
configfile: 'config/snakebids.yml' | ||
|
||
# Get input wildcards | ||
inputs = snakebids.generate_inputs( | ||
bids_dir=config["bids_dir"], | ||
pybids_inputs=config["pybids_inputs"], | ||
pybids_database_dir=config.get("pybids_db_dir"), | ||
pybids_reset_database=config.get("pybids_db_reset"), | ||
derivatives=config.get("derivatives"), | ||
participant_label=config.get("participant_label"), | ||
exclude_participant_label=config.get("exclude_participant_label"), | ||
use_bids_inputs=True, | ||
) | ||
|
||
``` | ||
|
||
Snakebids workflow features | ||
--------------------------- | ||
|
||
The [](#snakebids.bids) function generates a properly-formatted BIDS filename with the specified entities, as documented in more detail elsewhere in this documentation. | ||
|
||
[](#snakebids.generate_inputs) returns an instance of [](#snakebids.BidsDataset), a special [](#dict) with keys mapping to the {class}`~snakebids.BidsComponents` defined in [the config file](/bids_app/config). Each {class}`~snakebids.BidsComponent` contains a number of attributes to assist processing a BIDS dataset with snakemake. {func}`~snakebids.generate_inputs` should be called at the beginning of the workflow and assigned to a variable called `inputs`. | ||
|
||
The {attr}`~snakebids.BidsComponent.path` member of [](#snakebids.BidsComponent) is generated by snakebids and contains a list of matched files for every input type. Often, the first rule to be invoked will use one or more entries in `inputs.path` as the input file specification. | ||
|
||
The {attr}`~snakebids.BidsComponent.zip_lists` member of [](#snakebids.BidsComponent) is used with [`bids()`](#snakebids.bids) and [`expand()`](#snakefiles_expand) to fill the wildcards with corresponding values from input files. The usage pattern is as follows: | ||
|
||
```py | ||
expand( | ||
bids( | ||
root="results", | ||
datatype="func", | ||
suffix="bold.nii.gz", | ||
**inputs.wildcards["bold"] | ||
), | ||
zip, | ||
**inputs.zip_lists["bold"] | ||
) | ||
``` | ||
|
||
The {attr}`~snakebids.BidsComponent.wildcards` member of {class}`snakebids.BidsComponent` is generated by snakebids and contains a dictionary mapping the wildcards for each input type to snakemake-formatted wildcards, for convenient use in the ``bids`` function. | ||
|
||
|
||
## Accessing the underlying *pybids* dataset | ||
|
||
In addition to mapping all of the {class}`~snakebids.BidsComponents` to their names, {class}`~snakebids.BidsDataset` also has a {attr}`~snakebids.BidsDataset.layout` member which gives access to the underlying {class}`BIDSLayout <bids.layout.BIDSLayout>`. This can be used to access advanced pybids features not covered by `snakebids`. Note that if `custom_paths` are specified for every {class}`BidsComponent <snakebids.BidsComponent>`, pybids indexing will be skipped and `layout` will be set to `None`. If your workflow relies on accessing this `layout`, you must ensure your users do not provide a `custom_path` for every single component, either in the config file or [via the CLI](/running_snakebids/overview) (``--path_{component}``). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
(running overview)= | ||
|
||
Overview | ||
======== | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,48 @@ | ||
import snakebids | ||
from snakebids import bids | ||
from snakebids import bids, generate_inputs | ||
|
||
configfile: 'config.yml' | ||
|
||
config.update( | ||
snakebids.generate_inputs( | ||
bids_dir=config['bids_dir'], | ||
pybids_inputs=config['pybids_inputs'], | ||
) | ||
inputs = generate_inputs( | ||
bids_dir=config['bids_dir'], | ||
pybids_inputs=config['pybids_inputs'], | ||
use_bids_inputs=True, | ||
) | ||
|
||
import pprint | ||
pprint.pp(config) | ||
print(inputs) | ||
|
||
rule all: | ||
input: | ||
expand(bids(root='results', | ||
expand( | ||
bids(root='results', | ||
subject='{subject}', | ||
task='{task}', | ||
run='{run}', | ||
fwhm='{fwhm}', | ||
suffix='bold.nii.gz'), | ||
subject=config['subjects'], | ||
task=config['tasks'], | ||
run=config['runs'], | ||
fwhm=config['fwhm']) | ||
suffix='bold.nii.gz' | ||
), | ||
subject=config['subjects'], | ||
task=config['tasks'], | ||
run=config['runs'], | ||
fwhm=config['fwhm'] | ||
) | ||
|
||
|
||
def calc_sigma_from_fwhm(wildcards): | ||
return f'{float(wildcards.fwhm)/2.355:0.2f}' | ||
|
||
rule smooth: | ||
input: | ||
config['path']['bold'] | ||
inputs['bold'].path | ||
params: | ||
sigma = calc_sigma_from_fwhm | ||
output: | ||
bids(root='results', | ||
subject='{subject}', | ||
task='{task}', | ||
run='{run}', | ||
fwhm='{fwhm}', | ||
suffix='bold.nii.gz') | ||
bids( | ||
root='results', | ||
subject='{subject}', | ||
task='{task}', | ||
run='{run}', | ||
fwhm='{fwhm}', | ||
suffix='bold.nii.gz' | ||
) | ||
shell: | ||
'fslmaths {input} -s {params.sigma} {output}' |
Oops, something went wrong.