Skip to content

Commit

Permalink
chore: Switch to using noodles group (#459)
Browse files Browse the repository at this point in the history
Co-authored-by: varfish-bot <[email protected]>
  • Loading branch information
tedil and varfish-bot authored Jun 3, 2024
1 parent 7842351 commit 5868884
Show file tree
Hide file tree
Showing 28 changed files with 269 additions and 280 deletions.
83 changes: 45 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ indexmap = { version = "2.2", features = ["serde"] }
indicatif = { version = "0.17", features = ["rayon"] }
itertools = "0.13.0"
log = "0.4"
noodles-bed = "0.13"
noodles-bgzf = "0.30"
noodles-core = "0.15"
noodles-csi = "0.35"
noodles-gff = "0.33.0"
noodles-tabix = "0.41"
noodles-vcf = "0.57"
pbjson = "0.6"
pbjson-types = "0.6"
prost = "0.12"
Expand All @@ -53,13 +46,17 @@ rocksdb = { version = "0.22", features = ["multi-threaded-cf"] }
rocksdb-utils-lookup = "0.4"
rustc-hash = "1.1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features=["preserve_order"] }
serde_with = { version = "3.6", features=["alloc", "macros", "indexmap_2"], default-features = false }
serde_json = { version = "1.0", features = ["preserve_order"] }
serde_with = { version = "3.6", features = ["alloc", "macros", "indexmap_2"], default-features = false }
strum = { version = "0.26", features = ["strum_macros", "derive"] }
thiserror = "1.0"
tracing = "0.1"
tracing-subscriber = "0.3"

[dependencies.noodles]
version = "0.75.0"
features = ["bed", "bgzf", "core", "csi", "gff", "tabix", "vcf"]

[build-dependencies]
anyhow = "1.0"
pbjson-build = "0.6"
Expand Down
2 changes: 1 addition & 1 deletion src/common/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Var {
}

/// Create for all alternate alleles from the given VCF record.
pub fn from_vcf_allele(value: &noodles_vcf::variant::RecordBuf, allele_no: usize) -> Self {
pub fn from_vcf_allele(value: &noodles::vcf::variant::RecordBuf, allele_no: usize) -> Self {
let chrom = value.reference_sequence_name().to_string();
let pos: usize = value
.variant_start()
Expand Down
37 changes: 10 additions & 27 deletions src/common/noodles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
use std::str::FromStr;

use noodles_vcf::variant::record_buf::info::field;
use noodles::vcf::variant::record_buf::info::field;
use noodles::vcf::variant::RecordBuf as VcfRecord;

/// Extract a `String` field from a record.
pub fn get_string(
record: &noodles_vcf::variant::RecordBuf,
name: &str,
) -> Result<String, anyhow::Error> {
pub fn get_string(record: &VcfRecord, name: &str) -> Result<String, anyhow::Error> {
if let Some(Some(field::Value::String(v))) = record.info().get(name) {
Ok(v.to_string())
} else if let Some(Some(field::Value::Array(field::value::Array::String(vs)))) =
Expand All @@ -21,18 +19,15 @@ pub fn get_string(
}

/// Extract a flag field from a record.
pub fn get_flag(
record: &noodles_vcf::variant::RecordBuf,
name: &str,
) -> Result<bool, anyhow::Error> {
pub fn get_flag(record: &VcfRecord, name: &str) -> Result<bool, anyhow::Error> {
Ok(matches!(
record.info().get(name),
Some(Some(field::Value::Flag))
))
}

/// Extract an `i32` field from a record.
pub fn get_i32(record: &noodles_vcf::variant::RecordBuf, name: &str) -> Result<i32, anyhow::Error> {
pub fn get_i32(record: &VcfRecord, name: &str) -> Result<i32, anyhow::Error> {
if let Some(Some(field::Value::Integer(v))) = record.info().get(name) {
Ok(*v)
} else if let Some(Some(field::Value::Array(field::value::Array::Integer(vs)))) =
Expand All @@ -45,7 +40,7 @@ pub fn get_i32(record: &noodles_vcf::variant::RecordBuf, name: &str) -> Result<i
}

/// Extract an `f32` field from a record.
pub fn get_f32(record: &noodles_vcf::variant::RecordBuf, name: &str) -> Result<f32, anyhow::Error> {
pub fn get_f32(record: &VcfRecord, name: &str) -> Result<f32, anyhow::Error> {
if let Some(Some(field::Value::Float(v))) = record.info().get(name) {
Ok(*v)
} else if let Some(Some(field::Value::Array(field::value::Array::Float(vs)))) =
Expand All @@ -60,10 +55,7 @@ pub fn get_f32(record: &noodles_vcf::variant::RecordBuf, name: &str) -> Result<f
/// Extract an `Vec<String>` field from record with an array field.
///
/// This is different than parsing the histograms from pipe-separated strings.
pub fn get_vec_str(
record: &noodles_vcf::variant::RecordBuf,
name: &str,
) -> Result<Vec<String>, anyhow::Error> {
pub fn get_vec_str(record: &VcfRecord, name: &str) -> Result<Vec<String>, anyhow::Error> {
if let Some(Some(field::Value::Array(field::value::Array::String(vs)))) =
record.info().get(name)
{
Expand All @@ -76,10 +68,7 @@ pub fn get_vec_str(
/// Extract an `Vec<i32>` field from record with an array field.
///
/// This is different than parsing the histograms from pipe-separated strings.
pub fn get_vec_i32(
record: &noodles_vcf::variant::RecordBuf,
name: &str,
) -> Result<Vec<i32>, anyhow::Error> {
pub fn get_vec_i32(record: &VcfRecord, name: &str) -> Result<Vec<i32>, anyhow::Error> {
if let Some(Some(field::Value::Array(field::value::Array::Integer(vs)))) =
record.info().get(name)
{
Expand All @@ -90,10 +79,7 @@ pub fn get_vec_i32(
}

/// Extract an `Vec<FromStr>` field from a record encoded as a pipe symbol separated string.
pub fn get_vec<T>(
record: &noodles_vcf::variant::RecordBuf,
name: &str,
) -> Result<Vec<T>, anyhow::Error>
pub fn get_vec<T>(record: &VcfRecord, name: &str) -> Result<Vec<T>, anyhow::Error>
where
T: FromStr,
{
Expand All @@ -109,10 +95,7 @@ where

/// Extract an `Vec<Vec<FromStr>>` field from a record encoded as a list of pipe symbol
/// separated string.
pub fn get_vec_vec<T>(
record: &noodles_vcf::variant::RecordBuf,
name: &str,
) -> Result<Vec<T>, anyhow::Error>
pub fn get_vec_vec<T>(record: &VcfRecord, name: &str) -> Result<Vec<T>, anyhow::Error>
where
T: FromStr,
{
Expand Down
4 changes: 2 additions & 2 deletions src/db_utils/cli/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ fn copy_cf_bed(
) -> Result<(), anyhow::Error> {
let mut reader = File::open(path_bed)
.map(BufReader::new)
.map(noodles_bed::Reader::new)?;
.map(noodles::bed::Reader::new)?;

tracing::info!(" reading BED records...");
let bed_records = reader
.records::<3>()
.collect::<Result<Vec<noodles_bed::Record<3>>, _>>()?;
.collect::<Result<Vec<noodles::bed::Record<3>>, _>>()?;
tracing::info!(
" will process {} BED records in parallel...",
bed_records.len()
Expand Down
Loading

0 comments on commit 5868884

Please sign in to comment.