r3fang / SnapATAC

Analysis Pipeline for Single Cell ATAC-seq
GNU General Public License v3.0
301 stars 125 forks source link

no applicable method for 'runChromVAR' applied to an object of class "snap" #108

Open hjack123 opened 4 years ago

hjack123 commented 4 years ago

Error in UseMethod("runChromVAR", obj) : no applicable method for 'runChromVAR' applied to an object of class "snap"

what could be the reason?

r3fang commented 4 years ago

Can you install the most updated version and try it again? this was an error in the old version

-- Rongxin Fang Ph.D. Student, Ren Lab Ludwig Institute for Cancer Research University of California, San Diego

On Sep 27, 2019, at 2:40 PM, hjack123 notifications@github.com wrote:

Error in UseMethod("runChromVAR", obj) : no applicable method for 'runChromVAR' applied to an object of class "snap"

what could be the reason?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/r3fang/SnapATAC/issues/108?email_source=notifications&email_token=ABT6GGYO6VABGYDPPSG5GBTQLZHTFA5CNFSM4I3JTHQKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HOHFQRQ, or mute the thread https://github.com/notifications/unsubscribe-auth/ABT6GG3LOQTFCRT4IEY72S3QLZHTFANCNFSM4I3JTHQA.

hjack123 commented 4 years ago

Thank you so much for your reply. and whats the best way to work around this error? Error in loadFUN(x, seqname, ranges) : trying to load regions beyond the boundaries of non-circular sequence "chrUn_KI270438v1"

I can go back to remove these chromosomes, but then lots of things will have to be reran..

r3fang commented 4 years ago

hi,

