Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing untreated vs treated cells #33

Closed
ccruizm opened this issue Nov 17, 2019 · 6 comments
Closed

Comparing untreated vs treated cells #33

ccruizm opened this issue Nov 17, 2019 · 6 comments

Comments

@ccruizm
Copy link

ccruizm commented Nov 17, 2019

Good day!

I have been using this excellent package for analyzing tumor biology. Now, I have another type of dataset (four samples) where two of them are control cells in two different time points (7 and 28d), and the other two are treated cells and collected at the same time points. I would like to know how I can create a cisTopic object that contains the four datasets and perform comparative analysis and topic modeling. I am interested in checking on the same dimensional space, how the treatment affects the chromatin accessibility (cell memory), and which features don't change.

I have checked your tutorial (cisTopic on simulated single-cell epigenomes from melanoma cell line) and seems an approach that can be used in my case for this data. Still, I do not know how to create the object with the info for the four datasets and whether it can be used for my porpuses later in the downstream analysis.

Thank you in advance for your help!

@cbravo93
Copy link
Member

cbravo93 commented Nov 20, 2019

Hi @ccruizm !

You can create a combined cisTopicObject by merging the count matrices of your samples; for example, you can create the independent cisTopicObjects and then extract the matrices to combine from cisTopicObject@count.matrix; if needed, you can also extract the metadata from cisTopicObject@cell.data. Then you can use the combined matrix as input for createcisTopicObject().

Hope this is useful!

C

@ccruizm
Copy link
Author

ccruizm commented Nov 21, 2019

Hello @cbravo93

Thanks for the suggestion. I have merged the matrices, as you suggested. It seems to work, but now I have a problem when I want to plot the tsne and heatmap:

Error in scales::hue_pal(l = 60:100): length(l) == 1 is not TRUE
Traceback:

1. plotFeatures(cisTopicObject, method = "tSNE", target = "cell", 
 .     topic_contr = NULL, colorBy = c("nCounts", "nAcc", "densityClust", 
 .         "orig.ident"), cex.legend = 0.8, factor.max = 0.75, dim = 2, 
 .     legend = TRUE, intervals = 10)
2. .plotFactor(coordinates, variable, feature.names, main = columnName, 
 .     dim = dim, colVars = colVars, plot_ly = plot_ly, legend = legend, 
 .     cex.legend = cex.legend, factor.min = factor.min, factor.max = factor.max, 
 .     cex.dot = cex.dot)
3. setNames(.distinctColorPalette(k = length(levels)), levels)
4. .distinctColorPalette(k = length(levels))
5. t(unique(col2rgb((scales::hue_pal(l = 60:100))(2000))))
6. unique(col2rgb((scales::hue_pal(l = 60:100))(2000)))
7. col2rgb((scales::hue_pal(l = 60:100))(2000))
8. as.character(col) %in% "0"
9. scales::hue_pal(l = 60:100)
10. stopifnot(length(l) == 1)
Error in scales::hue_pal(l = 60:100): length(l) == 1 is not TRUE
Traceback:

1. cellTopicHeatmap(cisTopicObject, method = "Probability", colorBy = c("densityClust"))
2. setNames(.distinctColorPalette(length(unique(object@cell.data[, 
 .     variable]))), as.vector(sort(unique(object@cell.data[, variable]))))
3. .distinctColorPalette(length(unique(object@cell.data[, variable])))
4. t(unique(col2rgb((scales::hue_pal(l = 60:100))(2000))))
5. unique(col2rgb((scales::hue_pal(l = 60:100))(2000)))
6. col2rgb((scales::hue_pal(l = 60:100))(2000))
7. as.character(col) %in% "0"
8. scales::hue_pal(l = 60:100)
9. stopifnot(length(l) == 1)

It seems an issue with the predetermined scale on hue_pal. Do you know how I could solve this issue? Besides, I would like to use UMAP instead of tsne. Have you implemented it in your tool?

Thanks!

@JBreunig
Copy link

JBreunig commented Nov 21, 2019

Would you mind sharing your code for merging the 2 - cisTopicObject@count.matrices and 2 cisTopicObject@cell.data objects? I can try on my end to do the UMAP as well.

@ccruizm
Copy link
Author

ccruizm commented Nov 23, 2019

Sure @JBreunig

After creating an independent object for each sample, I extracted the count matrix:

matrix_ctr7d <-  ctr7d@count.matrix
matrix_ctr28d <-  ctr28d@count.matrix

Then using Seuratv3, I create a SeuratObject and merge the data, this to append the sampleID to each cell and later, one extract the raw count matrix:

seurat_ctr7d <- CreateSeuratObject(counts = matrix_ctr7d, )
seurat_ctr28d <- CreateSeuratObject(counts = matrix_ctr28d)
control.combined <- merge(seurat_ctr7d, y = seurat_ctr28d,  add.cell.ids = c("ctr7d", "ctr28d"))
control.raw.data <- GetAssayData(control.combined, slot = "counts")

With this combined matrix I create a new cisTopicObject:

cisTopicObject <- createcisTopicObject(control.raw.data, project.name = 'control')

So far, I have not merged the cell.data generated by cellranger into the object.

My concern its how the peaks are handled by cisTopic since the calling is performed separately on different objects, therefore the peaks do not overlap perfectly, and they might be treated as completely different features. I am having issues plotting tSNE to visually asses what is the contribution of each sample per cluster. I am not expecting a big shift or new clusters after the treatment.

I hope this might help you. I expect to solve the issue with the plotting as well so I can have a look at the handling of the merged matrix by cisTopic.

@cbravo93
Copy link
Member

Hi @ccruizm !

  • The hue_pal error should be solved now, it was related to an update in the scales package.
  • There is a wrap function called runUmap to run Umap from a cisTopicObject (on the topic-cell, or the region-topic matrix, you will have to specify).
  • For merging the matrices, it would be better if you used the same region set for all data sets before merging (e.g. do peak calling on the aggregate of all samples, or merge/intersect the peaks). If they are the same peak (with different start/end coordinates) they shouldn't be treated as a different feature.

Let me know if you have more questions!

C

@ccruizm
Copy link
Author

ccruizm commented Dec 2, 2019

Thank you very much for your help!

@ccruizm ccruizm closed this as completed Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants