Read Vcf file using htsjdk library
1
0
Entering edit mode
7.4 years ago

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 • 2.6k views
ADD COMMENT
0
Entering edit mode

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

show us the header.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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">
ADD REPLY
0
Entering edit mode

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

##KEY=VALUE
ADD REPLY
0
Entering edit mode
##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

ADD REPLY
1
Entering edit mode
7.4 years ago

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();
ADD COMMENT

Login before adding your answer.

Traffic: 2287 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

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

Powered by the version 2.3.6