use std::borrow::Cow;
use mzcore::{
prelude::SequencePosition,
sequence::{Linear, Peptidoform, SimpleModification},
};
use mzcv::Curie;
use crate::{CVTerm, EMPTY_FASTA_IDENTIFIER, FastaIdentifier, Reliability};
pub trait ProteinMetaData {
fn sequence(&self) -> Option<Cow<'_, Peptidoform<Linear>>>;
fn numerical_id(&self) -> Option<usize>;
fn id(&self) -> FastaIdentifier<Cow<'_, str>>;
fn description(&self) -> Option<&str>;
fn species(&self) -> Option<Curie>;
fn species_name(&self) -> Option<&str>;
fn search_engine(&self) -> &[(CVTerm, Option<(f64, CVTerm)>)];
fn ambiguity_members(&self) -> &[String];
fn database(&self) -> Option<(Cow<'_, str>, Option<Cow<'_, str>>)>;
fn modifications(&self) -> &[(Vec<(SequencePosition, Option<f64>)>, SimpleModification)];
fn coverage(&self) -> Option<f64>;
fn gene_ontology(&self) -> &[Curie];
fn reliability(&self) -> Option<Reliability>;
fn uri(&self) -> Option<&str>;
}
macro_rules! impl_ref {
($t:ty) => {
impl<T: ProteinMetaData> ProteinMetaData for $t {
fn sequence(&self) -> Option<Cow<'_, Peptidoform<Linear>>> {
(**self).sequence()
}
fn numerical_id(&self) -> Option<usize> {
(**self).numerical_id()
}
fn id(&self) -> FastaIdentifier<Cow<'_, str>> {
(**self).id()
}
fn description(&self) -> Option<&str> {
(**self).description()
}
fn species(&self) -> Option<Curie> {
(**self).species()
}
fn species_name(&self) -> Option<&str> {
(**self).species_name()
}
fn search_engine(&self) -> &[(CVTerm, Option<(f64, CVTerm)>)] {
(**self).search_engine()
}
fn ambiguity_members(&self) -> &[String] {
(**self).ambiguity_members()
}
fn database(&self) -> Option<(Cow<'_, str>, Option<Cow<'_, str>>)> {
(**self).database()
}
fn modifications(
&self,
) -> &[(Vec<(SequencePosition, Option<f64>)>, SimpleModification)] {
(**self).modifications()
}
fn coverage(&self) -> Option<f64> {
(**self).coverage()
}
fn gene_ontology(&self) -> &[Curie] {
(**self).gene_ontology()
}
fn reliability(&self) -> Option<Reliability> {
(**self).reliability()
}
fn uri(&self) -> Option<&str> {
(**self).uri()
}
}
};
}
impl_ref!(&T);
impl_ref!(std::rc::Rc<T>);
impl_ref!(std::sync::Arc<T>);
impl ProteinMetaData for Box<dyn ProteinMetaData + '_> {
fn sequence(&self) -> Option<Cow<'_, Peptidoform<Linear>>> {
(**self).sequence()
}
fn numerical_id(&self) -> Option<usize> {
(**self).numerical_id()
}
fn id(&self) -> FastaIdentifier<Cow<'_, str>> {
(**self).id()
}
fn description(&self) -> Option<&str> {
(**self).description()
}
fn species(&self) -> Option<Curie> {
(**self).species()
}
fn species_name(&self) -> Option<&str> {
(**self).species_name()
}
fn search_engine(&self) -> &[(CVTerm, Option<(f64, CVTerm)>)] {
(**self).search_engine()
}
fn ambiguity_members(&self) -> &[String] {
(**self).ambiguity_members()
}
fn database(&self) -> Option<(Cow<'_, str>, Option<Cow<'_, str>>)> {
(**self).database()
}
fn modifications(&self) -> &[(Vec<(SequencePosition, Option<f64>)>, SimpleModification)] {
(**self).modifications()
}
fn coverage(&self) -> Option<f64> {
(**self).coverage()
}
fn gene_ontology(&self) -> &[Curie] {
(**self).gene_ontology()
}
fn reliability(&self) -> Option<Reliability> {
(**self).reliability()
}
fn uri(&self) -> Option<&str> {
(**self).uri()
}
}
#[derive(
Clone, Copy, Debug, Default, serde::Deserialize, serde::Serialize, PartialEq, Eq, Hash,
)]
pub struct NoProtein {}
impl mzcore::space::Space for NoProtein {
fn space(&self) -> mzcore::space::UsedSpace {
mzcore::space::UsedSpace::default()
}
}
impl ProteinMetaData for NoProtein {
fn sequence(&self) -> Option<Cow<'_, Peptidoform<Linear>>> {
None
}
fn numerical_id(&self) -> Option<usize> {
None
}
fn id(&self) -> FastaIdentifier<Cow<'_, str>> {
EMPTY_FASTA_IDENTIFIER
}
fn description(&self) -> Option<&str> {
None
}
fn species(&self) -> Option<Curie> {
None
}
fn species_name(&self) -> Option<&str> {
None
}
fn search_engine(&self) -> &[(CVTerm, Option<(f64, CVTerm)>)] {
&[]
}
fn ambiguity_members(&self) -> &[String] {
&[]
}
fn database(&self) -> Option<(Cow<'_, str>, Option<Cow<'_, str>>)> {
None
}
fn modifications(&self) -> &[(Vec<(SequencePosition, Option<f64>)>, SimpleModification)] {
&[]
}
fn coverage(&self) -> Option<f64> {
None
}
fn gene_ontology(&self) -> &[Curie] {
&[]
}
fn reliability(&self) -> Option<Reliability> {
None
}
fn uri(&self) -> Option<&str> {
None
}
}
impl ProteinMetaData for FastaIdentifier<String> {
fn sequence(&self) -> Option<Cow<'_, Peptidoform<Linear>>> {
None
}
fn numerical_id(&self) -> Option<usize> {
None
}
fn id(&self) -> FastaIdentifier<Cow<'_, str>> {
self.as_cow_str()
}
fn description(&self) -> Option<&str> {
None
}
fn species(&self) -> Option<Curie> {
None
}
fn species_name(&self) -> Option<&str> {
None
}
fn search_engine(&self) -> &[(CVTerm, Option<(f64, CVTerm)>)] {
&[]
}
fn ambiguity_members(&self) -> &[String] {
&[]
}
fn database(&self) -> Option<(Cow<'_, str>, Option<Cow<'_, str>>)> {
None
}
fn modifications(&self) -> &[(Vec<(SequencePosition, Option<f64>)>, SimpleModification)] {
&[]
}
fn coverage(&self) -> Option<f64> {
None
}
fn gene_ontology(&self) -> &[Curie] {
&[]
}
fn reliability(&self) -> Option<Reliability> {
None
}
fn uri(&self) -> Option<&str> {
None
}
}
impl ProteinMetaData for FastaIdentifier<Box<str>> {
fn sequence(&self) -> Option<Cow<'_, Peptidoform<Linear>>> {
None
}
fn numerical_id(&self) -> Option<usize> {
None
}
fn id(&self) -> FastaIdentifier<Cow<'_, str>> {
self.as_cow_str()
}
fn description(&self) -> Option<&str> {
None
}
fn species(&self) -> Option<Curie> {
None
}
fn species_name(&self) -> Option<&str> {
None
}
fn search_engine(&self) -> &[(CVTerm, Option<(f64, CVTerm)>)] {
&[]
}
fn ambiguity_members(&self) -> &[String] {
&[]
}
fn database(&self) -> Option<(Cow<'_, str>, Option<Cow<'_, str>>)> {
None
}
fn modifications(&self) -> &[(Vec<(SequencePosition, Option<f64>)>, SimpleModification)] {
&[]
}
fn coverage(&self) -> Option<f64> {
None
}
fn gene_ontology(&self) -> &[Curie] {
&[]
}
fn reliability(&self) -> Option<Reliability> {
None
}
fn uri(&self) -> Option<&str> {
None
}
}
impl ProteinMetaData for FastaIdentifier<&str> {
fn sequence(&self) -> Option<Cow<'_, Peptidoform<Linear>>> {
None
}
fn numerical_id(&self) -> Option<usize> {
None
}
fn id(&self) -> FastaIdentifier<Cow<'_, str>> {
self.as_cow_str()
}
fn description(&self) -> Option<&str> {
None
}
fn species(&self) -> Option<Curie> {
None
}
fn species_name(&self) -> Option<&str> {
None
}
fn search_engine(&self) -> &[(CVTerm, Option<(f64, CVTerm)>)] {
&[]
}
fn ambiguity_members(&self) -> &[String] {
&[]
}
fn database(&self) -> Option<(Cow<'_, str>, Option<Cow<'_, str>>)> {
None
}
fn modifications(&self) -> &[(Vec<(SequencePosition, Option<f64>)>, SimpleModification)] {
&[]
}
fn coverage(&self) -> Option<f64> {
None
}
fn gene_ontology(&self) -> &[Curie] {
&[]
}
fn reliability(&self) -> Option<Reliability> {
None
}
fn uri(&self) -> Option<&str> {
None
}
}