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
impl BedCloud
Sourcepub async fn new_with_options<I, K, V>(
url: impl AsRef<str>,
cloud_options: I,
) -> Result<Self, Box<BedErrorPlus>>
pub async fn new_with_options<I, K, V>( url: impl AsRef<str>, cloud_options: I, ) -> Result<Self, Box<BedErrorPlus>>
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. SeeBedCloud::builderandBedCloud::builder_with_options, which does supportBedCloudoptions. Alternatively, you can useBedCloud::builder_from_cloud_fileto specify the cloud file via anCloudFile. For reading local files, seeBed.
§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]]);Sourcepub async fn new(url: impl AsRef<str>) -> Result<Self, Box<BedErrorPlus>>
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. SeeBedCloud::builderandBedCloud::builder_with_options, which does supportBedCloudoptions. Alternatively, you can useBedCloud::builder_from_cloud_fileto specify the cloud file via anCloudFile. For reading local files, seeBed.
§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]]);Sourcepub fn builder(
url: impl AsRef<str>,
) -> Result<BedCloudBuilder, Box<BedErrorPlus>>
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::newandBedCloud::new_with_options, which do not supportBedCloudoptions. Alternatively, you can useBedCloud::builder_from_cloud_fileto specify the cloud file via anCloudFile. For reading local files, seeBed.
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");Sourcepub fn builder_with_options<I, K, V>(
url: impl AsRef<str>,
options: I,
) -> Result<BedCloudBuilder, Box<BedErrorPlus>>
pub fn builder_with_options<I, K, V>( url: impl AsRef<str>, options: I, ) -> Result<BedCloudBuilder, Box<BedErrorPlus>>
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::newandBedCloud::new_with_options, which do not supportBedCloudoptions. Alternatively, you can useBedCloud::builder_from_cloud_fileto specify the cloud file via anCloudFile. For reading local files, seeBed.
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
impl BedCloud
Sourcepub fn builder_from_cloud_file(cloud_file: &CloudFile) -> BedCloudBuilder
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::neworBedCloud::builderto specify the cloud file via a URL string. For reading local files, seeBed.
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]
],
);Sourcepub async fn from_cloud_file(
cloud_file: &CloudFile,
) -> Result<Self, Box<BedErrorPlus>>
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::newandBedCloud::builderto specify the cloud file via a URL string. For reading local files, seeBed.
§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]
],
);Sourcepub async fn iid_count(&mut self) -> Result<usize, Box<BedErrorPlus>>
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);Sourcepub async fn sid_count(&mut self) -> Result<usize, Box<BedErrorPlus>>
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);Sourcepub async fn dim(&mut self) -> Result<(usize, usize), Box<BedErrorPlus>>
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));Sourcepub async fn fid(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>
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"]Sourcepub async fn iid(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>
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"]Sourcepub async fn father(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>
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"]Sourcepub async fn mother(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>
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"]Sourcepub async fn sex(&mut self) -> Result<&Array1<i32>, Box<BedErrorPlus>>
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]Sourcepub async fn pheno(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>
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"]Sourcepub async fn chromosome(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>
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"]Sourcepub async fn sid(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>
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"]Sourcepub async fn cm_position(&mut self) -> Result<&Array1<f32>, Box<BedErrorPlus>>
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]Sourcepub async fn bp_position(&mut self) -> Result<&Array1<i32>, Box<BedErrorPlus>>
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]Sourcepub async fn allele_1(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>
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"]Sourcepub async fn allele_2(&mut self) -> Result<&Array1<String>, Box<BedErrorPlus>>
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"]Sourcepub async fn metadata(&mut self) -> Result<Metadata, Box<BedErrorPlus>>
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"] ...)Sourcepub fn cloud_file(&self) -> CloudFile
pub fn cloud_file(&self) -> CloudFile
Return the CloudFile of the .bed file.
Sourcepub fn fam_cloud_file(&mut self) -> Result<CloudFile, Box<BedErrorPlus>>
pub fn fam_cloud_file(&mut self) -> Result<CloudFile, Box<BedErrorPlus>>
Return the cloud location of the .fam file.
Sourcepub fn bim_cloud_file(&mut self) -> Result<CloudFile, Box<BedErrorPlus>>
pub fn bim_cloud_file(&mut self) -> Result<CloudFile, Box<BedErrorPlus>>
Return the cloud location of the .bim file.
Sourcepub async fn read<TVal: BedVal>(
&mut self,
) -> Result<Array2<TVal>, Box<BedErrorPlus>>
pub async fn read<TVal: BedVal>( &mut self, ) -> Result<Array2<TVal>, Box<BedErrorPlus>>
Read genotype data.
Also see
ReadOptions::builderwhich 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]
],
);Sourcepub async fn read_and_fill_with_options<TVal: BedVal>(
&mut self,
val: &mut ArrayViewMut2<'_, TVal>,
read_options: &ReadOptions<TVal>,
) -> Result<(), Box<BedErrorPlus>>
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]]);Sourcepub async fn read_and_fill<TVal: BedVal>(
&mut self,
val: &mut ArrayViewMut2<'_, TVal>,
) -> Result<(), Box<BedErrorPlus>>
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]
],
);Sourcepub async fn read_with_options<TVal: BedVal>(
&mut self,
read_options: &ReadOptions<TVal>,
) -> Result<Array2<TVal>, Box<BedErrorPlus>>
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§
Auto Trait Implementations§
impl Freeze for BedCloud
impl !RefUnwindSafe for BedCloud
impl !Send for BedCloud
impl !Sync for BedCloud
impl Unpin for BedCloud
impl !UnwindSafe for BedCloud
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.