VariantAnnotation: no method for function 'path' for signature 'character'
1
1
Entering edit mode
@kipper-fletez-brant-6421
Last seen 4.2 years ago
United States

I am having difficulties reading in the genotypes from my VCF file and get a strange error I don't understand (code at the end of this message).  Essentially, the error is confusing given the definition at [1], or the docs, or ?readGT in which it seems there is a method designed to read in VCF files using filepaths.

I would appreciate any comments or insights.

[1] http://rgm.ogalab.net/RGM/R_rdfile?f=VariantAnnotation/man/readVcf-methods.Rd&d=R_BC

> basedir <- "home/"

> vcf <- paste0(basedir, "extdata/genos.vcf.gz")                                                                            


> gt <- readGT(vcf, nucleotides=TRUE)                                                                                                                     

 Error in (function (classes, fdef, mtable)  :
   unable to find an inherited method for function ‘path’ for signature ‘"character"’

!> sessionInfo()
 R Under development (unstable) (2014-12-03 r67101)
 Platform: x86_64-unknown-linux-gnu (64-bit)

 locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

 other attached packages:
 [1] VariantAnnotation_1.12.2 Rsamtools_1.18.1         Biostrings_2.34.0
 [4] XVector_0.6.0            GenomicRanges_1.18.1     GenomeInfoDb_1.2.2
 [7] IRanges_2.0.0            S4Vectors_0.4.0          BiocGenerics_0.12.0

 loaded via a namespace (and not attached):
  [1] AnnotationDbi_1.28.1    base64enc_0.1-2         BatchJobs_1.5
  [4] BBmisc_1.8              Biobase_2.26.0          BiocParallel_1.0.0
  [7] biomaRt_2.22.0          bitops_1.0-6            brew_1.0-6
 [10] BSgenome_1.34.0         checkmate_1.5.0         codetools_0.2-9
 [13] compiler_3.2.0          DBI_0.3.1               digest_0.6.4
 [16] fail_1.2                foreach_1.4.2           GenomicAlignments_1.2.0
 [19] GenomicFeatures_1.18.2  iterators_1.0.7         RCurl_1.95-4.3
 [22] RSQLite_1.0.0           rtracklayer_1.26.1      sendmailR_1.2-1
 [25] stringr_0.6.2           tools_3.2.0             XML_3.98-1.1
 [28] zlibbioc_1.12.0

 

variantannotation readvcf readgt • 2.2k views
ADD COMMENT
0
Entering edit mode

It's not clear from your code what you have done. Did you actually run all those commands? If so, note that you are over-writing your file path (vcf) with a VCF object, which you are then passing to readGT():

> vcf <- paste0(basedir, "extdata/genos.vcf.gz")
> vcf <- readVcf(vcf, "hg19") 
> gt <- readGT(vcf, nucleotides=TRUE) 

I have no idea if this would give rise to the error you see (I don't have a vcf file handy to try this with), but if this isn't what you are doing you might want to give code that does reflect what you are doing.

EDIT

I realize there IS an example for readVcf(). The first part of which sets up a file path called 'fl':

> fl
[1] "/data/oldR/R-3.1.1/lib64/R/library/VariantAnnotation/extdata/chr22.vcf.gz"
> z <- readGT(fl, nucleotides = TRUE)
> class(z)
[1] "matrix"
> head(z)
            HG00096 HG00097 HG00099 HG00100 HG00101
rs7410291   "A|A"   "A|A"   "G|A"   "A|A"   "A|A"  
rs147922003 "C|C"   "C|C"   "C|C"   "C|C"   "C|C"  
rs114143073 "G|G"   "G|G"   "G|G"   "G|G"   "G|G"  
rs141778433 "C|C"   "C|C"   "C|C"   "C|C"   "C|C"  
rs182170314 "C|C"   "C|C"   "C|C"   "C|C"   "C|C"  
rs115145310 "G|G"   "G|G"   "G|G"   "G|G"   "G|G" 
ADD REPLY
0
Entering edit mode

Whoops, sorry, the call to 'readVCF()' should not have been included as that is not what I ran.  The post has been amended to reflect the code I have entered.  Still confused, but thanks for catching that typo.  And yes, the example in the docs is what lead me to believe that I could call e.g. readGT using a filepath.

ADD REPLY
0
Entering edit mode

I can't reproduce your error using a character file path, using R-devel with the same packages as you. Does this work for you?

example(readVcf)
z <- readGT(f1, nucleotides = TRUE)

Also, it's not clear where your error is coming from. Will you re-run the code that doesn't work, and then a traceback() right after the error?

 

ADD REPLY
0
Entering edit mode

Maybe the file does not actually exist, and the warning message is somehow not being reported?

> readGT("I_am_not_a_file", "hg19")
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function 'path' for signature '"character"'
In addition: Warning message:
In normalizePath(path.expand(file)) :
  path[1]="I_am_not_a_file": No such file or directory

I guess this would fail: file.exists(vcf).

 

ADD REPLY
0
Entering edit mode

Interesting thought, but the file exists (below) as specified by the path.

 

!> file.exists(vcf)
 [1] TRUE

 

ADD REPLY
0
Entering edit mode

Below is the output of the proposed experiment - it works with the sample data.  Below that is the output to traceback().

**** experiment ****

> example(readVcf)
> ## ...lots of output,completes normally
> z <- readGT(fl, nucleotides = TRUE)
>​

**** traceback() output ****

!> traceback()
 13: stop(gettextf("unable to find an inherited method for function %s for signature %s",
         sQuote(fdef@generic), sQuote(cnames)), domain = NA)
 12: (function (classes, fdef, mtable)
     {
         methods <- .findInheritedMethods(classes, fdef, mtable)
         if (length(methods) == 1L)
             return(methods[[1L]])
         else if (length(methods) == 0L) {
             cnames <- paste0("\"", vapply(classes, as.character,
                 ""), "\"", collapse = ", ")
             stop(gettextf("unable to find an inherited method for function %s for signature %s",
                 sQuote(fdef@generic), sQuote(cnames)), domain = NA)
         }
         else stop("Internal error in finding inherited methods; didn't return a unique method",
             domain = NA)
     })(list("character"), function (object, ...)
     standardGeneric("path"), <environment>)
 11: path(file)
 10: stop("scanVcf: ", conditionMessage(err), "\n  path: ", path(file),
         call. = FALSE)
 9: value[[3L]](cond)
 8: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]),
        names[nh], parentenv, handlers[[nh]])
 7: tryCatchList(expr, classes, parentenv, handlers)
 6: tryCatch({
        file <- normalizePath(path.expand(file))
        if (!file.exists(file))
            stop("file does not exist")
        maps <- .vcf_scan_header_maps(file, fixed, info, geno, samples)
        result <- .Call(.scan_vcf_character, file, as.integer(yieldSize),
            maps$samples, maps$fmap, maps$imap, maps$gmap, row.names)
        setNames(result, "*:*-*")
    }, scanTabix_io = function(err) {
        stop("scanVcf: ", conditionMessage(err), call. = FALSE)
    }, error = function(err) {
        stop("scanVcf: ", conditionMessage(err), "\n  path: ", path(file),
            call. = FALSE)
    })
 5: .vcf_scan_character(file, ..., fixed = vcfFixed(param), info = vcfInfo(param),
        geno = vcfGeno(param), samples = vcfSamples(param))
 4: scanVcf(file, param = param, row.names = row.names)
 3: scanVcf(file, param = param, row.names = row.names)
 2: .readLite(file, "GT", param, "GT", row.names = row.names)
 1: readGT(vcf, nucleotides = TRUE)

 

