pub enum Index {
    All,
    One(isize),
    Vec(Vec<isize>),
    NDArray(Array1<isize>),
    VecBool(Vec<bool>),
    NDArrayBool(Array1<bool>),
    NDSliceInfo(SliceInfo1),
    RangeAny(RangeAny),
}
Expand description

A specification of which individuals (samples) or SNPs (variants) to read.

See the Table of Index Expressions for a list of expressions for selecting individuals (sample) and SNPs (variants).

By default, all individuals or SNPs are read. The indices can be specified as:

  • an index (negative numbers count from the end)
  • a vector or ndarray of indices
  • a Rust range (negatives not allowed)
  • a vector or ndarray of booleans
  • an ndarray slice (negative indexing and steps allowed)

Examples

use ndarray as nd;
use bed_reader::{Bed, ReadOptions, sample_bed_file};
use bed_reader::assert_eq_nan;
use ndarray::s;

let file_name = sample_bed_file("some_missing.bed")?;
let mut bed = Bed::new(file_name)?;
println!("{:?}", bed.dim()?); // prints (100, 100)

// Read all individuals and all SNPs
let val = ReadOptions::builder().f64().read(&mut bed)?;
assert!(val.dim() == (100, 100));

// Read the individual at index position 10 and all SNPs
let val = ReadOptions::builder().iid_index(10).f64().read(&mut bed)?;
assert!(val.dim() == (1, 100));

// Read the individuals at index positions 0,5, 1st-from-the-end and
// the SNP at index position 3
let val = ReadOptions::builder()
    .iid_index(vec![0, 5, -1])
    .sid_index(3)
    .f64()
    .read(&mut bed)?;
assert!(val.dim() == (3, 1));
// Repeat, but with an ndarray
let val = ReadOptions::builder()
    .iid_index(nd::array![0, 5, -1])
    .sid_index(3)
    .f64()
    .read(&mut bed)?;
assert!(val.dim() == (3, 1));
// Repeat, but with an Rust array
let val = ReadOptions::builder()
    .iid_index([0, 5, -1])
    .sid_index(3)
    .f64()
    .read(&mut bed)?;
assert!(val.dim() == (3, 1));
// Create a boolean ndarray identifying SNPs in chromosome 5,
// then select those SNPs.
let chrom_5 = bed.chromosome()?.map(|elem| elem == "5");
let val = ReadOptions::builder()
    .sid_index(chrom_5)
    .f64()
    .read(&mut bed)?;
assert!(val.dim() == (100, 6));
// Use ndarray's slice macro, [`s!`](https://docs.rs/ndarray/latest/ndarray/macro.s.html),
// to select every 2nd individual and every 3rd SNP.
let val = ReadOptions::builder()
    .iid_index(s![..;2])
    .sid_index(s![..;3])
    .f64()
    .read(&mut bed)?;
assert!(val.dim() == (50, 34));
// Use ndarray's slice macro, [`s!`](https://docs.rs/ndarray/latest/ndarray/macro.s.html),
// to select the 10th-from-last individual to the last, in reverse order,
// and every 3rd SNP in reverse order.)
let val = ReadOptions::builder()
    .iid_index(s![-10..;-1])
    .sid_index(s![..;-3])
    .f64()
    .read(&mut bed)?;
assert!(val.dim() == (10, 34));

Variants

All

One(isize)

Vec(Vec<isize>)

NDArray(Array1<isize>)

VecBool(Vec<bool>)

NDArrayBool(Array1<bool>)

NDSliceInfo(SliceInfo1)

RangeAny(RangeAny)

Implementations

Turns an Index into a vector of usize indexes. Negative means count from end.

Returns the number of elements in an Index.

Returns true if the Index is empty.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. 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.