forked from sbhattlab/phylo2vec
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add newick string operation functions
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ license = "LGPL-3.0" | |
|
||
[dependencies] | ||
rand = "*" | ||
regex = "1.11.1" | ||
|
||
[dev-dependencies] | ||
rstest = "0.23.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#[derive(Debug)] | ||
pub struct NewickPatterns { | ||
pub left_node: regex::Regex, | ||
pub right_node: regex::Regex, | ||
pub pairs: regex::Regex, | ||
pub branch_lengths: regex::Regex, | ||
pub parents: regex::Regex, | ||
} | ||
|
||
impl NewickPatterns { | ||
pub fn new() -> Self { | ||
let _left_node = r"\(\b(\d+)\b"; | ||
let _right_node = r",\b(\d+)\b"; | ||
let _branch_lengths = r":\d+(\.\d+)?"; | ||
let _parents = r"\)(\d+)"; | ||
let _pairs = format!(r"({})|({})", _left_node, _right_node); | ||
NewickPatterns { | ||
// Pattern of an integer label on the left of a pair | ||
left_node: regex::Regex::new(&_left_node).unwrap(), | ||
// Pattern of an integer label on the right of a pair | ||
right_node: regex::Regex::new(&_right_node).unwrap(), | ||
// Pattern of a pair of integer labels | ||
pairs: regex::Regex::new(&_pairs).unwrap(), | ||
// Pattern of a branch length annotation | ||
branch_lengths: regex::Regex::new(&_branch_lengths).unwrap(), | ||
// Pattern of a parent label | ||
parents: regex::Regex::new(&_parents).unwrap(), | ||
} | ||
} | ||
} |