diff --git a/test/Makefile b/test/Makefile index 400191d..8921346 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,7 +5,7 @@ CXX = g++ CXXFLAGS = -std=c++11 -Wall -fsanitize=address # CXXFLAGS = -std=c++11 -Wall -g LDFLAGS = -L$(HTSLIB) -Wl,-rpath,$(HTSLIB) -LIBS = -lhts +LIBS = -lhts -lz -lm -lbz2 -llzma -lcurl -lpthread INC = -I. -I.. -I${HTSINC} OBJS = test-main.o bcf-variant.o bcf-reader.o bcf-writer.o example.o diff --git a/test/bcf-reader.cpp b/test/bcf-reader.cpp index 73c3fc3..c2009a5 100644 --- a/test/bcf-reader.cpp +++ b/test/bcf-reader.cpp @@ -122,3 +122,23 @@ TEST_CASE("parse vcf with multialleles - vector", "[bcf-reader]") var.getGenotypes(gt); for(auto g : gt) cout << g << endl; } + +TEST_CASE("parse EV in vcf - vector", "[bcf-reader]") +{ + string vcffile{"test-GL.vcf.gz"}; + BcfWriter bw(vcffile, "VCF4.2"); + bw.header.addContig("chr20"); + bw.header.addINFO("AF", "A", "Float", "Estimated allele frequency in the range (0,1)"); + bw.header.addFORMAT("GT", "1", "String", "Genotype"); + bw.header.addFORMAT("EV", "G", "String", "Classes of evidence supporting final genotype"); + for(auto & s : {"id01", "id02"}) bw.header.addSample(s); // add 3 samples + bw.writeLine("chr20\t2006060\trs146931526\tG\tA\t100\tPASS\tAF=0.02\tGT:EV\t0/1:RD\t1/1:SR,PE"); + bw.close(); + BcfReader br(vcffile); + BcfRecord var(br.header); + vector ev; + REQUIRE(br.getNextVariant(var)==true); + var.getFORMAT("EV",ev); + REQUIRE(ev[0]=="RD"); + REQUIRE(ev[1]=="SR,PE"); +} diff --git a/vcfpp.h b/vcfpp.h index 78d0703..46bd7b2 100644 --- a/vcfpp.h +++ b/vcfpp.h @@ -2,7 +2,7 @@ * @file https://github.com/Zilong-Li/vcfpp/vcfpp.h * @author Zilong Li * @email zilong.dk@gmail.com - * @version v0.3.7 + * @version v0.3.8 * @breif a single C++ file for manipulating VCF * Copyright (C) 2022-2023.The use of this code is governed by the LICENSE file. ******************************************************************************/ @@ -648,12 +648,12 @@ class BcfRecord // Ugly: GT field is considered to be a string by the VCF header but BCF represents it as INT. v.emplace_back(dst[i]); }; - free(dst); + free(dst[0]); free(dst); return true; } else { - free(dst); + free(dst[0]); free(dst); throw std::runtime_error("couldn't parse the " + tag + " format of this variant.\n"); } }