perbase_lib/position/
range_positions.rs

1//! An implementation of `Position` that covers a range from `pos` to `end`.
2//!
3//! Whether this is 0-based or 1-based is up to the caller.
4use crate::position::Position;
5use serde::Serialize;
6use smartstring::alias::String;
7use std::default;
8
9/// Hold all information about a range of positions.
10#[derive(Debug, Serialize, Default)]
11#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
12pub struct RangePositions {
13    /// Reference sequence name.
14    #[serde(rename = "REF")]
15    pub ref_seq: String,
16    /// 1-based position in the sequence.
17    pub pos: u32,
18    /// The point at which this depth ends, non-inclusive
19    pub end: u32,
20    /// Total depth at this position.
21    pub depth: u32,
22}
23
24impl Position for RangePositions {
25    /// Create a new position for the given ref_seq name.
26    fn new(ref_seq: String, pos: u32) -> Self {
27        RangePositions {
28            ref_seq,
29            pos,
30            ..default::Default::default()
31        }
32    }
33}
34
35/// Bed-like formatting of [`RangePositions`]
36#[derive(Debug, Serialize, Default)]
37#[serde(rename_all = "camelCase")]
38pub struct BedFormatRangePositions {
39    /// Reference sequence name.
40    pub chrom: String,
41    /// 1-based position in the sequence.
42    pub chrom_start: u32,
43    /// The point at which this depth ends, non-inclusive
44    pub chrom_end: u32,
45    /// The name column of the bed file
46    pub name: String,
47    /// Total depth at this position.
48    pub score: u32,
49}
50
51impl From<RangePositions> for BedFormatRangePositions {
52    fn from(orig: RangePositions) -> Self {
53        BedFormatRangePositions {
54            chrom: orig.ref_seq,
55            chrom_start: orig.pos,
56            chrom_end: orig.end,
57            name: String::from(""),
58            score: orig.depth,
59        }
60    }
61}