Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
52 changed files
with
77 additions
and
2,747,278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.