This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Read Vcf file using htsjdk library

Hi, I am using htsjdk library and want to read vcf file. I tried the following code but it gives error "Exception in thread "main" htsjdk.tribble.TribbleException$InvalidHeader: Your input file has a malformed header: We never saw the required CHROM header line (starting with one #) for the input VCF file". I checked the file and created the sample file but same error. Any suggestion? Thanks for your time and consideration.

VCFCodec codec = new VCFCodec();

LineReader r= LineReaderUtil.fromBufferedStreamSystem.in);

LineIteratorImpl t= new LineIteratorImpl(r);

codec.readActualHeader(t);

while(t.hasNext()){

    VariantContext ctx = codec.decode(t.next());

}

r.close();

t.close();
ngs

I checked the file and created the sample file but same error. Any suggestion?

show us the header.

Case 1: The file "Sample2_Working" is working but the file "Sample_Error" gives an error. Both files are same but with the different header. Case 2: The file "Sample2_Working" is working but with another error. "An index is required, but none found". How can I generate the index file?

Thanks

Case1: Sample_Error header 3rd line

##HANDS2CommandLine<ID=assign,CommandLine="assign -s example/brassica/napus.bam -g example/brassica/rapa.fa.gff -hsp example/brassica/napus.hsp -snp1 example/brassica/rapa.snp -snp2 example/brassica/oleracea.snp -bc example/brassica/napus_test.bc -bc1 example/brassica/rapa.bc -bc2 example/brassica/oleracea.bc -out1 example/brassica/napus-a.vcf -out2 example/brassica/napus-c.vcf -m true">

this is not a valid header line. A VCF header line is

##KEY=VALUE
##fileformat=VCFv4.1
##source=HANDS2v1.0
##Genome=1
#CHROM  POS ID  REF ALT QUAL    FILTER  INFO
Bra1.27 3355    .   T   .   100 .   HSP=K;FC=Y;DB=T
Bra1.27 3527    .   G   A   100 .   HSP=R;FC=Y;DB=G
Bra1.27 3538    .   A   T   100 .   HSP=W;FC=Y;DB=A
Bra1.27 3543    .   T   C   100 .   HSP=Y;FC=N;DB=*
Bra1.27 3549    .   C   .   100 .   HSP=Y;FC=Y;DB=C

Okay i will remove those lines. This sample file is working but with another error "An index is required, but none found." I have created the .tbi index file but its not working. How we can resolve this error? Thanks

1 answer

something like:

VCFFileReader r=new VCFFileReader(new File("your.vcf") );
CloseableIterator<VariantContext> t=r.iterator();
while(t.hasNext()){
    VariantContext ctx =t.next();
}
t.close();
r.close();

Log in to answer this question.