use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SiteEntry {
pub(crate) index: Vec<u32>,
#[serde(rename = "type", default)]
pub(crate) kind: String,
}
impl SiteEntry {
pub fn index(&self) -> &[u32] {
&self.index
}
pub fn kind(&self) -> &str {
&self.kind
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegionEntry {
pub(crate) index: Vec<[u32; 2]>,
#[serde(rename = "type", default)]
pub(crate) kind: String,
}
impl RegionEntry {
pub fn index(&self) -> &[[u32; 2]] {
&self.index
}
pub fn kind(&self) -> &str {
&self.kind
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum A3Index {
Ranges(Vec<[u32; 2]>),
Positions(Vec<u32>),
}
impl A3Index {
pub fn as_positions(&self) -> Option<&[u32]> {
match self {
A3Index::Positions(p) => Some(p),
A3Index::Ranges(_) => None,
}
}
pub fn as_ranges(&self) -> Option<&[[u32; 2]]> {
match self {
A3Index::Ranges(r) => Some(r),
A3Index::Positions(_) => None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FlexEntry {
pub(crate) index: A3Index,
#[serde(rename = "type", default)]
pub(crate) kind: String,
}
impl FlexEntry {
pub fn index(&self) -> &A3Index {
&self.index
}
pub fn kind(&self) -> &str {
&self.kind
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VariantRecord {
pub(crate) position: u32,
#[serde(flatten)]
pub(crate) extra: HashMap<String, serde_json::Value>,
}
impl VariantRecord {
pub fn position(&self) -> u32 {
self.position
}
pub fn extra(&self) -> &HashMap<String, serde_json::Value> {
&self.extra
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct Annotations {
pub(crate) site: HashMap<String, SiteEntry>,
pub(crate) region: HashMap<String, RegionEntry>,
pub(crate) ptm: HashMap<String, FlexEntry>,
pub(crate) processing: HashMap<String, FlexEntry>,
pub(crate) variant: Vec<VariantRecord>,
}
impl Annotations {
pub fn site(&self) -> &HashMap<String, SiteEntry> {
&self.site
}
pub fn region(&self) -> &HashMap<String, RegionEntry> {
&self.region
}
pub fn ptm(&self) -> &HashMap<String, FlexEntry> {
&self.ptm
}
pub fn processing(&self) -> &HashMap<String, FlexEntry> {
&self.processing
}
pub fn variant(&self) -> &[VariantRecord] {
&self.variant
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct Metadata {
pub(crate) uniprot_id: String,
pub(crate) description: String,
pub(crate) reference: String,
pub(crate) organism: String,
}
impl Metadata {
pub fn uniprot_id(&self) -> &str {
&self.uniprot_id
}
pub fn description(&self) -> &str {
&self.description
}
pub fn reference(&self) -> &str {
&self.reference
}
pub fn organism(&self) -> &str {
&self.organism
}
}
pub const A3_SCHEMA_URI: &str = "https://schema.rtemis.org/a3/v1/schema.json";
pub const A3_VERSION: &str = "1.0.0";
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct A3 {
#[serde(rename = "$schema")]
pub(crate) schema: String,
pub(crate) a3_version: String,
pub(crate) sequence: String,
pub(crate) annotations: Annotations,
pub(crate) metadata: Metadata,
}
impl A3 {
pub fn schema(&self) -> &str {
&self.schema
}
pub fn a3_version(&self) -> &str {
&self.a3_version
}
pub fn sequence(&self) -> &str {
&self.sequence
}
pub fn annotations(&self) -> &Annotations {
&self.annotations
}
pub fn metadata(&self) -> &Metadata {
&self.metadata
}
}