Enum bed_reader::Index

source ·
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§

source§

impl Index

source

pub fn to_vec(&self, count: usize) -> Result<Vec<isize>, Box<BedErrorPlus>>

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

source§

impl Index

source

pub fn len(&self, count: usize) -> Result<usize, Box<BedErrorPlus>>

Returns the number of elements in an Index.

source

pub fn is_empty(&self, count: usize) -> Result<bool, Box<BedErrorPlus>>

Returns true if the Index is empty.

Trait Implementations§

source§

impl Clone for Index

source§

fn clone(&self) -> Index

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Index

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&[bool]> for Index

source§

fn from(array: &[bool]) -> Index

Converts to this type from the input type.
source§

impl<const N: usize> From<&[bool; N]> for Index

source§

fn from(array: &[bool; N]) -> Index

Converts to this type from the input type.
source§

impl From<&[isize]> for Index

source§

fn from(array: &[isize]) -> Index

Converts to this type from the input type.
source§

impl<const N: usize> From<&[isize; N]> for Index

source§

fn from(array: &[isize; N]) -> Index

Converts to this type from the input type.
source§

impl From<&ArrayBase<OwnedRepr<bool>, Dim<[usize; 1]>>> for Index

source§

fn from(nd_array_bool: &Array1<bool>) -> Index

Converts to this type from the input type.
source§

impl From<&ArrayBase<OwnedRepr<isize>, Dim<[usize; 1]>>> for Index

source§

fn from(nd_array: &Array1<isize>) -> Index

Converts to this type from the input type.
source§

impl From<&ArrayBase<ViewRepr<&bool>, Dim<[usize; 1]>>> for Index

source§

fn from(view: &ArrayView1<'_, bool>) -> Index

Converts to this type from the input type.
source§

impl From<&ArrayBase<ViewRepr<&isize>, Dim<[usize; 1]>>> for Index

source§

fn from(view: &ArrayView1<'_, isize>) -> Index

Converts to this type from the input type.
source§

impl From<&Range<usize>> for Index

source§

fn from(range_thing: &Range<usize>) -> Index

Converts to this type from the input type.
source§

impl From<&RangeFrom<usize>> for Index

source§

fn from(range_thing: &RangeFrom<usize>) -> Index

Converts to this type from the input type.
source§

impl From<&RangeFull> for Index

source§

fn from(range_thing: &RangeFull) -> Index

Converts to this type from the input type.
source§

impl From<&RangeInclusive<usize>> for Index

source§

fn from(range_thing: &RangeInclusive<usize>) -> Index

Converts to this type from the input type.
source§

impl From<&RangeTo<usize>> for Index

source§

fn from(range_thing: &RangeTo<usize>) -> Index

Converts to this type from the input type.
source§

impl From<&RangeToInclusive<usize>> for Index

source§

fn from(range_thing: &RangeToInclusive<usize>) -> Index

Converts to this type from the input type.
source§

impl From<&SliceInfo<[SliceInfoElem; 1], Dim<[usize; 1]>, Dim<[usize; 1]>>> for Index

source§

fn from(slice_info: &SliceInfo1) -> Index

Converts to this type from the input type.
source§

impl From<&Vec<bool>> for Index

source§

fn from(vec_ref: &Vec<bool>) -> Index

Converts to this type from the input type.
source§

impl From<&Vec<isize>> for Index

source§

fn from(vec_ref: &Vec<isize>) -> Index

Converts to this type from the input type.
source§

impl From<&isize> for Index

source§

fn from(one: &isize) -> Index

Converts to this type from the input type.
source§

impl<const N: usize> From<[bool; N]> for Index

source§

fn from(array: [bool; N]) -> Index

Converts to this type from the input type.
source§

impl<const N: usize> From<[isize; N]> for Index

source§

fn from(array: [isize; N]) -> Index

Converts to this type from the input type.
source§

impl From<()> for Index

source§

fn from(_: ()) -> Index

Converts to this type from the input type.
source§

impl From<ArrayBase<OwnedRepr<bool>, Dim<[usize; 1]>>> for Index

source§

fn from(nd_array_bool: Array1<bool>) -> Index

Converts to this type from the input type.
source§

impl From<ArrayBase<OwnedRepr<isize>, Dim<[usize; 1]>>> for Index

source§

fn from(nd_array: Array1<isize>) -> Index

Converts to this type from the input type.
source§

impl From<ArrayBase<ViewRepr<&bool>, Dim<[usize; 1]>>> for Index

source§

fn from(view: ArrayView1<'_, bool>) -> Index

Converts to this type from the input type.
source§

impl From<ArrayBase<ViewRepr<&isize>, Dim<[usize; 1]>>> for Index

source§

fn from(view: ArrayView1<'_, isize>) -> Index

Converts to this type from the input type.
source§

impl From<Range<usize>> for Index

source§

fn from(range_thing: Range<usize>) -> Index

Converts to this type from the input type.
source§

impl From<RangeFrom<usize>> for Index

source§

fn from(range_thing: RangeFrom<usize>) -> Index

Converts to this type from the input type.
source§

impl From<RangeFull> for Index

source§

fn from(range_thing: RangeFull) -> Index

Converts to this type from the input type.
source§

impl From<RangeInclusive<usize>> for Index

source§

fn from(range_thing: RangeInclusive<usize>) -> Index

Converts to this type from the input type.
source§

impl From<RangeTo<usize>> for Index

source§

fn from(range_thing: RangeTo<usize>) -> Index

Converts to this type from the input type.
source§

impl From<RangeToInclusive<usize>> for Index

source§

fn from(range_thing: RangeToInclusive<usize>) -> Index

Converts to this type from the input type.
source§

impl From<SliceInfo<[SliceInfoElem; 1], Dim<[usize; 1]>, Dim<[usize; 1]>>> for Index

source§

fn from(slice_info: SliceInfo1) -> Index

Converts to this type from the input type.
source§

impl From<Vec<bool>> for Index

source§

fn from(vec_bool: Vec<bool>) -> Index

Converts to this type from the input type.
source§

impl From<Vec<isize>> for Index

source§

fn from(vec: Vec<isize>) -> Index

Converts to this type from the input type.
source§

impl From<isize> for Index

source§

fn from(one: isize) -> Index

Converts to this type from the input type.

Auto Trait Implementations§

§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> Ungil for Twhere T: Send,