Struct ReadOptionsBuilder

Source
pub struct ReadOptionsBuilder<TVal: BedVal> { /* private fields */ }
Expand description

Builder for ReadOptions.

Implementations§

Source§

impl<TVal: BedVal + Clone> ReadOptionsBuilder<TVal>

Source

pub fn missing_value(&mut self, value: TVal) -> &mut Self

Value to use for missing values (defaults to -127 or NaN)

-127 is the default for i8 and NaN is the default for f32 and f64.

In this example, the missing value is set to -1:

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

let file_name = sample_bed_file("small.bed")?;
let mut bed = Bed::new(file_name)?;
let val = ReadOptions::builder().missing_value(-1).i8().read(&mut bed)?;

assert_eq_nan(
    &val,
    &nd::array![
        [1, 0, -1, 0],
        [2, 0, -1, 2],
        [0, 1, 2, 0]
    ],
);
Source

pub fn iid_index<VALUE: Into<Index>>(&mut self, value: VALUE) -> &mut Self

Select which individual (sample) values to read – Defaults to all.

Can select with a signed number, various lists of signed numbers, ranges, and various lists of booleans.

See the Table of Index Expressions for a list of the supported index expressions.

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

let file_name = sample_bed_file("some_missing.bed")?;
let mut bed = Bed::new(file_name)?;

// Read the individual at index position 3

let val = ReadOptions::builder()
    .iid_index(3)
    .f64()
    .read(&mut bed)?;
assert!(val.dim() == (1, 100));

// Read the individuals at index positions 0, 5, and 1st-from-last.

let val = ReadOptions::builder()
    .iid_index([0, 5, -1])
    .f64()
    .read(&mut bed)?;

assert!(val.dim() == (3, 100));

// Read the individuals at index positions 20 (inclusive) to 30 (exclusive).

let val = ReadOptions::builder()
    .iid_index(20..30)
    .f64()
    .read(&mut bed)?;

assert!(val.dim() == (10, 100));

// Read the individuals at every 2nd index position.

let val = ReadOptions::builder()
    .iid_index(s![..;2])
    .f64()
    .read(&mut bed)?;

assert!(val.dim() == (50, 100));

// Read chromosome 5 of the female individuals.

let female = bed.sex()?.map(|elem| *elem == 2);
let chrom_5 = bed.chromosome()?.map(|elem| elem == "5");
let val = ReadOptions::builder()
    .iid_index(female)
    .sid_index(chrom_5)
    .f64()
    .read(&mut bed)?;

assert!(val.dim() == (50, 6));
Source

pub fn sid_index<VALUE: Into<Index>>(&mut self, value: VALUE) -> &mut Self

Select which SNPs (variant) values to read – Defaults to all.

Can select with a signed number, various lists of signed numbers, ranges, and various lists of booleans.

See the Table of Index Expressions for a list of the supported index expressions.

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

let file_name = sample_bed_file("some_missing.bed")?;
let mut bed = Bed::new(file_name)?;

// Read the SNP at index position 3

let val = ReadOptions::builder()
    .sid_index(3)
    .f64()
    .read(&mut bed)?;
assert!(val.dim() == (100, 1));

// Read the SNPs at index positions 0, 5, and 1st-from-last.

let val = ReadOptions::builder()
    .sid_index([0, 5, -1])
    .f64()
    .read(&mut bed)?;

assert!(val.dim() == (100, 3));

// Read the SNPs at index positions 20 (inclusive) to 30 (exclusive).

let val = ReadOptions::builder()
    .sid_index(20..30)
    .f64()
    .read(&mut bed)?;

assert!(val.dim() == (100, 10));

// Read the SNPs at every 2nd index position.

let val = ReadOptions::builder()
    .sid_index(s![..;2])
    .f64()
    .read(&mut bed)?;

assert!(val.dim() == (100, 50));

// Read chromosome 5 of the female individuals.

let female = bed.sex()?.map(|elem| *elem == 2);
let chrom_5 = bed.chromosome()?.map(|elem| elem == "5");
let val = ReadOptions::builder()
    .iid_index(female)
    .sid_index(chrom_5)
    .f64()
    .read(&mut bed)?;

assert!(val.dim() == (50, 6));
Source

pub fn is_f(&mut self, value: bool) -> &mut Self

Sets if the order of the output array is Fortran-style – Default is true.

