@@ -11,55 +11,34 @@ Python package which implements split- and rank-based tools for inferring phylog
1111The latest version of SplitP can be installed via the command
1212` pip install splitp `
1313
14- ### Examples
14+ ### Example
15+
16+ The following computes 100 split scores from a 10000bp sequence generated from a balanced 10-taxon tree under the Jukes Cantor model.
1517
16- Import ` splitp ` and the associated helper functions
17- ``` python
18- import splitp as sp
19- from splitp import tree_helper_functions as hf
20- ```
21- Define trees and work with splits
22- ``` python
23- splits = list (hf.all_splits(4 )) # [01|23, 02|13, 03|12]
24- tree = sp.NXTree(' ((0,1),(2,3));' )
25- true_splits = tree.true_splits() # 01|23
26- ```
27- Let site patterns evolve under any submodel of the general markov model.
28- ``` python
29- JC_subs_matrix = tree.build_JC_matrix(branch_length:= 0.05 ) # Or any other numpy Markov matrix
30- tree.reassign_all_transition_matrices(JC_subs_matrix )
31- pattern_probs = tree.get_pattern_probabilities()
32- ```
33- ``` css
34- > 0 1
35- 0 AAAA 0.185844
36- 1 AAAC 0.003262
37- .. ... ...
38- 254 TTTG 0.003262
39- 255 TTTT 0.185844
40- ```
41- Simulate sequence alignments from pattern distributions
42- ```python
43- pattern_frequencies = tree.draw_from_multinomial(pattern_probs, 100)
44- ```
45- ``` css
46- > 0 1
47- 0 AAAA 0.22
48- 1 AAAC 0.01
49- .. ... ...
50- 2 CCGC 0.03
51- 3 TTTT 0.14
52- ```
53- Reconstruct trees using split based methods including flattenings:
54- ```python
55- F1 = tree.flattening('01|23', pattern_frequencies)
56- F2 = tree.flattening('02|13', pattern_frequencies)
57- print(tree.split_score(F1) < tree.split_score(F2)) # True
58- ```
59- Or subflattenings:
6018``` python
61- SF = tree.signed_sum_subflattening('01|23', pattern_probs)
62- print(tree.split_score(SF)) # 0.0
19+ # Imports
20+ import splitp
21+
22+ # Set parameters
23+ sequence_length = 10_000
24+ num_taxa = 10
25+ branch_length = 0.05
26+ number_of_splits = 100
27+
28+ # Define model
29+ model = splitp.model.GTR .JukesCantor(1 / 2 )
30+
31+ # Generate tree, splits and alignment
32+ tree = splitp.trees.balanced_newick_tree(num_taxa, branch_length)
33+ splits = splitp.all_splits(tree)
34+ alignment = splitp.generate_alignment(tree, model, sequence_length)
35+
36+ # Compute scores
37+ for s in range (number_of_splits):
38+ split = next (splits)
39+ flattening = splitp.flattening(split, alignment, splitp.FlatFormat.reduced)
40+ score = splitp.split_score(flattening)
41+ print (split, score)
6342```
6443For more functionality please see the documentation at [ splitp.joshuastevenson.me] ( http://splitp.joshuastevenson.me/splitp.html ) .
6544
0 commit comments