pub struct BedBuilder { /* private fields */ }
Expand description

Builder for Bed.

Implementations

Create Bed from the builder.

See Bed::builder for more details and examples.

Override the family id (fid) values found in the .fam file.

By default, if fid values are needed and haven’t already been found, they will be read from the .fam file. Providing them here avoids that file read and provides a way to give different values.

Override the individual id (iid) values found in the .fam file.

By default, if iid values are needed and haven’t already been found, they will be read from the .fam file. Providing them here avoids that file read and provides a way to give different values.

use ndarray as nd;
use bed_reader::{Bed, assert_eq_nan, sample_bed_file};
let file_name = sample_bed_file("small.bed")?;
use bed_reader::ReadOptions;

let mut bed = Bed::builder(file_name)
   .iid(["sample1", "sample2", "sample3"])
   .build()?;
println!("{:?}", bed.iid()?); // Outputs ndarray ["sample1", "sample2", "sample3"]

Override the father values found in the .fam file. nd By default, if father values are needed and haven’t already been found, they will be read from the .fam file. Providing them here avoids that file read and provides a way to gi&ve different values.

Override the mother values found in the .fam file.

By default, if mother values are needed and haven’t already been found, they will be read from the .fam file. Providing them here avoids that file read and provides a way to give different values.

Override the sex values found in the .fam file.

By default, if sex values are needed and haven’t already been found, they will be read from the .fam file. Providing them here avoids that file read and provides a way to give different values.

Override the phenotype values found in the .fam file.

Note that the phenotype values in the .fam file are seldom used. By default, if phenotype values are needed and haven’t already been found, they will be read from the .fam file. Providing them here avoids that file read and provides a way to give different values.

Override the chromosome values found in the .bim file.

By default, if chromosome values are needed and haven’t already been found, they will be read from the .bim file. Providing them here avoids that file read and provides a way to give different values.

Override the SNP id (sid) values found in the .fam file.

By default, if sid values are needed and haven’t already been found, they will be read from the .bim file. Providing them here avoids that file read and provides a way to give different values.

use ndarray as nd;
use bed_reader::{Bed, ReadOptions, assert_eq_nan, sample_bed_file};
let file_name = sample_bed_file("small.bed")?;

let mut bed = Bed::builder(file_name)
   .sid(["SNP1", "SNP2", "SNP3", "SNP4"])
   .build()?;
println!("{:?}", bed.sid()?); // Outputs ndarray ["SNP1", "SNP2", "SNP3", "SNP4"]

Override the centimorgan position values found in the .bim file.

By default, if centimorgan position values are needed and haven’t already been found, they will be read from the .bim file. Providing them here avoids that file read and provides a way to give different values.

Override the base-pair position values found in the .bim file.

By default, if base-pair position values are needed and haven’t already been found, they will be read from the .bim file. Providing them here avoids that file read and provides a way to give different values.

Override the allele 1 values found in the .bim file.

By default, if allele 1 values are needed and haven’t already been found, they will be read from the .bim file. Providing them here avoids that file read and provides a way to give different values.

Override the allele 2 values found in the .bim file.

By default, if allele 2 values are needed and haven’t already been found, they will be read from the .bim file. Providing them here avoids that file read and provides a way to give different values.

Set the number of individuals (samples) in the data.

By default, if this number is needed, it will be found and remembered by opening the .fam file and quickly counting the number of lines. Providing the number thus avoids a file read.

Set the number of SNPs in the data.

By default, if this number is needed, it will be found and remembered by opening the .bim file and quickly counting the number of lines. Providing the number thus avoids a file read.

Don’t check the header of the .bed file until and unless the file is actually read.

By default, when a Bed struct is created, the .bed file header is checked. This stops that early check.

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:

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

use bed_reader::{Bed, ReadOptions, sample_files};
let deb_maf_mib = sample_files(["small.deb", "small.maf", "small.mib"])?;
let mut bed = Bed::builder(&deb_maf_mib[0])
   .fam_path(&deb_maf_mib[1])
   .bim_path(&deb_maf_mib[2])
   .build()?;
println!("{:?}", bed.iid()?); // Outputs ndarray ["iid1", "iid2", "iid3"]
println!("{:?}", bed.sid()?); // Outputs ndarray ["sid1", "sid2", "sid3", "sid4"]

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:

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