ADD REPLY
0
Entering edit mode

I can track down what is happening, but I don't know exactly why. In VariantAnnotation:::.vcf_scan_character, there is a call to tryCatch(), where the file is supposed to be read in. If there is an error, it runs this code:

error = function(err) {
        stop("scanVcf: ", conditionMessage(err), "\n  path: ",
            path(file), call. = FALSE)

And the only path() function that is available after loading VariantAnnotation is
from Rsamtools:

> showMethods(path)
Function: path (package Rsamtools)
object="BcfFile"
    (inherited from: object="RsamtoolsFile")
object="BigWigFileList"
object="RsamtoolsFile"
object="RsamtoolsFileList"
object="RTLFile"
object="TabixFile"
    (inherited from: object="RsamtoolsFile")

Which is where the error is coming from, because your file object isn't any of those objects, being a character vector. So that's one problem - whatever path() is supposed to be doing in that error message, it can't do, and it should probably just be something like

error = function(err) {
        stop("scanVcf: ", conditionMessage(err), "\n  path: ",
            file, call. = FALSE)

But Valerie Obenchain would know better about that.

Anyway, I am betting that there is something wrong with your installation of VariantAnnotation, so you might just try re-installing, using biocLite(). I can run the code that is failing for you, so I have to assume it is something wrong locally, rather than a bug of some sort.

ADD REPLY
0
Entering edit mode

Interesting - you think this is the case even though I could load the package sample data?

ADD REPLY
0
Entering edit mode

I think if you

setMethod("path", "character", function(object, ...) object)
readGT(vcf, nucleotides = TRUE)

You'll get the actual error message.

ADD REPLY
0
Entering edit mode

Oh, sorry - I missed that you ran traceback() after readGT(vcf), rather than readGT(fl). In that case, you can try what Martin suggests below, to see what the error message is from the tryCatch() call.

ADD REPLY
0
Entering edit mode
@valerie-obenchain-4275
Last seen 4 months ago
United States

This cryptic message was my fault - I was calling path() on non *File objects. Martin has checked in a fix to both release (1.12.6) and devel (1.13.16). Thanks Martin!

Valerie

ADD COMMENT
0
Entering edit mode

Ah, thanks, I look forward to testing the change, and will report back.

ADD REPLY

Login before adding your answer.

Traffic: 175 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