BedCloud

Struct BedCloud 

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

Represents a PLINK .bed file in the cloud that is open for reading genotype data and metadata.

Construct with BedCloud::new, BedCloud::builder, BedCloud::from_cloud_file, or BedCloud::builder_from_cloud_file.

For reading local files, see Bed.

§Example

Open a file for reading. Then, read the individual (sample) ids and all the genotype data.

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::new(url).await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["iid1", "iid2", "iid3"]
let val = ReadOptions::builder().f64().read_cloud(&mut bed_cloud).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]
    ],
);

Implementations§

Source§

impl BedCloud

Source

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

Attempts to open a PLINK .bed file in the cloud for reading. The file is specified with a URL string and cloud options can be given.

See “Cloud URLs and CloudFile Examples” for details specifying a file.

You may give cloud options but not BedCloud options or ReadOptions. See “Options, Options, Options” for details.

Also see BedCloud::new, which does not support cloud options. See BedCloud::builder and BedCloud::builder_with_options, which does support BedCloud options. Alternatively, you can use BedCloud::builder_from_cloud_file to specify the cloud file via an CloudFile. For reading local files, see Bed.

§Errors

URL parsing may return an error. Also, by default, this method will return an error if the file is missing or its header is ill-formed. See BedError and BedErrorPlus for all possible errors.

§Examples

List individual (sample) iid and SNP (variant) sid, then read the whole file.

use ndarray as nd;
use bed_reader::{BedCloud, assert_eq_nan};

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let cloud_options = [("timeout", "10s")];
let mut bed_cloud = BedCloud::new_with_options(url, cloud_options).await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray: ["iid1", "iid2", "iid3"]
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray: ["sid1", "sid2", "sid3", "sid4"]
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]
    ],
);

Open the file and read data for one SNP (variant) at index position 2.

let mut bed_cloud = BedCloud::new_with_options(url, cloud_options).await?;
let val = ReadOptions::builder().sid_index(2).f64().read_cloud(&mut bed_cloud).await?;

assert_eq_nan(&val, &nd::array![[f64::NAN], [f64::NAN], [2.0]]);
Source

pub async fn new(url: impl AsRef<str>) -> Result<Self, Box<BedErrorPlus>>

Attempts to open a PLINK .bed file in the cloud for reading. The file is specified with a URL string.

See “Cloud URLs and CloudFile Examples” for details specifying a file.

See “Options, Options, Options” for details of the different option types.

Also see BedCloud::new_with_options, which supports cloud options. See BedCloud::builder and BedCloud::builder_with_options, which does support BedCloud options. Alternatively, you can use BedCloud::builder_from_cloud_file to specify the cloud file via an CloudFile. For reading local files, see Bed.

§Errors

URL parsing may return an error. Also, by default, this method will return an error if the file is missing or its header is ill-formed. See BedError and BedErrorPlus for all possible errors.

§Examples

List individual (sample) iid and SNP (variant) sid, then read the whole file.

use ndarray as nd;
use bed_reader::{BedCloud, assert_eq_nan};

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray: ["iid1", "iid2", "iid3"]
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray: ["sid1", "sid2", "sid3", "sid4"]
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]
    ],
);

Open the file and read data for one SNP (variant) at index position 2.

let mut bed_cloud = BedCloud::new(url).await?;
let val = ReadOptions::builder().sid_index(2).f64().read_cloud(&mut bed_cloud).await?;

assert_eq_nan(&val, &nd::array![[f64::NAN], [f64::NAN], [2.0]]);
Source

pub fn builder( url: impl AsRef<str>, ) -> Result<BedCloudBuilder, Box<BedErrorPlus>>

Attempts to open a PLINK .bed file in the cloud for reading. The file is specified with a URL string. Supports BedCloud options but not cloud options.

See “Cloud URLs and CloudFile Examples” for details of specifying a file. See “Options, Options, Options” for an overview of options types.

Also see BedCloud::new and BedCloud::new_with_options, which do not support BedCloud options. Alternatively, you can use BedCloud::builder_from_cloud_file to specify the cloud file via an CloudFile. For reading local files, see Bed.

