[Bioc-devel] VariantAnnotation: writeVcf fails for factors with unused levels

Julian Gehring julian.gehring at embl.de
Fri Feb 7 09:09:34 CET 2014


Hi,

I got two more (with VariantAnnotation_1.9.35, Rsamtools_1.15.27).  They 
may be related to what we discussed before, so I'm leaving them in this 
thread.

** Some example data

#+BEGIN_SRC R
   library(VariantAnnotation)

   example(VRanges) ## gives us 'vr' and 'vcf'

   vr_small = vr
   width(vr_small) = 1  ## widths > 1 can become ambiguous in the VCF
#+END_SRC


** Convertion between VCF and VRanges

#+BEGIN_SRC R
   vcf_small = as(vr_small, "VCF")
   vr_back = as(vcf_small, "VRanges") ## fails in devel
#+END_SRC

#+BEGIN_EXAMPLE
Error in ad[, , 1, drop = FALSE] : incorrect number of dimensions
#+END_EXAMPLE

In bioc-stable, this does not fail, but results in 4 variants (see 
below).  Maybe the latest patch will change this once it is out.


** Writing to VCF, reading, and converting

Converting back and forth duplicates variants.

#+BEGIN_SRC R
   vr_small ## 2 variants

   temp_file = tempfile()
   writeVcf(vr_small, temp_file)

   vr_read = readVcf(temp_file, "hg19")
   rowData(vr_read) ## 2 variants

   vr_conv = as(vr_read, "VRanges")
   vr_conv ## "4" variants (duplicated)
#+END_SRC


Best wishes
Julian


On 02/06/2014 01:58 PM, Michael Lawrence wrote:
> Hi Julian,
>
> Thanks for this one. It was a bug in Rsamtools, now fixed in devel, version
> 1.15.27. I'll leave it to Martin/Val to OK it and push to release.
>
> Michael
>
>
> On Thu, Feb 6, 2014 at 1:46 AM, Julian Gehring <julian.gehring at embl.de>wrote:
>
>> Hi Michael,
>>
>> Thanks for the fast patching.  However, going a step further and trying to
>> read the VCF again fails (with VariantAnnotation_1.9.35
>> ).  I'm not sure if this is related to the same issue.
>>
>>
>> #+BEGIN_SRC R
>>
>> library(VariantAnnotation)
>> example(VRanges)
>> writeVcf(vr, "out.vcf") ## works
>> readVcf("out.vcf", "hg19") ## fails
>>
>> #+END_SRC
>>
>> Error in `rownames<-`(`*tmp*`, value = c("chr1", "chr2")) :
>>    invalid rownames length
>>
>> Best wishes
>> Julian
>>
>>
>>
>> On 02/05/2014 08:38 PM, Michael Lawrence wrote:
>>
>>> Thanks, fixed in 1.9.35/1.8.11.
>>>
>>>
>>> On Wed, Feb 5, 2014 at 12:35 AM, Julian Gehring <julian.gehring at embl.de
>>>> wrote:
>>>
>>>   Hi,
>>>>
>>>> I just stumbled over the fact that 'writeVcf' for a 'VRanges' fails if
>>>> 'sampleNames' is a factor with unused levels.  Here a small example:
>>>>
>>>> #+BEGIN_SRC R
>>>>
>>>> library(VariantAnnotation)
>>>> example(VRanges)
>>>> writeVcf(vr, "out.vcf") ## works
>>>>
>>>> f = sampleNames(vr)
>>>> f ## levels: a, b
>>>> levels(f) = c("a", "b", "c") ## c in unused
>>>> f ## levels: a, b, c
>>>> sampleNames(vr) = f
>>>> writeVcf(vr, "out.vcf")  ## fails
>>>>
>>>> #+END_SRC
>>>>
>>>> Error in writeVcf(as(obj, "VCF"), filename, ...) :
>>>>     error in evaluating the argument 'obj' in selecting a method for
>>>> function 'writeVcf': Error in ans[sampleToUniq] <- as.vector(v) :
>>>> replacement has length zero
>>>>
>>>> This occurs both with the latest bioc-release and bioc-devel.  I don't
>>>> know what exactly is causing this, but please let me know if I can be of
>>>> any help.
>>>>
>>>> Best wishes
>>>> Julian
>>>>
>>>> _______________________________________________
>>>> Bioc-devel at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>>>>
>>>>
>>>
>



More information about the Bioc-devel mailing list