logo
pub struct IndexedReader<R: Read + Seek> {
    pub index: Index,
    /* private fields */
}
Expand description

A FASTA reader with an index as created by SAMtools (.fai).

Fields

index: Index

Implementations

Read from a given file path. This assumes the index ref.fasta.fai to be present for FASTA ref.fasta.

Read from a FASTA and its index, both given as io::Read. FASTA has to be io::Seek in addition.

Read from a FASTA and its index, the first given as io::Read, the second given as index object.

Fetch an interval from the sequence with the given name for reading.

start and stop are 0-based and stop is exclusive - i.e. [start, stop)

Example
use bio::io::fasta::IndexedReader;
// create dummy files
const FASTA_FILE: &[u8] = b">chr1\nGTAGGCTGAAAA\nCCCC";
const FAI_FILE: &[u8] = b"chr1\t16\t6\t12\t13";

let seq_name = "chr1";
let start: u64 = 0; // start is 0-based, inclusive
let stop: u64 = 10; // stop is 0-based, exclusive
                    // load the index
let mut faidx = IndexedReader::new(std::io::Cursor::new(FASTA_FILE), FAI_FILE).unwrap();
// move the pointer in the index to the desired sequence and interval
faidx
    .fetch(seq_name, start, stop)
    .expect("Couldn't fetch interval");
// read the subsequence defined by the interval into a vector
let mut seq = Vec::new();
faidx.read(&mut seq).expect("Couldn't read the interval");
assert_eq!(seq, b"GTAGGCTGAA");
Errors

If the seq_name does not exist within the index.

Fetch an interval from the sequence with the given record index for reading.

start and stop are 0-based and stop is exclusive - i.e. [start, stop)

Example
use bio::io::fasta::IndexedReader;
// create dummy files
const FASTA_FILE: &[u8] = b">chr1\nGTAGGCTGAAAA\nCCCC";
const FAI_FILE: &[u8] = b"chr1\t16\t6\t12\t13";

let rid: usize = 0;
let start: u64 = 0; // start is 0-based, inclusive
let stop: u64 = 10; // stop is 0-based, exclusive
                    // load the index
let mut faidx = IndexedReader::new(std::io::Cursor::new(FASTA_FILE), FAI_FILE).unwrap();
// move the pointer in the index to the desired sequence and interval
faidx
    .fetch_by_rid(rid, start, stop)
    .expect("Couldn't fetch interval");
// read the subsequence defined by the interval into a vector
let mut seq = Vec::new();
faidx.read(&mut seq).expect("Couldn't read the interval");
assert_eq!(seq, b"GTAGGCTGAA");
Errors

If rid does not exist within the index.

Fetch the whole sequence with the given name for reading.

Fetch the whole sequence with the given record index for reading.

Read the fetched sequence into the given vector.

Return an iterator yielding the fetched sequence.

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

Performs the conversion.

Performs the conversion.

Should always be Self

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

Checks if self is actually part of its subset T (and can be converted to it).

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

The inclusion map: converts self to the equivalent element of its superset.

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.