The BedCloud options, listed here, can:

  • set the cloud location of the .fam and/or .bim file
  • override some metadata, for example, replace the individual ids.
  • set the number of individuals (samples) or SNPs (variants)
  • control checking the validity of the .bed file’s header
  • skip reading selected metadata
§Errors

URL parsing may return an error. Also, by default, this method will return an error if the file is missing or its header is ill-formed. It will also return an error if the options contradict each other. See BedError and BedErrorPlus for all possible errors.

§Examples

List individual (sample) iid and SNP (variant) sid, then read the whole file.

use ndarray as nd;
use bed_reader::{BedCloud, assert_eq_nan};

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::builder(url)?.build().await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["iid1", "iid2", "iid3"]
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray ["snp1", "snp2", "snp3", "snp4"]
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]
    ],
);

Replace iid.

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

Give the number of individuals (samples) and SNPs (variants) so that the .fam and .bim files need never be opened. Use .skip_early_check() to avoid opening the .bed before the first read.

let mut bed_cloud = BedCloud::builder(url)?
    .iid_count(3)
    .sid_count(4)
    .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]
    ],
);

Mark some properties as “don’t read or offer”.

let mut bed_cloud = BedCloud::builder(url)?
    .skip_father()
    .skip_mother()
    .skip_sex()
    .skip_pheno()
    .skip_allele_1()
    .skip_allele_2()
    .build().await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["iid1", "iid2", "iid3"]
bed_cloud.allele_2().await.expect_err("Can't be read");
Source

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

Attempts to open a PLINK .bed file in the cloud for reading. The file is specified with a URL string and cloud options can be given. Supports both cloud options and BedCloud options.

See “Cloud URLs and CloudFile Examples” for details of specifying a file. See “Options, Options, Options” for an overview of options types.

Also see BedCloud::new and BedCloud::new_with_options, which do not support BedCloud options. Alternatively, you can use BedCloud::builder_from_cloud_file to specify the cloud file via an CloudFile. For reading local files, see Bed.

The BedCloud options, listed here, can:

  • set the cloud location of the .fam and/or .bim file
  • override some metadata, for example, replace the individual ids.
  • set the number of individuals (samples) or SNPs (variants)
  • control checking the validity of the .bed file’s header
  • skip reading selected metadata
§Errors

URL parsing may return an error. Also, by default, this method will return an error if the file is missing or its header is ill-formed. It will also return an error if the options contradict each other. See BedError and BedErrorPlus for all possible errors.

§Examples

List individual (sample) iid and SNP (variant) sid, then read the whole file.

use ndarray as nd;
use bed_reader::{BedCloud, assert_eq_nan};

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let cloud_options = [("timeout", "10s")];
let mut bed_cloud = BedCloud::builder_with_options(url, cloud_options)?.build().await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["iid1", "iid2", "iid3"]
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray ["snp1", "snp2", "snp3", "snp4"]
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]
    ],
);

Replace iid.

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

Give the number of individuals (samples) and SNPs (variants) so that the .fam and .bim files need never be opened. Use .skip_early_check() to avoid opening the .bed before the first read.

let mut bed_cloud = BedCloud::builder_with_options(url, cloud_options)?
    .iid_count(3)
    .sid_count(4)
    .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]
    ],
);

Mark some properties as “don’t read or offer”.

let mut bed_cloud = BedCloud::builder_with_options(url, cloud_options)?
    .skip_father()
    .skip_mother()
    .skip_sex()
    .skip_pheno()
    .skip_allele_1()
    .skip_allele_2()
    .build().await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["iid1", "iid2", "iid3"]
bed_cloud.allele_2().await.expect_err("Can't be read");
Source§

impl BedCloud

Source

pub fn builder_from_cloud_file(cloud_file: &CloudFile) -> BedCloudBuilder

Attempts to open a PLINK .bed file in the cloud for reading. Specify the file with an CloudFile. Supports BedCloud options.

Alternatively, you can use BedCloud::new or BedCloud::builder to specify the cloud file via a URL string. For reading local files, see Bed.

