BedCloudBuilder

Struct BedCloudBuilder 

Source
pub struct BedCloudBuilder { /* private fields */ }
Expand description

Builder for BedCloud.

Implementations§

Source§

impl BedCloudBuilder

Source

pub fn fam<I, K, V>( self, url: impl AsRef<str>, options: I, ) -> Result<Self, Box<BedErrorPlus>>
where I: IntoIterator<Item = (K, V)>, K: AsRef<str>, V: Into<String>,

Set the cloud location of the .fam file. Specify the file with a URL string.

If not set, the .fam file will be assumed to have the same location as the .bed file, but with the extension .fam.

See BedCloudBuilder::fam_cloud_file to specify the file with an CloudFile instead of a URL string.

§Example:

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

use bed_reader::{BedCloud, ReadOptions, sample_urls, EMPTY_OPTIONS};
let deb_maf_mib = sample_urls(["small.deb", "small.maf", "small.mib"])?;
let mut bed_cloud = BedCloud::builder(&deb_maf_mib[0])?
   .fam(&deb_maf_mib[1], EMPTY_OPTIONS)?
   .bim(&deb_maf_mib[2], EMPTY_OPTIONS)?
   .build().await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["iid1", "iid2", "iid3"]
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray ["sid1", "sid2", "sid3", "sid4"]
Source

pub fn bim<I, K, V>( self, url: impl AsRef<str>, options: I, ) -> Result<Self, Box<BedErrorPlus>>
where I: IntoIterator<Item = (K, V)>, K: AsRef<str>, V: Into<String>,

Set the cloud location of the .bim file. Specify the file with a URL string.

If not set, the .bim file will be assumed to have the same location as the .bed file, but with the extension .bim.

See BedCloudBuilder::fam_cloud_file to specify the file with an CloudFile instead of a URL string.

§Example:

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

use bed_reader::{BedCloud, ReadOptions, sample_urls, EMPTY_OPTIONS};
let deb_maf_mib = sample_urls(["small.deb", "small.maf", "small.mib"])?;
let mut bed_cloud = BedCloud::builder(&deb_maf_mib[0])?
   .fam(&deb_maf_mib[1], EMPTY_OPTIONS)?
   .bim(&deb_maf_mib[2], EMPTY_OPTIONS)?
   .build().await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["iid1", "iid2", "iid3"]
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray ["sid1", "sid2", "sid3", "sid4"]
Source§

impl BedCloudBuilder

Source

pub async fn build(&self) -> Result<BedCloud, Box<BedErrorPlus>>

Create a BedCloud from the builder.

See BedCloud::builder for more details and examples.

Source

