VCFFileReader doesn't close
1
0
Entering edit mode
9.7 years ago
timofeevbog ▴ 30

I am using htsjdk.variant.vcf.VCFFileReader class to parse .vcf document, so I've got a constructor

VCFFileReader vcfReader = new VCFFileReader(inputFile, false);

and some code like

        for (VariantContext variantContext : vcfReader) {
           //..         
        }
vcfReader.close()

Unfortunately, my file isn't released after I close VCFReader (even if it is an empty cycle), but in construction like

VCFFileReader vcfReader = new VCFFileReader(inputFile, false);
vcfReader.close();

Everything is ok. Does anybody know how to solve it?

Thanks

htsjdk java • 1.9k views
ADD COMMENT
1
Entering edit mode

Are you sure the code gets to vcfReader.close()?

ADD REPLY
0
Entering edit mode

Yes, it gets

ADD REPLY
0
Entering edit mode

how do you know that the file isn't realeased ? an exception ? what's in the loop ?

ADD REPLY
0
Entering edit mode

I can't delete my file after vcfReader.close()

ADD REPLY
0
Entering edit mode

Are you sure nothing else is accessing it? What does lsof say?

ADD REPLY
1
Entering edit mode
9.7 years ago

To be sure that your Reader is closed, use a try/finally statement

VCFFileReader in=null;
try {
in=new VCFFileReader(inputFile, false);
for(VariantContext ctx: in)
   {
   /* something */
   }
}
finally
{
htsjdk.samtools.util.CloserUtil.close(in);
}
ADD COMMENT
0
Entering edit mode

Thanks for your reply, but I still can't delete file even after this construction.

ADD REPLY

Login before adding your answer.

Traffic: 1615 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