Struct bed_reader::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,
impl<TVal> WriteOptionsBuilder<TVal>where TVal: BedVal,
sourcepub fn write<S: Data<Elem = TVal>>(
&mut self,
val: &ArrayBase<S, Ix2>
) -> Result<(), BedErrorPlus>
pub fn write<S: Data<Elem = TVal>>( &mut self, val: &ArrayBase<S, Ix2> ) -> Result<(), 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) -> Selfwhere
AnyString0: AsRef<str>,
AnyIter1: IntoIterator<Item = AnyString0>,
pub fn fid<AnyString0, AnyIter1>(self, fid: AnyIter1) -> Selfwhere AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,
Set the family id (fid) values for each individual (sample).
Defaults to zeros.
See
WriteOptionsfor examples.
sourcepub fn iid<AnyString0, AnyIter1>(self, iid: AnyIter1) -> Selfwhere
AnyString0: AsRef<str>,
AnyIter1: IntoIterator<Item = AnyString0>,
pub fn iid<AnyString0, AnyIter1>(self, iid: AnyIter1) -> Selfwhere AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,
Set the individual id (iid) values for each individual (sample).
Defaults to “iid1”, “iid2”, …
See
WriteOptionsfor examples.
sourcepub fn father<AnyString0, AnyIter1>(self, father: AnyIter1) -> Selfwhere
AnyString0: AsRef<str>,
AnyIter1: IntoIterator<Item = AnyString0>,
pub fn father<AnyString0, AnyIter1>(self, father: AnyIter1) -> Selfwhere AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,
Set the father id values for each individual (sample).
Defaults to zeros.
See
WriteOptionsfor examples.
sourcepub fn mother<AnyString0, AnyIter1>(self, mother: AnyIter1) -> Selfwhere
AnyString0: AsRef<str>,
AnyIter1: IntoIterator<Item = AnyString0>,
pub fn mother<AnyString0, AnyIter1>(self, mother: AnyIter1) -> Selfwhere AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,
Set the mother id values for each individual (sample).
Defaults to zeros.
See
WriteOptionsfor 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) -> Selfwhere
AnyString0: AsRef<str>,
AnyIter1: IntoIterator<Item = AnyString0>,
pub fn pheno<AnyString0, AnyIter1>(self, pheno: AnyIter1) -> Selfwhere AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,
Set a phenotype for each individual (sample). Seldom used.
Defaults to zeros.
See
WriteOptionsfor examples.
sourcepub fn chromosome<AnyString0, AnyIter1>(self, chromosome: AnyIter1) -> Selfwhere
AnyString0: AsRef<str>,
AnyIter1: IntoIterator<Item = AnyString0>,
pub fn chromosome<AnyString0, AnyIter1>(self, chromosome: AnyIter1) -> Selfwhere AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,
Set the chromosome for each SNP (variant).
Defaults to zeros.
sourcepub fn sid<AnyString0, AnyIter1>(self, sid: AnyIter1) -> Selfwhere
AnyString0: AsRef<str>,
AnyIter1: IntoIterator<Item = AnyString0>,
pub fn sid<AnyString0, AnyIter1>(self, sid: AnyIter1) -> Selfwhere AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,
Set the SNP id (sid) for each SNP (variant).
Defaults to “sid1”, “sid2”, …
See
WriteOptionsfor 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
WriteOptionsfor examples.
sourcepub fn allele_1<AnyString0, AnyIter1>(self, allele_1: AnyIter1) -> Selfwhere
AnyString0: AsRef<str>,
AnyIter1: IntoIterator<Item = AnyString0>,
pub fn allele_1<AnyString0, AnyIter1>(self, allele_1: AnyIter1) -> Selfwhere AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,
sourcepub fn allele_2<AnyString0, AnyIter1>(self, allele_2: AnyIter1) -> Selfwhere
AnyString0: AsRef<str>,
AnyIter1: IntoIterator<Item = AnyString0>,
pub fn allele_2<AnyString0, AnyIter1>(self, allele_2: AnyIter1) -> Selfwhere AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,
Set the second allele for each SNP (variant).
Defaults to “A2”, A2“ …
See
WriteOptionsfor 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) -> Selfwhere
AnyPath0: AsRef<Path>,
pub fn fam_path<AnyPath0>(self, path: AnyPath0) -> Selfwhere 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)?;sourcepub fn bim_path<AnyPath0>(self, path: AnyPath0) -> Selfwhere
AnyPath0: AsRef<Path>,
pub fn bim_path<AnyPath0>(self, path: AnyPath0) -> Selfwhere 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)?;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>, BedErrorPlus>
pub fn build( &self, iid_count: usize, sid_count: usize ) -> Result<WriteOptions<TVal>, BedErrorPlus>
Creates a new WriteOptions with the options given.
Also see
WriteOptionsBuilder::write, which creates aWriteOptionsand 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§
Auto Trait Implementations§
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
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.