# Class VCFFileReader

java.lang.Object
htsjdk.variant.vcf.VCFFileReader

All Implemented Interfaces:
  `VCFReader, Closeable, AutoCloseable, Iterable<VariantContext>`

public class VCFFileReader extends Object implements VCFReader
Simplified interface for reading from VCF/BCF files.

## Constructor Summary

Constructors
Constructor
Description
`VCFFileReader(File file)`
Constructs a VCFFileReader that requires the index to be present.
`VCFFileReader(File file, boolean requireIndex)`
Allows construction of a VCFFileReader that will or will not assert the presence of an index as desired.
`VCFFileReader(File file, File indexFile)`
Constructs a VCFFileReader with a specified index.
`VCFFileReader(File file, File indexFile, boolean requireIndex)`
Allows construction of a VCFFileReader with a specified index file.
`VCFFileReader(Path path)`
Constructs a VCFFileReader that requires the index to be present.
`VCFFileReader(Path path, boolean requireIndex)`
Allows construction of a VCFFileReader that will or will not assert the presence of an index as desired.
`VCFFileReader(Path path, Path indexPath)`
Constructs a VCFFileReader with a specified index.
`VCFFileReader(Path path, Path indexPath, boolean requireIndex)`
Allows construction of a VCFFileReader with a specified index path.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
`static IntervalList`
`fromVcf(VCFFileReader vcf)`
Deprecated.
since July 2018 since use `toIntervalList(VCFFileReader)` instead
`static IntervalList`
`fromVcf(VCFFileReader vcf, boolean includeFiltered)`
Deprecated.
since July 2018 since use `toIntervalList(VCFFileReader, boolean)` instead
`static IntervalList`
`fromVcf(File file)`
Deprecated.
since July 2018 use `toIntervalList(Path)` instead
`static IntervalList`
`fromVcf(File file, boolean includeFiltered)`
Deprecated.
since July 2018 use `toIntervalList(Path, boolean)` instead
`final VCFHeader`
`getFileHeader()`
Synonym of `getHeader()`
`VCFHeader`
`getHeader()`
Returns the VCFHeader associated with this VCF/BCF file.
`static SAMSequenceDictionary`
`getSequenceDictionary(File file)`
Returns the SAMSequenceDictionary from the provided VCF file.
`static SAMSequenceDictionary`
`getSequenceDictionary(Path path)`
Returns the SAMSequenceDictionary from the provided VCF file.
`static boolean`
`isBCF(File file)`
Returns true if the given file appears to be a BCF file.
`static boolean`
`isBCF(Path path)`
Returns true if the given path appears to be a BCF file.
`boolean`
`isQueryable()`
A method to check if the reader is query-able, i.e.
`CloseableIterator<VariantContext>`
`iterator()`
Returns an iterator over all records in this VCF/BCF file.
`CloseableIterator<VariantContext>`
`query(String chrom, int start, int end)`
Queries for records overlapping the region specified.
`IntervalList`
`toIntervalList()`
Converts the underlying VCFFileReader to an IntervalList.
`IntervalList`
`toIntervalList(boolean includeFiltered)`
`static IntervalList`
`toIntervalList(VCFFileReader vcf)`
Converts a vcf to an IntervalList.
`static IntervalList`
`toIntervalList(VCFFileReader vcf, boolean includeFiltered)`
Converts a `VCFFileReader` to an IntervalList.
`static IntervalList`
`toIntervalList(Path path)`
Parse a VCF file and convert to an IntervalList The name field of the IntervalList is taken from the ID field of the variant, if it exists.
`static IntervalList`
`toIntervalList(Path path, boolean includeFiltered)`
`static Iterator<Interval>`
`toIntervals(VCFFileReader vcf, boolean includeFiltered)`
Converts a `VCFFileReader` to an `Iterator<Interval>` The name field of the Interval is taken from the ID field of the variant, if it exists.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface Iterable

`forEach, spliterator`

### Methods inherited from interface VCFReader

`query`

## Constructor Details

### VCFFileReader

public VCFFileReader(File file)
Constructs a VCFFileReader that requires the index to be present.

### VCFFileReader

public VCFFileReader(File file, File indexFile)
Constructs a VCFFileReader with a specified index.

### VCFFileReader

public VCFFileReader(File file, boolean requireIndex)
Allows construction of a VCFFileReader that will or will not assert the presence of an index as desired.

### VCFFileReader

public VCFFileReader(File file, File indexFile, boolean requireIndex)
Allows construction of a VCFFileReader with a specified index file.

### VCFFileReader

public VCFFileReader(Path path)
Constructs a VCFFileReader that requires the index to be present.

### VCFFileReader

public VCFFileReader(Path path, Path indexPath)
Constructs a VCFFileReader with a specified index.

### VCFFileReader

public VCFFileReader(Path path, boolean requireIndex)
Allows construction of a VCFFileReader that will or will not assert the presence of an index as desired.

### VCFFileReader

public VCFFileReader(Path path, Path indexPath, boolean requireIndex)
Allows construction of a VCFFileReader with a specified index path.

## Method Details

### isBCF

public static boolean isBCF(File file)
Returns true if the given file appears to be a BCF file.

### isBCF

public static boolean isBCF(Path path)
Returns true if the given path appears to be a BCF file.

### getSequenceDictionary

public static SAMSequenceDictionary getSequenceDictionary(File file)
Returns the SAMSequenceDictionary from the provided VCF file.

### getSequenceDictionary

public static SAMSequenceDictionary getSequenceDictionary(Path path)
Returns the SAMSequenceDictionary from the provided VCF file.

### toIntervalList

