Commit 45b7ec13 authored by NOEL Philippe's avatar NOEL Philippe

Add conversion to fasta sequence

parent 64412560
......@@ -2,6 +2,8 @@ use super::atom::Atom;
use super::chain::Chain;
use super::residue::Residue;
use std::collections::HashMap;
use super::selection_atom;
use std::char;
......@@ -327,8 +329,8 @@ impl<'a> Protein {
/// let lst_atom_id = backbone.get_atom_index();
/// assert_eq!(1, lst_atom_id[0]);
/// assert_eq!(2, lst_atom_id[1]);
pub fn refine_dialing(&mut self){
/// ```
pub fn refine_dialing(&mut self) {
let mut n_atom = 1;
for chain in &mut self.lst_chain {
for residue in &mut chain.lst_res {
......@@ -339,4 +341,41 @@ impl<'a> Protein {
}
}
}
/// Convert the protein to a FASTA sequence (1 residue as 1 char)
/// Consult the corresponding table to have the code 1 letter <-> 3 letters
/// [Wikipedia amino acid](https://en.wikipedia.org/wiki/Amino_acid)
///
/// # Examples
/// ```
/// use pdbparser;
///
/// let my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
/// assert_eq!("TSPQPYSIERTIRWLTYQVANSLALVSEADKIMQTEYMKMIQNSGEITDRGEAILRLLKTNKHYEH", my_prot.fasta_seq());
/// ```
pub fn fasta_seq(&self) -> String{
let res: HashMap<&str, char> = [
("ARG", 'R'), ("LYS", 'K'), ("ASN", 'N'), ("ASP", 'D'),
("GLU", 'E'), ("SER", 'S'), ("THR", 'T'), ("GLN", 'Q'),
("CYS", 'C'), ("HIS", 'H'), ("HSD", 'H'), ("HSP", 'H'),
("HSD", 'H'), ("SEC", 'U'), ("GLY", 'G'), ("PRO", 'P'),
("ALA", 'A'), ("VAL", 'V'), ("ILE", 'I'), ("LEU", 'L'),
("MET", 'M'), ("PHE", 'P'), ("TYR", 'Y'), ("TRP", 'W'),
].iter()
.cloned()
.collect();
let mut fasta = String::with_capacity(self.get_number_residue() as usize);
for chain in &self.lst_chain {
for residue in &chain.lst_res {
match res.get(&residue.name()[..]) {
Some(r) => fasta.push(*r),
None => (),
};
}
}
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