1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#![doc = include_str!("../README.md")]
#![allow(unused)]

extern crate memchr;

use std::io::BufRead;

use lightmotif::abc::Alphabet;
use lightmotif::abc::Symbol;
use lightmotif::dense::DenseMatrix;
use lightmotif::pwm::CountMatrix;

pub mod error;
#[doc(hidden)]
pub mod parse;
pub mod reader;

#[derive(Clone)]
pub struct Matrix<A: Alphabet> {
    id: Option<String>,
    accession: Option<String>,
    name: Option<String>,
    description: Option<String>,
    counts: CountMatrix<A>,
    dates: Vec<Date>,
    references: Vec<Reference>,
    sites: Vec<String>,
}

impl<A: Alphabet> Matrix<A> {
    pub fn id(&self) -> Option<&str> {
        self.id.as_deref()
    }

    pub fn accession(&self) -> Option<&str> {
        self.accession.as_deref()
    }

    pub fn name(&self) -> Option<&str> {
        self.name.as_deref()
    }

    pub fn description(&self) -> Option<&str> {
        self.description.as_deref()
    }
}

impl<A: Alphabet> AsRef<CountMatrix<A>> for Matrix<A> {
    fn as_ref(&self) -> &CountMatrix<A> {
        &self.counts
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DateKind {
    Created,
    Updated,
}

#[derive(Debug, Clone)]
pub struct Date {
    kind: DateKind,
    author: String,
    day: u8,
    month: u8,
    year: u16,
}

#[derive(Clone, Debug)]
pub struct ReferenceNumber {
    local: u32,
    xref: Option<String>,
}

impl ReferenceNumber {
    pub fn new(local: u32) -> Self {
        Self { local, xref: None }
    }

    pub fn with_xref<X>(local: u32, xref: X) -> Self
    where
        X: Into<Option<String>>,
    {
        Self {
            local,
            xref: xref.into(),
        }
    }
}

#[derive(Clone, Debug)]
pub struct Reference {
    number: ReferenceNumber,
    // authors: String,
    title: Option<String>,
    link: Option<String>,
    pmid: Option<String>,
}

pub fn read<B: BufRead, A: Alphabet>(reader: B) -> self::reader::Reader<B, A> {
    self::reader::Reader::new(reader)
}