Scan gene promoters for a set of TF PWMs

MotifScan(seurat_obj, species_genome, pfm, EnsDb, wgcna_name = NULL)

Examples

MotifScan
#> function (seurat_obj, species_genome, pfm, EnsDb, wgcna_name = NULL) 
#> {
#>     if (is.null(wgcna_name)) {
#>         wgcna_name <- seurat_obj@misc$active_wgcna
#>     }
#>     motif_df <- data.frame(motif_name = purrr::map(1:length(pfm), 
#>         function(i) {
#>             pfm[[i]]@name
#>         }) %>% unlist, motif_ID = purrr::map(1:length(pfm), function(i) {
#>         pfm[[i]]@ID
#>     }) %>% unlist)
#>     gene.promoters <- ensembldb::promoters(EnsDb)
#>     gene.coords <- ensembldb::genes(EnsDb)
#>     gene.promoters <- gene.promoters[gene.promoters$tx_biotype == 
#>         "protein_coding"]
#>     gene.coords <- gene.coords[gene.coords$gene_biotype == "protein_coding"]
#>     gene.promoters <- gene.promoters[as.character(GenomeInfoDb::seqnames(gene.promoters)) %in% 
#>         c(1:100, "X", "Y")]
#>     gene.coords <- gene.coords[as.character(GenomeInfoDb::seqnames(gene.coords)) %in% 
#>         c(1:100, "X", "Y")]
#>     gene.promoters$symbol <- gene.coords$symbol[base::match(gene.promoters$gene_id, 
#>         names(gene.coords))]
#>     gene.promoters <- GenomeInfoDb::keepSeqlevels(gene.promoters, 
#>         value = levels(droplevels(GenomeInfoDb::seqnames(gene.promoters))))
#>     old_levels <- levels(GenomeInfoDb::seqnames(gene.promoters))
#>     new_levels <- paste0("chr", old_levels)
#>     gene.promoters <- GenomeInfoDb::renameSeqlevels(gene.promoters, 
#>         new_levels)
#>     GenomeInfoDb::genome(GenomeInfoDb::seqinfo(gene.promoters)) <- species_genome
#>     my_promoters <- GRanges(seqnames = droplevels(GenomeInfoDb::seqnames(gene.promoters)), 
#>         IRanges(start = start(gene.promoters), end = end(gene.promoters)), 
#>         symbol = gene.promoters$symbol, genome = species_genome)
#>     print("Matching motifs...")
#>     motif_ix <- motifmatchr::matchMotifs(pfm, my_promoters, genome = species_genome)
#>     tf_match <- motifmatchr::motifMatches(motif_ix)
#>     rownames(tf_match) <- my_promoters$symbol
#>     colnames(tf_match) <- motif_df$motif_name
#>     gene_list <- rownames(seurat_obj)
#>     gene_list <- gene_list[gene_list %in% rownames(tf_match)]
#>     tf_match <- tf_match[gene_list, ]
#>     print("Getting putative TF target genes...")
#>     tfs <- motif_df$motif_name
#>     tf_targets <- list()
#>     n_targets <- list()
#>     for (cur_tf in tfs) {
#>         tf_targets[[cur_tf]] <- names(tf_match[, cur_tf][tf_match[, 
#>             cur_tf]])
#>         n_targets[[cur_tf]] <- length(tf_targets[[cur_tf]])
#>     }
#>     n_targets <- unlist(n_targets)
#>     motif_df$n_targets <- n_targets
#>     seurat_obj <- SetMotifMatrix(seurat_obj, tf_match)
#>     seurat_obj <- SetMotifs(seurat_obj, motif_df)
#>     seurat_obj <- SetMotifTargets(seurat_obj, tf_targets)
#>     seurat_obj <- SetPFMList(seurat_obj, pfm)
#>     seurat_obj
#> }
#> <bytecode: 0x7f77b99fac78>
#> <environment: namespace:hdWGCNA>