-
Notifications
You must be signed in to change notification settings - Fork 5
/
bsc_GenROIfromPairStringList_BL.m
83 lines (75 loc) · 2.89 KB
/
bsc_GenROIfromPairStringList_BL.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function bsc_GenROIfromPairStringList_BL()
% bsc_genNiftiROIfromStringList(feORwbfg,atlas,ROIstring, smoothKernel)
%
% Given a string list of rois (in the specified format) loops over
% the list and generates nifti ROI files for each
%
% INPUTS:
% -feORwbfg: either a string or an object, to either a wbFG or an FE
% structure
%
% -atlas: path to an atlas or an atlas.
%
% -ROIstring: a string list of atlas based roi specifications from the
% atlas that you would like merged into a single ROI. eg: '2 56 30 54; 34
% 654 \n 25 45 56; 23 \n 456 34; 35 75'. Must correspond to the values in
% the atlas nifti itself.
%
% OUTPUTS:
% -classification:
% The strucure has a field "names" with (N) names of the tracts classified
% while the field "indexes" has a j long vector (where j = the nubmer of
% streamlines in wbFG (i.e. length(wbFG.fibers)). This j long vector has
% a 0 for to indicate a streamline has gone unclassified, or a number 1:N
% indicatate that the streamline has been classified as a member of tract
% (N).
%
% NOTE: Makes a call to mri_convert, so requires that FreeSurfer be
% installed and set up properly.
%
% (C) Daniel Bullock 2018 Bloomington, Indiana
%% Begin code
if ~isdeployed
disp('adding paths');
addpath(genpath('/N/soft/rhel7/spm/8')) %spm needs to be loaded before vistasoft as vistasoft provides anmean that works
addpath(genpath('/N/u/brlife/git/jsonlab'))
addpath(genpath('/N/u/brlife/git/vistasoft'))
addpath(genpath('/N/u/brlife/git/wma_tools'))
end
%config = loadjson('/N/dc2/projects/lifebid/HCP/Dan/GitStoreDir/ROIs2ROIsSegment/config.json');
config = loadjson('config.json')
ROIstring=config.roiPairs;
smoothKernel=config.smoothKernel;
if isfield(config,'atlas')
atlas=config.atlas
end
if isfield(config,'ROI')
ROIdir=config.ROI
end
%% gen ROI
fprintf('Generating ROIs for the following indicies: \n %s',ROIstring);
%just in case
ROIstring=strrep(ROIstring,'\n',newline);
ROIstring=strrep(ROIstring,';',newline);
stringCells = splitlines(ROIstring);
mkdir('roi/')
for iROIs=1:length(stringCells)
ROInums=str2num(stringCells{iROIs});
%% run the merge roi function
if ~notDefined('atlas')
mergedROI =bsc_roiFromAtlasNums(atlas,ROInums, smoothKernel);
currROIName=fullfile(pwd,strcat('/roi/ROI',num2str(iROIs),'.nii.gz'));
[~, ~]=dtiRoiNiftiFromMat (mergedROI,atlas,currROIName,1);
elseif ~notDefined('ROIdir')
for iROInums=1:length(ROInums)
niiPaths{iROInums}=strcat(ROIdir,'ROI',num2str(ROInums(iROInums)),'.nii.gz');
end
if length(ROInums)>1
mergedROI = niftiMerge(niiPaths, strcat('rois/ROI',strrep(num2str(ROInums),' ','_'),'.nii.gz'));
end
currROIName=fullfile(pwd,strcat('/roi/ROI',num2str(iROIs),'.nii.gz'));
fprintf('\n saving %s',currROIName)
niftiWrite(mergedROI,currROIName)
end
end
end