Error in mapply(function(x, y)
Entering edit mode
2.1 years ago

Dear all,

I am working on R and using the rehh package. I am converting the vcf file to an object of haplohh-class using the command

> hp_vcf <- data2haplohh(hap_file = "sample.vcf", polarize_vcf = FALSE, vcf_reader = "data.table", = "CM004562.1", verbose = TRUE)

But I am getting an error

* Reading input file(s) *
Using package 'data.table' to read vcf.
Extracting map information.
Extracting haplotypes.
Number of individuals which are 
Haploid Diploid Triploid, ... : 
1 2 
0 1 
Error in mapply(function(x, y) { : 
  zero-length inputs cannot be mixed with those of non-zero length

Someone please help me in resolving this error. Any help would be highly appreciated

Thanks in advance

rehh R • 786 views
Entering edit mode
2.1 years ago

I am unfortunately not familiar with the package, but out of curiosity, I had a look at the source code of that function.

The error is thrown by the function that will create haplotype names out of the combination of individuals and the ploidy. The names of the individuals are taken from colnames(gt), but there are apparently no column names.

if (nrow(gt) > 0) {
  # set haplotype names as individual + underscore + 1:ploidy
  rownames(tmp_haplo) <-
      mapply(function(x, y) {
        if (y == 1) {
          # haploid -> return un-changed
        } else{
          # return vector c("HG1_1",...,"HG1_y")
          paste(x, 1:y, sep = "_")
      }, colnames(gt), ind_ploidy, USE.NAMES = FALSE),
      use.names = FALSE

So it seems that you are trying to read a vcf file with multiple samples, however there are issues with reading the header. Therefore, I would try to manually read your file in the same manner as the function and inspect the result:

      gt <- sub(":.*$", "", as.matrix(
          skip = "#CHROM",
          drop = c(
          stringsAsFactors = FALSE,
          showProgress = FALSE,

So on this matrix, have a look what colnames(gt) looks like...

Alternatively, you could try the external VCF reader package that is supported: library(vcfR)

Good luck!

Entering edit mode

I am very grateful to Matthias Zepper for the quick response and guidance. I am going to try the vcfR package to read the vcf file. Hopefully, it will work. Thank you so much.


Login before adding your answer.

Traffic: 1435 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6