Struct noodles_vcf::Reader[][src]

pub struct Reader<R> { /* fields omitted */ }
Expand description

A VCF reader.

The VCF format has two main parts: 1) a header and 2) a list of VCF records.

Each header line is prefixed with a # (number sign) and is terminated by the header header (#CHROM…; inclusive).

VCF records are line-based and follow directly after the header until EOF.

Examples

use noodles_vcf as vcf;

let mut reader = File::open("sample.vcf")
    .map(BufReader::new)
    .map(vcf::Reader::new)?;

reader.read_header()?;

for result in reader.records() {
    let record = result?;
    println!("{:?}", record);
}

Implementations

Creates a VCF reader.

Examples

use noodles_vcf as vcf;

let data = b"##fileformat=VCFv4.3
#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO
sq0\t1\t.\tA\t.\t.\tPASS\t.
";

let reader = vcf::Reader::new(&data[..]);

Reads the raw VCF header.

This reads all header lines prefixed with a # (number sign), which includes the header header (#CHROM…).

The position of the stream is expected to be at the start.

This returns the raw VCF header as a std::string::String, and as such, it is not necessarily valid. The raw header can subsequently be parsed as a crate::Header.

Examples

use noodles_vcf as vcf;

let data = b"##fileformat=VCFv4.3
#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO
sq0\t1\t.\tA\t.\t.\tPASS\t.
";

let mut reader = vcf::Reader::new(&data[..]);
let header = reader.read_header()?;

assert_eq!(header, "##fileformat=VCFv4.3\n#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n");

Reads a single raw VCF record.

This reads from the underlying stream until a newline is reached and appends it to the given buffer, sans the final newline character. The buffer can subsequently be parsed as a crate::Record.

The stream is expected to be directly after the header or at the start of another record.

It is more ergonomic to read records using an iterator (see Self::records), but using this method allows control of the line buffer and whether the raw record should be parsed.

If successful, the number of bytes is returned. If the number of bytes read is 0, the stream reached EOF.

Examples

use noodles_vcf as vcf;

let data = b"##fileformat=VCFv4.3
#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO
sq0\t1\t.\tA\t.\t.\tPASS\t.
";

let mut reader = vcf::Reader::new(&data[..]);
reader.read_header()?;

let mut buf = String::new();
reader.read_record(&mut buf)?;

assert_eq!(buf, "sq0\t1\t.\tA\t.\t.\tPASS\t.");

Returns an iterator over records starting from the current stream position.

The stream is expected to be directly after the header or at the start of another record.

Unlike Self::read_record, each record is parsed as a crate::Record.

Examples

use noodles_vcf as vcf;

let data = b"##fileformat=VCFv4.3
#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO
sq0\t1\t.\tA\t.\t.\tPASS\t.
";

let mut reader = vcf::Reader::new(&data[..]);
let header = reader.read_header()?;

let mut records = reader.records();
assert!(records.next().is_some());
assert!(records.next().is_none());

Returns the current virtual position of the underlying BGZF reader.

Examples

use noodles_bgzf as bgzf;
use noodles_vcf as vcf;

let data = Vec::new();
let reader = vcf::Reader::new(bgzf::Reader::new(&data[..]));
let virtual_position = reader.virtual_position();

assert_eq!(virtual_position.compressed(), 0);
assert_eq!(virtual_position.uncompressed(), 0);

Seeks the underlying BGZF stream to the given virtual position.

Virtual positions typically come from an associated index.

Examples

use noodles_bgzf as bgzf;
use noodles_vcf as vcf;

let data = Cursor::new(Vec::new());
let mut reader = vcf::Reader::new(bgzf::Reader::new(data));

let virtual_position = bgzf::VirtualPosition::default();
reader.seek(virtual_position)?;

Returns an iterator over records that intersects the given region.

Examples

use noodles_core::Region;
use noodles_bgzf as bgzf;;
use noodles_tabix as tabix;
use noodles_vcf as vcf;

let mut reader = File::open("sample.vcf.gz")
    .map(bgzf::Reader::new)
    .map(vcf::Reader::new)?;

let index = tabix::read("sample.vcf.gz.tbi")?;
let region = Region::mapped("sq0", 8..=13);
let query = reader.query(&index, &region)?;

for result in query {
    let record = result?;
    println!("{:?}", record);
}
Ok::<(), io::Error>(())

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Converts self into a target type. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Provides immutable access for inspection. Read more

Calls tap in debug builds, and does nothing in release builds.

Provides mutable access for modification. Read more

Calls tap_mut in debug builds, and does nothing in release builds.

Provides immutable access to the reference for inspection.

Calls tap_ref in debug builds, and does nothing in release builds.

Provides mutable access to the reference for modification.

Calls tap_ref_mut in debug builds, and does nothing in release builds.

Provides immutable access to the borrow for inspection. Read more

Calls tap_borrow in debug builds, and does nothing in release builds.

Provides mutable access to the borrow for modification.

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

Immutably dereferences self for inspection.

Calls tap_deref in debug builds, and does nothing in release builds.

Mutably dereferences self for modification.

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

Attempts to convert self into T using TryInto<T>. Read more

Attempts to convert self into a target type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.