Skip to content

Commit

Permalink
use xvcf-rs in index
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Sep 21, 2023
1 parent 54f0049 commit ed1c7c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 42 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ path = "src/main.rs"

[dependencies]
rand = "0.8.5"
smartstring = {version = "1.0.1", optional = true }
smol_str = {version = "0.2.0", optional = true }
compact_str = {version = "0.7.0", optional = true }
kstring = {version = "2.0.0", optional = true }
noodles = {version = "0.45.0"}
smartstring = { version = "1.0.1", optional = true }
smol_str = { version = "0.2.0", optional = true }
compact_str = { version = "0.7.0", optional = true }
kstring = { version = "2.0.0", optional = true }
noodles = { version = "0.51.0" }
flate2 = "1.0.26"
clap = {version="4.2.7", features=['derive']}
clap = { version = "4.2.7", features = ['derive'] }
env_logger = "0.10.0"
log = "0.4.19"
linear-map = "1.2.0"
hashbrown = "0.14.0"
xvcf = { version = "0.1.1", git = "https://github.com/brentp/xvcf-rs" }

[features]
default = ["bed", "vcf", "bcf", "csi", "core", "bam", "sam", "bgzf"]
Expand All @@ -43,12 +44,11 @@ dyn_positioned = []

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }
clap = {version = "4.2.7", features=["derive"]}
clap = { version = "4.2.7", features = ["derive"] }

[[bench]]
name = "random_intervals"
harness = false

[profile.release]
lto = true

49 changes: 15 additions & 34 deletions src/bedder_vcf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,36 @@ use crate::position::{Field, FieldError, Position, Positioned, Value};
use crate::string::String;
use noodles::bcf;

Check warning on line 3 in src/bedder_vcf.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `noodles::bcf`

Check warning on line 3 in src/bedder_vcf.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `noodles::bcf`
use noodles::vcf::{self, record::Chromosome};
use std::io::{self, BufRead};
use std::io::{self, BufRead, Read};

Check warning on line 5 in src/bedder_vcf.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `BufRead`

Check warning on line 5 in src/bedder_vcf.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `BufRead`
use std::result;
use vcf::record::info::field;
use vcf::record::QualityScore;
pub use vcf::Record;

pub trait VCFReader {
fn read_record(&mut self, header: &vcf::Header, v: &mut vcf::Record) -> io::Result<usize>;
// fn queryable
}

pub enum VCF<R> {
VCF(vcf::Reader<R>),
IndexedVCF(vcf::indexed_reader::IndexedReader<R>),
BCF(bcf::Reader<R>),
IndexedBCF(bcf::indexed_reader::IndexedReader<R>),
}

impl<R> VCFReader for VCF<R>
where
R: BufRead,
{
fn read_record(&mut self, header: &vcf::Header, v: &mut vcf::Record) -> io::Result<usize> {
match self {
VCF::VCF(r) => r.read_record(header, v),
VCF::IndexedVCF(r) => r.read_record(header, v),
VCF::BCF(r) => r.read_record(header, v),
VCF::IndexedBCF(r) => r.read_record(header, v),
}
}
}
pub use xvcf;

pub struct BedderVCF<R> {
reader: VCF<R>,
header: vcf::Header,
reader: xvcf::Reader<R>,
record_number: u64,
}

impl<R> BedderVCF<R> {
pub fn new(r: VCF<R>, header: vcf::Header) -> io::Result<BedderVCF<R>> {
impl<R> BedderVCF<R>
where
R: Read + 'static,
{
pub fn new(r: xvcf::Reader<R>) -> io::Result<BedderVCF<R>> {
let v = BedderVCF {
reader: r,
header,
record_number: 0,
};
Ok(v)
}
}

pub fn from_reader<R: Read>(r: Box<R>) -> io::Result<BedderVCF<R>> {
let reader = xvcf::Reader::from_reader(r, None)?;
BedderVCF::new(reader)
}

fn match_info_value(info: &vcf::record::Info, name: &str) -> result::Result<Value, FieldError> {
//let info = record.info();
let key: vcf::record::info::field::Key = name
Expand Down Expand Up @@ -153,15 +134,15 @@ impl Positioned for vcf::record::Record {

impl<R> crate::position::PositionedIterator for BedderVCF<R>
where
R: BufRead,
R: Read + 'static,
{
fn next_position(
&mut self,
_q: Option<&crate::position::Position>,
) -> Option<std::result::Result<Position, std::io::Error>> {
let mut v = vcf::Record::default();

match self.reader.read_record(&self.header, &mut v) {
match self.reader.next_record(&self.reader.header(), &mut v) {
Ok(0) => None, // EOF
Ok(_) => {
self.record_number += 1;
Expand Down

0 comments on commit ed1c7c4

Please sign in to comment.