This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to read a gzipped VCF file from a R connection

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

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.

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.

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?

0 answers

No answers yet.

Log in to answer this question.