drieslab / Giotto

Spatial omics analysis toolbox
https://drieslab.github.io/Giotto_website/
Other
258 stars 98 forks source link

spatPlot2D not recognizing color vector fi select: point shape="voronoi" #141

Closed stefanonard85 closed 2 years ago

stefanonard85 commented 2 years ago

Hello Ruben,

I am contacting you because I have noticed something strange happening when I call spatPlot2D(). Basically I have a vector of colors that I would like to use instead of the default ones. If I select as point shape either "border" or "no_border" the function accept the colors, but if I select "voronoi" it plots only the first color of the list. I am attaching a plot I have generated with default color to show you that data are fine, it is just a banal problem that I do not understand if depend on something wrong i am doing or it is a possible bug

image

Thanks in advance for your help SN

RubD commented 2 years ago

Hi Stefano,

I have been trying to reproduce this bug, but it actually works fine on my end.

Here is a small example you can run in less than a minute. It did use the development version, which has a couple of other bug fixes but is otherwise completely the same as the current version.

remotes::install_github("RubD/Giotto@cless") 
library(Giotto)

temp_dir = '~/Temp/'
myinstructions = createGiottoInstructions(save_dir = temp_dir,
                                          save_plot = FALSE, 
                                          return_plot = TRUE,
                                          show_plot = FALSE)

expr_path = system.file("extdata", "seqfish_field_expr.txt.gz", package = 'Giotto')
loc_path = system.file("extdata", "seqfish_field_locs.txt", package = 'Giotto')
seqfish_mini <- createGiottoObject(raw_exprs = expr_path,
                                   spatial_locs = loc_path,
                                   instructions = myinstructions)

# processing
seqfish_mini <- filterGiotto(gobject = seqfish_mini, 
                             expression_threshold = 0.5, 
                             gene_det_in_min_cells = 20, 
                             min_det_genes_per_cell = 0)
seqfish_mini <- normalizeGiotto(gobject = seqfish_mini, scalefactor = 6000, verbose = T)
seqfish_mini <- addStatistics(gobject = seqfish_mini)
seqfish_mini <- adjustGiottoMatrix(gobject = seqfish_mini, 
                                   expression_values = c('normalized'),
                                   covariate_columns = c('nr_genes', 'total_expr'))

# dimension reduction
seqfish_mini <- calculateHVG(gobject = seqfish_mini)
seqfish_mini <- runPCA(gobject = seqfish_mini)
seqfish_mini <- runUMAP(seqfish_mini, dimensions_to_use = 1:5, n_threads = 2)
seqfish_mini <- createNearestNetwork(gobject = seqfish_mini, dimensions_to_use = 1:5, k = 5)
seqfish_mini <- doLeidenCluster(gobject = seqfish_mini, resolution = 0.4, n_iterations = 1000)

## provide annotation for the leiden identified groups
clusters_cell_types = c('cell A', 'cell B', 'cell C', 'cell D',
                        'cell E', 'cell F', 'cell G', 'cell H')
names(clusters_cell_types) = 1:8
seqfish_mini = annotateGiotto(gobject = seqfish_mini, 
                              annotation_vector = clusters_cell_types, 
                              cluster_column = 'leiden_clus', 
                              name = 'cell_types')

## default colors
spatPlot2D(gobject = seqfish_mini, point_shape = 'border', cell_color = 'cell_types')
spatPlot2D(gobject = seqfish_mini, point_shape = 'no_border', cell_color = 'cell_types')
spatPlot2D(gobject = seqfish_mini, point_shape = 'voronoi', cell_color = 'cell_types')

## identify your own colors
my_color_code = c('blue', 'pink', 'green', 'yellow', 
                  'purple', 'black', 'orange', 'brown')
names(my_color_code) = clusters_cell_types

spatPlot2D(gobject = seqfish_mini, point_shape = 'border', cell_color = 'cell_types', cell_color_code = my_color_code, point_size = 3)
spatPlot2D(gobject = seqfish_mini, point_shape = 'no_border', cell_color = 'cell_types',  cell_color_code = my_color_code, point_size = 3)
spatPlot2D(gobject = seqfish_mini, point_shape = 'voronoi', cell_color = 'cell_types',  cell_color_code = my_color_code)
stefanonard85 commented 2 years ago

Hello Ruben,

Thanks a lot for looking into this. Indeed, it looks very strange. I guess I am doing something wrong and I am not realizing it. Anyway I have installed the new version and I will try to do a voronoi plot following your suggestion. I have actually one question that I think is also relevant for all the Giotto users: is the Giotto object I have created with Giotto compatible with the new version , Giotto Suite? I really appreciated your help. Thanks in advance.

