Closed AlessandroBalestrucci closed 6 months ago
@AlessandroBalestrucci It is a bit confusing, but you can't use for each on an iterator
; only an Iterable.
The correct syntax to use is:
for (VariantContext variant: vcfReader)
It should work fine if you do it that way.
You can take a look at a project that uses htsjdk, for example Picard.
https://github.com/broadinstitute/picard/blob/master/src/main/java/picard/vcf/LiftoverVcf.java has this use-case (one of many).
you should remove the .iterator()
from you code, since the reader is
iterable, but the iterator is not...
Cheers,
Y.
On Tue, Jan 23, 2024 at 10:30 AM Chris Norman @.***> wrote:
Closed #1701 https://github.com/samtools/htsjdk/issues/1701 as completed.
— Reply to this email directly, view it on GitHub https://github.com/samtools/htsjdk/issues/1701#event-11571942968, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAU6JUWPX3LBQNYWLH6XKG3YP7JRXAVCNFSM6AAAAABCHE42NWVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRGU3TCOJUGI4TMOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Thanks everyone for your helps
Description of the issue:
Not possible to invoke the iterator() method on object VCFFileReader
Your environment:
version of htsjdk: 4.1.0 version of java: 17
Steps to reproduce
VCFFileReader vcfReader = new VCFFileReader(new File(vcf), false); for (VariantContext variant: vcfReader.iterator()) { //some code here }
Expected behaviour
It should complie
Actual behaviour
Compile error: "Can only iterate over an array or an instance of java.lang.Iterable"