Commit 035fbbc3 authored by NOEL Philippe's avatar NOEL Philippe

Remove the Protein structure

parent fda434c6
......@@ -9,13 +9,11 @@ extern crate lazy_static;
mod pdb;
pub use self::pdb::read_pdb::parse_pdb;
pub use self::pdb::read_pdb::read_pdb;
pub use self::pdb::tools::*;
pub use self::pdb::write_pdb::write_pdb;
pub use self::pdb::atom::*;
pub use self::pdb::chain::Chain;
pub use self::pdb::protein::Protein;
pub use self::pdb::residue::Residue;
pub use self::pdb::structure::Structure;
\ No newline at end of file
......@@ -3,7 +3,7 @@ extern crate pdbparser;
use pdbparser::*;
fn main() {
let my_prot = parse_pdb("tests/tests_file/f2.pdb", "5jpq");
let my_prot = read_pdb("tests/tests_file/f2.pdb", "5jpq");
match write_pdb(&my_prot, "toto.pdb") {
Ok(_) => (),
Err(e) => println!("Error : {}", e),
......@@ -11,7 +11,8 @@ fn main() {
use pdbparser;
let my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
let my_prot = pdbparser::read_pdb("tests/tests_file/f2.pdb", "f2");
/*
let mut backbone = my_prot.select_atoms("backbone").unwrap();
let lst_atom_id = backbone.get_atom_index();
assert_eq!(1, lst_atom_id[0]);
......@@ -26,4 +27,5 @@ fn main() {
// let chain_a = my_prot.select_atoms("chain a").unwrap();
// println!("Prot : {} \nn chain: {}\nn res: {}\nn atom: {}", chain_a.name, chain_a.get_number_chain(), chain_a.get_number_residue(), chain_a.get_number_atom());
*/
}
pub mod atom;
pub mod chain;
pub mod protein;
pub mod structure;
pub mod read_pdb;
pub mod residue;
......
This diff is collapsed.
......@@ -4,7 +4,6 @@ use std::io::BufReader;
use std::process;
use super::atom::AtomTypes;
use super::protein::Protein;
use super::structure::Structure;
......@@ -101,62 +100,4 @@ pub fn read_pdb(pdb: &str, name: &str) -> Structure {
}
}
structure
}
/// Parse the pdb file and return a protein structure
///
/// # Examples
/// ```
/// use pdbparser;
/// let my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
/// assert_eq!(66, my_prot.get_number_residue());
/// ```
pub fn parse_pdb(pdb: &str, name: &str) -> Protein {
// Check if the file exist and/or can be read
let pdb = match File::open(pdb) {
Ok(f) => f,
Err(e) => {
println!("Could not open the file \"{}\"\nError: {}", pdb, e);
process::exit(1);
}
};
let reader = BufReader::new(pdb);
let mut structure = Structure::new(String::from("toto"));
let mut protein = Protein::new(name.to_string());
for line in reader.lines() {
let l = line.unwrap();
if l.starts_with("HETAM") || l.starts_with("ATOM") {
// First get the resname.
// If the "residue" is a protein residue, continue to parse the line and add informations to the protein
// else continue to the next one line
let residue_name = &l[17..20].trim();
match AtomTypes::get(&residue_name.to_uppercase()[..]) {
Some(AtomTypes::AminoAcid) => {
let atom_name = &l[12..17].trim().to_string();
let chain = l[21..22].chars().next().unwrap();
let atom_number = parse_int(&l[6..11].to_string());
let residue_number = parse_int(&l[22..26].to_string());
let x = parse_float(&l[30..38].to_string());
let y = parse_float(&l[38..46].to_string());
let z = parse_float(&l[46..54].to_string());
// Add informations to the protein
protein.update_protein(
chain,
residue_name.to_string(),
residue_number as u64,
atom_name.clone(),
atom_number as u64,
[x, y, z],
);
}
Some(AtomTypes::Water) => (),
Some(AtomTypes::Lipid) => (),
Some(AtomTypes::NucleicAcid) => (),
_ => (), //TODO: Warning with unrecognize atom
}
}
}
protein
}
}
\ No newline at end of file
use std::collections::HashMap;
use super::protein::Protein;
use super::structure::Structure;
/// Convert the protein to a FASTA sequence (1 residue as 1 char)
/// Convert the all amino acid 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)
///
......@@ -10,10 +10,10 @@ use super::protein::Protein;
/// ```
/// use pdbparser;
///
/// let my_prot = pdbparser::parse_pdb("tests/tests_file/f2.pdb", "f2");
/// assert_eq!("TSPQPYSIERTIRWLTYQVANSLALVSEADKIMQTEYMKMIQNSGEITDRGEAILRLLKTNKHYEH", pdbparser::fasta_seq(my_prot));
/// let my_struct = pdbparser::read_pdb("tests/tests_file/f2.pdb", "f2");
/// assert_eq!("TSPQPYSIERTIRWLTYQVANSLALVSEADKIMQTEYMKMIQNSGEITDRGEAILRLLKTNKHYEH", pdbparser::fasta_seq(&my_struct));
/// ```
pub fn fasta_seq(my_prot: Protein) -> String {
pub fn fasta_seq(my_struct: &Structure) -> String {
let res: HashMap<&str, char> = [
("ARG", 'R'),
("LYS", 'K'),
......@@ -44,9 +44,10 @@ pub fn fasta_seq(my_prot: Protein) -> String {
.cloned()
.collect();
let mut fasta = String::with_capacity(my_prot.get_number_residue() as usize);
//TODO: Change the with_capacity(my_struct.get_residue_number()) because get all residue (dna, lipid, etc..)
let mut fasta = String::with_capacity(my_struct.get_residue_number() as usize);
for chain in &my_prot.lst_chain {
for chain in &my_struct.chains {
for residue in &chain.lst_res {
match res.get(&residue.name()[..]) {
Some(r) => fasta.push(*r),
......
use super::protein::Protein;
use super::structure::Structure;
use std::fs::File;
use std::io;
......@@ -7,10 +7,10 @@ use std::io::Write;
/// Write a PDB file for the `Protein`.
/// Be careful, the protein is write with the atom numbers in its structure. Remind to use the method
/// my_protein.refine_dialing() before !
pub fn write_pdb(my_prot: &Protein, file: &str) -> io::Result<()> {
pub fn write_pdb(my_prot: &Structure, file: &str) -> io::Result<()> {
let mut output_pdb = File::create(file)?;
for chain in &my_prot.lst_chain {
for chain in &my_prot.chains {
let chain_name = chain.get_name();
for residue in &chain.lst_res {
let res_name = residue.name();
......
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