Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 59b6dff

Browse files
add ability to plot gccontent and chrombins for genomes that not in GDdata
1 parent 0a8b508 commit 59b6dff

1 file changed

Lines changed: 50 additions & 5 deletions

File tree

‎tools/regionstat.R‎

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
library(GenomicDistributions)
22
library(GenomicDistributionsData)
3+
library(GenomeInfoDb)
34
library(optparse)
45
library(tools)
56
library(R.utils)
@@ -39,6 +40,18 @@ if (is.null(opt$digest)) {
3940
}
4041

4142

43+
myChromSizes <- function(genome){
44+
if (requireNamespace(BSgm, quietly=TRUE)){
45+
library (BSgm, character.only = TRUE)
46+
BSG = eval(as.name(BSgm))
47+
} else {
48+
library (BSg, character.only = TRUE)
49+
BSG = eval(as.name(BSg))
50+
}
51+
chromSizesGenome = seqlengths(BSG)
52+
return(chromSizesGenome)
53+
}
54+
4255
plotBoth <- function(plotId, g){
4356
pth = paste0(opt$outputFolder, "/", fileId, "_", plotId)
4457
print(paste0("Plotting: ", pth))
@@ -80,7 +93,14 @@ doItAall <- function(query, fileId, genome, cellMatrix) {
8093
# Chromosomes region distribution plot
8194
tryCatch(
8295
expr = {
83-
plotBoth("chrombins", plotChromBins(calcChromBinsRef(query, genome)))
96+
if (genome %in% c("mm39", "dm3", "dm6", "ce10", "ce11", "danRer10", "danRer10", "T2T")){
97+
chromSizes = myChromSizes(genome)
98+
genomeBins = getGenomeBins(chromSizes)
99+
plotBoth("chrombins", plotChromBins(calcChromBins(query, genomeBins)))
100+
} else{
101+
plotBoth("chrombins", plotChromBins(calcChromBinsRef(query, genome)))
102+
}
103+
84104
plots = rbind(plots, getPlotReportDF("chrombins", "Regions distribution over chromosomes"))
85105
message("Successfully calculated and plot chromosomes region distribution.")
86106
},
@@ -95,7 +115,15 @@ doItAall <- function(query, fileId, genome, cellMatrix) {
95115
if (bsGenomeAvail) {
96116
tryCatch(
97117
expr = {
98-
gcvec = calcGCContentRef(query, genome)
118+
if (requireNamespace(BSgm, quietly=TRUE)){
119+
library (BSgm, character.only = TRUE)
120+
bsg = eval(as.name(BSgm))
121+
gcvec = calcGCContent(query, bsg)
122+
} else {
123+
library (BSg, character.only = TRUE)
124+
bsg = eval(as.name(BSg))
125+
gcvec = calcGCContent(query, bsg)
126+
}
99127
plotBoth("gccontent", plotGCContent(gcvec))
100128
plots = rbind(plots, getPlotReportDF("gccontent", "GC content"))
101129
message("Successfully calculated and plot GC content.")
@@ -232,14 +260,31 @@ bedPath = opt$bedfilePath
232260
outfolder = opt$outputFolder
233261
genome = opt$genome
234262
cellMatrix = opt$openSignalMatrix
235-
orgName = "Mmusculus"
263+
236264

237265
# build BSgenome package ID to check whether it's installed
238-
if (startsWith(genome, "hg") | startsWith(genome, "grch")) orgName = "Hsapiens"
266+
if (genome == "T2T"){
267+
BSg = "BSgenome.Hsapiens.NCBI.T2T.CHM13v2.0"
268+
} else {
269+
if (startsWith(genome, "hg") | startsWith(genome, "grch")) {
270+
orgName = "Hsapiens"
271+
} else if (startsWith(genome, "mm") | startsWith(genome, "grcm")){
272+
orgName = "Mmusculus"
273+
} else if (startsWith(genome, "dm")){
274+
orgName = "Dmelanogaster"
275+
} else if (startsWith(genome, "ce")){
276+
orgName = "Celegans"
277+
} else if (startsWith(genome, "danRer")){
278+
orgName = "Drerio"
279+
}
280+
BSg = paste0("BSgenome.", orgName , ".UCSC.", genome)
281+
}
239282

240-
BSg = paste0("BSgenome.", orgName , ".UCSC.", genome)
241283
BSgm = paste0(BSg, ".masked")
242284

285+
286+
287+
243288
# read bed file and run doitall()
244289
query = LOLA::readBed(bedPath)
245290
doItAall(query, fileId, genome, cellMatrix)

0 commit comments

Comments
 (0)