Commit 823247e7 authored by NOEL Philippe's avatar NOEL Philippe

update doc in select atom

parent 0d2afd1a
...@@ -3,7 +3,7 @@ extern crate pdbparser; ...@@ -3,7 +3,7 @@ extern crate pdbparser;
use pdbparser::*; use pdbparser::*;
fn main() { fn main() {
let toto = parse_pdb("src/tests_file/f2_adn.pdb"); let toto = parse_pdb("src/tests_file/f2.pdb");
println!("Nb res : {}", toto.get_number_residue()); println!("Nb res : {}", toto.get_number_residue());
println!("Nb chain : {}", toto.get_number_chain()); println!("Nb chain : {}", toto.get_number_chain());
println!("Nb atom : {}", toto.get_atom_index().len()); println!("Nb atom : {}", toto.get_atom_index().len());
...@@ -12,7 +12,7 @@ fn main() { ...@@ -12,7 +12,7 @@ fn main() {
println!("Nb res : {}", toto_A.get_number_residue()); println!("Nb res : {}", toto_A.get_number_residue());
println!("Nb chain : {}", toto_A.get_number_chain()); println!("Nb chain : {}", toto_A.get_number_chain());
println!("Nb atom : {}", toto_A.get_atom_index().len()); println!("Nb atom : {}", toto_A.get_atom_index().len());
let toto_A_b = toto.select_atoms("chain A and backbone").unwrap(); let toto_A_b = toto.select_atoms("resid 10 to 50 and backbone").unwrap();
println!("Nb res : {}", toto_A_b.get_number_residue()); println!("Nb res : {}", toto_A_b.get_number_residue());
println!("Nb chain : {}", toto_A_b.get_number_chain()); println!("Nb chain : {}", toto_A_b.get_number_chain());
println!("Nb atom : {}", toto_A_b.get_atom_index().len()); println!("Nb atom : {}", toto_A_b.get_atom_index().len());
......
...@@ -232,25 +232,43 @@ impl<'a> Protein { ...@@ -232,25 +232,43 @@ impl<'a> Protein {
/// ///
/// ## "Chain" /// ## "Chain"
/// The Chain keyword is used to select chain. It must be follow by one or two chain names separate by the "to" keyword. /// The Chain keyword is used to select chain. It must be follow by one or two chain names separate by the "to" keyword.
/// The chain name is case sensitive. /// The chain name is case sensitive.
/// examples: /// examples:
/// "Chain A" will select only the Chain A. /// "Chain A" will select only the Chain A.
/// "Chain A to D" will select chains A, B, C and D. /// "Chain A to D" will select chains A, B, C and D.
/// ///
/// ## "Resid" /// ## "Resid"
/// The Resid keyword is used to select residues. It must be follow by one or two chain names separate by the "to" keyword. /// The Resid keyword is used to select residues. It must be follow by one or two chain names separate by the "to" keyword.
/// In case where the protein has multiple chains, the Resid will return residue(s) for all chains. /// In case where the protein has multiple chains, the Resid will return residue(s) for all chains.
/// examples: /// examples:
/// "Resid 1" will select only the residue 1 of each chain /// "Resid 1" will select only the residue 1 of each chain
/// "Resid 12 to 50" will select residues 12, 13, .., 50 for all chains /// "Resid 12 to 50" will select residues 12, 13, .., 50 for all chains
/// ///
/// ## "Backbone" /// ## "Backbone"
/// The Backbone keyword is used to select atoms in the backbone for each residues. It don't take parameters. /// The Backbone keyword is used to select atoms in the backbone for each residues. It don't take parameters.
/// ///
/// TODO: The methode is idiot and need to be improve. /// ## Special keyword "and"
/// ex: don't parse the chain if it's not selected /// You can use the keyword "and" to separate 2 or more differents selection.
/// examples:
/// "Chain A and Resid 40 to 150"
/// ///
/// # Examples
///
/// ```
/// use pdbparser;
///
/// let my_prot = pdbparser::parse_pdb("src/tests_file/f2.pdb");
///
/// assert_eq!(66, my_prot.get_number_residue());
/// assert_eq!(1085, my_prot.get_number_atom());
///
/// let prot_backbone = my_prot.select_atoms("resid 10 to 50 and backbone").unwrap();
///
/// assert_eq!(41, prot_backbone.get_number_residue());
/// assert_eq!(164, prot_backbone.get_number_atom());
/// ```
// TODO: The methode is idiot and need to be improve.
// ex: don't parse the chain if it's not selected
pub fn select_atoms(&self, pattern: &str) -> Option<Protein> { pub fn select_atoms(&self, pattern: &str) -> Option<Protein> {
let mut n_prot = Protein::new(String::from(self.name.clone())); let mut n_prot = Protein::new(String::from(self.name.clone()));
......
/// Structure enum for the different pattern keywords.
/// Chain(begin, end) for the selection of proteic chain with names
/// Resid(begin, end)
/// Backbone
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum Select { pub enum Select {
Chain(char, char), Chain(char, char),
...@@ -8,8 +13,6 @@ pub enum Select { ...@@ -8,8 +13,6 @@ pub enum Select {
/// Parse option given for the selection of residues and return /// Parse option given for the selection of residues and return
/// the index of begin and end of select residues. /// the index of begin and end of select residues.
/// ///
///
///
fn parse_options_int(opt: &[&str]) -> Option<[usize; 2]> { fn parse_options_int(opt: &[&str]) -> Option<[usize; 2]> {
// if the len is 1 mean that the request is like "Resid 1". // if the len is 1 mean that the request is like "Resid 1".
// return Some(1, 1) // return Some(1, 1)
...@@ -66,8 +69,6 @@ pub fn parse_select(pattern: &str) -> Option<Vec<Select>> { ...@@ -66,8 +69,6 @@ pub fn parse_select(pattern: &str) -> Option<Vec<Select>> {
// //
// Return None if there is a probleme in the pattern parsing // Return None if there is a probleme in the pattern parsing
if pattern == "" { if pattern == "" {
return None; //selection empty return None; //selection empty
} }
......
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