From 940a3d787b21dfec26537a8a67c0d56a9b2ddb7f Mon Sep 17 00:00:00 2001 From: Carl Kadie Date: Sat, 3 Feb 2024 15:13:59 -0800 Subject: [PATCH] ci7 --- examples/cloud.rs | 34 ++++++++++++++++++++++++++++++++++ examples/no_cloud.rs | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 examples/cloud.rs create mode 100644 examples/no_cloud.rs diff --git a/examples/cloud.rs b/examples/cloud.rs new file mode 100644 index 0000000..8c36250 --- /dev/null +++ b/examples/cloud.rs @@ -0,0 +1,34 @@ +#[cfg(feature = "tokio")] +use bed_reader::{BedCloud, BedErrorPlus, ReadOptions}; +#[cfg(feature = "tokio")] +use ndarray::s; +#[cfg(feature = "tokio")] +use std::collections::HashSet; + +#[cfg(feature = "tokio")] +#[tokio::main] +async fn main() -> Result<(), Box> { + let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/some_missing.bed"; + let cloud_options = [("timeout", "10s")]; + + let mut bed_cloud = BedCloud::new_with_options(url, cloud_options).await?; + println!("{:?}", bed_cloud.iid().await?.slice(s![..5])); // Outputs ndarray: ["iid_0", "iid_1", "iid_2", "iid_3", "iid_4"] + println!("{:?}", bed_cloud.sid().await?.slice(s![..5])); // Outputs ndarray: ["sid_0", "sid_1", "sid_2", "sid_3", "sid_4"] + println!( + "{:?}", + bed_cloud.chromosome().await?.iter().collect::>() + ); + // Outputs: {"12", "10", "4", "8", "19", "21", "9", "15", "6", "16", "13", "7", "17", "18", "1", "22", "11", "2", "20", "3", "5", "14"} + let _ = ReadOptions::builder() + .sid_index(bed_cloud.chromosome().await?.map(|elem| elem == "5")) + .f64() + .read_cloud(&mut bed_cloud) + .await?; + + Ok(()) +} + +#[cfg(not(feature = "tokio"))] +pub fn main() { + println!("This example requires the 'tokio/full' feature to be enabled"); +} diff --git a/examples/no_cloud.rs b/examples/no_cloud.rs new file mode 100644 index 0000000..fe03b69 --- /dev/null +++ b/examples/no_cloud.rs @@ -0,0 +1,19 @@ +use bed_reader::{sample_bed_file, Bed, BedErrorPlus, ReadOptions}; +use ndarray::s; +use std::collections::HashSet; + +fn main() -> Result<(), Box> { + let file_name = sample_bed_file("some_missing.bed")?; + + let mut bed = Bed::new(file_name)?; + println!("{:?}", bed.iid()?.slice(s![..5])); // Outputs ndarray: ["iid_0", "iid_1", "iid_2", "iid_3", "iid_4"] + println!("{:?}", bed.sid()?.slice(s![..5])); // Outputs ndarray: ["sid_0", "sid_1", "sid_2", "sid_3", "sid_4"] + println!("{:?}", bed.chromosome()?.iter().collect::>()); + // Outputs: {"12", "10", "4", "8", "19", "21", "9", "15", "6", "16", "13", "7", "17", "18", "1", "22", "11", "2", "20", "3", "5", "14"} + let _ = ReadOptions::builder() + .sid_index(bed.chromosome()?.map(|elem| elem == "5")) + .f64() + .read(&mut bed)?; + + Ok(()) +}