Commit a9d6a938 authored by NOEL Philippe's avatar NOEL Philippe

Move AtomType to ChainType

parent b7d8aded
use super::residue::Residue;
use std::collections::HashMap;
/// A [`Chain`] is a sub-structure linked to a [`Protein`].
/// It contain one or more [`Residue`] and a name
......@@ -96,3 +97,107 @@ impl Chain {
self.name
}
}
/// Enumerate to check the types of the parsed atom.
///
/// [`Atom`] will be class into the following map:
/// "ARG" => ChainTypes::Protein
/// "LYS" => ChainTypes::Protein
/// "ASN" => ChainTypes::Protein
/// "ASP" => ChainTypes::Protein
/// "GLU" => ChainTypes::Protein
/// "SER" => ChainTypes::Protein
/// "THR" => ChainTypes::Protein
/// "GLN" => ChainTypes::Protein
/// "CYS" => ChainTypes::Protein
/// "HIS" => ChainTypes::Protein
/// "HSD" => ChainTypes::Protein
/// "HSP" => ChainTypes::Protein
/// "HSD" => ChainTypes::Protein
/// "SEC" => ChainTypes::Protein
/// "GLY" => ChainTypes::Protein
/// "PRO" => ChainTypes::Protein
/// "ALA" => ChainTypes::Protein
/// "VAL" => ChainTypes::Protein
/// "ILE" => ChainTypes::Protein
/// "LEU" => ChainTypes::Protein
/// "MET" => ChainTypes::Protein
/// "PHE" => ChainTypes::Protein
/// "TYR" => ChainTypes::Protein
/// "TRP" => ChainTypes::Protein
/// "ADE" => ChainTypes::NucleicAcid
/// "GUA" => ChainTypes::NucleicAcid
/// "THY" => ChainTypes::NucleicAcid
/// "CYT" => ChainTypes::NucleicAcid
/// "TIP3W" => ChainTypes::Wat
/// "POPC" => ChainTypes::Lipid
/// "POPE" => ChainTypes::Lipid
/// "HOH" => ChainTypes::Water
///
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum ChainTypes {
Protein,
NucleicAcid,
Lipid,
Water,
Unknown,
}
impl ChainTypes {
/// Return a [`ChainTypes`] according to the "residue" of the atom
///
/// ````
/// use pdbparser::ChainTypes;
///
/// assert_eq!(ChainTypes::Protein, *ChainTypes::get("trp").unwrap());
/// assert_eq!(ChainTypes::Lipid, *ChainTypes::get("POPC").unwrap());
/// assert_eq!(None, ChainTypes::get("toto"));
///
/// ````
pub fn get(atom: &str) -> ChainTypes {
match ATOM_TYPES.get(&atom.to_uppercase()[..]) {
Some(x) => *x,
None => ChainTypes::Unknown,
}
}
}
lazy_static! {
static ref ATOM_TYPES: HashMap<&'static str, ChainTypes> = [
("ARG", ChainTypes::Protein),
("LYS", ChainTypes::Protein),
("ASN", ChainTypes::Protein),
("ASP", ChainTypes::Protein),
("GLU", ChainTypes::Protein),
("SER", ChainTypes::Protein),
("THR", ChainTypes::Protein),
("GLN", ChainTypes::Protein),
("CYS", ChainTypes::Protein),
("HIS", ChainTypes::Protein),
("HSD", ChainTypes::Protein),
("HSP", ChainTypes::Protein),
("HSD", ChainTypes::Protein),
("SEC", ChainTypes::Protein),
("GLY", ChainTypes::Protein),
("PRO", ChainTypes::Protein),
("ALA", ChainTypes::Protein),
("VAL", ChainTypes::Protein),
("ILE", ChainTypes::Protein),
("LEU", ChainTypes::Protein),
("MET", ChainTypes::Protein),
("PHE", ChainTypes::Protein),
("TYR", ChainTypes::Protein),
("TRP", ChainTypes::Protein),
("ADE", ChainTypes::NucleicAcid),
("GUA", ChainTypes::NucleicAcid),
("THY", ChainTypes::NucleicAcid),
("CYT", ChainTypes::NucleicAcid),
("TIP3W", ChainTypes::Water),
("POPC", ChainTypes::Lipid),
("POPE", ChainTypes::Lipid),
("HOH", ChainTypes::Water),
]
.iter()
.cloned()
.collect();
}
pub mod atom;
pub mod chain;
pub mod structure;
pub mod read_pdb;
pub mod residue;
pub mod structure;
pub mod tools;
pub mod write_pdb;
......
......@@ -3,7 +3,7 @@ use std::io::prelude::*;
use std::io::BufReader;
use std::process;
use super::atom::AtomTypes;
use super::chain::ChainTypes;
use super::structure::Structure;
......@@ -44,7 +44,6 @@ fn parse_int(s: &str) -> i64 {
}
}
/// Parse the pdb file and return a [`Structure`]
///
/// # Examples
......
use super::atom::Atom;
use super::chain::Chain;
use super::residue::Residue;
use super::atom::Atom;
use super::selection_atom;
/// A [`Structure`] is the SUPER structure which contain molecules like Protein, DNA, etc.
///
pub struct Structure {
......@@ -109,7 +108,7 @@ impl Structure {
/// Return the number of [`Residue`] in the [`Structure`]
///
/// According to PDB format, residue can be molecules of amino acid, nucleic acid, lipid or ligand
///
///
/// # Examples
///
/// ````
......@@ -210,7 +209,6 @@ impl Structure {
None
}
/// Function that add information on the [`Structure`] (used in the parsing)
/// /!\Change this to a macro!
///
......
......@@ -49,10 +49,9 @@ pub fn fasta_seq(my_struct: &Structure) -> String {
for chain in &my_struct.chains {
for residue in &chain.lst_res {
match res.get(&residue.name()[..]) {
Some(r) => fasta.push(*r),
None => (),
};
if let Some(r) = res.get(&residue.name()[..]) {
fasta.push(*r);
}
}
}
fasta
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment