Contents

1 Introduction

Sequence-based TF affinity scoring can be conducted with the FIMO suite, see @Sonawane2017. We have serialized an object with references to FIMO outputs for 16 TFs.

suppressPackageStartupMessages({
library(TFutils)
library(GenomicRanges)
})
fimo16
## GenomicFiles object with 0 ranges and 16 files: 
## files: M0635_1.02sort.bed.gz, M3433_1.02sort.bed.gz, ..., M6159_1.02sort.bed.gz, M6497_1.02sort.bed.gz 
## detail: use files(), rowRanges(), colData(), ...

While the token bed is used in the filenames, the files are not actually bed format!

2 Importing with scanTabix

We can use reduceByRange to import selected scans.

if (.Platform$OS.type != "windows") {
 si = TFutils::seqinfo_hg19_chr17
 myg = GRanges("chr17", IRanges(38.07e6,38.09e6), seqinfo=si)
 colnames(fimo16) = fimo16$HGNC 
 lk2 = reduceByRange(fimo16[, c("POU2F1", "VDR")],
   MAP=function(r,f) scanTabix(f, param=r))
 str(lk2)
}

This result can be massaged into a GRanges or other desirable structure. fimo_granges takes care of this.

#fimo_ranges = function(gf, query) { # prototypical code
# rowRanges(gf) = query
# ans = reduceByRange(gf, MAP=function(r,f) scanTabix(f, param=r))
# ans = unlist(ans, recursive=FALSE)  # drop top list structure
# tabs = lapply(ans, lapply, function(x) {
#     con = textConnection(x)
#     on.exit(close(con))
#     dtf = read.delim(con, h=FALSE, stringsAsFactors=FALSE, sep="\t")
#     colnames(dtf) = c("chr", "start", "end", "rname", "score", "dir", "pval")
#     ans = with(dtf, GRanges(seqnames=chr, IRanges(start, end),
#            rname=rname, score=score, dir=dir, pval=pval))
#     ans
#     })
# GRangesList(unlist(tabs, recursive=FALSE))
#}
if (.Platform$OS.type != "windows") {
 rr = fimo_granges(fimo16[, c("POU2F1", "VDR")], myg)
 rr
}
sessionInfo()
## R version 4.4.0 RC (2024-04-16 r86468 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows Server 2022 x64 (build 20348)
## 
## Matrix products: default
## 
## 
## locale:
## [1] LC_COLLATE=C                          
## [2] LC_CTYPE=English_United States.utf8   
## [3] LC_MONETARY=English_United States.utf8
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.utf8    
## 
## time zone: America/New_York
## tzcode source: internal
## 
## attached base packages:
## [1] grid      stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] UpSetR_1.4.0                magrittr_2.0.3             
##  [3] dplyr_1.1.4                 gwascat_2.37.0             
##  [5] GSEABase_1.67.0             graph_1.83.0               
##  [7] annotate_1.83.0             XML_3.99-0.16.1            
##  [9] png_0.1-8                   ggplot2_3.5.1              
## [11] knitr_1.46                  data.table_1.15.4          
## [13] GO.db_3.19.1                GenomicFiles_1.41.0        
## [15] rtracklayer_1.65.0          Rsamtools_2.21.0           
## [17] Biostrings_2.73.0           XVector_0.45.0             
## [19] BiocParallel_1.39.0         SummarizedExperiment_1.35.0
## [21] GenomicRanges_1.57.0        GenomeInfoDb_1.41.0        
## [23] MatrixGenerics_1.17.0       matrixStats_1.3.0          
## [25] org.Hs.eg.db_3.19.1         AnnotationDbi_1.67.0       
## [27] IRanges_2.39.0              S4Vectors_0.43.0           
## [29] Biobase_2.65.0              BiocGenerics_0.51.0        
## [31] TFutils_1.25.0              BiocStyle_2.33.0           
## 
## loaded via a namespace (and not attached):
##  [1] DBI_1.2.2                bitops_1.0-7             gridExtra_2.3           
##  [4] readxl_1.4.3             rlang_1.1.3              compiler_4.4.0          
##  [7] RSQLite_2.3.6            GenomicFeatures_1.57.0   vctrs_0.6.5             
## [10] pkgconfig_2.0.3          crayon_1.5.2             fastmap_1.2.0           
## [13] dbplyr_2.5.0             labeling_0.4.3           utf8_1.2.4              
## [16] promises_1.3.0           rmarkdown_2.26           tzdb_0.4.0              
## [19] UCSC.utils_1.1.0         bit_4.0.5                xfun_0.44               
## [22] zlibbioc_1.51.0          cachem_1.0.8             jsonlite_1.8.8          
## [25] blob_1.2.4               highr_0.10               later_1.3.2             
## [28] DelayedArray_0.31.1      parallel_4.4.0           R6_2.5.1                
## [31] VariantAnnotation_1.51.0 bslib_0.7.0              jquerylib_0.1.4         
## [34] cellranger_1.1.0         bookdown_0.39            Rcpp_1.0.12             
## [37] readr_2.1.5              splines_4.4.0            httpuv_1.6.15           
## [40] Matrix_1.7-0             tidyselect_1.2.1         abind_1.4-5             
## [43] yaml_2.3.8               codetools_0.2-20         miniUI_0.1.1.1          
## [46] curl_5.2.1               plyr_1.8.9               lattice_0.22-6          
## [49] tibble_3.2.1             withr_3.0.0              shiny_1.8.1.1           
## [52] KEGGREST_1.45.0          evaluate_0.23            survival_3.6-4          
## [55] BiocFileCache_2.13.0     snpStats_1.55.0          pillar_1.9.0            
## [58] BiocManager_1.30.23      filelock_1.0.3           generics_0.1.3          
## [61] RCurl_1.98-1.14          hms_1.1.3                munsell_0.5.1           
## [64] scales_1.3.0             xtable_1.8-4             glue_1.7.0              
## [67] tools_4.4.0              BiocIO_1.15.0            BSgenome_1.73.0         
## [70] GenomicAlignments_1.41.0 colorspace_2.1-0         GenomeInfoDbData_1.2.12 
## [73] restfulr_0.0.15          cli_3.6.2                fansi_1.0.6             
## [76] S4Arrays_1.5.0           gtable_0.3.5             sass_0.4.9              
## [79] digest_0.6.35            SparseArray_1.5.4        farver_2.1.2            
## [82] rjson_0.2.21             memoise_2.0.1            htmltools_0.5.8.1       
## [85] lifecycle_1.0.4          httr_1.4.7               mime_0.12               
## [88] bit64_4.0.5