Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
checking installation
  • Loading branch information
Tanusree Chaudhuri authored and Tanusree Chaudhuri committed Jul 16, 2020
0 parents commit 3969282
Show file tree
Hide file tree
Showing 75 changed files with 2,748,546 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .~lock.manual.odt#
@@ -0,0 +1 @@
,tchaudhuri,PCR15,25.05.2020 17:56,file:///home/tchaudhuri/.config/libreoffice/4;
63 changes: 63 additions & 0 deletions Allen_to_GroupSpace.m
@@ -0,0 +1,63 @@
function Allen_to_GroupSpace(Templates)

% ------ Transformation of ANO to group template space ------ %
global DataDir;
global TemplatesDir;


% 1. Increase resolution of allen templates (TPMs,ANO) to match group template resolution%
MC_change_voxel_size(Templates);

% 2. Register TPMs to group template (Template_6) %
matlabbatch{1}.spm.spatial.coreg.write.ref = cellstr(strcat(DataDir,'Template_6.nii,1'));
matlabbatch{1}.spm.spatial.coreg.write.source = cellstr(Templates);
matlabbatch{1}.spm.spatial.coreg.write.roptions.interp = 0;
matlabbatch{1}.spm.spatial.coreg.write.roptions.wrap = [0 0 0];
matlabbatch{1}.spm.spatial.coreg.write.roptions.mask = 0;
matlabbatch{1}.spm.spatial.coreg.write.roptions.prefix = 'r';

spm_jobman('run',matlabbatch);

% Generate deformation fields (u_* files) %
Registered_Templates = {strcat(TemplatesDir,'r_b1grey.nii,1');strcat(TemplatesDir,'r_b2white.nii,1')};
matlabbatch{1}.spm.tools.dartel.warp1.images = cellstr(Registered_Templates);
matlabbatch{1}.spm.tools.dartel.warp1.settings.rform = 0;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(1).its = 3;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(1).rparam = [4 2 1e-06];
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(1).K = 0;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(1).template = cellstr(strcat(DataDir,'Template_0.nii'));
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(2).its = 3;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(2).rparam = [2 1 1e-06];
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(2).K = 0;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(2).template = cellstr(strcat(DataDir,'Template_1.nii'));
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(3).its = 3;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(3).rparam = [1 0.5 1e-06];
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(3).K = 1;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(3).template = cellstr(strcat(DataDir,'Template_2.nii'));
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(4).its = 3;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(4).rparam = [0.5 0.25 1e-06];
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(4).K = 2;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(4).template = cellstr(strcat(DataDir,'Template_3.nii'));
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(5).its = 3;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(5).rparam = [0.25 0.125 1e-06];
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(5).K = 4;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(5).template = cellstr(strcat(DataDir,'Template_4.nii'));
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(6).its = 3;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(6).rparam = [0.25 0.125 1e-06];
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(6).K = 6;
matlabbatch{1}.spm.tools.dartel.warp1.settings.param(6).template = cellstr(strcat(DataDir,'Template_6.nii'));
matlabbatch{1}.spm.tools.dartel.warp1.settings.optim.lmreg = 0.01;
matlabbatch{1}.spm.tools.dartel.warp1.settings.optim.cyc = 3;
matlabbatch{1}.spm.tools.dartel.warp1.settings.optim.its = 3;

spm_jobman('run',matlabbatch);

% 3. Normalise registered TPMs & ANO to group template space %
matlabbatch{1}.spm.tools.dartel.crt_warped.flowfields = cellstr(strcat(TemplatesDir,'u_r_b1grey.nii'));
TemplatesToWarp = {strcat(TemplatesDir,'r_b1grey.nii,1'); strcat(TemplatesDir,'r_b2white.nii,1');strcat(TemplatesDir,'ANO.nii')};
matlabbatch{1}.spm.tools.dartel.crt_warped.images = cellstr(TemplatesToWarp);
matlabbatch{1}.spm.tools.dartel.crt_warped.jactransf = 0;
matlabbatch{1}.spm.tools.dartel.crt_warped.K = 6;
matlabbatch{1}.spm.tools.dartel.crt_warped.interp = 0;

