11library(GenomicDistributions )
22library(GenomicDistributionsData )
3+ library(GenomeInfoDb )
34library(optparse )
45library(tools )
56library(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+
4255plotBoth <- 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
232260outfolder = opt $ outputFolder
233261genome = opt $ genome
234262cellMatrix = 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 )
241283BSgm = paste0(BSg , " .masked" )
242284
285+
286+
287+
243288# read bed file and run doitall()
244289query = LOLA :: readBed(bedPath )
245290doItAall(query , fileId , genome , cellMatrix )
0 commit comments