“Fortran order” is also called “column-major order” Wikipedia.

Also see f and c.

Source

pub fn is_a1_counted(&mut self, value: bool) -> &mut Self

Sets if allele 1 is counted. Default is true.

Also see count_a1 and count_a2.

Source

pub fn num_threads(&mut self, value: usize) -> &mut Self

Number of threads to use (defaults to all processors)

Can also be set with an environment variable. See Environment Variables.

In this example, we read using only one thread.

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

let file_name = sample_bed_file("small.bed")?;
let mut bed = Bed::new(file_name)?;
let val = ReadOptions::builder().num_threads(1).i8().read(&mut bed)?;

assert_eq_nan(
    &val,
    &nd::array![
        [1, 0, -127, 0],
        [2, 0, -127, 2],
        [0, 1, 2, 0]
    ],
);
Source

pub fn max_concurrent_requests(&mut self, value: usize) -> &mut Self

Maximum number of concurrent async requests (defaults to 10) – Used by BedCloud.

In this example, we read using only request at a time.

use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(&url).await?;
let val = ReadOptions::builder().max_concurrent_requests(1).i8().read_cloud(&mut bed_cloud).await?;

assert_eq_nan(
    &val,
    &nd::array![
        [1, 0, -127, 0],
        [2, 0, -127, 2],
        [0, 1, 2, 0]
    ],
);
Source

pub fn max_chunk_bytes(&mut self, value: usize) -> &mut Self

Maximum chunk size of async requests (defaults to 8_000_000 bytes) – Used by BedCloud.

In this example, we read using only 1_000_000 bytes per request.

use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(&url).await?;
let val = ReadOptions::builder().max_chunk_bytes(1_000_000).i8().read_cloud(&mut bed_cloud).await?;

assert_eq_nan(
    &val,
    &nd::array![
        [1, 0, -127, 0],
        [2, 0, -127, 2],
        [0, 1, 2, 0]
    ],
);
Source

pub fn build(&self) -> Result<ReadOptions<TVal>, Box<BedErrorPlus>>

Builds a new ReadOptions.

§Errors

If a required field has not been initialized.

Source§

impl<TVal: BedVal> ReadOptionsBuilder<TVal>

Source

pub fn read(&self, bed: &mut Bed) -> Result<Array2<TVal>, Box<BedErrorPlus>>

See ReadOptions::builder for details and examples.

Source

pub async fn read_cloud( &self, bed_cloud: &mut BedCloud, ) -> Result<Array2<TVal>, Box<BedErrorPlus>>

Read genotype data from the cloud.

Also see BedCloud::read_with_options.

§Errors

See BedError and BedErrorPlus for all possible errors.

§Example
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

// Read the SNPs indexed by 2.
let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(&url).await?;
let mut val = ReadOptions::builder()
    .sid_index(2)
    .read_cloud(&mut bed_cloud).await?;

assert_eq_nan(&val, &nd::array![[f64::NAN], [f64::NAN], [2.0]]);
Source

