ImmuneDynamics / Spectre

A computational toolkit in R for the integration, exploration, and analysis of high-dimensional single-cell cytometry and imaging data.
https://immunedynamics.github.io/spectre/
MIT License
56 stars 21 forks source link

transpose = T/F in make.pheatmap() produced inconsistent results #140

Open denvercal1234GitHub opened 1 year ago

denvercal1234GitHub commented 1 year ago

Hi there,

Thank you for the package.

When I plotted the same data and markers but with transpose=T or transpose = F, the expression for markers per cluster were different. For example, cluster 5 showed much more expression for more markers compared to that shown for cluster 5 when transpose = T.

Would you mind helping me clarify potential source of this inconsistency?

Note I used only a few markers in run.flowsom(), but I set use.cols in make.pheatmap and do.aggregate = to all cellular markers because I want to visualize the median expression of all markers and not only markers that were used in the clustering.

Thank you again.

exp_all_cellular.cols <- do.aggregate(F33_data.list_cell.dat_runflowsom_cellular.cols, use.cols=all_cellular.cols, by = "FlowSOM_metacluster")

make.pheatmap(exp_all_cellular.cols, "FlowSOM_metacluster", plot.cols = all_cellular.cols, transpose = F)

make.pheatmap(exp_all_cellular.cols, "FlowSOM_metacluster", plot.cols = all_cellular.cols, transpose = T)
Screenshot 2022-10-20 at 00 36 47 Screenshot 2022-10-20 at 00 37 02
ghar1821 commented 1 year ago

It may have been due to the normalisation function applied to each column. By default, normalise parameter is set to TRUE, which I think transform the values between the range of 0 to 1 based on the min and max value in each column: x_ij=(x_ij-min(col_i) / (max(col_i) - min(col_i)) for cell j's marker i. When transforming, the columns and rows are swapped, which caused the min and max values to be different. Perhaps try setting normalise to FALSE?

tomashhurst commented 1 year ago

@ghar1821 spot on! @denvercal1234GitHub normalisation will run on the columns, regardless of whether it has been transposed or not.

denvercal1234GitHub commented 1 year ago

Thank you @tomashhurst and @ghar1821! I am confused. Would you mind clarifying whether the below statement is accurate?

Q1. If transpose = T, normalise=T, then does it mean the marker expression in the heatmap are first aggregated within a cluster with do.aggregate (with default parameters), then expression of each marker is normalised between 0-1 within each cluster?

Q2. Does transpose happens first or normalise happens first?