Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cluster labelling
  • Loading branch information
Tanusree Chaudhuri authored and Tanusree Chaudhuri committed Jul 27, 2020
1 parent 1b54e18 commit 8251bfc
Show file tree
Hide file tree
Showing 52 changed files with 77 additions and 2,747,278 deletions.
Binary file modified .DS_Store
Binary file not shown.
41 changes: 41 additions & 0 deletions ClusterLabelling.m
@@ -0,0 +1,41 @@

function [ClusterLabels, ClusterParents] = ClusterLabelling(ClusterIntensities,ANO)
Region = table2array(ANO(:,1));
ID = table2array(ANO(:,4));
colHex = table2array(ANO(:,2));
Children = table2array(ANO(:,5));

Region_index = {}; ClusterLabels = {}; ClusterParents = {};
for i = 1:length(ClusterIntensities)

Region_index{end + 1} = find(ID == ClusterIntensities(i));
ClusterLabels{end + 1} = Region(Region_index{end});


% if a cluster label is a leaf continue, else leave the label
% as it is.
ClusterLabel_children = str2num(Children{Region_index{end},1})';

if(isempty(ClusterLabel_children) == 1) % if the label is a leaf, find parent.

dec = 1;
arr = Children{Region_index{end} - dec,1}; arr = str2num(arr);
cond = isempty(find(ismember(arr,ClusterIntensities(i)), 1));
while cond == 1
dec = dec + 1;
arr = Children{Region_index{end} - dec,1};
arr = str2num(arr);
cond = isempty(find(ismember(arr,ClusterIntensities(i)), 1));

end
ClusterParents{end + 1} = Region(Region_index{end} - dec,1);
else % if the label is a parent, leave parent column in output table empty.
ClusterParents{end +1} = [];

end

disp(i);
end

ClusterLabels = ClusterLabels';
end
257 changes: 24 additions & 233 deletions ClusterProportionInPercentages.m
@@ -1,237 +1,28 @@
% function combinedtxt = ClusterProportionInPercentages(TemplatesDir,CC,img_cluster)
function [ClusterLabels, ClusterLabelsPercent] = 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});

% Counts & Percent of unique intensities in Cluster intensities array %
a = ClusterIntensitiesArr;
[C,ia,ic] = unique(a);
a_counts = accumarray(ic,1);
value_counts = [C, a_counts];
value_counts(:,end+1) = (value_counts(:,2)/sum(value_counts(:,2)))*100;
ClusterIntensitiesFreq = value_counts;

ClusterIntensities = ClusterIntensitiesFreq(:,1);
ClusterLabelsPercent = ClusterIntensitiesFreq(:,3);

% ---------- 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(ClusterIntensities)
Region_index{end + 1} = find(ID == ClusterIntensities(i));

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

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



end
function [ClusterLabels,ClusterParents, ClusterLabelsPercent] = 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});

% Counts & Percent of unique intensities in Cluster intensities array %
a = ClusterIntensitiesArr;
[C,ia,ic] = unique(a);
a_counts = accumarray(ic,1);
value_counts = [C, a_counts];
value_counts(:,end+1) = (value_counts(:,2)/sum(value_counts(:,2)))*100;
ClusterIntensitiesFreq = value_counts;

ClusterIntensities = ClusterIntensitiesFreq(:,1);
ClusterIntensities = ClusterIntensities(find(ClusterIntensities));
ClusterLabelsPercent = ClusterIntensitiesFreq(:,3);
ClusterLabelsPercent = ClusterLabelsPercent(find(ClusterIntensities));
while((isempty(ClusterIntensities) == 1) && (isempty(ClusterLabelsPercent) == 1))
break;
end







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

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

% --------------------------- %
ANO = readtable(strcat(TemplatesDir,'/ANO.xlsx'));
[ClusterLabels, ClusterParents] = ClusterLabelling(ClusterIntensities,ANO);


%%

% %%%%%%%%% ------ 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;
%
%
%
% % ----- DISPLAY RESULTS ----- %
%
% %x = cell2mat(ClusterConstituents(:,2));
% % x = tabulate(ClusterLabels);
% ClusterIntensitiesCounts = cell2mat(ClusterIntensitiesFreq(:,2));
% p = pie(ClusterIntensitiesCounts);
% % 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 = ClusterIntensitiesFreq(:,1);
% txt = strcat(NamesOfClusterConstituents,': ');
% combinedtxt = strcat(txt,percentValues);
15 changes: 11 additions & 4 deletions Cluster_Overlap_main.m
Expand Up @@ -37,11 +37,18 @@


for img_cluster = 1:NumberOfClusters

[ClusterLabels,ClusterLabelsPercent] = ClusterProportionInPercentages(TemplatesDir,CC,img_cluster);

[ClusterLabels,ClusterParents,ClusterLabelsPercent] = ClusterProportionInPercentages(TemplatesDir,CC,img_cluster);
if(isempty(ClusterLabels))
Cluster_blob_num = cellstr(repmat(['Cluster',' ',num2str(img_cluster)],[1, 1]));
ClusterLabels{end + 1} = [];
ClusterLabelsPercent = 100;
ClusterParents{end + 1} = [];
end
Cluster_blob_num = cellstr(repmat(['Cluster',' ',num2str(img_cluster)],[length(ClusterLabels) 1]));
ClusterLabels = ClusterLabels';
ClusterImageInfo = table(Cluster_blob_num,ClusterLabels,ClusterLabelsPercent);
ClusterParents = ClusterParents';
ClusterImageInfo = table(Cluster_blob_num,ClusterLabels,ClusterParents,ClusterLabelsPercent);
disp(strcat('Blob','_',num2str(img_cluster),'_','done'));


if(img_cluster == 1)
Expand Down
Binary file removed DetectedRegions_gtm.mat
Binary file not shown.
Binary file removed Int_Isocortex.mat
Binary file not shown.
2 changes: 1 addition & 1 deletion Start_ARET.m
Expand Up @@ -11,7 +11,7 @@

%%

DataDir = strcat(DataDir,'/');
DataDir = strcat(DataDir,'/'); cd(DataDir);
ToolboxDir = strcat(ToolboxDir,'/');
global TemplatesDir;
TemplatesDir = strcat(ToolboxDir,'/','templates');
Expand Down
Binary file removed Striatum ventral region_Mask.nii
Binary file not shown.
Binary file removed WM.nii
Binary file not shown.

0 comments on commit 8251bfc

Please sign in to comment.