Struct bed_reader::ReadOptionsBuilder
source · [−]pub struct ReadOptionsBuilder<TVal: BedVal> { /* private fields */ }Expand description
Builder for ReadOptions.
Implementations
sourceimpl<TVal: BedVal + Clone> ReadOptionsBuilder<TVal>
impl<TVal: BedVal + Clone> ReadOptionsBuilder<TVal>
sourcepub fn missing_value(&mut self, value: TVal) -> &mut Self
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]
],
);sourcepub fn iid_index<VALUE: Into<Index>>(&mut self, value: VALUE) -> &mut Self
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));sourcepub fn sid_index<VALUE: Into<Index>>(&mut self, value: VALUE) -> &mut Self
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));sourcepub fn is_a1_counted(&mut self, value: bool) -> &mut Self
pub fn is_a1_counted(&mut self, value: bool) -> &mut Self
sourcepub fn num_threads(&mut self, value: usize) -> &mut Self
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]
],
);sourcepub fn build(&self) -> Result<ReadOptions<TVal>, BedErrorPlus>
pub fn build(&self) -> Result<ReadOptions<TVal>, BedErrorPlus>
sourceimpl<TVal: BedVal> ReadOptionsBuilder<TVal>
impl<TVal: BedVal> ReadOptionsBuilder<TVal>
sourcepub fn read(&self, bed: &mut Bed) -> Result<Array2<TVal>, BedErrorPlus>
pub fn read(&self, bed: &mut Bed) -> Result<Array2<TVal>, BedErrorPlus>
See
ReadOptions::builderfor details and examples.
sourcepub fn read_and_fill(
&self,
bed: &mut Bed,
val: &mut ArrayViewMut2<'_, TVal>
) -> Result<(), BedErrorPlus>
pub fn read_and_fill(
&self,
bed: &mut Bed,
val: &mut ArrayViewMut2<'_, TVal>
) -> Result<(), BedErrorPlus>
Read genotype data with options, into a preallocated array.
Also see
Bed::read_and_fillandBed::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]]);sourcepub fn count_a1(&mut self) -> &mut Self
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]
],
);sourcepub fn count_a2(&mut self) -> &mut Self
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]
],
);sourceimpl ReadOptionsBuilder<i8>
impl ReadOptionsBuilder<i8>
sourcepub fn i8(&mut self) -> &mut Self
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]
],
);sourceimpl ReadOptionsBuilder<f32>
impl ReadOptionsBuilder<f32>
sourcepub fn f32(&mut self) -> &mut Self
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]
],
);sourceimpl ReadOptionsBuilder<f64>
impl ReadOptionsBuilder<f64>
sourcepub fn f64(&mut self) -> &mut Self
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
sourceimpl<TVal: Clone + BedVal> Clone for ReadOptionsBuilder<TVal>
impl<TVal: Clone + BedVal> Clone for ReadOptionsBuilder<TVal>
sourcefn clone(&self) -> ReadOptionsBuilder<TVal>
fn clone(&self) -> ReadOptionsBuilder<TVal>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
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 more
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).
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.
fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts self to the equivalent element of its superset.