Kind Regards,

Stefano Nardone, PhD

research scientist, Harvard Medical School Beth Israel Deaconess Medical Center Center for Life Sciences, 3 Blackfan Circle, Boston, MA 02115 phone +1 413-695-1678

On Tue, Oct 19, 2021 at 7:58 PM Ruben Dries @.***> wrote:

Hi Stefano,

I have been trying to reproduce this bug, but it actually works fine on my end.

Here is a small example you can run in less than a minute. It did use the development version, which has a couple of other bug fixes but is otherwise completely the same as the current version.

@.***")

library(Giotto)

temp_dir = '~/Temp/' myinstructions = createGiottoInstructions(save_dir = temp_dir, save_plot = FALSE, return_plot = TRUE, show_plot = FALSE)

expr_path = system.file("extdata", "seqfish_field_expr.txt.gz", package = 'Giotto') loc_path = system.file("extdata", "seqfish_field_locs.txt", package = 'Giotto') seqfish_mini <- createGiottoObject(raw_exprs = expr_path, spatial_locs = loc_path, instructions = myinstructions)

processing

seqfish_mini <- filterGiotto(gobject = seqfish_mini, expression_threshold = 0.5, gene_det_in_min_cells = 20, min_det_genes_per_cell = 0) seqfish_mini <- normalizeGiotto(gobject = seqfish_mini, scalefactor = 6000, verbose = T) seqfish_mini <- addStatistics(gobject = seqfish_mini) seqfish_mini <- adjustGiottoMatrix(gobject = seqfish_mini, expression_values = c('normalized'), covariate_columns = c('nr_genes', 'total_expr'))

dimension reduction

seqfish_mini <- calculateHVG(gobject = seqfish_mini) seqfish_mini <- runPCA(gobject = seqfish_mini) seqfish_mini <- runUMAP(seqfish_mini, dimensions_to_use = 1:5, n_threads = 2) seqfish_mini <- createNearestNetwork(gobject = seqfish_mini, dimensions_to_use = 1:5, k = 5) seqfish_mini <- doLeidenCluster(gobject = seqfish_mini, resolution = 0.4, n_iterations = 1000)

provide annotation for the leiden identified groups

clusters_cell_types = c('cell A', 'cell B', 'cell C', 'cell D', 'cell E', 'cell F', 'cell G', 'cell H') names(clusters_cell_types) = 1:8 seqfish_mini = annotateGiotto(gobject = seqfish_mini, annotation_vector = clusters_cell_types, cluster_column = 'leiden_clus', name = 'cell_types')

default colors

spatPlot2D(gobject = seqfish_mini, point_shape = 'border', cell_color = 'cell_types') spatPlot2D(gobject = seqfish_mini, point_shape = 'no_border', cell_color = 'cell_types') spatPlot2D(gobject = seqfish_mini, point_shape = 'voronoi', cell_color = 'cell_types')

identify your own colors

my_color_code = c('blue', 'pink', 'green', 'yellow', 'purple', 'black', 'orange', 'brown') names(my_color_code) = clusters_cell_types

spatPlot2D(gobject = seqfish_mini, point_shape = 'border', cell_color = 'cell_types', cell_color_code = my_color_code, point_size = 3) spatPlot2D(gobject = seqfish_mini, point_shape = 'no_border', cell_color = 'cell_types', cell_color_code = my_color_code, point_size = 3) spatPlot2D(gobject = seqfish_mini, point_shape = 'voronoi', cell_color = 'cell_types', cell_color_code = my_color_code)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RubD/Giotto/issues/141#issuecomment-947193313, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEBOCZSLTF2QAHZSRSWYV7DUHYA3XANCNFSM5F4GHQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

RubD commented 2 years ago

Ok, no problem. Let me know if you can't figure it out.

The current Giotto object is currently not directly compatible with the new Giotto Suite object, but it shouldn't be that hard for us to make a conversion function. Thanks for the idea!

Best, Ruben

stefanonard85 commented 2 years ago

Hello Ruben,

as always was my mistake. I want to apologize if I have wasted your time and thank you again for helping me in sorting this out. I have found the error. It is working fine now and I can assign the colors. Also our viewer is nearly ready. I will send it once ready for your feedback. Have a nice day.

Kind Regards,

Stefano Nardone, PhD

