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

Builder for WriteOptions.

Implementations

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

See WriteOptions for details and examples.

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

Defaults to zeros.

See WriteOptions for examples.

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

Defaults to “iid1”, “iid2”, …

See WriteOptions for examples.

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

Defaults to zeros.

See WriteOptions for examples.

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

Defaults to zeros.

See WriteOptions for examples.

Set the sex for each individual (sample).

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

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

Defaults to zeros.

See WriteOptions for examples.

Set the chromosome for each SNP (variant).

Defaults to zeros.

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

Defaults to “sid1”, “sid2”, …

See WriteOptions for examples.

Set the centimorgan position for each SNP (variant).

Defaults to zeros.

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

Defaults to zeros.

See WriteOptions for examples.

Set the first allele for each SNP (variant).

Defaults to “A1”, A1“ …

See WriteOptions for examples.

Set the second allele for each SNP (variant).

Defaults to “A2”, A2“ …

See WriteOptions for examples.

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

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,tmp_path};
let output_folder = tmp_path()?;
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)?;

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,tmp_path};
let output_folder = tmp_path()?;
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)?;

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

Count the number allele 1 (default and PLINK standard).

Also see is_a1_counted and count_a2.

Count the number allele 2.

Also see is_a1_counted and count_a1.

Sets if allele 1 is counted. Default is true.

Also see count_a1 and count_a2.

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, tmp_path};
let output_folder = tmp_path()?;
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)?;

Skip 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());

Skip 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());

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, tmp_path, Bed};

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"]
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)?;

The input ndarray will be i8.

The input ndarray will be f32.

The input ndarray will be f64.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

Checks if self is actually part of its subset T (and can be converted to it).

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

The inclusion map: converts self to the equivalent element of its superset.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.