Skip to content

Commit

Permalink
work on writer
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Mar 5, 2024
1 parent b246b3e commit 168eede
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use crate::string::String;
use linear_map::LinearMap;
use std::fmt::Debug;

/// half-open interval
#[derive(Debug, Default)]
pub struct Interval {
pub chrom: String,
/// 0-based start
pub start: u64,
pub stop: u64,
pub fields: LinearMap<String, Value>,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub mod sniff;

pub mod chrom_ordering;

pub mod writer;

#[cfg(feature = "bed")]
/// Bed parser implementing the PositionedIterator trait.
pub mod bedder_bed;
Expand Down
1 change: 1 addition & 0 deletions src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl Position {
}

#[inline]
/// 0-based start position.
pub fn start(&self) -> u64 {
match self {
Position::Bed(b) => b.start(),
Expand Down
80 changes: 80 additions & 0 deletions src/writer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use crate::sniff::Compression;
use crate::sniff::FileFormat;
use crate::report::Report;
use std::string::String;

pub struct Writer {
in_fmt: FileFormat,
out_fmt: FileFormat,
compression: Compression,
}

pub enum Type {
Integer,
Float,
Character,
String,
Flag,
}

pub enum Number {
Not,
One,
R,
A,
Dot,
}

pub trait ColumnReporter {
/// report the name, e.g. `count` for the INFO field of the VCF
fn name(&self) -> String;
/// report the type, for the INFO field of the VCF
fn ftype(&self) -> Type; // Type is some enum from noodles or here that limits to relevant types
fn description(&self) -> String;
fn number(&self) -> Number;

fn value(&self, r: &Report) -> Value // Value probably something from noodles that encapsulates Float/Int/Vec<Float>/String/...
}

pub enum FormatConversionError {
IncompatibleFormats(FileFormat, FileFormat, String),
}

impl Writer {
pub fn init(
in_fmt: FileFormat,
out_fmt: Option<FileFormat>,
compression: Compression,
) -> Result<Self, FormatConversionError> {
let out_fmt = match out_fmt {
Some(f) => f,
// TODO: may want, e.g. BAM/CRAM to default to SAM
// and BCF to default to VCF.
None => in_fmt,
};

// if out_fmt is the same as in_fmt, then we can just pass through
if in_fmt == out_fmt {
return Ok(Self {
in_fmt,
out_fmt,
compression,
});
}

// if out_fmt is different from in_fmt, then we need to convert
match (in_fmt, out_fmt) {
(FileFormat::VCF, FileFormat::BED) => {
// convert vcf to bed
}
(FileFormat::BED, FileFormat::VCF) => {
// convert bed to vcf
}
_ => Err(FormatConversionError::IncompatibleFormats(
in_fmt,
out_fmt,
String::from("No conversion yet available. Please report"),
)),
}
}
}

0 comments on commit 168eede

Please sign in to comment.