use bed_reader::{Bed, ReadOptions, sample_files};
let deb_maf_mib = sample_files(["small.deb", "small.maf", "small.mib"])?;
let mut bed = Bed::builder(&deb_maf_mib[0])
   .fam_path(&deb_maf_mib[1])
   .bim_path(&deb_maf_mib[2])
   .build()?;
println!("{:?}", bed.iid()?); // Outputs ndarray ["iid1", "iid2", "iid3"]
println!("{:?}", bed.sid()?); // Outputs ndarray ["sid1", "sid2", "sid3", "sid4"]

Don’t read the fid information from the .fam file.

By default, when the .fam is read, the fid (the family id) is recorded. This stops that recording. This is useful if the fid is not needed. Asking for the fid after skipping it results in an error.

Don’t read the iid information from the .fam file.

By default, when the .fam is read, the iid (the individual id) is recorded. This stops that recording. This is useful if the iid is not needed. Asking for the iid after skipping it results in an error.

Don’t read the father information from the .fam file.

By default, when the .fam is read, the father id is recorded. This stops that recording. This is useful if the father id is not needed. Asking for the father id after skipping it results in an error.

Don’t read the mother information from the .fam file.

By default, when the .fam is read, the mother id is recorded. This stops that recording. This is useful if the mother id is not needed. Asking for the mother id after skipping it results in an error.

Don’t read the sex information from the .fam file.

By default, when the .fam is read, the sex is recorded. This stops that recording. This is useful if sex is not needed. Asking for sex after skipping it results in an error.

Don’t read the phenotype information from the .fam file.

Note that the phenotype information in the .fam file is seldom used.

By default, when the .fam is read, the phenotype is recorded. This stops that recording. This is useful if this phenotype information is not needed. Asking for the phenotype after skipping it results in an error.

Don’t read the chromosome information from the .bim file.

By default, when the .bim is read, the chromosome is recorded. This stops that recording. This is useful if the chromosome is not needed. Asking for the chromosome after skipping it results in an error.

Don’t read the SNP id information from the .bim file.

By default, when the .bim is read, the sid (SNP id) is recorded. This stops that recording. This is useful if the sid is not needed. Asking for the sid after skipping it results in an error.

Don’t read the centimorgan position information from the .bim file.

By default, when the .bim is read, the cm position is recorded. This stops that recording. This is useful if the cm position is not needed. Asking for the cm position after skipping it results in an error.

Don’t read the base-pair position information from the .bim file.

By default, when the .bim is read, the bp position is recorded. This stops that recording. This is useful if the bp position is not needed. Asking for the cp position after skipping it results in an error.

Don’t read the allele 1 information from the .bim file.

By default, when the .bim is read, allele 1 is recorded. This stops that recording. This is useful if allele 1 is not needed. Asking for allele 1 after skipping it results in an error.

Don’t read the allele 2 information from the .bim file.

By default, when the .bim is read, allele 2 is recorded. This stops that recording. This is useful if allele 2 is not needed. Asking for allele 2 after skipping it results in an error.

Override the metadata in the .fam and .bim files with info merged in from a Metadata.

Example

In the example, we create a Metadata with iid and sid arrays. Next, we use BedBuilder to override the fid array and an iid array. Then, we add the metadata to the BedBuilder, overwriting iid (again) and overriding sid. Finally, we print these three arrays and chromosome. Chromosome was never overridden so it is read from the *.bim file.

 use ndarray as nd;
 use bed_reader::{Bed, Metadata, sample_bed_file};

 let file_name = sample_bed_file("small.bed")?;
 let metadata = Metadata::builder()
     .iid(["i1", "i2", "i3"])
     .sid(["s1", "s2", "s3", "s4"])
     .build()?;
 let mut bed = Bed::builder(file_name)
     .fid(["f1", "f2", "f3"])
     .iid(["x1", "x2", "x3"])
     .metadata(&metadata)
     .build()?;
 println!("{0:?}", bed.fid()?);  // Outputs ndarray ["f1", "f2", "f3"]
 println!("{0:?}", bed.iid()?);  // Outputs ndarray ["i1", "i2", "i3"]
 println!("{0:?}", bed.sid()?);  // Outputs ndarray ["s1", "s2", "s3", "s4"]
 println!("{0:?}", bed.chromosome()?);  // Outputs ndarray ["1", "1", "5", "Y"]

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.