public static IntervalList toIntervalList(Path path)
Parse a VCF file and convert to an IntervalList The name field of the IntervalList is taken from the ID field of the variant, if it exists. if not, creates a name of the format interval-n where n is a running number that increments only on un-named intervals

Parameters:
  `path` - a VCF
Returns:

### toIntervalList

public static IntervalList toIntervalList(Path path, boolean includeFiltered)

### fromVcf

@Deprecated public static IntervalList fromVcf(File file)
Deprecated.
since July 2018 use `toIntervalList(Path)` instead
Parse a VCF file and convert to an IntervalList The name field of the IntervalList is taken from the ID field of the variant, if it exists. if not, creates a name of the format interval-n where n is a running number that increments only on un-named intervals

Parameters:
  `file` - a VCF
Returns:
  an `IntervalList`

### fromVcf

@Deprecated public static IntervalList fromVcf(File file, boolean includeFiltered)
Deprecated.
since July 2018 use `toIntervalList(Path, boolean)` instead
Parse a VCF file and convert to an IntervalList The name field of the IntervalList is taken from the ID field of the variant, if it exists. if not, creates a name of the format interval-n where n is a running number that increments only on un-named intervals

Parameters:
  `file` -
Returns:

### toIntervalList

public IntervalList toIntervalList()
Converts the underlying VCFFileReader to an IntervalList. The name field of the IntervalList is taken from the ID field of the variant, if it exists. If not, creates a name of the format 'interval-n' where n is a running number that increments on un-named intervals. Will use the "END" tag in the INFO field as the end of the interval (if exists).

Returns:
  an IntervalList constructed from input vcf

### toIntervalList

public IntervalList toIntervalList(boolean includeFiltered)

### fromVcf

@Deprecated public static IntervalList fromVcf(VCFFileReader vcf)
Deprecated.
since July 2018 since use `toIntervalList(VCFFileReader)` instead
Converts a vcf to an IntervalList. The name field of the IntervalList is taken from the ID field of the variant, if it exists. If not, creates a name of the format interval-n where n is a running number that increments only on un-named intervals. Will use a "END" tag in the INFO field as the end of the interval (if exists).

Parameters:
  `vcf` - the vcfReader to be used for the conversion
Returns:
  an IntervalList constructed from input vcf

### toIntervalList

public static IntervalList toIntervalList(VCFFileReader vcf)
Converts a vcf to an IntervalList. The name field of the IntervalList is taken from the ID field of the variant, if it exists. If not, creates a name of the format interval-n where n is a running number that increments only on un-named intervals. Will use a "END" tag in the INFO field as the end of the interval (if exists).

Parameters:
  `vcf` - the vcfReader to be used for the conversion
Returns:
  an IntervalList constructed from input vcf

### fromVcf

@Deprecated public static IntervalList fromVcf(VCFFileReader vcf, boolean includeFiltered)
Deprecated.
since July 2018 since use `toIntervalList(VCFFileReader, boolean)` instead
Converts a vcf to an IntervalList. The name field of the IntervalList is taken from the ID field of the variant, if it exists. If not, creates a name of the format interval-n where n is a running number that increments only on un-named intervals. Will use a "END" tag in the INFO field as the end of the interval (if exists).

Parameters:
  `vcf` - the vcfReader to be used for the conversion
Returns:
  an IntervalList constructed from input vcf

### toIntervalList

public static IntervalList toIntervalList(VCFFileReader vcf, boolean includeFiltered)
Converts a `VCFFileReader` to an IntervalList. The name field of the Interval is taken from the ID field of the variant, if it exists. If not, creates a name of the format interval-n where n is a running number that increments only on un-named intervals. Will use a "END" tag in the INFO field as the end of the interval (if exists).

Parameters:
  `vcf` - the vcfReader to be used for the conversion
Returns:
  an IntervalList constructed from input vcf

### toIntervals

public static Iterator<Interval> toIntervals(VCFFileReader vcf, boolean includeFiltered)
Converts a `VCFFileReader` to an `Iterator<Interval>` The name field of the Interval is taken from the ID field of the variant, if it exists. If not, creates a name of the format interval-n where n is a running number that increments only on un-named intervals. Will use a "END" tag in the INFO field as the end of the interval (if exists).

Parameters:
  `vcf` - the vcfReader to be used for the conversion
Returns:
  a Iterator<Interval> constructed from input vcf

### getHeader

public VCFHeader getHeader()
Returns the VCFHeader associated with this VCF/BCF file.

Specified by:
  `getHeader` in interface `VCFReader`

### getFileHeader

public final VCFHeader getFileHeader()
Synonym of `getHeader()`

### iterator

public CloseableIterator<VariantContext> iterator()
Returns an iterator over all records in this VCF/BCF file.

Specified by:
  `iterator` in interface `Iterable<VariantContext>`
Specified by:
  `iterator` in interface `VCFReader`

### query

public CloseableIterator<VariantContext> query(String chrom, int start, int end)
Queries for records overlapping the region specified. Note that this method requires VCF files with an associated index. If no index exists a TribbleException will be thrown.

Specified by:
  `query` in interface `VCFReader`
Parameters:
  `chrom` - the chomosome to query
  `start` - query interval start
  `end` - query interval end
Returns:
  non-null iterator over VariantContexts

### close

public void close()

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`

### isQueryable

public boolean isQueryable()
A method to check if the reader is query-able, i.e. if a call to `query(String, int, int)` can be successful

Specified by:
  `isQueryable` in interface `VCFReader`
Returns:
  true if the reader can be queried, i.e. if the underlying Tribble reader is queryable.