spm_jobman('run',matlabbatch);
33 changes: 33 additions & 0 deletions BrAt_ComputeAreaSize.m
@@ -0,0 +1,33 @@
function idxLUT = BrAt_ComputeAreaSize(idxLUT,ANO,FIBT)

iio = find(ANO>0);
F = sparse(ANO(iio),ones(length(iio),1),ones(length(iio),1));
idx = find(F>0);
sz = full(F(idx));
for k = 1:length(idx),
%iii = find(idx(k) == [idxLUT.id]);
%idxLUT(iii).voxsz = sz(k);
idxLUT(idx(k) == [idxLUT.id]).voxsz = sz(k);
end

iio = find(FIBT>0);
F = sparse(FIBT(iio),ones(length(iio),1),ones(length(iio),1));
idx = find(F>0);
sz = full(F(idx));
for k = 1:length(idx),
%iii = find(idx(k) == [idxLUT.id]);
%idxLUT(iii).voxsz = sz(k);
idxLUT(idx(k) == [idxLUT.id]).voxsz = sz(k);
end

voxsz = zeros(1,length(idxLUT));
for k = 1:length(idxLUT)
if isempty(idxLUT(k).voxsz)
[common, ia, ib] = intersect([idxLUT.id],idxLUT(k).children);
if not(isempty(ia))
voxsz = sum([idxLUT(ia).voxsz]);
idxLUT(k).voxsz = voxsz;
end
end
end
end
5 changes: 5 additions & 0 deletions CheckSubset.m
@@ -0,0 +1,5 @@
function isSubset = CheckSubset(brain_region,ClusterLeaf)
Int_region = annotation_tan(brain_region);
Int_ClusterLeaf = annotation_tan(ClusterLeaf);
isSubset = all(ismember(Int_ClusterLeaf,Int_region));
end
29 changes: 29 additions & 0 deletions ClusterLeafPath.m
@@ -0,0 +1,29 @@
%function NamesOfClusterConstituents = ClusterLeafPath(NamesOfClusterConstituents,tree,ClusterLeaf,decValue)
function single_path = ClusterLeafPath(tree,ClusterLeaf)

% --Path of cluster leaf-- %
% load TREE
[table idxLUT] = buildtable(tree);
cluster_const = {};
paths_in_brain = {};

for c = 1:length(table)

paths_in_brain{end + 1} = extractfield(table{c,1},'name');
end

for d = 1:length(paths_in_brain)
single_path = paths_in_brain{1,d};

indication_of_presence = find(ismember(single_path,ClusterLeaf));
if(~isempty(indication_of_presence) == 1)
% cluster_const{end + 1} = single_path(end - 1); %% Replace string 'Flocculus' in Cluster_leaves with..
% disp(strcat('ClusterLeaf in path ',num2str(d)));
% disp(single_path);
%NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,single_path(end - decValue));
break;
end

end

end
12 changes: 12 additions & 0 deletions ClusterProportion.m
@@ -0,0 +1,12 @@
function NamesOfClusterConstituents = ClusterProportion(tree,brain_region, decValue,NamesOfClusterConstituents)
for z = 2:length(NamesOfClusterConstituents)
ClusterLeaf = NamesOfClusterConstituents{z,1};
isSubset = CheckSubset(brain_region,ClusterLeaf);

if(isSubset == 1)
NamesOfClusterConstituents = ClusterLeafPath(NamesOfClusterConstituents,tree,ClusterLeaf,decValue);
end

end
end

224 changes: 224 additions & 0 deletions ClusterProportionInPercentages.m
@@ -0,0 +1,224 @@
function combinedtxt = ClusterProportionInPercentages(TemplatesDir,CC,img_cluster)


