Skip to content
Merged
43 changes: 22 additions & 21 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ jobs:
keys:
- my_cache
- run:
name: Get ds001734
name: Get ds000001
command: |
# Git set up: to keep datalad warnings away
git config --global --add user.name "Ford Escort"
git config --global --add user.email 42@H2G2.com
mkdir -p ${HOME}/data/
datalad install -s ///openneuro/ds001734 ${HOME}/data/ds001734
datalad install -s ///openneuro-derivatives/ds001734-fmriprep ${HOME}/data/ds001734-fmriprep
cd ${HOME}/data/ds001734-fmriprep/
datalad get sub-00[1-2]/anat/*MNI152NLin2009cAsym*mask.nii.gz \
sub-00[1-2]/anat/*MNI152NLin2009cAsym*T1w.nii.gz \
sub-00[1-2]/func/*MNI152NLin2009cAsym*desc-preproc*bold.nii.gz \
datalad install -s ///openneuro/ds000001 ${HOME}/data/ds000001
datalad install -s ///openneuro-derivatives/ds000001-fmriprep ${HOME}/data/ds000001-fmriprep
cd ${HOME}/data/ds000001-fmriprep/
datalad get sub-0[1-2]/anat/*MNI*mask.nii.gz \
sub-0[1-2]/anat/*MNI*T1w.nii.gz \
sub-0[1-2]/func/*MNI*desc-preproc*bold.nii.gz \
sub-*/func/*tsv \
sub-*/func/*json
sub-*/func/*json -J 12
datalad status
- save_cache:
key: my_cache
Expand All @@ -71,8 +71,8 @@ jobs:
- persist_to_workspace:
root: /home/circleci
paths:
- data/ds001734
- data/ds001734-fmriprep
- data/ds000001
- data/ds000001-fmriprep

test:
machine:
Expand All @@ -83,15 +83,15 @@ jobs:
at: /tmp/workspace
- run: docker load -i /tmp/workspace/docker/image.tar

- run: mkdir -p ${HOME}/outputs/ds001734/derivatives
- run: mkdir -p ${HOME}/outputs/ds000001/derivatives

- run:
name: print version
command: |
user_name=cpplab
repo_name=$(echo "${CIRCLE_PROJECT_REPONAME}" | tr '[:upper:]' '[:lower:]')
docker run -ti --rm \
-v /tmp/workspace/data/ds001734:/bids_dataset \
-v /tmp/workspace/data/ds000001:/bids_dataset \
${user_name}/${repo_name} --version

- run:
Expand All @@ -100,15 +100,15 @@ jobs:
user_name=cpplab
repo_name=$(echo "${CIRCLE_PROJECT_REPONAME}" | tr '[:upper:]' '[:lower:]')
docker run -ti --rm \
-v /tmp/workspace/data/ds001734-fmriprep:/bids_dataset \
-v /tmp/workspace/data/ds000001-fmriprep:/bids_dataset \
-v ${HOME}/outputs:/outputs \
${user_name}/${repo_name} \
/bids_dataset \
/outputs/ds001734 \
/outputs/ds000001 \
subject \
--action smooth \
--task MGT \
--participant_label 001 002 \
--task balloonanalogrisktask \
--participant_label 01 02 \
--space MNI152NLin2009cAsym \
--fwhm 8 \
--verbosity 2
Expand All @@ -123,20 +123,21 @@ jobs:
user_name=cpplab
repo_name=$(echo "${CIRCLE_PROJECT_REPONAME}" | tr '[:upper:]' '[:lower:]')
docker run -ti --rm \
-v /tmp/workspace/data/ds001734:/bids_dataset \
-v /tmp/workspace/data/ds000001:/bids_dataset \
-v ${HOME}/outputs:/outputs \
-v ~/project/demos/openneuro/models:/models \
${user_name}/${repo_name} \
/bids_dataset \
/outputs/ds001734 \
/outputs/ds000001 \
subject \
--action stats \
--preproc_dir /outputs/ds001734/derivatives/bidspm-preproc \
--model_file /models/model-narps_desc-U26C_smdl.json \
--preproc_dir /outputs/ds000001/derivatives/bidspm-preproc \
--model_file /models/model-balloonanalogrisktaskDefault_smdl.json \
--ignore slicetiming \
--space MNI152NLin2009cAsym \
--skip_validation \
--fwhm 8 \
--participant_label 001 002 \
--participant_label 01 02 \
--verbosity 2
no_output_timeout: 6h

Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* [REF] Refactor and update CLI (#1096) @Remi-Gau
* [REF] Refactor and update CLI in #1096 @Remi-Gau

### Deprecated

### Removed

* [REF] Remove old CLI (#1096) @Remi-Gau
* [REF] Remove old CLI in #1096 @Remi-Gau

### Fixed

* [INFRA] copy `RepetitionTime` in sidecar JSON after running smoothing in #1099 by @Remi-Gau

### Security


Expand Down
8 changes: 3 additions & 5 deletions bidspm.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
else
bugReport(opt, ME);
end
returnCode = 1;
rethrow(ME);
end
end

function returnCode = executeAction(varargin)

returnCode = 0;

action = varargin{1};

returnCode = 0;

switch lower(action)

case 'init'
Expand Down Expand Up @@ -278,8 +278,6 @@ function uninitBidspm()

% (C) Copyright 2019 bidspm developers

% Elapsed time is 284 seconds.

tic;

bidspm('action', 'dev');
Expand Down
29 changes: 16 additions & 13 deletions demos/MoAE/moae_fmriprep.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,37 @@
addpath(fullfile(pwd, '..', '..'));
bidspm();

% Getting the raw dataset to get the events.tsv
download_data = true;
smooth = true;

% Getting the raw dataset to get the events.tsv
download_moae_ds(download_data);

%%
subject_label = {'01'};
task = {'auditory'};
space = {'MNI152NLin6Asym'};

%% Copy and smooth
%
% fmriprep data is not smoothed so we need to do that first
%

WD = fileparts(mfilename('fullpath'));

bids_dir = fullfile(WD, 'inputs', 'raw');
fmriprep_dir = fullfile(WD, 'inputs', 'fmriprep');

% we need to specify where the smoothed data will go
output_dir = fullfile(WD, 'outputs', 'derivatives');

bidspm(fmriprep_dir, output_dir, 'subject', ...
'action', 'smooth', ...
'participant_label', subject_label, ...
'task', task, ...
'space', space, ...
'fwhm', 8);
%% Copy and smooth
%
% fmriprep data is not smoothed so we need to do that first
%

if smooth
bidspm(fmriprep_dir, output_dir, 'subject', ...
'action', 'smooth', ...
'participant_label', subject_label, ...
'task', task, ...
'space', space, ...
'fwhm', 8);
end

%% STATS

Expand Down
3 changes: 2 additions & 1 deletion demos/openneuro/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ data_ds000001:
cd inputs/ds000001 && datalad get sub-0[123] -J 3
cd inputs/ds000001-fmriprep && datalad get sub-0[123]/func/*tsv -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[123]/func/*json -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[123]/func/*MNI*desc-*AROMA*bold.nii.gz -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[123]/func/*MNI*desc-*bold.nii.gz -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[123]/anat/*MNI*desc-preproc*.nii.gz -J 12


data_ds000114:
Expand Down
2 changes: 2 additions & 0 deletions demos/openneuro/ds000001_run.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
'action', 'stats', ...
'participant_label', participant_label(i_participant), ...
'preproc_dir', preproc_dir, ...
'space', {'IXI549Space'}, ...
'model_file', model_file);
end

%% dataset level
bidspm(bids_dir, output_dir, 'dataset', ...
'action', 'stats', ...
'preproc_dir', preproc_dir, ...
'space', {'IXI549Space'}, ...
'model_file', model_file);
46 changes: 46 additions & 0 deletions demos/openneuro/ds000001_smooth_run.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
% (C) Copyright 2020 bidspm developers
%
% shows how to smooth files from fmriprep to run a first level
%

clear;
clc;

SMOOTH = true;

addpath(fullfile(pwd, '..', '..'));
bidspm();

% The directory where the data are located
root_dir = fileparts(mfilename('fullpath'));
bids_dir = fullfile(root_dir, 'inputs', 'ds000001');
fmriprep_dir = fullfile(root_dir, 'inputs', 'ds000001-fmriprep');
output_dir = fullfile(root_dir, 'outputs', 'ds000001', 'derivatives');

participant_label = {'02', '03'};
task = {'balloonanalogrisktask'};
space = {'MNI152NLin2009cAsym'};

%% Copy preprocessed data
if SMOOTH
bidspm(fmriprep_dir, output_dir, 'subject', ...
'action', 'smooth', ...
'participant_label', participant_label, ...
'task', task, ...
'space', space, ...
'verbosity', 3);
end

%% Stats
preproc_dir = fullfile(root_dir, 'outputs', 'ds000001', 'derivatives', 'bidspm-preproc');

model_file = fullfile(root_dir, 'models', 'model-balloonanalogrisktaskDefault_smdl.json');

%% subject level
bidspm(bids_dir, output_dir, 'subject', ...
'action', 'stats', ...
'participant_label', participant_label, ...
'preproc_dir', preproc_dir, ...
'task', task, ...
'space', space, ...
'model_file', model_file);
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"Input": {
"task": [
"balloonanalogrisktask"
],
"space": [
"IXI549Space"
]
},
"Nodes": [
Expand Down
5 changes: 3 additions & 2 deletions src/IO/saveAndRunWorkflow.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function status = saveAndRunWorkflow(matlabbatch, batchName, opt, subLabel)
function [status, output] = saveAndRunWorkflow(matlabbatch, batchName, opt, subLabel)
%
% Saves the SPM matlabbatch and runs it
%
Expand Down Expand Up @@ -28,13 +28,14 @@
end

status = true;
output = {};

if ~isempty(matlabbatch)

saveMatlabBatch(matlabbatch, batchName, opt, subLabel);

if ~opt.dryRun
spm_jobman('run', matlabbatch);
output = spm_jobman('run', matlabbatch);
else
status = false;
end
Expand Down
29 changes: 22 additions & 7 deletions src/batches/preproc/setBatchSmoothingFunc.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function matlabbatch = setBatchSmoothingFunc(matlabbatch, BIDS, opt, subLabel)
function [matlabbatch, allRT] = setBatchSmoothingFunc(matlabbatch, BIDS, opt, subLabel)
%
% Creates a batch to smooth the bold files of a subject
%
Expand Down Expand Up @@ -42,24 +42,38 @@
[sessions, nbSessions] = getInfo(BIDS, subLabel, opt, 'Sessions');

allFiles = [];
allRT = [];

for iSes = 1:nbSessions

[runs, nbRuns] = getInfo(BIDS, subLabel, opt, 'Runs', sessions{iSes});

for iRun = 1:nbRuns

[fileName, subFuncDataDir] = getBoldFilename(BIDS, ...
subLabel, sessions{iSes}, runs{iRun}, opt);
[fileName, subFuncDataDir, metadata] = getBoldFilename(BIDS, ...
subLabel, ...
sessions{iSes}, ...
runs{iRun}, ...
opt);
if isstruct(metadata)
metadata = {metadata};
end

% TODO remove this extra check
for iFile = 1:size(fileName, 1)
files{iFile, 1} = validationInputFile(subFuncDataDir(iFile, :), fileName(iFile, :));
files{iFile, 1} = validationInputFile(subFuncDataDir(iFile, :), ...
fileName(iFile, :)); %#ok<*AGROW>

if isfield(metadata{iFile, 1}, 'RepetitionTime')
allRT = metadata{iFile, 1}.RepetitionTime;
else
allRT = nan;
end

end

% add the files to list
allFilesTemp = cellstr(char(files));
allFiles = [allFiles; allFilesTemp]; %#ok<AGROW>
allFiles = [allFiles; allFilesTemp];

end
end
Expand All @@ -69,6 +83,7 @@
opt, ...
allFiles, ...
opt.fwhm.func, ...
[spm_get_defaults('smooth.prefix'), num2str(opt.fwhm.func)]);
[spm_get_defaults('smooth.prefix'), ...
num2str(opt.fwhm.func)]);

end
9 changes: 8 additions & 1 deletion src/bids/getBoldFilename.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [boldFilename, subFuncDataDir] = getBoldFilename(varargin)
function [boldFilename, subFuncDataDir, metadata] = getBoldFilename(varargin)
%
% Get the filename and the directory of a bold file for a given session /
% run.
Expand Down Expand Up @@ -66,4 +66,11 @@
boldFilename = spm_file(fullPathBoldFilename, 'filename');
subFuncDataDir = spm_file(fullPathBoldFilename, 'path');

metadata = getInfo(BIDS, ...
subLabel, ...
opt, ...
'metadata', ...
sessionID, ...
runID, opt.bidsFilterFile.bold.suffix);

end
Loading