The BedCloud options, listed here, can:

  • set the cloud location of the .fam and/or .bim file
  • override some metadata, for example, replace the individual ids.
  • set the number of individuals (samples) or SNPs (variants)
  • control checking the validity of the .bed file’s header
  • skip reading selected metadata
§Errors

By default, this method will return an error if the file is missing or its header is ill-formed. It will also return an error if the options contradict each other. See BedError and BedErrorPlus for all possible errors.

§Examples

List individual (sample) iid and SNP (variant) sid, then read the whole file.

use ndarray as nd;
use bed_reader::{BedCloud, assert_eq_nan};
use cloud_file::CloudFile;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let cloud_file = CloudFile::new(url)?;
let mut bed_cloud = BedCloud::builder_from_cloud_file(&cloud_file).build().await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray ["iid1", "iid2", "iid3"]
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray ["snp1", "snp2", "snp3", "snp4"]
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 async fn from_cloud_file( cloud_file: &CloudFile, ) -> Result<Self, Box<BedErrorPlus>>

Attempts to open a PLINK .bed file in the cloud for reading. Specify the file with an CloudFile.

You may not give BedCloud options. See BedCloud::builder_from_cloud_file, which does support BedCloud options.

Also see, BedCloud::new and BedCloud::builder to specify the cloud file via a URL string. For reading local files, see Bed.

§Errors

By default, this method will return an error if the file is missing or its header is ill-formed. See BedError and BedErrorPlus for all possible errors.

§Examples

List individual (sample) iid and SNP (variant) sid, then read the whole file.

use ndarray as nd;
use bed_reader::{BedCloud, assert_eq_nan};
use cloud_file::CloudFile;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let cloud_file = CloudFile::new(url)?;
let mut bed_cloud = BedCloud::from_cloud_file(&cloud_file).await?;
println!("{:?}", bed_cloud.iid().await?); // Outputs ndarray: ["iid1", "iid2", "iid3"]
println!("{:?}", bed_cloud.sid().await?); // Outputs ndarray: ["sid1", "sid2", "sid3", "sid4"]
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 async fn iid_count(&mut self) -> Result<usize, Box<BedErrorPlus>>

Number of individuals (samples)

If this number is needed, it will be found by opening the .fam file and quickly counting the number of lines. Once found, the number will be remembered. The file read can be avoided by setting the number with BedCloudBuilder::iid_count or, for example, BedCloudBuilder::iid.

§Example:
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::new(url).await?;
let iid_count = bed_cloud.iid_count().await?;

assert!(iid_count == 3);
Source

pub async fn sid_count(&mut self) -> Result<usize, Box<BedErrorPlus>>

Number of SNPs (variants)

If this number is needed, it will be found by opening the .bim file and quickly counting the number of lines. Once found, the number will be remembered. The file read can be avoided by setting the number with BedCloudBuilder::sid_count or, for example, BedCloudBuilder::sid.

§Example:
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::new(url).await?;
let sid_count = bed_cloud.sid_count().await?;

assert!(sid_count == 4);
Source

pub async fn dim(&mut self) -> Result<(usize, usize), Box<BedErrorPlus>>

Number of individuals (samples) and SNPs (variants)

If these numbers aren’t known, they will be found by opening the .fam and .bim files and quickly counting the number of lines. Once found, the numbers will be remembered. The file read can be avoided by setting the number with BedCloudBuilder::iid_count and BedCloudBuilder::sid_count.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let dim = bed_cloud.dim().await?;

assert!(dim == (3,4));
Source