I am sorry for the error. this might be because you have stored the whole space as “RData” and when you load the image, the previous environment variable will be loaded as well. Can you save the snap object as “rds” file by saveRDS(x.sp, “tmp.rds”) and just load the object by readRDS(“tmp.rds")

Rongxin Fang Ph.D. Student, Ren Lab Ludwig Institute for Cancer Research University of California, San Diego

On Sep 30, 2019, at 3:06 PM, hjack123 notifications@github.com wrote:

Thank you so much for your reply. and whats the best way to work around this error? Error in loadFUN(x, seqname, ranges) : trying to load regions beyond the boundaries of non-circular sequence "chrUn_KI270438v1"

I can go back to remove these chromosomes, but then lots of things will have to be reran..

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/r3fang/SnapATAC/issues/108?email_source=notifications&email_token=ABT6GG2B4LFZU3Z5JRLB6SDQMJE4NA5CNFSM4I3JTHQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD76X3MA#issuecomment-536706480, or mute the thread https://github.com/notifications/unsubscribe-auth/ABT6GG6OTRGIHFK7FSIADHTQMJE4NANCNFSM4I3JTHQA.

cschmidl commented 4 years ago

I have the same problem, and the provided solution did not work: Error in loadFUN(x, seqname, ranges) : trying to load regions beyond the boundaries of non-circular sequence "chr17" Is it possible that one (or more) peaks are somehow out of the annotated chr17 boundaries? I used the hg19 bowtie genome, and run chromvar for hg19. Thanks for your help and thanks again for this great package! Chris

ccruizm commented 4 years ago

Hello @r3fang

I am also having the same issue. In the beggining I had the the message error mentioned before:

Error in UseMethod("runChromVAR", obj): no applicable method for 'runChromVAR' applied to an object of class "snap"
Traceback:

1. runChromVAR(obj = x.sp, input.mat = "pmat", genome = BSgenome.Mmusculus.UCSC.mm10, 
 .     min.count = 10, species = "Homo sapiens")

and after updating I am able to run:

x.sp@mmat = runChromVAR(
    obj=x.sp,
    input.mat="pmat",
    genome=BSgenome.Mmusculus.UCSC.mm10,
    min.count=10,
    species="Mus musculus" # or using Homo sapiens like in the tutorial
  );
x.sp;

but stops with the next message error:

Error in loadFUN(x, seqname, ranges): trying to load regions beyond the boundaries of non-circular sequence "chr4_JH584295_random"
Traceback:

1. runChromVAR(obj = x.sp, input.mat = "pmat", genome = BSgenome.Mmusculus.UCSC.mm10, 
 .     min.count = 10, species = "Homo sapiens")
2. addGCBias(rse, genome = genome)
3. addGCBias(rse, genome = genome)
4. .local(object, ...)
5. getSeq(genome, peaks)
6. getSeq(genome, peaks)
7. .local(x, ...)
8. .extractFromBSgenomeSingleSequences(x, sseq_args$names, sseq_args$start, 
 .     sseq_args$end, sseq_args$width, sseq_args$strand)
9. lapply(seq_len(length(grl)), function(i) {
 .     gr <- grl[[i]]
 .     if (length(gr) == 0L) 
 .         return(DNAStringSet())
 .     seqlevel <- grl_seqlevels[i]
 .     is_circular <- isCircular(x)[[seqlevel]]
 .     idx <- match(seqlevel, x@user_seqnames)
 .     if (is.na(idx)) 
 .         stop("invalid sequence name: ", seqlevel)
 .     seqname <- names(x@user_seqnames)[[idx]]
 .     if (is.null(snplocs(x, seqname))) {
 .         subject <- try(get(seqname, envir = x@.seqs_cache, inherits = FALSE), 
 .             silent = TRUE)
 .         if (is(subject, "try-error")) {
 .             ans <- loadSubseqsFromStrandedSequence(x@single_sequences, 
 .                 seqname, ranges(gr), strand(gr), is_circular)
 .             return(ans)
 .         }
 .         .linkToCachedObject(subject) <- .newLinkToCachedObject(seqname, 
 .             x@.seqs_cache, x@.link_counts)
 .     }
 .     else {
 .         subject <- x[[seqlevel]]
 .     }
 .     masks(subject) <- NULL
 .     loadSubseqsFromStrandedSequence(subject, seqlevel, ranges(gr), 
 .         strand(gr), is_circular)
 . })
10. lapply(seq_len(length(grl)), function(i) {
  .     gr <- grl[[i]]
  .     if (length(gr) == 0L) 
  .         return(DNAStringSet())
  .     seqlevel <- grl_seqlevels[i]
  .     is_circular <- isCircular(x)[[seqlevel]]
  .     idx <- match(seqlevel, x@user_seqnames)
  .     if (is.na(idx)) 
  .         stop("invalid sequence name: ", seqlevel)
  .     seqname <- names(x@user_seqnames)[[idx]]
  .     if (is.null(snplocs(x, seqname))) {
  .         subject <- try(get(seqname, envir = x@.seqs_cache, inherits = FALSE), 
  .             silent = TRUE)
  .         if (is(subject, "try-error")) {
  .             ans <- loadSubseqsFromStrandedSequence(x@single_sequences, 
  .                 seqname, ranges(gr), strand(gr), is_circular)
  .             return(ans)
  .         }
  .         .linkToCachedObject(subject) <- .newLinkToCachedObject(seqname, 
  .             x@.seqs_cache, x@.link_counts)
  .     }
  .     else {
  .         subject <- x[[seqlevel]]
  .     }
  .     masks(subject) <- NULL
  .     loadSubseqsFromStrandedSequence(subject, seqlevel, ranges(gr), 
  .         strand(gr), is_circular)
  . })
11. FUN(X[[i]], ...)
12. loadSubseqsFromStrandedSequence(x@single_sequences, seqname, 
  .     ranges(gr), strand(gr), is_circular)
13. loadFUN(x, seqname, ranges)
14. loadFUN(x, seqname, ranges)
15. stop("trying to load regions beyond the boundaries ", "of non-circular sequence \"", 
  .     seqname, "\"")

Do you have any idea what might be happening?

Thanks in advance for your help.

ravipatel4 commented 4 years ago

Hello @r3fang,

+1 I get the same error while running the runChromVar function: Error in loadFUN(x, seqname, ranges) : trying to load regions beyond the boundaries of non-circular sequence "chrUn_GL456396"

Little digging revealed that some of the macs2 peaks are extended beyond the end of chromosomes ("chrUn_GL456396" in my case), which is then also propagated in the peaks.combined.bed file. For example, Peak: chrUn_GL456396 20846 21283, while the length of chrUn_GL456396 is 21240 bases in the genome (mm10) that I am using for both the initial alignments and the SnapATAC analysis. As a result, these extended peaks end up in the snap object, making chromVar to throw the above error.

Do you know why some of the macs2 peaks extend beyond the ends of chromosomes?

Thank you in advance.

jindalk commented 4 years ago

Hi, I am getting a similar error Error in loadFUN(x, seqname, ranges) : trying to load regions beyond the boundaries of non-circular sequence "chr4_GL456216_random" Were you able to fix this?

Thanks

cacaonib commented 3 years ago

anyone solve this problem in hear? if you solve this error, please tell me how to solve thank you

Error in loadFUN(x, seqname, ranges) : trying to load regions beyond the boundaries of non-circular sequence "chr4_JH584295_random"

cacaonib commented 3 years ago

Hi, I am getting a similar error Error in loadFUN(x, seqname, ranges) : trying to load regions beyond the boundaries of non-circular sequence "chr4_GL456216_random" Were you able to fix this?

Thanks

did you solve this error?

ravipatel4 commented 3 years ago

@jindalk & @cacaonib,

Like I said in my previous message, this error is being generated because some macs2 peaks extend beyond the chromosome lengths. This typically happens for short contigs, e.g. chrUn_xxx, chrN_xxxx_random, etc. A temporary solution that found was to remove data/fragments mapping to these short contigs; the command ran fine after that.

When I did little more digging to find why some of these macs2 peaks exceed the bounds of the contigs, I found that there was bug in cellranger-atac (the adjusted fragment bounds exceed the size of contig to which the fragment is mapped.), which they fixed in v1.2.0 of the cellranger-atac (https://support.10xgenomics.com/single-cell-atac/software/release-notes/1-2). I haven't tested this myself, but my guess is that using the newer version of cellranger-atac should resolve this issue.

I hope this helps.

cacaonib commented 3 years ago

@jindalk & @cacaonib,

Like I said in my previous message, this error is being generated because some macs2 peaks extend beyond the chromosome lengths. This typically happens for short contigs, e.g. chrUn_xxx, chrN_xxxx_random, etc. A temporary solution that found was to remove data/fragments mapping to these short contigs; the command ran fine after that.

When I did little more digging to find why some of these macs2 peaks exceed the bounds of the contigs, I found that there was bug in cellranger-atac (the adjusted fragment bounds exceed the size of contig to which the fragment is mapped.), which they fixed in v1.2.0 of the cellranger-atac (https://support.10xgenomics.com/single-cell-atac/software/release-notes/1-2). I haven't tested this myself, but my guess is that using the newer version of cellranger-atac should resolve this issue.

I hope this helps.

thank you for reply.!! i wonder that you gave two different advice. [A temporary solution that found was to remove data/fragments mapping to these short contigs; the command ran fine after that.]
this advice means, i need to remove short contigs, e.g. chrUn_xxx, chrN_xxxx_random in peaks.combined,bed file? or snap file?

thank you for your advice

ravipatel4 commented 3 years ago

I removed chrM and all contigs whose names match "_" from individual matrices in R. Below is an example code snippet to remove these chromosomes from a bmat.

chr.exclude = seqlevels(x.sp@feature)[grep("_|chrM", seqlevels(x.sp@feature))];
idy = grep(paste(chr.exclude, collapse="|"), x.sp@feature);
if(length(idy) > 0){x.sp = x.sp[,-idy, mat="bmat"]};

EDIT: But, I would recommend rerunning the newer version of cellranger-atac (and not worrying about removing the short contigs), in case if there were any other issues in the older version of cellranger-atac with read mapping such as incorrect mappings in the middle (and not at the ends) of a chromosome that were not picked up by runChromVar function.

cacaonib commented 3 years ago

I removed chrM and all contigs whose names match "_" from individual matrices in R. Below is an example code snippet to remove these chromosomes from a bmat.

chr.exclude = seqlevels(x.sp@feature)[grep("_|chrM", seqlevels(x.sp@feature))];
idy = grep(paste(chr.exclude, collapse="|"), x.sp@feature);
if(length(idy) > 0){x.sp = x.sp[,-idy, mat="bmat"]};

EDIT: But, I would recommend rerunning the newer version of cellranger-atac (and not worrying about removing the short contigs), in case if there were any other issues in the older version of cellranger-atac with read mapping such as incorrect mappings in the middle (and not at the ends) of a chromosome that were not picked up by runChromVar function.

I also tried to remove chrM, and others. but still get a error when i did addsnappmat. So, i tried to do other direction. i used fragment file when make a snapfile (snaptools pre). as result i didn't meet any chrM or chr4_unknown peaks. and also can do downstream analysis (runchromvar, homer)

thank you.

SSICreative83 commented 3 years ago

Hi, I also have an issue although scATAC data from cellranger-atac 1.2.0.

"Error in loadFUN(x, seqname, ranges) : trying to load regions beyond the boundaries of non-circular sequence "chr10_NW_021160244v1_random"

Could you help me for that ?

Thanks

SSICreative83 commented 3 years ago

In addition, when I run DAR, I always got the following error:

plotFeatureSingle(

Could you help me?

Thanks