Skip to content

Commit

Permalink
n3d fixed. apicoBasalNeighbours replacing lateralSides
Browse files Browse the repository at this point in the history
  • Loading branch information
pedgomgal1 committed Nov 11, 2021
1 parent 21604a3 commit 7e59f3d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
5 changes: 2 additions & 3 deletions lib/featuresExtraction/calculate3DMorphologicalFeatures.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions lib/featuresExtraction/calculate_CellularFeatures.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
11 changes: 2 additions & 9 deletions lib/featuresExtraction/obtain3DFeatures.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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

13 changes: 3 additions & 10 deletions lib/featuresExtraction/summarizeAllTissuesProperties.m
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
function summarizeAllTissuesProperties(allGeneralInfo,allTissues,allLumens,allHollowTissue3dFeatures,allNetworkFeatures,totalMeanCellsFeatures,totalStdCellsFeatures,path2save)


allGeneralInfo = vertcat(allGeneralInfo{:});
allTissues = vertcat(allTissues{:});
allLumens = vertcat(allLumens{:});
allHollowTissue3dFeatures = vertcat(allHollowTissue3dFeatures{:});
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');
%%Polygon distribtutions
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

0 comments on commit 7e59f3d

Please sign in to comment.