From 7e59f3d0169bdf89b91cc2a790a3548d6715661e Mon Sep 17 00:00:00 2001 From: pedgomgal1 Date: Thu, 11 Nov 2021 17:18:16 +0100 Subject: [PATCH] n3d fixed. apicoBasalNeighbours replacing lateralSides --- .../calculate3DMorphologicalFeatures.m | 5 ++--- lib/featuresExtraction/calculate_CellularFeatures.m | 8 ++++---- lib/featuresExtraction/obtain3DFeatures.m | 11 ++--------- .../summarizeAllTissuesProperties.m | 13 +++---------- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/lib/featuresExtraction/calculate3DMorphologicalFeatures.m b/lib/featuresExtraction/calculate3DMorphologicalFeatures.m index a35b790..c46ef78 100644 --- a/lib/featuresExtraction/calculate3DMorphologicalFeatures.m +++ b/lib/featuresExtraction/calculate3DMorphologicalFeatures.m @@ -21,8 +21,8 @@ %% Calculate mean and std of 3D features cells3dFeatures((cells3dFeatures.ID_Cell == "Lumen" | cells3dFeatures.ID_Cell == "Tissue and Lumen"),:)=[]; - meanCellsFeatures = varfun(@(x) mean(x),cells3dFeatures(:, 2:end-2)); - stdCellsFeatures = varfun(@(x) std(x),cells3dFeatures(:, 2:end-2)); + meanCellsFeatures = varfun(@(x) mean(x),cells3dFeatures(:, [(2:end-3),end])); + stdCellsFeatures = varfun(@(x) std(x),cells3dFeatures(:, [(2:end-3),end])); % Voxels/Pixels to Micrometers [totalMeanCellsFeatures,totalStdCellsFeatures, tissue3dFeatures, allLumens,allHollowTissue3dFeatures] = convertPixelsToMicrons(meanCellsFeatures,stdCellsFeatures, tissue3dFeatures, lumen3dFeatures,hollowTissue3dFeatures,pixelScale); @@ -32,7 +32,6 @@ save(fullfile(path2save, 'global_3dFeatures.mat'), 'allGeneralInfo', 'totalMeanCellsFeatures','totalStdCellsFeatures', 'allLumens', 'allTissues', 'allNetworkFeatures', 'allHollowTissue3dFeatures'); else - load(fullfile(path2save, 'global_3dFeatures.mat'), 'allGeneralInfo', 'totalMeanCellsFeatures','totalStdCellsFeatures', 'allLumens', 'allTissues', 'allNetworkFeatures', 'allHollowTissue3dFeatures'); end diff --git a/lib/featuresExtraction/calculate_CellularFeatures.m b/lib/featuresExtraction/calculate_CellularFeatures.m index fbb9a23..5383279 100644 --- a/lib/featuresExtraction/calculate_CellularFeatures.m +++ b/lib/featuresExtraction/calculate_CellularFeatures.m @@ -13,7 +13,7 @@ %% Calculate number of neighbours of each cell number_neighbours = table(cellfun(@length,(apical3dInfo)),cellfun(@length,(basal3dInfo)),cellfun(@length,(lateral3dInfo))); - + apicobasal_neighbours=cellfun(@(x,y)(unique(vertcat(x,y))), apical3dInfo, basal3dInfo, 'UniformOutput',false); apicobasal_neighboursRecount= cellfun(@length ,apicobasal_neighbours); @@ -31,9 +31,9 @@ volume_cells=table2array(regionprops3(labelledImage,'Volume')); %% Determine if a cell is a scutoid or not - scutoids_cells=cellfun(@(x,y) double(~isequal(x,y)), neighbours_data.Apical,neighbours_data.Basal); - apicoBasalTransitions = cellfun(@(x, y) length(unique(vertcat(setdiff(x, y), setdiff(y, x)))), neighbours_data.Apical,neighbours_data.Basal); - + apicoBasalTransitions = cellfun(@(x, y) length(unique(vertcat(setdiff(y,x), setdiff(x,y)))), neighbours_data.Apical,neighbours_data.Basal); + scutoids_cells = double(apicoBasalTransitions>0); + %% Calculate cell height cell_heights = calculateCellHeight(apicalLayer, basalLayer); diff --git a/lib/featuresExtraction/obtain3DFeatures.m b/lib/featuresExtraction/obtain3DFeatures.m index cbc9d9f..b0ddf7b 100644 --- a/lib/featuresExtraction/obtain3DFeatures.m +++ b/lib/featuresExtraction/obtain3DFeatures.m @@ -6,8 +6,6 @@ dilatedVx = 4; [lateral3dInfo_total,totalLateralCellsArea,absoluteLateralContacts] = getLateralContacts(lateralLayer,dilatedVx,contactThreshold); - %lateral3dInfo = lateral3dInfo.neighbourhood'; - %% Cellular features [apical3dInfo] = calculateNeighbours3D(apicalLayer, dilatedVx, apicalLayer == 0); apical3dInfo = cellfun(@(x,y) intersect(x,y),lateral3dInfo_total,apical3dInfo.neighbourhood','UniformOutput',false); @@ -26,11 +24,6 @@ lateral3dInfo = lateral3dInfo_total; clearvars lateral3dInfo_total lateralLayerAux end - - %delete non real neighbours assuming lateral contact threshold - apical3dInfo = cellfun(@(x,y) x(ismember(x,y)), apical3dInfo,lateral3dInfo,'UniformOutput',false); - basal3dInfo = cellfun(@(x,y) x(ismember(x,y)), basal3dInfo,lateral3dInfo,'UniformOutput',false); - %check for non considered valid cells, and delete cells "0" volume missingCells = find(totalLateralCellsArea==0); @@ -80,13 +73,13 @@ refactorLateralAreas = cellularFeaturesValidCells.Lateral_area./lateralAreas; cellAreaNeighsInfo = table(cellularFeaturesValidCells.Apical_sides, cellularFeaturesValidCells.Apical_area./refactorApicalAreas,cellularFeaturesValidCells.Basal_sides, cellularFeaturesValidCells.Basal_area./refactorBasalAreas,cellularFeaturesValidCells.Cell_height,cellularFeaturesValidCells.Lateral_sides, cellularFeaturesValidCells.Lateral_area./refactorLateralAreas,cellularFeaturesValidCells.Average_cell_wall_area./refactorLateralAreas,cellularFeaturesValidCells.Std_cell_wall_area./refactorLateralAreas,'VariableNames',{'apical_NumNeighs','apical_Area','basal_NumNeighs','basal_Area','cell_height','lateral_NumNeighs','lateral_Area','average_cell_wall_Area','std_cell_wall_Area'}); - cells3dFeatures = horzcat(cells3dFeatures, cellAreaNeighsInfo,table(cellularFeaturesValidCells.Scutoids, cellularFeaturesValidCells.apicoBasalTransitions,'VariableNames',{'scutoids','apicoBasalTransitions'})); + cells3dFeatures = horzcat(cells3dFeatures, cellAreaNeighsInfo,table(cellularFeaturesValidCells.Scutoids, cellularFeaturesValidCells.apicoBasalTransitions,cellularFeaturesValidCells.Apicobasal_neighbours,'VariableNames',{'scutoids','apicoBasalTransitions','n3d_apicoBasalNeighbours'})); %% Save variables save(fullfile(path2save, 'morphological3dFeatures.mat'), 'cells3dFeatures', 'tissue3dFeatures', 'lumen3dFeatures', 'polygon_distribution_apical', 'polygon_distribution_basal','polygon_distribution_lateral', 'cellularFeaturesValidCells', 'numValidCells','numTotalCells', 'surfaceRatio3D', 'polygon_distribution_lateral','apicoBasalNeighs', 'hollowTissue3dFeatures','apical3dInfo','basal3dInfo','lateral3dInfo'); else - load(fullfile(path2save, 'morphological3dFeatures.mat'), 'cells3dFeatures', 'tissue3dFeatures', 'lumen3dFeatures', 'polygon_distribution_apical', 'polygon_distribution_basal','polygon_distribution_lateral', 'cellularFeaturesValidCells', 'numValidCells','numTotalCells', 'surfaceRatio3D', 'polygon_distribution_lateral','apicoBasalNeighs', 'hollowTissue3dFeatures','apical3dInfo','basal3dInfo','lateral3dInfo'); + load(fullfile(path2save, 'morphological3dFeatures.mat'), 'cells3dFeatures', 'tissue3dFeatures', 'lumen3dFeatures', 'polygon_distribution_apical', 'polygon_distribution_basal','polygon_distribution_lateral', 'cellularFeaturesValidCells', 'numValidCells','numTotalCells', 'surfaceRatio3D', 'polygon_distribution_lateral','apicoBasalNeighs', 'hollowTissue3dFeatures','apical3dInfo','basal3dInfo','lateral3dInfo'); end end diff --git a/lib/featuresExtraction/summarizeAllTissuesProperties.m b/lib/featuresExtraction/summarizeAllTissuesProperties.m index 2ef305b..35fac38 100644 --- a/lib/featuresExtraction/summarizeAllTissuesProperties.m +++ b/lib/featuresExtraction/summarizeAllTissuesProperties.m @@ -1,6 +1,5 @@ function summarizeAllTissuesProperties(allGeneralInfo,allTissues,allLumens,allHollowTissue3dFeatures,allNetworkFeatures,totalMeanCellsFeatures,totalStdCellsFeatures,path2save) - allGeneralInfo = vertcat(allGeneralInfo{:}); allTissues = vertcat(allTissues{:}); allLumens = vertcat(allLumens{:}); @@ -8,19 +7,16 @@ function summarizeAllTissuesProperties(allGeneralInfo,allTissues,allLumens,allHo allNetworkFeatures= vertcat(allNetworkFeatures{:}); totalMeanCellsFeatures = vertcat(totalMeanCellsFeatures{:}); totalStdCellsFeatures = vertcat(totalStdCellsFeatures{:}); - allTissues.Properties.VariableNames = cellfun(@(x) strcat('Tissue_', x), allTissues.Properties.VariableNames, 'UniformOutput', false); allHollowTissue3dFeatures.Properties.VariableNames = cellfun(@(x) strcat('HollowTissue_', x), allHollowTissue3dFeatures.Properties.VariableNames, 'UniformOutput', false); allLumens.Properties.VariableNames = cellfun(@(x) strcat('Lumen_', x), allLumens.Properties.VariableNames, 'UniformOutput', false); totalMeanCellsFeatures.Properties.VariableNames = cellfun(@(x) strcat('AverageCell_', x(5:end)), totalMeanCellsFeatures.Properties.VariableNames, 'UniformOutput', false); totalStdCellsFeatures.Properties.VariableNames = cellfun(@(x) strcat('STDCell_', x(5:end)), totalStdCellsFeatures.Properties.VariableNames, 'UniformOutput', false); - PercentageLumenSpace = table(allLumens.Lumen_Volume./allTissues.Tissue_Volume,'VariableNames',{'PercentageLumenSpace'}); FeaturesPerCell=table(allTissues.Tissue_Volume./allGeneralInfo.NCells_total, allHollowTissue3dFeatures.HollowTissue_Volume./allGeneralInfo.NCells_total, allLumens.Lumen_Volume./allGeneralInfo.NCells_total,'VariableNames',{'TissueVolume_perCell','HollowTissueVolume_perCell','LumenVolume_perCell'}); - %%Global parameters globalFeatures = [allGeneralInfo(:,[1,4,3]),allTissues(:,[4,8]),allHollowTissue3dFeatures(:,2),PercentageLumenSpace(:,1),allGeneralInfo(:,[2,5,6]),allTissues(:,[6,2,5,7,9,11]),FeaturesPerCell,allLumens(:,[6,2,5,7,9,4,8,11]),allHollowTissue3dFeatures(:,[6,7,9,4,8])]; writetable(globalFeatures, [path2save,'global_3dFeatures_' date '.xls'],'Sheet', 'globalFeatures','Range','B2'); @@ -28,14 +24,11 @@ function summarizeAllTissuesProperties(allGeneralInfo,allTissues,allLumens,allHo polDistributions = [allGeneralInfo(:,1),allTissues(:,12:35)]; writetable(polDistributions, [path2save,'global_3dFeatures_' date '.xls'],'Sheet', 'polygonDistributions','Range','B2'); %%Celullar parameters - cellularParameter_mean = [allGeneralInfo(:,1),totalMeanCellsFeatures(:,[12,14,15,17,18,19,1,11,13,16,4,5,6,8,3,7,10]),allNetworkFeatures(:,[1,2])]; + cellularParameter_mean = [allGeneralInfo(:,1),totalMeanCellsFeatures(:,[12,14,15,17,18,19,1,11,13,16,end,4,5,6,8,3,7,10]),allNetworkFeatures(:,[1,2])]; writetable(cellularParameter_mean, [path2save,'global_3dFeatures_' date '.xls'],'Sheet', 'meanCellParameters','Range','B2'); %%Std parameters - cellularParameter_std = [allGeneralInfo(:,1),totalStdCellsFeatures(:,[12,14,15,17,18,19,1,11,13,16,4,5,6,8,3,7,10]),allNetworkFeatures(:,[4,5])]; - writetable(cellularParameter_std, [path2save,'global_3dFeatures_' date '.xls'],'Sheet', 'stdCellParameters','Range','B2'); - - - + cellularParameter_std = [allGeneralInfo(:,1),totalStdCellsFeatures(:,[12,14,15,17,18,19,1,11,13,16,end,4,5,6,8,3,7,10]),allNetworkFeatures(:,[4,5])]; + writetable(cellularParameter_std, [path2save,'global_3dFeatures_' date '.xls'],'Sheet', 'stdCellParameters','Range','B2'); end