• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rust-bio / rust-bio-types / 5550351717

pending completion
5550351717

Pull #63

github

web-flow
Merge be9eac796 into 907b3d9da
Pull Request #63: fix: pretty print with suffix xclip or yclip

2 of 2 new or added lines in 1 file covered. (100.0%)

474 of 746 relevant lines covered (63.54%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/genome.rs
1
use std::cmp;
2
use std::ops::Range;
3

4
#[cfg(feature = "serde")]
5
use serde::{Deserialize, Serialize};
6

7
pub type Position = u64;
8
pub type Length = u64;
9

10
pub trait AbstractInterval {
11
    /// Identifier for a genomic contig, e.g., a chromosome
12
    fn contig(&self) -> &str;
13
    /// Interval on the contig
14
    fn range(&self) -> Range<Position>;
15
    /// Return true if interval contains given locus.
16
    fn contains<L>(&self, locus: L) -> bool
17
    where
18
        L: AbstractLocus,
19
    {
20
        self.contig() == locus.contig()
×
21
            && locus.pos() >= self.range().start
×
22
            && locus.pos() < self.range().end
×
23
    }
24
}
25
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
26
#[derive(new, Debug, PartialEq, Eq, Clone, Hash)]
27
pub struct Interval {
28
    contig: String,
29
    range: Range<Position>,
30
}
31

32
impl PartialOrd for Interval {
33
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
×
34
        Some(self.contig.cmp(&other.contig).then_with(|| {
×
35
            self.range
×
36
                .start
37
                .cmp(&other.range.start)
×
38
                .then_with(|| self.range.end.cmp(&other.range.end))
×
39
        }))
40
    }
41
}
42

43
impl Ord for Interval {
44
    fn cmp(&self, other: &Self) -> cmp::Ordering {
×
45
        self.partial_cmp(other).unwrap()
×
46
    }
47
}
48

49
impl Interval {
50
    /// Mutable reference to interval on the contig
51
    pub fn range_mut(&mut self) -> &mut Range<Position> {
×
52
        &mut self.range
×
53
    }
54
}
55

56
impl AbstractInterval for Interval {
57
    fn contig(&self) -> &str {
×
58
        &self.contig
×
59
    }
60

61
    fn range(&self) -> Range<Position> {
×
62
        self.range.clone()
×
63
    }
64
}
65

66
pub trait AbstractLocus {
67
    /// Identifier for a genomic contig, e.g., a chromosome
68
    fn contig(&self) -> &str;
69
    /// Position on the contig
70
    fn pos(&self) -> Position;
71
}
72

73
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
74
#[derive(new, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
75
pub struct Locus {
76
    contig: String,
77
    pos: Position,
78
}
79

80
impl Locus {
81
    /// Mutable reference to position.
82
    pub fn pos_mut(&mut self) -> &mut Position {
×
83
        &mut self.pos
×
84
    }
85
}
86

87
impl AbstractLocus for Locus {
88
    fn contig(&self) -> &str {
×
89
        &self.contig
×
90
    }
91

92
    fn pos(&self) -> Position {
×
93
        self.pos
×
94
    }
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc