pub struct WriteOptionsBuilder<TVal>where
TVal: BedVal,{ /* private fields */ }
Expand description
Builder for WriteOptions
.
Implementations§
Source§impl<TVal> WriteOptionsBuilder<TVal>where
TVal: BedVal,
impl<TVal> WriteOptionsBuilder<TVal>where
TVal: BedVal,
Sourcepub fn write<S: Data<Elem = TVal>>(
&mut self,
val: &ArrayBase<S, Ix2>,
) -> Result<(), Box<BedErrorPlus>>
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.
Sourcepub fn fid<AnyString0, AnyIter1>(self, fid: AnyIter1) -> Self
pub fn fid<AnyString0, AnyIter1>(self, fid: AnyIter1) -> Self
Set the family id (fid) values for each individual (sample).
Defaults to zeros.
See
WriteOptions
for examples.
Sourcepub fn iid<AnyString0, AnyIter1>(self, iid: AnyIter1) -> Self
pub fn iid<AnyString0, AnyIter1>(self, iid: AnyIter1) -> Self
Set the individual id (iid) values for each individual (sample).
Defaults to “iid1”, “iid2”, …
See
WriteOptions
for examples.
Sourcepub fn father<AnyString0, AnyIter1>(self, father: AnyIter1) -> Self
pub fn father<AnyString0, AnyIter1>(self, father: AnyIter1) -> Self
Set the father id values for each individual (sample).
Defaults to zeros.
See
WriteOptions
for examples.
Sourcepub fn mother<AnyString0, AnyIter1>(self, mother: AnyIter1) -> Self
pub fn mother<AnyString0, AnyIter1>(self, mother: AnyIter1) -> Self
Set the mother id values for each individual (sample).
Defaults to zeros.
See
WriteOptions
for examples.
Sourcepub fn sex<AnyIter0>(self, sex: AnyIter0) -> Selfwhere
AnyIter0: IntoIterator<Item = i32>,
pub fn sex<AnyIter0>(self, sex: AnyIter0) -> Selfwhere
AnyIter0: IntoIterator<Item = i32>,
Set the sex for each individual (sample).
0 is unknown (default), 1 is male, 2 is female
Sourcepub fn pheno<AnyString0, AnyIter1>(self, pheno: AnyIter1) -> Self
pub fn pheno<AnyString0, AnyIter1>(self, pheno: AnyIter1) -> Self
Set a phenotype for each individual (sample). Seldom used.
Defaults to zeros.
See
WriteOptions
for examples.
Sourcepub fn chromosome<AnyString0, AnyIter1>(self, chromosome: AnyIter1) -> Self
pub fn chromosome<AnyString0, AnyIter1>(self, chromosome: AnyIter1) -> Self
Set the chromosome for each SNP (variant).
Defaults to zeros.
Sourcepub fn sid<AnyString0, AnyIter1>(self, sid: AnyIter1) -> Self
pub fn sid<AnyString0, AnyIter1>(self, sid: AnyIter1) -> Self
Set the SNP id (sid) for each SNP (variant).
Defaults to “sid1”, “sid2”, …
See
WriteOptions
for examples.
Sourcepub fn cm_position<AnyIter0>(self, cm_position: AnyIter0) -> Selfwhere
AnyIter0: IntoIterator<Item = f32>,
pub fn cm_position<AnyIter0>(self, cm_position: AnyIter0) -> Selfwhere
AnyIter0: IntoIterator<Item = f32>,
Set the centimorgan position for each SNP (variant).
Defaults to zeros.
Sourcepub fn bp_position<AnyIter0>(self, bp_position: AnyIter0) -> Selfwhere
AnyIter0: IntoIterator<Item = i32>,
pub fn bp_position<AnyIter0>(self, bp_position: AnyIter0) -> Selfwhere
AnyIter0: IntoIterator<Item = i32>,
Set the base-pair position for each SNP (variant).
Defaults to zeros.
See
WriteOptions
for examples.
Sourcepub fn allele_2<AnyString0, AnyIter1>(self, allele_2: AnyIter1) -> Self
pub fn allele_2<AnyString0, AnyIter1>(self, allele_2: AnyIter1) -> Self
Set the second allele for each SNP (variant).
Defaults to “A2”, A2“ …
See
WriteOptions
for examples.
Sourcepub fn metadata(self, metadata: &Metadata) -> Self
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)?;
Sourcepub fn fam_path<AnyPath0>(self, path: AnyPath0) -> Self
pub fn fam_path<AnyPath0>(self, path: AnyPath0) -> Self
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)?;
Sourcepub fn bim_path<AnyPath0>(self, path: AnyPath0) -> Self
pub fn bim_path<AnyPath0>(self, path: AnyPath0) -> Self
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)?;
Sourcepub fn missing_value(&mut self, missing_value: TVal) -> &mut Self
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)?;
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
.
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
.
Sourcepub fn is_a1_counted(&mut self, is_a1_counted: bool) -> &mut Self
pub fn is_a1_counted(&mut self, is_a1_counted: bool) -> &mut Self
Sourcepub fn num_threads(&mut self, num_threads: usize) -> &mut Self
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)?;
Sourcepub fn skip_fam(&mut self) -> &mut Self
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());
Sourcepub fn skip_bim(&mut self) -> &mut Self
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());
Sourcepub fn build(
&self,
iid_count: usize,
sid_count: usize,
) -> Result<WriteOptions<TVal>, Box<BedErrorPlus>>
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 aWriteOptions
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)?;
Trait Implementations§
Source§impl<TVal> Clone for WriteOptionsBuilder<TVal>
impl<TVal> Clone for WriteOptionsBuilder<TVal>
Source§fn clone(&self) -> WriteOptionsBuilder<TVal>
fn clone(&self) -> WriteOptionsBuilder<TVal>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto 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> 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
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>
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>
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>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.