How to read a gzipped VCF file from a R connection
0
0
Entering edit mode
3.3 years ago
user31888 ▴ 130

Below is an example R connection to a gzipped .vcf file that I would like to read.

vcf <- file(description = "https://github.com/zhanxw/checkVCF/blob/master/example.vcf.gz")

vcf
A connection with                                                                           
description "https://github.com/zhanxw/checkVCF/blob/master/example.vcf.gz"
class       "url-libcurl"                                                  
mode        "r"                                                            
text        "text"                                                         
opened      "closed"                                                       
can read    "yes"                                                          
can write   "no"

How could one read the .vcf file? I tried with vcfR and VariantAnnotation packages without success.

library(vcfR)
read.vcfR(vcf)
Error in read.vcfR(vcf) : 
  The parameter file is expected to be a character.

library(VariantAnnotation)
readVcf(vcf)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘readVcf’ for signature ‘"url", "missing"’
R vcf • 1.9k views
ADD COMMENT
1
Entering edit mode

The error message is pretty clear. You're passing a file object to a parameter that expects a character. Try passing the file path directly.

ADD REPLY
0
Entering edit mode

The connection vcf I created is for example purpose only. In the real life I will not know the URL (I did not manage to obtain the URL from a R connection). read.vcfR(<URL>) downloads the file but dose not read it. The point of the task is to read the file without downloading it.

ADD REPLY
0
Entering edit mode

Do you mean that you wish to stream a VCF file without reading it entirely to memory? I know data.table can do something like that with local files, maybe that is a lead worth pursuing?

ADD REPLY

Login before adding your answer.

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