% ---------- Annotation Template ------------ %
AnnotatedAllenBrain = spm_vol(strcat(TemplatesDir,'/','wANO.nii'));
AnnotatedAllenBrain = spm_read_vols(AnnotatedAllenBrain);
ClusterIntensitiesArr = AnnotatedAllenBrain(CC.PixelIdxList{1,img_cluster});
% ---------- Allen table ------------ %
ANO = readtable(strcat(TemplatesDir,'/ANO.xlsx'));
Region = table2array(ANO(:,1));
ID = table2array(ANO(:,4));
ID = ID';

Region_index = {};
Labels = {};
ClusterLabels = {};
for i = 1:length(ClusterIntensitiesArr)
Region_index{end + 1} = find(ID == ClusterIntensitiesArr(i));

Labels{end + 1} = Region(Region_index{end});

if(isempty(Labels{i}) == 0)
ClusterLabels{end + 1} = Labels{1,i}{1,1};

% ----- DISPLAY RESULTS ----- %

%x = cell2mat(ClusterConstituents(:,2));
x = tabulate(ClusterLabels);
x2 = cell2mat(x(:,2));
p = pie(x2);
% Get the percent contributions for each pie slice from the String
% properties of the text objects.Then, specify the text that you want in the cell array txt. Concatenate the text with the associated percent values in the cell array combinedtxt.
pText = findobj(p,'Type','text');
percentValues = get(pText,'String');
NamesOfClusterConstituents = x(:,1);
txt = strcat(NamesOfClusterConstituents,': ');
combinedtxt = strcat(txt,percentValues);
else

combinedtxt = cellstr('cluster intensities not present in the annotation template');

end
end







%% ----- Old Allen Table ---- %

%load TREE
%[table idxLUT] = buildtable(allen_brain_tree);
%ID = extractfield(idxLUT,'id');
%ID = ID';
%Region = extractfield(idxLUT,'name');
%Region = Region';

% --------------------------- %


%%