pub async fn fid(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>

Family id of each of individual (sample)

If this ndarray is needed, it will be found by reading the .fam file. Once found, this ndarray and other information in the .fam file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::fid.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let fid = bed_cloud.fid().await?;
println!("{fid:?}"); // Outputs ndarray ["fid1", "fid1", "fid2"]
Source

pub async fn iid(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>

Individual id of each of individual (sample)

If this ndarray is needed, it will be found by reading the .fam file. Once found, this ndarray and other information in the .fam file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::iid.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let iid = bed_cloud.iid().await?;    ///
println!("{iid:?}"); // Outputs ndarray ["iid1", "iid2", "iid3"]
Source

pub async fn father(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>

Father id of each of individual (sample)

If this ndarray is needed, it will be found by reading the .fam file. Once found, this ndarray and other information in the .fam file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::father.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let father = bed_cloud.father().await?;
println!("{father:?}"); // Outputs ndarray ["iid23", "iid23", "iid22"]
Source

pub async fn mother(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>

Mother id of each of individual (sample)

If this ndarray is needed, it will be found by reading the .fam file. Once found, this ndarray and other information in the .fam file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::mother.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let mother = bed_cloud.mother().await?;
println!("{mother:?}"); // Outputs ndarray ["iid34", "iid34", "iid33"]
Source

pub async fn sex(&mut self) -> Result<&Array1<i32>, Box<BedErrorPlus>>

Sex each of individual (sample)

0 is unknown, 1 is male, 2 is female

If this ndarray is needed, it will be found by reading the .fam file. Once found, this ndarray and other information in the .fam file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::sex.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let sex = bed_cloud.sex().await?;
println!("{sex:?}"); // Outputs ndarray [1, 2, 0]
Source

pub async fn pheno(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>

A phenotype for each individual (seldom used)

If this ndarray is needed, it will be found by reading the .fam file. Once found, this ndarray and other information in the .fam file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::pheno.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let pheno = bed_cloud.pheno().await?;
println!("{pheno:?}"); // Outputs ndarray ["red", "red", "blue"]
Source

pub async fn chromosome(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>

Chromosome of each SNP (variant)

If this ndarray is needed, it will be found by reading the .bim file. Once found, this ndarray and other information in the .bim file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::chromosome.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let chromosome = bed_cloud.chromosome().await?;
println!("{chromosome:?}"); // Outputs ndarray ["1", "1", "5", "Y"]
Source

pub async fn sid(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>

SNP id of each SNP (variant)

If this ndarray is needed, it will be found by reading the .bim file. Once found, this ndarray and other information in the .bim file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::sid.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let sid = bed_cloud.sid().await?;
println!("{sid:?}"); // Outputs ndarray "sid1", "sid2", "sid3", "sid4"]
Source

pub async fn cm_position(&mut self) -> Result<&Array1<f32>, Box<BedErrorPlus>>

Centimorgan position of each SNP (variant)

If this ndarray is needed, it will be found by reading the .bim file. Once found, this ndarray and other information in the .bim file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::cm_position.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let cm_position = bed_cloud.cm_position().await?;
println!("{cm_position:?}"); // Outputs ndarray [100.4, 2000.5, 4000.7, 7000.9]
Source

pub async fn bp_position(&mut self) -> Result<&Array1<i32>, Box<BedErrorPlus>>

Base-pair position of each SNP (variant)

If this ndarray is needed, it will be found by reading the .bim file. Once found, this ndarray and other information in the .bim file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::bp_position.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let bp_position = bed_cloud.bp_position().await?;
println!("{bp_position:?}"); // Outputs ndarray [1, 100, 1000, 1004]
Source

pub async fn allele_1(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>

First allele of each SNP (variant)

If this ndarray is needed, it will be found by reading the .bim file. Once found, this ndarray and other information in the .bim file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::allele_1.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let allele_1 = bed_cloud.allele_1().await?;
println!("{allele_1:?}"); // Outputs ndarray ["A", "T", "A", "T"]
Source

pub async fn allele_2(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>

Second allele of each SNP (variant)

If this ndarray is needed, it will be found by reading the .bim file. Once found, this ndarray and other information in the .bim file will be remembered. The file read can be avoided by setting the array with BedCloudBuilder::allele_2.

§Example:
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let allele_2 = bed_cloud.allele_2().await?;
println!("{allele_2:?}"); // Outputs ndarray ["A", "C", "C", "G"]
Source

pub async fn metadata(&mut self) -> Result<Metadata, Box<BedErrorPlus>>

Metadata for this dataset, 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 BedCloud.

If the needed, the metadata will be read from the .fam and/or .bim files.

use ndarray as nd;
use bed_reader::{BedCloud};

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let metadata = bed_cloud.metadata().await?;
println!("{0:?}", metadata.iid()); // Outputs Some(["iid1", "iid2", "iid3"] ...)
println!("{0:?}", metadata.sid()); // Outputs Some(["sid1", "sid2", "sid3", "sid4"] ...)
Source

pub fn cloud_file(&self) -> CloudFile

Return the CloudFile of the .bed file.

Source

pub fn fam_cloud_file(&mut self) -> Result<CloudFile, Box<BedErrorPlus>>

Return the cloud location of the .fam file.

Source

pub fn bim_cloud_file(&mut self) -> Result<CloudFile, Box<BedErrorPlus>>

Return the cloud location of the .bim file.

Source

pub async fn read<TVal: BedVal>( &mut self, ) -> Result<Array2<TVal>, Box<BedErrorPlus>>

Read genotype data.

Also see ReadOptions::builder which supports selection and options.

§Errors

See BedError and BedErrorPlus for all possible errors.

§Examples

Read all data in a .bed file.

use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).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]
    ],
);

// Your output array can be f32, f64, or i8
let val = bed_cloud.read::<i8>().await?;
assert_eq_nan(
    &val,
    &nd::array![
        [1, 0, -127, 0],
        [2, 0, -127, 2],
        [0, 1, 2, 0]
    ],
);
Source

pub async fn read_and_fill_with_options<TVal: BedVal>( &mut self, val: &mut ArrayViewMut2<'_, TVal>, read_options: &ReadOptions<TVal>, ) -> Result<(), Box<BedErrorPlus>>

Read genotype data with options, into a preallocated array.

Also see ReadOptionsBuilder::read_and_fill.

Note that options ReadOptions::f, ReadOptions::c, and ReadOptions::is_f are ignored. Instead, the order of the preallocated array is used.

§Errors

See BedError and BedErrorPlus for all possible errors.

§Example
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

// Read the SNPs indexed by 2.
let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let read_options = ReadOptions::builder().sid_index(2).build()?;
let mut val = nd::Array2::<f64>::default((3, 1));
bed_cloud.read_and_fill_with_options(&mut val.view_mut(), &read_options).await?;

assert_eq_nan(&val, &nd::array![[f64::NAN], [f64::NAN], [2.0]]);
Source

pub async fn read_and_fill<TVal: BedVal>( &mut self, val: &mut ArrayViewMut2<'_, TVal>, ) -> Result<(), Box<BedErrorPlus>>

Read all genotype data into a preallocated array.

Also see ReadOptions::builder.

§Errors

See BedError and BedErrorPlus for all possible errors.

§Example
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let mut val = nd::Array2::<i8>::default(bed_cloud.dim().await?);
bed_cloud.read_and_fill(&mut val.view_mut()).await?;

assert_eq_nan(
    &val,
    &nd::array![
        [1, 0, -127, 0],
        [2, 0, -127, 2],
        [0, 1, 2, 0]
    ],
);
Source

pub async fn read_with_options<TVal: BedVal>( &mut self, read_options: &ReadOptions<TVal>, ) -> Result<Array2<TVal>, Box<BedErrorPlus>>

Read genotype data with options.

Also see ReadOptions::builder.

§Errors

See BedError and BedErrorPlus for all possible errors.

§Example
use ndarray as nd;
use bed_reader::{BedCloud, ReadOptions};
use bed_reader::assert_eq_nan;

// Read the SNPs indexed by 2.
let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed";
let mut bed_cloud = BedCloud::new(url).await?;
let read_options = ReadOptions::builder().sid_index(2).f64().build()?;
let val = bed_cloud.read_with_options(&read_options).await?;

assert_eq_nan(&val, &nd::array![[f64::NAN], [f64::NAN], [2.0]]);

Trait Implementations§

Source§

impl Clone for BedCloud

Source§

fn clone(&self) -> BedCloud

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 Debug for BedCloud

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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