Struct bed_reader::WriteOptions
source · [−]pub struct WriteOptions<TVal> where
TVal: BedVal, { /* private fields */ }Expand description
Represents options for writing genotype data and metadata to a PLINK .bed file.
Construct with WriteOptions::builder.
Implementations
sourceimpl<TVal> WriteOptions<TVal> where
TVal: BedVal,
impl<TVal> WriteOptions<TVal> where
TVal: BedVal,
sourcepub fn builder<P: AsRef<Path>>(path: P) -> WriteOptionsBuilder<TVal>
pub fn builder<P: AsRef<Path>>(path: P) -> WriteOptionsBuilder<TVal>
Write values to a file in PLINK .bed format. Supports metadata and options.
Also see
Bed::write, which does not support metadata or options.
The options, listed here, can specify the:
- items of metadata, for example the individual ids or the SNP ids
- a non-default path for the .fam and/or .bim files
- a non-default value that represents missing data
- whether the first allele is counted (default) or the second
- number of threads to use for writing
- a
Metadata
Examples
In this example, all metadata is given one item at a time.
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
let output_file = output_folder.join("small.bed");
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]
];
WriteOptions::builder(output_file)
.fid(["fid1", "fid1", "fid2"])
.iid(["iid1", "iid2", "iid3"])
.father(["iid23", "iid23", "iid22"])
.mother(["iid34", "iid34", "iid33"])
.sex([1, 2, 0])
.pheno(["red", "red", "blue"])
.chromosome(["1", "1", "5", "Y"])
.sid(["sid1", "sid2", "sid3", "sid4"])
.cm_position([100.4, 2000.5, 4000.7, 7000.9])
.bp_position([1, 100, 1000, 1004])
.allele_1(["A", "T", "A", "T"])
.allele_2(["A", "C", "C", "G"])
.write(&val)?;Here, no metadata is given, so default values are assigned. If we then read the new file and list the chromosome property, it is an array of zeros, the default chromosome value.
let output_file2 = output_folder.join("small2.bed");
let val = nd::array![[1, 0, -127, 0], [2, 0, -127, 2], [0, 1, 2, 0]];
WriteOptions::builder(&output_file2).write(&val)?;
let mut bed2 = Bed::new(&output_file2)?;
println!("{:?}", bed2.chromosome()?); // Outputs ndarray ["0", "0", "0", "0"]sourcepub fn fid(&self) -> &Array1<String>
pub fn fid(&self) -> &Array1<String>
Family id of each of individual (sample). Defaults to “0”’s
Example
use ndarray as nd;
use bed_reader::{WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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"]sourcepub fn iid(&self) -> &Array1<String>
pub fn iid(&self) -> &Array1<String>
Individual id of each of individual (sample). Defaults to “iid1”, “iid2” …
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.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)?;sourcepub fn father(&self) -> &Array1<String>
pub fn father(&self) -> &Array1<String>
Father id of each of individual (sample). Defaults to “0”’s
Example
use ndarray as nd;
use bed_reader::{WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.father()); // Outputs ndarray ["0", "0", "0"]sourcepub fn mother(&self) -> &Array1<String>
pub fn mother(&self) -> &Array1<String>
Mother id of each of individual (sample). Defaults to “0”’s
Example
use ndarray as nd;
use bed_reader::{WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.mother()); // Outputs ndarray ["0", "0", "0"]sourcepub fn sex(&self) -> &Array1<i32>
pub fn sex(&self) -> &Array1<i32>
Sex of each of individual (sample). Defaults to 0’s
0 is unknown, 1 is male, 2 is female
Example
use ndarray as nd;
use bed_reader::{WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.sex()); // Outputs ndarray [0, 0, 0]sourcepub fn pheno(&self) -> &Array1<String>
pub fn pheno(&self) -> &Array1<String>
Phenotype of each of individual (sample). Seldom used. Defaults to 0’s
Example
use ndarray as nd;
use bed_reader::{WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.pheno()); // Outputs ndarray ["0", "0", "0"]sourcepub fn chromosome(&self) -> &Array1<String>
pub fn chromosome(&self) -> &Array1<String>
Chromosome of each of SNP (variant). Defaults to “0”’s
Example
use ndarray as nd;
use bed_reader::{WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.chromosome()); // Outputs ndarray ["0", "0", "0", "0"]sourcepub fn sid(&self) -> &Array1<String>
pub fn sid(&self) -> &Array1<String>
SNP id of each of SNP (variant). Defaults to “sid1”, “sid2”, …
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.sid()); // Outputs ndarray ["s1", "s2", "s3", "s4"]
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)?;sourcepub fn cm_position(&self) -> &Array1<f32>
pub fn cm_position(&self) -> &Array1<f32>
Centimorgan position of each SNP (variant). Defaults to 0.0’s.
Example
use ndarray as nd;
use bed_reader::{WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.cm_position()); // Outputs ndarray [0.0, 0.0, 0.0, 0.0]sourcepub fn bp_position(&self) -> &Array1<i32>
pub fn bp_position(&self) -> &Array1<i32>
Base-pair position of each SNP (variant). Defaults to 0’s.
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.bp_position()); // Outputs ndarray [0, 0, 0, 0]sourcepub fn allele_1(&self) -> &Array1<String>
pub fn allele_1(&self) -> &Array1<String>
First allele of each SNP (variant). Defaults to “A1”
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.allele_1()); // Outputs ndarray ["A1", "A1", "A1", "A1"]
println!("{0:?}", write_options.allele_2()); // Outputs ndarray ["A2", "A2", "A2", "A2"]sourcepub fn allele_2(&self) -> &Array1<String>
pub fn allele_2(&self) -> &Array1<String>
Second allele of each SNP (variant). Defaults to “A2”
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.allele_1()); // Outputs ndarray ["A1", "A1", "A1", "A1"]
println!("{0:?}", write_options.allele_2()); // Outputs ndarray ["A2", "A2", "A2", "A2"]sourcepub fn metadata(&self) -> Metadata
pub fn metadata(&self) -> Metadata
Metadata for this WriteOptions, for example, the individual (sample) Ids.
This returns a struct with 12 fields. Each field is a ndarray.
The struct will always be new, but the 12 ndarrays will be
shared with this WriteOptions.
If the needed, default values will be used.
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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)?;
let metadata = write_options.metadata();
println!("{0:?}", metadata.iid()); // Outputs optional ndarray Some(["i1", "i2", "i3"])sourcepub fn iid_count(&self) -> usize
pub fn iid_count(&self) -> usize
The number of individuals (samples)
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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)?;
assert_eq!(write_options.iid_count(), 3);
assert_eq!(write_options.sid_count(), 4);sourcepub fn sid_count(&self) -> usize
pub fn sid_count(&self) -> usize
The number of SNPs (variants)
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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)?;
assert_eq!(write_options.iid_count(), 3);
assert_eq!(write_options.sid_count(), 4);sourcepub fn dim(&self) -> (usize, usize)
pub fn dim(&self) -> (usize, usize)
Number of individuals (samples) and SNPs (variants)
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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)?;
assert_eq!(write_options.dim(), (3, 4));sourcepub fn path(&self) -> &PathBuf
pub fn path(&self) -> &PathBuf
Path to .bed file.
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.path()); // Outputs "...small.bed"
println!("{0:?}", write_options.fam_path()); // Outputs "...small.fam"
println!("{0:?}", write_options.bim_path()); // Outputs "...small.bim"sourcepub fn fam_path(&self) -> &PathBuf
pub fn fam_path(&self) -> &PathBuf
Path to .fam file.
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.path()); // Outputs "...small.bed"
println!("{0:?}", write_options.fam_path()); // Outputs "...small.fam"
println!("{0:?}", write_options.bim_path()); // Outputs "...small.bim"sourcepub fn bim_path(&self) -> &PathBuf
pub fn bim_path(&self) -> &PathBuf
Path to .bim file.
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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.path()); // Outputs "...small.bed"
println!("{0:?}", write_options.fam_path()); // Outputs "...small.fam"
println!("{0:?}", write_options.bim_path()); // Outputs "...small.bim"sourcepub fn is_a1_counted(&self) -> bool
pub fn is_a1_counted(&self) -> bool
If allele 1 will be counted (defaults to true).
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
let output_file = output_folder.join("small.bed");
let write_options = WriteOptions::builder(output_file)
.i8()
.iid(["i1", "i2", "i3"])
.sid(["s1", "s2", "s3", "s4"])
.build(3, 4)?;
assert!(write_options.is_a1_counted());sourcepub fn num_threads(&self) -> Option<usize>
pub fn num_threads(&self) -> Option<usize>
Number of threads to be used (None means set with
Environment Variables or use all processors).
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
let output_file = output_folder.join("small.bed");
let write_options = WriteOptions::builder(output_file)
.i8()
.iid(["i1", "i2", "i3"])
.sid(["s1", "s2", "s3", "s4"])
.build(3, 4)?;
assert!(write_options.num_threads().is_none());sourcepub fn missing_value(&self) -> TVal
pub fn missing_value(&self) -> TVal
Value to be used for missing values (defaults to -127 or NaN).
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
let output_file = output_folder.join("small.bed");
let write_options = WriteOptions::builder(output_file)
.i8()
.iid(["i1", "i2", "i3"])
.sid(["s1", "s2", "s3", "s4"])
.build(3, 4)?;
assert!(write_options.missing_value() == -127);sourcepub fn skip_fam(&self) -> bool
pub fn skip_fam(&self) -> bool
If skipping writing .fam file.
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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(&self) -> bool
pub fn skip_bim(&self) -> bool
If skipping writing .bim file.
Example
use ndarray as nd;
use bed_reader::{Bed, WriteOptions, tmp_path};
let output_folder = tmp_path()?;
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());Trait Implementations
sourceimpl<TVal: Clone> Clone for WriteOptions<TVal> where
TVal: BedVal,
impl<TVal: Clone> Clone for WriteOptions<TVal> where
TVal: BedVal,
sourcefn clone(&self) -> WriteOptions<TVal>
fn clone(&self) -> WriteOptions<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 WriteOptions<TVal> where
TVal: RefUnwindSafe,
impl<TVal> !Send for WriteOptions<TVal>
impl<TVal> !Sync for WriteOptions<TVal>
impl<TVal> Unpin for WriteOptions<TVal> where
TVal: Unpin,
impl<TVal> UnwindSafe for WriteOptions<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.