use chrono::NaiveDateTime;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use crate::{data::error::Error, sequences::TranslationTable};
#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize)]
pub struct GeneInfoRecord {
pub hgnc: String,
pub maploc: String,
pub descr: String,
pub summary: String,
pub aliases: Vec<String>,
pub added: NaiveDateTime,
}
#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize)]
pub struct TxSimilarityRecord {
pub tx_ac1: String,
pub tx_ac2: String,
pub hgnc_eq: bool,
pub cds_eq: bool,
pub es_fp_eq: bool,
pub cds_es_fp_eq: bool,
pub cds_exon_lengths_fp_eq: bool,
}
#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize)]
pub struct TxExonsRecord {
pub hgnc: String,
pub tx_ac: String,
pub alt_ac: String,
pub alt_aln_method: String,
pub alt_strand: i16,
pub ord: i32,
pub tx_start_i: i32,
pub tx_end_i: i32,
pub alt_start_i: i32,
pub alt_end_i: i32,
pub cigar: String,
pub tx_aseq: Option<String>,
pub alt_aseq: Option<String>,
pub tx_exon_set_id: i32,
pub alt_exon_set_id: i32,
pub tx_exon_id: i32,
pub alt_exon_id: i32,
pub exon_aln_id: i32,
}
#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize)]
pub struct TxForRegionRecord {
pub tx_ac: String,
pub alt_ac: String,
pub alt_strand: i16,
pub alt_aln_method: String,
pub start_i: i32,
pub end_i: i32,
}
#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize)]
pub struct TxIdentityInfo {
pub tx_ac: String,
pub alt_ac: String,
pub alt_aln_method: String,
pub cds_start_i: Option<i32>,
pub cds_end_i: Option<i32>,
pub lengths: Vec<i32>,
pub hgnc: String,
pub translation_table: TranslationTable,
}
impl TxIdentityInfo {
pub fn has_cds_defined(&self) -> bool {
self.cds_start_i.is_some() && self.cds_end_i.is_some()
}
}
#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize)]
pub struct TxInfoRecord {
pub hgnc: String,
pub cds_start_i: Option<i32>,
pub cds_end_i: Option<i32>,
pub tx_ac: String,
pub alt_ac: String,
pub alt_aln_method: String,
}
#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize)]
pub struct TxMappingOptionsRecord {
pub tx_ac: String,
pub alt_ac: String,
pub alt_aln_method: String,
}
pub trait Provider {
fn data_version(&self) -> &str;
fn schema_version(&self) -> &str;
fn get_assembly_map(&self, assembly: &str) -> Result<IndexMap<String, String>, Error>;
fn get_gene_info(&self, hgnc: &str) -> Result<GeneInfoRecord, Error>;
fn get_pro_ac_for_tx_ac(&self, tx_ac: &str) -> Result<Option<String>, Error>;
fn get_seq(&self, ac: &str) -> Result<String, Error> {
self.get_seq_part(ac, None, None)
}
fn get_seq_part(
&self,
ac: &str,
begin: Option<usize>,
end: Option<usize>,
) -> Result<String, Error>;
fn get_acs_for_protein_seq(&self, seq: &str) -> Result<Vec<String>, Error>;
fn get_similar_transcripts(&self, tx_ac: &str) -> Result<Vec<TxSimilarityRecord>, Error>;
fn get_tx_exons(
&self,
tx_ac: &str,
alt_ac: &str,
alt_aln_method: &str,
) -> Result<Vec<TxExonsRecord>, Error>;
fn get_tx_exon_coords(
&self,
tx_ac: &str,
alt_ac: &str,
alt_aln_method: &str,
) -> Result<Vec<(i32, i32)>, Error> {
let exons = self.get_tx_exons(tx_ac, alt_ac, alt_aln_method)?;
Ok(exons
.into_iter()
.map(|e| (e.tx_start_i, e.tx_end_i))
.collect())
}
fn get_cds_start_end(
&self,
tx_ac: &str,
alt_ac: &str,
alt_aln_method: &str,
) -> Result<(Option<i32>, Option<i32>), Error> {
let info = self.get_tx_info(tx_ac, alt_ac, alt_aln_method)?;
Ok((info.cds_start_i, info.cds_end_i))
}
fn get_tx_for_gene(&self, gene: &str) -> Result<Vec<TxInfoRecord>, Error>;
fn get_tx_for_region(
&self,
alt_ac: &str,
alt_aln_method: &str,
start_i: i32,
end_i: i32,
) -> Result<Vec<TxForRegionRecord>, Error>;
fn get_tx_identity_info(&self, tx_ac: &str) -> Result<TxIdentityInfo, Error>;
fn get_tx_info(
&self,
tx_ac: &str,
alt_ac: &str,
alt_aln_method: &str,
) -> Result<TxInfoRecord, Error>;
fn get_tx_mapping_options(&self, tx_ac: &str) -> Result<Vec<TxMappingOptionsRecord>, Error>;
}