Struct WriteOptionsBuilder

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

Builder for WriteOptions.

Implementations§

Source§

impl<TVal> WriteOptionsBuilder<TVal>
where TVal: BedVal,

Source

pub fn write<S: Data<Elem = TVal>>( &mut self, val: &ArrayBase<S, Ix2>, ) -> Result<(), Box<BedErrorPlus>>

Creates a new WriteOptions with the options given and then writes a .bed (and .fam and .bim) file.

See WriteOptions for details and examples.

Source

pub fn fid<AnyString0, AnyIter1>(self, fid: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

Set the family id (fid) values for each individual (sample).

Defaults to zeros.

See WriteOptions for examples.

Source

pub fn iid<AnyString0, AnyIter1>(self, iid: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

Set the individual id (iid) values for each individual (sample).

Defaults to “iid1”, “iid2”, …

See WriteOptions for examples.

Source

pub fn father<AnyString0, AnyIter1>(self, father: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

Set the father id values for each individual (sample).

Defaults to zeros.

See WriteOptions for examples.

Source

pub fn mother<AnyString0, AnyIter1>(self, mother: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

Set the mother id values for each individual (sample).

Defaults to zeros.

See WriteOptions for examples.

Source

pub fn sex<AnyIter0>(self, sex: AnyIter0) -> Self
where AnyIter0: IntoIterator<Item = i32>,

Set the sex for each individual (sample).

0 is unknown (default), 1 is male, 2 is female

Source

pub fn pheno<AnyString0, AnyIter1>(self, pheno: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

Set a phenotype for each individual (sample). Seldom used.

Defaults to zeros.

See WriteOptions for examples.

Source

pub fn chromosome<AnyString0, AnyIter1>(self, chromosome: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

Set the chromosome for each SNP (variant).

Defaults to zeros.

Source

pub fn sid<AnyString0, AnyIter1>(self, sid: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

Set the SNP id (sid) for each SNP (variant).

Defaults to “sid1”, “sid2”, …

See WriteOptions for examples.

Source

pub fn cm_position<AnyIter0>(self, cm_position: AnyIter0) -> Self
where AnyIter0: IntoIterator<Item = f32>,

Set the centimorgan position for each SNP (variant).

Defaults to zeros.

Source

pub fn bp_position<AnyIter0>(self, bp_position: AnyIter0) -> Self
where AnyIter0: IntoIterator<Item = i32>,

Set the base-pair position for each SNP (variant).

Defaults to zeros.

See WriteOptions for examples.

Source

pub fn allele_1<AnyString0, AnyIter1>(self, allele_1: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

Set the first allele for each SNP (variant).

Defaults to “A1”, A1“ …

See WriteOptions for examples.

Source

pub fn allele_2<AnyString0, AnyIter1>(self, allele_2: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

Set the second allele for each SNP (variant).

Defaults to “A2”, A2“ …

See WriteOptions for examples.

Source

pub fn metadata(self, metadata: &Metadata) -> Self

Merge metadata from a Metadata.

If a field is set in both Metadata’s, it will be overridden.

§Example

Extract metadata from a file. Create a random file with the same metadata.

use ndarray as nd;
use bed_reader::{Bed, WriteOptions, sample_bed_file};
use ndarray_rand::{rand::prelude::StdRng, rand::SeedableRng, rand_distr::Uniform, RandomExt};

let mut bed = Bed::new(sample_bed_file("small.bed")?)?;
let metadata = bed.metadata()?;
let shape = bed.dim()?;

let mut rng = StdRng::seed_from_u64(0);
let val = nd::Array::random_using(shape, Uniform::from(-1..3), &mut rng);

let temp_out = temp_testdir::TempDir::default();
let output_file = temp_out.join("random.bed");
WriteOptions::builder(output_file)
    .metadata(&metadata)
    .missing_value(-1)
    .write(&val)?;
Source

pub fn fam_path<AnyPath0>(self, path: AnyPath0) -> Self
where AnyPath0: AsRef<Path>,

Set the path to the .fam file.

If not set, the .fam file will be assumed to have the same name as the .bed file, but with the extension .fam.

§Example:

Write .bed, .fam, and .bim files with non-standard names.

use ndarray as nd;
use bed_reader::WriteOptions;
let output_folder = temp_testdir::TempDir::default();
let output_file = output_folder.join("small.deb");
let val = nd::array![[1, 0, -127, 0], [2, 0, -127, 2], [0, 1, 2, 0]];
WriteOptions::builder(output_file)
    .fam_path(output_folder.join("small.maf"))
    .bim_path(output_folder.join("small.mib"))
    .write(&val)?;
Source

pub fn bim_path<AnyPath0>(self, path: AnyPath0) -> Self
where AnyPath0: AsRef<Path>,

Set the path to the .bim file.

If not set, the .bim file will be assumed to have the same name as the .bed file, but with the extension .bim.

§Example:

Write .bed, .fam, and .bim files with non-standard names.

use ndarray as nd;
use bed_reader::{WriteOptions};
let output_folder = temp_testdir::TempDir::default();
let output_file = output_folder.join("small.deb");
let val = nd::array![[1, 0, -127, 0], [2, 0, -127, 2], [0, 1, 2, 0]];
WriteOptions::builder(output_file)
    .fam_path(output_folder.join("small.maf"))
    .bim_path(output_folder.join("small.mib"))
    .write(&val)?;
Source

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

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

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

§Example

Extract metadata from a file. Create a random file with the same metadata.

use ndarray as nd;
use bed_reader::{Bed, WriteOptions, sample_bed_file};
use ndarray_rand::{rand::prelude::StdRng, rand::SeedableRng, rand_distr::Uniform, RandomExt};

let mut bed = Bed::new(sample_bed_file("small.bed")?)?;
let metadata = bed.metadata()?;
let shape = bed.dim()?;

let mut rng = StdRng::seed_from_u64(0);
let val = nd::Array::random_using(shape, Uniform::from(-1..3), &mut rng);

let temp_out = temp_testdir::TempDir::default();
let output_file = temp_out.join("random.bed");
WriteOptions::builder(output_file)
    .metadata(&metadata)
    .missing_value(-1)
    .write(&val)?;
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.

Source

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

Count the number allele 2.

Also see is_a1_counted and count_a1.

Source

pub fn is_a1_counted(&mut self, is_a1_counted: 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, num_threads: usize) -> &mut Self

Number of threads to use (defaults to all processors)

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

§Example:

Write using only one thread.

use ndarray as nd;
use bed_reader::WriteOptions;
let output_folder = temp_testdir::TempDir::default();
let output_file = output_folder.join("small.bed");
let val = nd::array![[1, 0, -127, 0], [2, 0, -127, 2], [0, 1, 2, 0]];
WriteOptions::builder(output_file)
    .num_threads(1)
    .write(&val)?;
Source

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

Skip writing .fam file.

§Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions};
let output_folder = temp_testdir::TempDir::default();
let output_file = output_folder.join("small.bed");
let write_options = WriteOptions::builder(output_file)
    .i8()
    .skip_fam()
    .skip_bim()
    .build(3, 4)?;
assert!(write_options.skip_fam());
assert!(write_options.skip_bim());
Source

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

Skip writing .bim file.

§Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions};
let output_folder = temp_testdir::TempDir::default();
let output_file = output_folder.join("small.bed");
let write_options = WriteOptions::builder(output_file)
    .i8()
    .skip_fam()
    .skip_bim()
    .build(3, 4)?;
assert!(write_options.skip_fam());
assert!(write_options.skip_bim());
Source

pub fn build( &self, iid_count: usize, sid_count: usize, ) -> Result<WriteOptions<TVal>, Box<BedErrorPlus>>

Creates a new WriteOptions with the options given.

Also see WriteOptionsBuilder::write, which creates a WriteOptions and writes to file in one step.

§Example

Create a new WriteOptions with some given values and some default values. Then use it to write a .bed file.

use ndarray as nd;
use bed_reader::{WriteOptions, Bed};

let output_folder = temp_testdir::TempDir::default();
let output_file = output_folder.join("small.bed");
let write_options = WriteOptions::builder(output_file)
    .f64()
    .iid(["i1", "i2", "i3"])
    .sid(["s1", "s2", "s3", "s4"])
    .build(3, 4)?;
println!("{0:?}", write_options.fid()); // Outputs ndarray ["0", "0", "0"]
println!("{0:?}", write_options.iid()); // Outputs ndarray ["i1", "i2", "i3"]

let 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]
];
Bed::write_with_options(&val, &write_options)?;
Source§

impl WriteOptionsBuilder<i8>

Source

pub fn i8(self) -> Self

The input ndarray will be i8.

Source§

impl WriteOptionsBuilder<f32>

Source

pub fn f32(self) -> Self

The input ndarray will be f32.

Source§

impl WriteOptionsBuilder<f64>

Source

pub fn f64(self) -> Self

The input ndarray will be f64.

Trait Implementations§

Source§

impl<TVal> Clone for WriteOptionsBuilder<TVal>
where TVal: BedVal + Clone,

Source§

fn clone(&self) -> WriteOptionsBuilder<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> Default for WriteOptionsBuilder<TVal>
where TVal: BedVal + Clone,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

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

§

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

§

impl<TVal> !Send for WriteOptionsBuilder<TVal>

§

impl<TVal> !Sync for WriteOptionsBuilder<TVal>

§

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

§

impl<TVal> UnwindSafe for WriteOptionsBuilder<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,