first error: could not find function "readGAlignments" in BiocParallel
2
1
Entering edit mode
@shangguandong1996-21805
Last seen 2.1 years ago
China

Hi, Dear developer I try to run code in BiocParallel manual, but there is error about it

library(RNAseqData.HNRNPC.bam.chr14)
library(GenomicAlignments)
library(BiocParallel)

fls <- RNAseqData.HNRNPC.bam.chr14_BAMFILES


gr <- GRanges("chr14", IRanges((1000:3999)*5000, width=1000))

param <- ScanBamParam(which=range(gr))

FUN <- function(fl, param) {
  gal <- readGAlignments(fl, param = param)
  sum(countOverlaps(gr, gal))
}
> SnowParam()
class: SnowParam
  bpisup: FALSE; bpnworkers: 10; bptasks: 0; bpjobname: BPJOB
  bplog: FALSE; bpthreshold: INFO; bpstopOnError: TRUE
  bpRNGseed: ; bptimeout: 2592000; bpprogressbar: FALSE
  bpexportglobals: TRUE
  bplogdir: NA
  bpresultdir: NA
  cluster type: SOCK
> bplapply(fls[1:3], FUN, BPPARAM = SnowParam(), param = param)
Error: BiocParallel errors
  element index: 1, 2, 3
  first error: could not find function "readGAlignments"
In addition: Warning messages:
1: In serialize(data, node$con) :
  'package:stats' may not be available when loading
2: In serialize(data, node$con) :
  'package:stats' may not be available when loading
3: In serialize(data, node$con) :
  'package:stats' may not be available when loading
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] stats4    parallel  stats     graphics  grDevices utils     datasets  methods  
[9] base     

other attached packages:
 [1] BiocParallel_1.22.0                GenomicAlignments_1.24.0          
 [3] Rsamtools_2.4.0                    Biostrings_2.56.0                 
 [5] XVector_0.28.0                     SummarizedExperiment_1.18.2       
 [7] DelayedArray_0.14.1                matrixStats_0.57.0                
 [9] Biobase_2.48.0                     GenomicRanges_1.40.0              
[11] GenomeInfoDb_1.24.2                IRanges_2.22.2                    
[13] S4Vectors_0.26.1                   BiocGenerics_0.34.0               
[15] RNAseqData.HNRNPC.bam.chr14_0.26.0

loaded via a namespace (and not attached):
 [1] rstudioapi_0.11        zlibbioc_1.34.0        lattice_0.20-41       
 [4] tools_4.0.2            grid_4.0.2             snow_0.4-3            
 [7] crayon_1.3.4           Matrix_1.2-18          GenomeInfoDbData_1.2.3
[10] bitops_1.0-6           RCurl_1.98-1.2         compiler_4.0.2
BiocParallel • 1.8k views
ADD COMMENT
1
Entering edit mode
@james-w-macdonald-5106
Last seen 1 day ago
United States

You have a set of packages that shouldn't be installed for the version of R you are using. The first step for you should be to do

library(BiocManager)
BiocManager::valid()

And do whatever valid says you need to do to fix your installation. Then try your code again.

ADD COMMENT
1
Entering edit mode
@martin-morgan-1513
Last seen 5 months ago
United States

The 'snow' workers are independent processes and do not 'know' about the packages loaded on the main node. Load the packages on the workers, e.g.,

FUN <- function(fl, param) {
  library(GenomicAlignments)
  gal <- readGAlignments(fl, param = param)
  sum(countOverlaps(gr, gal))
}

But note also that the workers don't know about gr either, so make sure to pass that as part of the function

FUN <- function(fl, gr, param) {
  library(GenomicAlignments)
  gal <- readGAlignments(fl, param = param)
  sum(countOverlaps(gr, gal))
}
bplapply(fls[1:3], FUN, BPPARAM = SnowParam(), gr = gr, param = param)

The bpvalidate() function is meant to help with this, and it indicates the two problems mentioned in this case, but is not entirely satisfactory.

> bpvalidate(FUN)
$inPath
$inPath$countOverlaps
[1] "package:GenomicRanges"

$inPath$gr
[1] ".GlobalEnv"

$inPath$readGAlignments
[1] "package:GenomicAlignments"


$unknown
character(0)

Warning message:
In bpvalidate(FUN) : function references symbol(s) in .GlobalEnv
ADD COMMENT
0
Entering edit mode

Thanks your reply, I make it :).

But my bpvalidate(FUN) message is different from yours. It seems that there is no "package:GenomicAlignments" in bpvalidate(FUN) output.

library(RNAseqData.HNRNPC.bam.chr14)
library(BiocParallel)
library(GenomicAlignments)

fls <- RNAseqData.HNRNPC.bam.chr14_BAMFILES

gr <- GRanges("chr14", IRanges((1000:3999)*5000, width=1000))

param <- ScanBamParam(which=range(gr))


FUN <- function(fl, gr, param) {
  suppressPackageStartupMessages({
    library(GenomicAlignments)
  })
  gal <- readGAlignments(fl, param = param)
  sum(countOverlaps(gr, gal))
}

> bplapply(fls[1:3], FUN, BPPARAM = SnowParam(), gr = gr, param = param)
$ERR127306
[1] 1185

$ERR127307
[1] 1123

$ERR127308
[1] 1241

Warning messages:
1: In serialize(data, node$con) :
  'package:stats' may not be available when loading
2: In serialize(data, node$con) :
  'package:stats' may not be available when loading
3: In serialize(data, node$con) :
  'package:stats' may not be available when loading
> bpvalidate(FUN)
$inPath
$inPath$countOverlaps
[1] "package:GenomicRanges"


$unknown
character(0)
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] stats4    parallel  stats     graphics  grDevices utils     datasets  methods  
[9] base     

other attached packages:
 [1] GenomicAlignments_1.26.0           Rsamtools_2.6.0                   
 [3] Biostrings_2.58.0                  XVector_0.30.0                    
 [5] SummarizedExperiment_1.20.0        Biobase_2.50.0                    
 [7] MatrixGenerics_1.2.0               matrixStats_0.57.0                
 [9] GenomicRanges_1.42.0               GenomeInfoDb_1.26.2               
[11] IRanges_2.24.1                     S4Vectors_0.28.1                  
[13] BiocGenerics_0.36.0                BiocParallel_1.24.1               
[15] RNAseqData.HNRNPC.bam.chr14_0.28.0

loaded via a namespace (and not attached):
 [1] rstudioapi_0.13        zlibbioc_1.36.0        lattice_0.20-41       
 [4] tools_4.0.2            grid_4.0.2             snow_0.4-3            
 [7] crayon_1.3.4           Matrix_1.2-18          GenomeInfoDbData_1.2.4
[10] codetools_0.2-18       bitops_1.0-6           RCurl_1.98-1.2        
[13] DelayedArray_0.16.0    compiler_4.0.2
ADD REPLY

Login before adding your answer.

Traffic: 495 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6