reticulate::py_discover_config(required_module="phate")
python: /usr/local/bin/python3
libpython: /usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/config-3.8-darwin/libpython3.8.dylib
pythonhome: /usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8:/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8
version: 3.8.5 (default, Jul 21 2020, 10:41:41) [Clang 10.0.0 (clang-1000.11.45.5)]
numpy: /Users/emmabriggs/Library/Python/3.8/lib/python/site-packages/numpy
numpy_version: 1.19.2
phate: /Users/emmabriggs/Library/Python/3.8/lib/python/site-packages/phate
NOTE: Python version was forced by RETICULATE_PYTHON
## gglot2 plotting themes used for UMAP plots
UMAP_theme <- theme(axis.line=element_blank(), axis.ticks = element_blank(), panel.background = element_rect(size=0.5,linetype="solid",color="black"), plot.title = element_text(size = 10, face = "bold", hjust = 0.05, vjust = -8), axis.text.x = element_blank(), axis.title.x = element_blank(), axis.title.y = element_blank(), axis.text.y = element_blank(), legend.title = element_blank())
head(var_genes_02)
[1] "Tbrucei---Tb927.11.880" "Tbrucei---Tb927.10.8940"
[3] "Tbrucei---Tb927.3.3270" "Tbrucei---Tb927.1.2390"
[5] "Tbrucei---Tb927.10.14140" "Tbrucei---Tb927.9.6210"
# Find integration anchors - 8 dims was found to give the most robust results by performing several iteration, varying this parameter and asses expression of known marker genes
WT.tryp.anchors <- FindIntegrationAnchors(object.list = list, dims = 1:8, anchor.features = WT_features)
Some cell names are duplicated across objects provided. Renaming to enforce unique cell names.Scaling features for provided objects
| | 0 % ~calculating
|+++++++++++++++++++++++++ | 50% ~01s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=02s
Finding all pairwise anchors
| | 0 % ~calculating
Running CCA
Merging objects
Finding neighborhoods
Finding anchors
Found 11571 anchors
Filtering anchors
Retained 3064 anchors
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=01m 17s
# Find integration anchors - 8 dims was found to give the most robust results by performing several iteration, varying this parameter and asses expression of known marker genes
WT.tryp.anchors <- FindIntegrationAnchors(object.list = list, dims = 1:8, anchor.features = WT_features)
Some cell names are duplicated across objects provided. Renaming to enforce unique cell names.Scaling features for provided objects
| | 0 % ~calculating
|+++++++++++++++++++++++++ | 50% ~01s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=01s
Finding all pairwise anchors
| | 0 % ~calculating
Running CCA
Merging objects
Finding neighborhoods
Finding anchors
Found 11571 anchors
Filtering anchors
Retained 3064 anchors
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=01m 10s
# Get all genes in both replicate experiment objects
all.genes <- row.names(list[[1]])
# Rerun clustering with selected resolution parameter (selected 0.4 based on clustree results and several iterations)
WT.integrated <- FindClusters(WT.integrated, resolution = 0.4)
Error in FindClusters.Seurat(WT.integrated, resolution = 0.4) :
Provided graph.name not present in Seurat object
#pdf(file = "WT_intergation_ident_PHATE.pdf", width = 4.5, height = 4.5)
plot(reducedDims(sce)$PHATE, col = mycolours[sce$ident], pch = 16, cex = 0.5, bty='l', xlim=rev(c(-0.022, 0.032))) + lines(SlingshotDataSet(sce), col = "black", lwd = 2)
integer(0)
#pdf(file = "WT_intergation_pseudo_PHATE_TI.pdf", width = 4.8, height = 5.3)
plot(reducedDims(sce)$PHATE, col = plotcol, alpha = 0.5,pch = 16, cex = 0.5, xlim=rev(c(-0.023, 0.033)), axes = FALSE, ann = FALSE, xaxt='n', yaxt='n') + lines(SlingshotDataSet(sce), col = "black", lwd = 2)
integer(0)
#pdf(file = "PHATE_WT_GAPHD.pdf", width = 1.8, height = 2)
p + labs(title = "GAPDH", color = "Expression") + NoLegend() + PHATE_theme + ylim(-0.01, 0.01) + xlim(0.033, -0.023)
Scale for 'y' is already present. Adding another scale for 'y', which
will replace the existing scale.
Scale for 'x' is already present. Adding another scale for 'x', which
will replace the existing scale.
p <- FeaturePlot(object = WT.integrated, features = "Tbrucei---Tb927.10.14140", min.cutoff = 0, max.cutoff = 4, reduction = "phate")
p[[1]]$layers[[1]]$aes_params$alpha = 0.5
p[[1]]$layers[[1]]$aes_params$shape = 16
#pdf(file = "PHATE_WT_PYK1.pdf", width = 1.8, height = 2)
p + labs(title = "PYK1", color = "Expression") + NoLegend() + PHATE_theme + ylim(-0.01, 0.01) + xlim(0.033, -0.023)
Scale for 'y' is already present. Adding another scale for 'y', which
will replace the existing scale.
Scale for 'x' is already present. Adding another scale for 'x', which
will replace the existing scale.
#dev.off()
p <- FeaturePlot(object = WT.integrated, features = "Tbrucei---Tb927.7.5940", min.cutoff = 0, max.cutoff = 4, reduction = "phate")
p[[1]]$layers[[1]]$aes_params$alpha = 0.5
p[[1]]$layers[[1]]$aes_params$shape = 16
#pdf(file = "PHATE_WT_PAD2.pdf", width = 1.8, height = 2)
p + labs(title = "PAD2", color = "Expression") + NoLegend() + PHATE_theme + ylim(-0.01, 0.01) + xlim(0.033, -0.023)
Scale for 'y' is already present. Adding another scale for 'y', which
will replace the existing scale.
Scale for 'x' is already present. Adding another scale for 'x', which
will replace the existing scale.
#dev.off()
#pdf(file = "PHATE_WT_EP1.pdf", width = 1.8, height = 2)
p + labs(title = "EP1", color = "Expression") + NoLegend() + PHATE_theme + ylim(-0.01, 0.01) + xlim(0.033, -0.023)
Scale for 'y' is already present. Adding another scale for 'y', which
will replace the existing scale.
Scale for 'x' is already present. Adding another scale for 'x', which
will replace the existing scale.
# You can set this control to try and prevent overfitting the data
control <- gam.control()
control$maxit <- 1000
# Get the counts data for the genes you want to use
counts <- as.matrix(WT.integrated@assays[["RNA"]]@counts)
# Determine the appropriate number of knots (read on trade-seq page how to select best number of knots (points on trajectory))
# Test 3 to 15 knots, select best based on plots
#icMat <- evaluateK(counts = counts, sds = crv, k=3:15, nGenes = 200, verbose=FALSE)
# fit the GAM to the data (selected 6 knots). This takes a bit of time.
sce_GAM_all_genes <- fitGAM(counts = counts, sds = crv, nknots = 6, control = control)
# save the single cell with GAM
save(sce_GAM_all_genes, file = "sce_GAM_WT_integrated")
# Test gene expression association with trajectory
assoRes <- associationTest(sce_GAM_all_genes)
write.csv(assoRes, file = "assoRes_WT_integrated2.csv")
## Select genes for clustering into gene modules
## select p value < 0.05 and FC > 2
diff.genes <- subset(assoRes, pvalue < 0.05)
diff.genes <- subset(diff.genes, meanLogFC > 0.301)
#Get list of genes
diff.genes <- as.character(rownames(diff.genes))
write.csv(diff.genes, file = "diff_genes.csv")
# Can test different merging thresholds but just running RSEC.
RSEC <- RSEC(clusPat$rsec, eraseOld = FALSE, rerunClusterMany = FALSE, mergeMethod="adjP", mergeCutoff=0.95)
Note: Merging will be done on ' makeConsensus ', with clustering index 1
cluster_info <- WT.integrated@active.ident
sce_GAM_all_genes$cluster <- cluster_info
# Get raw counts data
counts <- WT.integrated@assays[["RNA"]]@counts
# Plot
#pdf(file = "Tb927.11.15100_WT_smooth.pdf", width = 1.8, height = 1.5)
plotSmoothers(sce_GAM_all_genes, counts, gene = "Tbrucei---Tb927.11.15100", lwd = 1, sample = 1, alpha = 0.1, pointCol = "cluster") +
labs(title = "Tb927.11.15100") + scale_color_manual(values = c("#f8766d", "#7cae00", "#01bfc4", "#c77cff")) + guides(color = FALSE)
theme(plot.title = element_text(size = 9, face = "bold"), axis.text.x = element_text(size = 8), axis.title.x = element_text(size = 8), axis.title.y = element_text(size = 8), axis.text.y = element_text(size = 8))
#dev.off()
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.