-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathet_concatenateconnectomes.m
83 lines (71 loc) · 2.53 KB
/
et_concatenateconnectomes.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
function et_concatenateconnectomes(fginput,fname, numconcatenate)
% Concatenate connectomes generated by different parameters and algorithms
% to create new candidate set of connectomes.
%
% In Ensemble Tractography, this function will be used to create a new
% candidate Ensemble Tractography Connectome (ETC). The candidate ETC
% should be futher optimized using LiFE.
%
% In this function, we simply concatenate streamlines in each connectome
% (fg structure) to create new connectome as fg file.
%
% The default in this function is including all streamlines to output new connectome files
% (add-them-all).
%
% If you specify the parameter "numconcatenate", you could include a subset
% of streamlines from each connectomes
%
% Reference:
% Takemura, H., Caiafa, C., Wandell, B.A. & Pestilli, F. (under review) Ensemble
% Tractography.
%
% INPUT:
% fginput: Files of connectomes generated by various type of tractography
% algorithms and parameters (.pdb or .mat format)
% fname: File name for output file. (.pdb or .mat format)
% numconcatenate: This variable defines how many streamlines from each
% connectome shold be included into ETC-rand candidate connectomes.
% 1 x N matrix.
%
% (C) Hiromasa Takemura, CiNet HHS/Stanford VISTA Lab 2015
%
%
% EXAMPLE:
% fginput = {'S1_LH_Occipital_curv0p25SPC_cand.mat',
% 'S1_LH_Occipital_curv0p5SPC_cand.mat',
% 'S1_LH_Occipital_curv1SPC_cand.mat',
% 'S1_LH_Occipital_curv2SPC_cand.mat'}
% numconcatenate = [40000 40000 40000 40000];
% fname = 'S1_LH_Occipital_ETCrand_cand.mat';
% et_concatenateconnectomes(fginput, fname, numconcatenate)
% Load fgfile to input;
for i = 1:length(fginput)
fg{i} = fgRead(fginput{i});
end
% Unless specified, add all streamlines into new connectomes.
if notDefined('numconcatenate'),
for k=1:length(fginput)
numconcatenate(k) = length(fg{k}.fibers);
end
else
% Argument checking
if ~length(fginput) == length(numconcatenate)
error('Matrix size of fginput and numnconcatenate should be identical.');
end
end
% Create fg structure
fg_etc = fgCreate;
% Set name for connectome file to save
fg_etc.name = fname;
% Concatenate connectomes
for i = 1:length(fginput)
if i == 1
fg_etc.fibers(1:numconcatenate(i)) = fg{1}.fibers(1:numconcatenate(1));
else
fg_etc.fibers(1+sum(numconcatenate(1:(i-1))):sum(numconcatenate(1:i))) = fg{i}.fibers(1:numconcatenate(i));
end
end
% Transpose dimension of fiber matrix
fg_etc.fibers = transpose(fg_etc.fibers);
% Write file
fgWrite(fg_etc);