Skip to content

Commit

Permalink
force seek
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Oct 2, 2023
1 parent 2a995f2 commit ca1ff34
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ 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" }
noodles = { version = "0.52.0" }
flate2 = "1.0.26"
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.2", git = "https://github.com/brentp/xvcf-rs" }
xvcf = { version = "0.1.4", git = "https://github.com/brentp/xvcf-rs" }

[features]
default = ["bed", "vcf", "bcf", "csi", "core", "bam", "sam", "bgzf"]
Expand Down
24 changes: 21 additions & 3 deletions src/bedder_vcf.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#![allow(clippy::useless_conversion)] // these are needed to support e.g. smartstring
use crate::position::{Field, FieldError, Position, Positioned, Value};
use crate::string::String;
use noodles::core::Region;
use noodles::vcf::{self, record::Chromosome};
use std::io::{self, Read};
use std::io::{self, Read, Seek};
use std::result;
use vcf::record::info::field;
use vcf::record::QualityScore;
pub use vcf::Record;
pub use xvcf;
use xvcf::Skip;

pub struct BedderVCF<R> {
reader: xvcf::Reader<R>,
Expand Down Expand Up @@ -128,12 +130,28 @@ impl Positioned for vcf::record::Record {

impl<R> crate::position::PositionedIterator for BedderVCF<R>
where
R: Read + 'static,
R: Read + Seek + 'static,
{
fn next_position(
&mut self,
_q: Option<&crate::position::Position>,
q: Option<&crate::position::Position>,
) -> Option<std::result::Result<Position, std::io::Error>> {
if let Some(q) = q {
let s = noodles::core::Position::new(q.start() as usize + 1)?;
let e = noodles::core::Position::new(q.stop() as usize + 1)?;
let region = Region::new(q.chrom(), s..=e);
match self.reader.skip_to(&self.header, &region) {
Ok(_) => (),
Err(e) => return Some(Err(e)),
}
}

// take self.reader.variant if it's there
if let Some(v) = self.reader.take() {
self.record_number += 1;
return Some(Ok(Position::Vcf(Box::new(v))));
}

let mut v = vcf::Record::default();

match self.reader.next_record(&self.header, &mut v) {
Expand Down
4 changes: 2 additions & 2 deletions src/sniff.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use flate2::read::GzDecoder;
use std::io::{BufRead, Read};
use std::io::{BufRead, Read, Seek};
use std::path::Path;

use crate::bedder_bed::BedderBed;
Expand Down Expand Up @@ -40,7 +40,7 @@ where

pub fn open_reader<R, P>(reader: R, path: P) -> std::io::Result<Box<dyn PositionedIterator>>
where
R: Read + 'static,
R: Read + Seek + 'static,
P: AsRef<Path>,
{
let mut reader = std::io::BufReader::new(reader);
Expand Down

0 comments on commit ca1ff34

Please sign in to comment.