research scientist, Harvard Medical School Beth Israel Deaconess Medical Center Center for Life Sciences, 3 Blackfan Circle, Boston, MA 02115 phone +1 413-695-1678

On Thu, Oct 21, 2021 at 12:36 PM stefano nardone @.***> wrote:

Hello Ruben,

Thanks a lot for looking into this. Indeed, it looks very strange. I guess I am doing something wrong and I am not realizing it. Anyway I have installed the new version and I will try to do a voronoi plot following your suggestion. I have actually one question that I think is also relevant for all the Giotto users: is the Giotto object I have created with Giotto compatible with the new version , Giotto Suite? I really appreciated your help. Thanks in advance.

Kind Regards,

Stefano Nardone, PhD

research scientist, Harvard Medical School Beth Israel Deaconess Medical Center Center for Life Sciences, 3 Blackfan Circle, Boston, MA 02115 phone +1 413-695-1678

On Tue, Oct 19, 2021 at 7:58 PM Ruben Dries @.***> wrote:

Hi Stefano,

I have been trying to reproduce this bug, but it actually works fine on my end.

Here is a small example you can run in less than a minute. It did use the development version, which has a couple of other bug fixes but is otherwise completely the same as the current version.

@.***")

library(Giotto)

temp_dir = '~/Temp/' myinstructions = createGiottoInstructions(save_dir = temp_dir, save_plot = FALSE, return_plot = TRUE, show_plot = FALSE)

expr_path = system.file("extdata", "seqfish_field_expr.txt.gz", package = 'Giotto') loc_path = system.file("extdata", "seqfish_field_locs.txt", package = 'Giotto') seqfish_mini <- createGiottoObject(raw_exprs = expr_path, spatial_locs = loc_path, instructions = myinstructions)

processing

seqfish_mini <- filterGiotto(gobject = seqfish_mini, expression_threshold = 0.5, gene_det_in_min_cells = 20, min_det_genes_per_cell = 0) seqfish_mini <- normalizeGiotto(gobject = seqfish_mini, scalefactor = 6000, verbose = T) seqfish_mini <- addStatistics(gobject = seqfish_mini) seqfish_mini <- adjustGiottoMatrix(gobject = seqfish_mini, expression_values = c('normalized'), covariate_columns = c('nr_genes', 'total_expr'))

dimension reduction

seqfish_mini <- calculateHVG(gobject = seqfish_mini) seqfish_mini <- runPCA(gobject = seqfish_mini) seqfish_mini <- runUMAP(seqfish_mini, dimensions_to_use = 1:5, n_threads = 2) seqfish_mini <- createNearestNetwork(gobject = seqfish_mini, dimensions_to_use = 1:5, k = 5) seqfish_mini <- doLeidenCluster(gobject = seqfish_mini, resolution = 0.4, n_iterations = 1000)

provide annotation for the leiden identified groups

clusters_cell_types = c('cell A', 'cell B', 'cell C', 'cell D', 'cell E', 'cell F', 'cell G', 'cell H') names(clusters_cell_types) = 1:8 seqfish_mini = annotateGiotto(gobject = seqfish_mini, annotation_vector = clusters_cell_types, cluster_column = 'leiden_clus', name = 'cell_types')

default colors

spatPlot2D(gobject = seqfish_mini, point_shape = 'border', cell_color = 'cell_types') spatPlot2D(gobject = seqfish_mini, point_shape = 'no_border', cell_color = 'cell_types') spatPlot2D(gobject = seqfish_mini, point_shape = 'voronoi', cell_color = 'cell_types')

identify your own colors

my_color_code = c('blue', 'pink', 'green', 'yellow', 'purple', 'black', 'orange', 'brown') names(my_color_code) = clusters_cell_types

spatPlot2D(gobject = seqfish_mini, point_shape = 'border', cell_color = 'cell_types', cell_color_code = my_color_code, point_size = 3) spatPlot2D(gobject = seqfish_mini, point_shape = 'no_border', cell_color = 'cell_types', cell_color_code = my_color_code, point_size = 3) spatPlot2D(gobject = seqfish_mini, point_shape = 'voronoi', cell_color = 'cell_types', cell_color_code = my_color_code)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RubD/Giotto/issues/141#issuecomment-947193313, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEBOCZSLTF2QAHZSRSWYV7DUHYA3XANCNFSM5F4GHQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

RubD commented 2 years ago

Hi Stefano, No worries and I'm happy you figured it out! Looking forward to see what your viewer can do. Best, Ruben