use std::ops::Deref;
use rust_htslib::bcf;
use crate::{common::coords::GenomeRegion, vcf::pipeline::clusterizer::phasing::Genotype};
#[derive(Debug, Clone)]
pub struct InputRecord {
record: bcf::Record,
input_gt: Genotype,
local_gt: Option<Genotype>,
sample_ix: usize,
}
impl InputRecord {
pub fn new(record: bcf::Record, sample_ix: usize) -> Self {
let input_gt = Genotype::from_record(&record, sample_ix);
Self {
record,
input_gt,
local_gt: None,
sample_ix,
}
}
pub const fn with_gt(record: bcf::Record, input_gt: Genotype, sample_ix: usize) -> Self {
Self {
record,
input_gt,
local_gt: None,
sample_ix,
}
}
pub const fn sample_ix(&self) -> usize {
self.sample_ix
}
pub const fn gt(&self) -> Genotype {
match self.local_gt {
Some(gt) => gt,
None => self.input_gt,
}
}
pub const fn input_gt(&self) -> Genotype {
self.input_gt
}
pub fn with_local_gt(&self, local_gt: Genotype) -> Self {
Self {
record: self.record.clone(),
input_gt: self.input_gt,
local_gt: Some(local_gt),
sample_ix: self.sample_ix,
}
}
pub const fn record(&self) -> &bcf::Record {
&self.record
}
pub(super) fn into_record(self) -> bcf::Record {
self.record
}
}
impl Deref for InputRecord {
type Target = bcf::Record;
fn deref(&self) -> &Self::Target {
&self.record
}
}
impl TryFrom<&InputRecord> for GenomeRegion {
type Error = anyhow::Error;
fn try_from(rec: &InputRecord) -> Result<Self, Self::Error> {
Self::try_from(rec.record())
}
}