yuchaojiang / TRIPOD

Nonparametric Interrogation of Transcriptional Regulation in Single-Cell RNA and Chromatin Accessibility Multiomic Data
GNU General Public License v3.0
7 stars 1 forks source link

Multiple TFs with the same motifs #5

Closed Zhanzhang-2020 closed 1 year ago

Zhanzhang-2020 commented 1 year ago

Hi Yuchao,

Thanks for developing such wonderful tool! I have tried out the tool, everything went well and I just got some amazing results for my single-cell multiome data.

However, I did get some issues when I tried to handle the situation where multiple TFs could correspond to the same motifs. Here is the script I used:

library(TRIPOD)
library(Seurat)
library(Signac)
library(GenomicRanges)
library(dplyr)
library(ggplot2)
library(EnsDb.Hsapiens.v86)
library(BSgenome.Hsapiens.UCSC.hg38)
library(GenomeInfoDb)
library(patchwork)
library(BiocParallel)
library(dendextend)
library(patchwork)
library(igraph)
library(data.table)
## load data for further filtering
seurat <- readRDS('./Immune_sub.rds')
tripod.Immune <- getObjectsForModelFit2(
  object = seurat,
  chr = paste0("chr", 1:22), # human
  convert = FALSE)
transcripts.gr <- tripod.Immune$transcripts.gr
peaks.gr <- tripod.Immune$peaks.gr
motifxTF <- tripod.Immune$motifxTF
peakxmotif <- tripod.Immune$peakxmotif
seurat <- filterSeuratObject2(
  object = seurat, tripod.object = tripod.Immune)
set.seed(123)
num.clusters <- optimizeResolution(
  object = seurat,
  graph.name = "wsnn",
  assay.name = "WNN",
  resolutions = seq(10, 20, 2),
  min.num = 10
)
res <- 14
seurat <- getClusters(
  object = seurat,
  graph.name = "wsnn",
  resolution = res,
  verbose = FALSE
)
metacell <- getMetacellMatrices(
  object = seurat,
  cluster.name = "seurat_clusters",
  min.num = 10
)
seurat <- removeSmallMetacells(object = seurat, min.num = 10)
metacell.rna <- metacell$rna
metacell.peak <- metacell$peak
seurat$celltype=factor(seurat$cluster)
color.Immune <- getColors(object = seurat)
metacell.celltype <- color.Immune$metacell$celltype
metacell.celltype.col <- color.Immune$metacell$color
ext.upstream <- 1e5
genes <- readRDS('./targets.rds')

xymats.list <- bplapply(
  genes,
  getXYMatrices2,
  ext.upstream = ext.upstream,
  tripod = tripod.Immune,
  metacell = metacell)
names(xymats.list) <- genes

xymats.tripod.Xt.list <- bplapply(
  xymats.list,
  fitModel2,
  model.name = "TRIPOD",
  match.by = "Xp"
)
names(xymats.tripod.Xt.list) <- genes
fdr.thresh <- 0.05
# focus on positive sign
sign <- "positive"

xymats.tX1.pos.df <- getTrios(
  xymats.list = xymats.tripod.Xt.list,
  fdr.thresh = fdr.thresh,
  sign = sign,
  model.name = "TRIPOD",
  level = 1
)

And I got the following error when I tried running getTrios function:

Error: BiocParallel errors
  17 remote errors, element index: 1, 2, 3, 4, 5, 6, ...
  0 unevaluated and other errors
  first remote error:
Error in order(...): argument 1 is not a vector

I highly suspected there were something wrong in the GetTrio function, making it incompatible with the input generated by the other alternative set of functions. For example, nonzero.peakxmotif.g was not stored in xymats.list returned by getXYMatrices2.

It would be very helpful if you could provide some advice, thanks!

In addition, this might be an irrelevant question to the title, but I would like some suggestions from you regarding the choice of correlation tests. I am wondering if there is any criterion for choosing the test type (e.g should I prioritize results obtained from controlling for TF expression or chromatin accessibility at Level 1 or Level 2 ?).

Thanks, Zhan

yuchaojiang commented 1 year ago

Hi Zhan,

Thanks for your interest and feedback.

I made some changes to the getXYMatrices2 function, which was written by a trainee and I think it was of a different version than getXYMatrices. I suspect that there would be more errors, but could you please update the package and give it a try again? I will look into more if the problem persists.

For your other question, I would look at the union of the four testing, and likely together with the marginal/pairwise testing as well. From what they show, they overlap but are not the same and corroborates and complements with each other.

Yuchao

Zhanzhang-2020 commented 1 year ago

Thanks for the reply. I will update the package and try again, and will keep you posted.