MCPcopy Create free account
hub / github.com/RealTimeGenomics/rtg-tools / VcfReader

Class VcfReader

src/main/java/com/rtg/vcf/VcfReader.java:48–183  ·  view source on GitHub ↗

Reads a .vcf input stream and converts it into VCF records.

Source from the content-addressed store, hash-verified

46 * Reads a <code>.vcf</code> input stream and converts it into VCF records.
47 */
48public class VcfReader implements VcfIterator {
49
50 private final VcfParser mParser;
51 private final LineReader mIn;
52 private final VcfHeader mHeader;
53 private final int mNumSamples;
54 private VcfRecord mCurrent;
55
56 // Constructor for use by VcfReaderFactory
57 VcfReader(VcfParser parser, BrLineReader in) throws IOException {
58 this(parser, in, parser.parseHeader(in));
59 }
60
61 /**
62 * Read VcfRecords from a region of a block-compressed file, pre-parsed header
63 * @param parser used to parse each record line
64 * @param reader source of record lines
65 * @param header header for file currently being read (callers responsibility)
66 * @throws IOException if an IO error occurs
67 */
68 VcfReader(VcfParser parser, LineReader reader, VcfHeader header) throws IOException {
69 mParser = parser;
70 mIn = reader;
71 mHeader = header;
72 mNumSamples = mHeader.getNumberOfSamples();
73 setNext();
74 }
75
76 /**
77 * Open a <code>VCF</code> reader from commonly used flag arguments
78 * @param flags the flags parser with all arguments set
79 * @return the reader
80 * @throws IOException if an IO Error occurs
81 */
82 static VcfReader openVcfReader(CFlags flags) throws IOException {
83 return new VcfReaderFactory(flags).make(flags);
84 }
85
86 /**
87 * Open a <code>VCF</code> reader
88 * @param f <code>VCF</code> file, optionally gzipped. If f is '-', input will be read from System.in instead
89 * @return the reader
90 * @throws IOException if an IO Error occurs
91 */
92 public static VcfReader openVcfReader(File f) throws IOException {
93 return new VcfReaderFactory().make(f);
94 }
95
96 /**
97 * Open a <code>VCF</code> reader, optionally with a region restriction
98 * @param f <code>VCF</code> file, optionally gzipped. If f is '-', input will be read from System.in instead
99 * @param ranges regions to restrict to, null if whole file should be used
100 * @return the reader
101 * @throws IOException if an IO Error occurs or if trying to apply a region restriction when reading from System.in
102 */
103 public static VcfReader openVcfReader(File f, ReferenceRanges<String> ranges) throws IOException {
104 return new VcfReaderFactory().regions(ranges).make(f);
105 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected