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
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():
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':
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.
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?
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?
Maybe the file does not actually exist, and the warning message is somehow not being reported?
I guess this would fail:
file.exists(vcf)
.Interesting thought, but the file exists (below) as specified by the path.
!> file.exists(vcf)
[1] TRUE
Below is the output of the proposed experiment - it works with the sample data. Below that is the output to traceback().
**** experiment ****
**** traceback() output ****
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:
And the only path() function that is available after loading VariantAnnotation is
from Rsamtools:
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
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.
Interesting - you think this is the case even though I could load the package sample data?
I think if you
You'll get the actual error message.
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.