% %%%%%%%%% ------ Old Allen table --------%%%%%%%%%
% [table idxLUT] = buildtable(allen_brain_tree);
% RegionsHierarchyOfAllenBrain = extractfield(idxLUT,'nameinlist')';
% ID = {};
% for j = 1:length(idxLUT)
% ID{end + 1} = extractfield(idxLUT(j),'children');
% end
% ID = ID';
% %%%%%%%%% ----------------------------- %%%%%%%%%%%%%
%
%
% % ------ Cluster Known Constituents.------ %
% ClusterKnownConstituents = {};
% for k = 1:length(ClusterIntensitiesArr)
% for l = 1:length(ID)
% idx = find(ID{l,1} == ClusterIntensitiesArr(k));
% if(isempty(idx) == 0)
% ClusterKnownConstituents{end + 1} = RegionsHierarchyOfAllenBrain{l,1};
% end
% end
% end
% ClusterKnownConstituents = ClusterKnownConstituents';
% % save(strcat('Paths_',ClusterMasks_files{1,i}),'ClusterKnownConstituents');
%
% % --Proportion of cluster constituents in voxels-- %
% ClusterSizeInVoxels = length(ClusterIntensitiesArr);
% hierarchy = ClusterKnownConstituents;
% idx_nodes = Nodes_Idx(hierarchy);
% KnownCluster_SizeInVoxels = length(idx_nodes{1,1});
% UnknownCluster_SizeInVoxels = ClusterSizeInVoxels - KnownCluster_SizeInVoxels;
%
% % --Names of Cluster Leaves-- %%
% root_idx = idx_nodes{1,1};
% leaves_idx = [];
% for m=2:length(root_idx)
% leaves_idx(end + 1) = root_idx(m)-1;
% end
% Cluster_leaves = hierarchy(leaves_idx);
% Cluster_leaves = strip(Cluster_leaves,'left','-');
%
% name = 'Unknown';
% [ClusterUnknown{1:UnknownCluster_SizeInVoxels(1),1}] = deal(name);
% SizeOfClusterUnknown = size(ClusterUnknown);
% % disp(strcat('Size of unknown: ',num2str(SizeOfClusterUnknown)));
% % ClusterUnknown = ClusterUnknown';
% ClusterKnown = Cluster_leaves;
% ClusterConstituents = [ClusterUnknown;ClusterKnown];
% ClusterConstituents = tabulate(ClusterConstituents);
% NamesOfClusterConstituents = ClusterConstituents(:,1);
%
% for z = 2:length(NamesOfClusterConstituents)
% ClusterLeaf = NamesOfClusterConstituents{z,1};
%
% isSubset_Cerebrum = CheckSubset('Cerebrum',ClusterLeaf);
% isSubset_BrainStem = CheckSubset('Brain stem',ClusterLeaf);
% isSubset_Cerebellum = CheckSubset('Cerebellum',ClusterLeaf);
% if(isSubset_Cerebrum == 1)
% isSubset_Isocortex = CheckSubset('Isocortex',ClusterLeaf);
% isSubset_OLF = CheckSubset('Olfactory areas',ClusterLeaf);
% isSubset_HPF = CheckSubset('Hippocampal formation',ClusterLeaf);
% if(isSubset_Isocortex == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 1));
% end
%
% if(isSubset_OLF == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 1));
% end
%
%
% if(isSubset_HPF == 1)
% isSubset_HIP = CheckSubset('Hippocampal region',ClusterLeaf);
% isSubset_RHP = CheckSubset('Retrohippocampal region',ClusterLeaf);
% if(isSubset_HIP == 1)
% isSubset_FC = CheckSubset('Fasciola cinerea',ClusterLeaf);
% isSubset_IG = CheckSubset('Induseum griseum',ClusterLeaf);
% if((isSubset_FC == 1) || (isSubset_IG == 1))
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 0));
% else
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 1));
% end
% end
% if(isSubset_RHP == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 1));
% end
%
% end
%
% isSubset_CTXsp = CheckSubset('Cortical subplate',ClusterLeaf);
% if(isSubset_CTXsp == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 0));
% end
%
% isSubset_CNU = CheckSubset('Cerebral nuclei',ClusterLeaf);
% if(isSubset_CNU == 1)
% isSubset_CNU = CheckSubset('Olfactory tubercle',ClusterLeaf);
% if(isSubset_CNU == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 1));
% else
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 0));
% end
% end
% end
%
% if(isSubset_BrainStem == 1)
% isSubset_TH = CheckSubset('Thalamus',ClusterLeaf);
% isSubset_HY = CheckSubset('Hypothalamus',ClusterLeaf);
% isSubset_MB = CheckSubset('Midbrain',ClusterLeaf);
% isSubset_HB = CheckSubset('Hindbrain',ClusterLeaf);
%
% if(isSubset_TH == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 0));
% end
% % if(isSubset_HY == 1)
% %
% % end
% if(isSubset_MB == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 0));
% end
% if(isSubset_HB == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(end - 0));
% end
% end
%
% if(isSubset_Cerebellum == 1)
% isSubset_VERM = CheckSubset('Vermal regions',ClusterLeaf);
% isSubset_HEM = CheckSubset('Hemispheric regions',ClusterLeaf);
% isSubset_CBN = CheckSubset('Cerebellar nuclei',ClusterLeaf);
% if(isSubset_VERM == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% VERM_id = find(contains(Path,'Vermal regions'));
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(VERM_id + 1));
% end
% if(isSubset_HEM == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% HEM_id = find(contains(Path,'Hemispheric regions'));
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(HEM_id + 1));
% end
% if(isSubset_CBN == 1)
% Path = ClusterLeafPath(tree,ClusterLeaf);
% CBN_id = find(contains(Path,'Cerebellar nuclei'));
% NamesOfClusterConstituents = strrep(NamesOfClusterConstituents,ClusterLeaf,Path(CBN_id + 1));
% end
% end
% end
% ClusterConstituents(:,1) = NamesOfClusterConstituents;
%
%
%

0 comments on commit 3969282

Please sign in to comment.