pub fn read_and_fill( &self, bed: &mut Bed, val: &mut ArrayViewMut2<'_, TVal>, ) -> Result<(), Box<BedErrorPlus>>

Read genotype data into a preallocated array.

Also see Bed::read_and_fill and Bed::read_and_fill_with_options.

Note that options ReadOptions::f, ReadOptions::c, and ReadOptions::is_f are ignored. Instead, the order of the preallocated array is used.

§Errors

See BedError and BedErrorPlus for all possible errors.

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

// Read the SNPs indexed by 2.
let file_name = sample_bed_file("small.bed")?;
let mut bed = Bed::new(file_name)?;
let mut val = nd::Array2::<f64>::default((3, 1));
ReadOptions::builder()
    .sid_index(2)
    .read_and_fill(&mut bed, &mut val.view_mut())?;

assert_eq_nan(&val, &nd::array![[f64::NAN], [f64::NAN], [2.0]]);
Source

pub async fn read_and_fill_cloud( &self, bed_cloud: &mut BedCloud, val: &mut ArrayViewMut2<'_, TVal>, ) -> Result<(), Box<BedErrorPlus>>

Read genotype data from the cloud into a preallocated array.

Also see BedCloud::read_and_fill and BedCloud::read_and_fill_with_options.

Note that options ReadOptions::f, ReadOptions::c, and ReadOptions::is_f are ignored. Instead, the order of the preallocated array is used.

§Errors

See BedError and BedErrorPlus for all possible errors.

§Example
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

// Read the SNPs indexed by 2.
let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(&url).await?;
let mut val = nd::Array2::<f64>::default((3, 1));
ReadOptions::builder()
    .sid_index(2)
    .read_and_fill_cloud(&mut bed_cloud, &mut val.view_mut()).await?;

assert_eq_nan(&val, &nd::array![[f64::NAN], [f64::NAN], [2.0]]);
Source

pub fn f(&mut self) -> &mut Self

Order of the output array, Fortran-style (default)

Also called “column-major order” Wikipedia.

Also see is_f and c.

Source

pub fn c(&mut self) -> &mut Self

Order of the output array, C (default)

Also called “row-major order” Wikipedia.

Also see is_f and f.

Source

pub fn count_a1(&mut self) -> &mut Self

Count the number allele 1 (default and PLINK standard).

Also see is_a1_counted and count_a2.

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

let file_name = sample_bed_file("small.bed")?;
let mut bed = Bed::new(file_name)?;
let val = ReadOptions::builder().count_a1().i8().read(&mut bed)?;

assert_eq_nan(
    &val,
    &nd::array![
        [1, 0, -127, 0],
        [2, 0, -127, 2],
        [0, 1, 2, 0]
    ],
);
Source

pub fn count_a2(&mut self) -> &mut Self

Count the number allele 2.

Also see is_a1_counted and count_a1.

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

let file_name = sample_bed_file("small.bed")?;
let mut bed = Bed::new(file_name)?;
let val = ReadOptions::builder().count_a2().i8().read(&mut bed)?;

assert_eq_nan(
    &val,
    &nd::array![
        [1, 2, -127, 2],
        [0, 2, -127, 0],
        [2, 1, 0, 2]
    ],
);
Source§

impl ReadOptionsBuilder<i8>

Source

pub fn i8(&mut self) -> &mut Self

Output an ndarray of i8.

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

let file_name = sample_bed_file("small.bed")?;
let mut bed = Bed::new(file_name)?;
let val = ReadOptions::builder().i8().read(&mut bed)?;

assert_eq_nan(
    &val,
    &nd::array![
        [1, 0, -127, 0],
        [2, 0, -127, 2],
        [0, 1, 2, 0]
    ],
);
Source§

impl ReadOptionsBuilder<f32>

Source

pub fn f32(&mut self) -> &mut Self

Output an ndarray of f32.

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

let file_name = sample_bed_file("small.bed")?;
let mut bed = Bed::new(file_name)?;
let val = ReadOptions::builder().f32().read(&mut bed)?;

assert_eq_nan(
    &val,
    &nd::array![
        [1.0, 0.0, f32::NAN, 0.0],
        [2.0, 0.0, f32::NAN, 2.0],
        [0.0, 1.0, 2.0, 0.0]
    ],
);
Source§

impl ReadOptionsBuilder<f64>

Source

pub fn f64(&mut self) -> &mut Self

Output an ndarray of f64.

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

let file_name = sample_bed_file("small.bed")?;
let mut bed = Bed::new(file_name)?;
let val = ReadOptions::builder().f64().read(&mut bed)?;

assert_eq_nan(
    &val,
    &nd::array![
        [1.0, 0.0, f64::NAN, 0.0],
        [2.0, 0.0, f64::NAN, 2.0],
        [0.0, 1.0, 2.0, 0.0]
    ],
);

Trait Implementations§

Source§

impl<TVal: Clone + BedVal> Clone for ReadOptionsBuilder<TVal>

Source§

fn clone(&self) -> ReadOptionsBuilder<TVal>

Returns a duplicate 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<TVal: BedVal + Clone> Default for ReadOptionsBuilder<TVal>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<TVal> Freeze for ReadOptionsBuilder<TVal>
where TVal: Freeze,

§

impl<TVal> RefUnwindSafe for ReadOptionsBuilder<TVal>
where TVal: RefUnwindSafe,

§

impl<TVal> Send for ReadOptionsBuilder<TVal>

§

impl<TVal> Sync for ReadOptionsBuilder<TVal>

§

impl<TVal> Unpin for ReadOptionsBuilder<TVal>
where TVal: Unpin,

§

impl<TVal> UnwindSafe for ReadOptionsBuilder<TVal>
where TVal: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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

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

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,