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§
Trait Implementations§
Source§impl From<&SliceInfo<[SliceInfoElem; 1], Dim<[usize; 1]>, Dim<[usize; 1]>>> for Index
impl From<&SliceInfo<[SliceInfoElem; 1], Dim<[usize; 1]>, Dim<[usize; 1]>>> for Index
Source§fn from(slice_info: &SliceInfo1) -> Index
fn from(slice_info: &SliceInfo1) -> Index
Converts to this type from the input type.
Source§impl From<SliceInfo<[SliceInfoElem; 1], Dim<[usize; 1]>, Dim<[usize; 1]>>> for Index
impl From<SliceInfo<[SliceInfoElem; 1], Dim<[usize; 1]>, Dim<[usize; 1]>>> for Index
Source§fn from(slice_info: SliceInfo1) -> Index
fn from(slice_info: SliceInfo1) -> Index
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Index
impl RefUnwindSafe for Index
impl Send for Index
impl Sync for Index
impl Unpin for Index
impl UnwindSafe for Index
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.