pub fn fid<AnyString0, AnyIter1>(self, fid: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

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.

Source

pub fn iid<AnyString0, AnyIter1>(self, iid: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

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::{BedCloud, assert_eq_nan};
let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
use bed_reader::ReadOptions;

let mut bed_cloud = BedCloud::builder(url)?
   .iid(["sample1", "sample2", "sample3"])
   .build().await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["sample1", "sample2", "sample3"]
Source

pub fn father<AnyString0, AnyIter1>(self, father: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

Override the father values found in the .fam file.

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.

Source

pub fn mother<AnyString0, AnyIter1>(self, mother: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

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.

Source

pub fn sex<AnyIter0>(self, sex: AnyIter0) -> Self
where AnyIter0: IntoIterator<Item = i32>,

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.

Source

pub fn pheno<AnyString0, AnyIter1>(self, pheno: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

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.

Source

pub fn chromosome<AnyString0, AnyIter1>(self, chromosome: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

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.

Source

pub fn sid<AnyString0, AnyIter1>(self, sid: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

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::{BedCloud, ReadOptions, assert_eq_nan};
let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";

let mut bed_cloud = BedCloud::builder(url)?
   .sid(["SNP1", "SNP2", "SNP3", "SNP4"])
   .build().await?;
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray ["SNP1", "SNP2", "SNP3", "SNP4"]
Source

pub fn cm_position<AnyIter0>(self, cm_position: AnyIter0) -> Self
where AnyIter0: IntoIterator<Item = f32>,

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.

Source

pub fn bp_position<AnyIter0>(self, bp_position: AnyIter0) -> Self
where AnyIter0: IntoIterator<Item = i32>,

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.

Source

pub fn allele_1<AnyString0, AnyIter1>(self, allele_1: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

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.

Source

pub fn allele_2<AnyString0, AnyIter1>(self, allele_2: AnyIter1) -> Self
where AnyString0: AsRef<str>, AnyIter1: IntoIterator<Item = AnyString0>,

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.

Source

pub fn iid_count(self, count: usize) -> Self

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.

Source

pub fn sid_count(self, count: usize) -> Self

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.

Source

pub fn skip_early_check(self) -> Self

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

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

let mut bed_cloud = BedCloud::builder(url)?.skip_early_check().build().await?;
let val = bed_cloud.read::<f64>().await?;

assert_eq_nan(
    &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]
    ],
);
Source

pub fn fam_cloud_file(self, cloud_file: &CloudFile) -> Self

Set the cloud location of the .fam file.

If not set, the .fam file will be assumed to have the same location as the .bed file, but with the extension .fam.

§Example:

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

use bed_reader::{BedCloud, ReadOptions, sample_urls, EMPTY_OPTIONS};
let deb_maf_mib = sample_urls(["small.deb", "small.maf", "small.mib"])?;
let mut bed_cloud = BedCloud::builder(&deb_maf_mib[0])?
   .fam(&deb_maf_mib[1], EMPTY_OPTIONS)?
   .bim(&deb_maf_mib[2], EMPTY_OPTIONS)?
   .build().await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["iid1", "iid2", "iid3"]
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray ["sid1", "sid2", "sid3", "sid4"]
Source

pub fn bim_cloud_file(self, cloud_file: &CloudFile) -> Self

Set the cloud location of the .bim file.

If not set, the .bim file will be assumed to have the same location as the .bed file, but with the extension .bim.

§Example:

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

use bed_reader::{BedCloud, ReadOptions, sample_urls, CloudFile};

let deb_maf_mib = sample_urls(["small.deb", "small.maf", "small.mib"])?
   .iter()
   .map(|url| CloudFile::new(url))
   .collect::<Result<Vec<CloudFile>, _>>()?;
let mut bed_cloud = BedCloud::builder_from_cloud_file(&deb_maf_mib[0])
   .fam_cloud_file(&deb_maf_mib[1])
   .bim_cloud_file(&deb_maf_mib[2])
   .build().await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["iid1", "iid2", "iid3"]
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray ["sid1", "sid2", "sid3", "sid4"]
Source

pub fn skip_fid(self) -> Self

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.

Source

pub fn skip_iid(self) -> Self

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.

Source

pub fn skip_father(self) -> Self

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.

Source

pub fn skip_mother(self) -> Self

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.

Source

pub fn skip_sex(self) -> Self

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.

Source

pub fn skip_pheno(self) -> Self

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.

Source

pub fn skip_chromosome(self) -> Self

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.

Source

pub fn skip_sid(self) -> Self

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.

Source

pub fn skip_cm_position(self) -> Self

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.

Source

pub fn skip_bp_position(self) -> Self

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.

Source

pub fn skip_allele_1(self) -> Self

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.

Source

pub fn skip_allele_2(self) -> Self

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.

Source

pub fn metadata(self, metadata: &Metadata) -> Self

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 BedCloudBuilder to override the fid array and an iid array. Then, we add the metadata to the BedCloudBuilder, 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::{BedCloud, Metadata};

 let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
 let metadata = Metadata::builder()
     .iid(["i1", "i2", "i3"])
     .sid(["s1", "s2", "s3", "s4"])
     .build()?;
 let mut bed_cloud = BedCloud::builder(url)?
     .fid(["f1", "f2", "f3"])
     .iid(["x1", "x2", "x3"])
     .metadata(&metadata)
     .build().await?;
 println!("{0:?}", bed_cloud.fid().await?);  // Outputs ndarray ["f1", "f2", "f3"]
 println!("{0:?}", bed_cloud.iid().await?);  // Outputs ndarray ["i1", "i2", "i3"]
 println!("{0:?}", bed_cloud.sid().await?);  // Outputs ndarray ["s1", "s2", "s3", "s4"]
 println!("{0:?}", bed_cloud.chromosome().await?);  // Outputs ndarray ["1", "1", "5", "Y"]

Trait Implementations§

Source§

impl Clone for BedCloudBuilder

Source§

fn clone(&self) -> BedCloudBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for BedCloudBuilder

Source§

fn default() -> Self

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

impl From<&CloudFile> for BedCloudBuilder

Source§

fn from(cloud_file: &CloudFile) -> Self

Converts to this type from the input type.
Source§

impl From<CloudFile> for BedCloudBuilder

Source§

fn from(cloud_file: CloudFile) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more