Package htsjdk.variant.vcf
Class VCFFileReader
- java.lang.Object
-
- htsjdk.variant.vcf.VCFFileReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<VariantContext>
public class VCFFileReader extends Object implements Closeable, Iterable<VariantContext>
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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()static IntervalListfromVcf(VCFFileReader vcf)Deprecated.since July 2018 since usetoIntervalList(VCFFileReader)insteadstatic IntervalListfromVcf(VCFFileReader vcf, boolean includeFiltered)Deprecated.since July 2018 since usetoIntervalList(VCFFileReader, boolean)insteadstatic IntervalListfromVcf(File file)Deprecated.since July 2018 usetoIntervalList(Path)insteadstatic IntervalListfromVcf(File file, boolean includeFiltered)Deprecated.since July 2018 usetoIntervalList(Path, boolean)insteadVCFHeadergetFileHeader()Returns the VCFHeader associated with this VCF/BCF file.static SAMSequenceDictionarygetSequenceDictionary(File file)Returns the SAMSequenceDictionary from the provided VCF file.static SAMSequenceDictionarygetSequenceDictionary(Path path)Returns the SAMSequenceDictionary from the provided VCF file.static booleanisBCF(File file)Returns true if the given file appears to be a BCF file.static booleanisBCF(Path path)Returns true if the given path appears to be a BCF file.booleanisQueryable()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(Locatable locatable)Queries for records overlapping theLocatablespecified.CloseableIterator<VariantContext>query(String chrom, int start, int end)Queries for records overlapping the region specified.IntervalListtoIntervalList()Converts the underlying VCFFileReader to an IntervalList.IntervalListtoIntervalList(boolean includeFiltered)static IntervalListtoIntervalList(VCFFileReader vcf)Converts a vcf to an IntervalList.static IntervalListtoIntervalList(VCFFileReader vcf, boolean includeFiltered)Converts aVCFFileReaderto an IntervalList.static IntervalListtoIntervalList(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 IntervalListtoIntervalList(Path path, boolean includeFiltered)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
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.
-
-
Method Detail
-
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 usetoIntervalList(Path)insteadParse 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 usetoIntervalList(Path, boolean)insteadParse 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 usetoIntervalList(VCFFileReader)insteadConverts 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 usetoIntervalList(VCFFileReader, boolean)insteadConverts 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 aVCFFileReaderto 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
-
getFileHeader
public VCFHeader getFileHeader()
Returns the VCFHeader associated with this VCF/BCF file.
-
iterator
public CloseableIterator<VariantContext> iterator()
Returns an iterator over all records in this VCF/BCF file.- Specified by:
iteratorin interfaceIterable<VariantContext>
-
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.- Parameters:
chrom- the chomosome to querystart- query interval startend- query interval end- Returns:
- non-null iterator over VariantContexts
-
query
public CloseableIterator<VariantContext> query(Locatable locatable)
Queries for records overlapping theLocatablespecified. Note that this method requires VCF files with an associated index. If no index exists a TribbleException will be thrown.- Returns:
- non-null iterator over VariantContexts
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isQueryable
public boolean isQueryable()
A method to check if the reader is query-able, i.e. if a call toquery(String, int, int)can be successful- Returns:
- true if the reader can be queried, i.e. if the underlying Tribble reader is queryable.
-
-