Skip to content

Commit

Permalink
test fasttree
Browse files Browse the repository at this point in the history
  • Loading branch information
db036 committed Nov 27, 2023
1 parent 7ce2875 commit a97f855
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 1 deletion.
26 changes: 26 additions & 0 deletions tests/testFiles/fasttree/tree_1000_1199.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.phyloxml.org" xsi:schemaLocation="http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd">
<phylogeny rooted="false">
<clade>
<clade>
<name>ON134852</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OM739053</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>ON129429</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OU471040</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OL989074</name>
<branch_length>0.0</branch_length>
</clade>
</clade>
</phylogeny>
</phyloxml>
26 changes: 26 additions & 0 deletions tests/testFiles/fasttree/tree_200_399.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.phyloxml.org" xsi:schemaLocation="http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd">
<phylogeny rooted="false">
<clade>
<clade>
<name>ON134852</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OM739053</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>ON129429</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OU471040</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OL989074</name>
<branch_length>0.0</branch_length>
</clade>
</clade>
</phylogeny>
</phyloxml>
29 changes: 29 additions & 0 deletions tests/testFiles/fasttree/tree_400_599.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.phyloxml.org" xsi:schemaLocation="http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd">
<phylogeny rooted="false">
<clade>
<clade>
<branch_length>0.00252</branch_length>
<clade>
<name>ON134852</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OM739053</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OU471040</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OL989074</name>
<branch_length>0.0</branch_length>
</clade>
</clade>
<clade>
<name>ON129429</name>
<branch_length>0.00252</branch_length>
</clade>
</clade>
</phylogeny>
</phyloxml>
29 changes: 29 additions & 0 deletions tests/testFiles/fasttree/tree_600_799.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.phyloxml.org" xsi:schemaLocation="http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd">
<phylogeny rooted="false">
<clade>
<clade>
<branch_length>0.00027</branch_length>
<clade>
<name>ON134852</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OM739053</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>ON129429</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OU471040</name>
<branch_length>0.0</branch_length>
</clade>
</clade>
<clade>
<name>OL989074</name>
<branch_length>0.00027</branch_length>
</clade>
</clade>
</phylogeny>
</phyloxml>
29 changes: 29 additions & 0 deletions tests/testFiles/fasttree/tree_800_999.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.phyloxml.org" xsi:schemaLocation="http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd">
<phylogeny rooted="false">
<clade>
<clade>
<branch_length>0.00504</branch_length>
<clade>
<name>ON134852</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OM739053</name>
<branch_length>0.0</branch_length>
</clade>
<clade>
<name>OL989074</name>
<branch_length>0.0</branch_length>
</clade>
</clade>
<clade>
<name>ON129429</name>
<branch_length>0.00504</branch_length>
</clade>
<clade>
<name>OU471040</name>
<branch_length>0.00055</branch_length>
</clade>
</clade>
</phylogeny>
</phyloxml>
45 changes: 44 additions & 1 deletion tests/test_genetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from Bio.Phylo.PhyloXML import Phylogeny

from aphylogeo import utils
from aphylogeo.alignement import Alignment
from aphylogeo.alignement import AlignSequences
from aphylogeo.params import Params
from aphylogeo.utils import fasttree

current_file = os.path.dirname(__file__)

Expand Down Expand Up @@ -211,4 +213,45 @@ def test_mafft(self):
expected = {rec.id: str(rec.seq) for rec in records}

# Assert
assert muscle_alignment == expected
assert muscle_alignment == expected

def test_fasttree(self):
"""
This test is used to test the fastTree function.
"""
Params.load_from_file(params_file = "tests/clustal_align.yaml")

# load parameters
ref_gene_dir = Params.reference_gene_dir
ref_gene_file = Params.reference_gene_file
sequences_very_small = utils.loadSequenceFile(os.path.join(ref_gene_dir, ref_gene_file))

# Build AlignSequence object
sequences = sequences_very_small.copy()
seq_alignment = AlignSequences(sequences)

# Call clustal Alignment and msa
clustal_alignment = seq_alignment.clustalAlign()
[os.remove(file) for file in glob.glob("bin/tmp/*.fasta")]
windowed = self.seq_alignment.slidingWindow(clustal_alignment)
msa = self.seq_alignment.makeMSA(windowed)
alignment = Alignment(Params.alignment_method, msa)

# Generate Tree using fasttree algorithm
trees = fasttree(alignment.msa, Params.bootstrap_amount, True)

# To generate test files (keep commented out unless another batch of test files needs to be generated)
# [Phylo.write(tree, f"tests/testFiles/fasttree/tree_{window}.xml", "phyloxml") for window, tree in trees.items()]

# Assert
for window, tree in trees.items():

expected = Phylo.read(f"tests/testFiles/fasttree/tree_{window}.xml", "phyloxml")
expected_str = str(expected).split("\n")[1:]
expected_strip = list(map(str.strip, expected_str))

tree_str = str(tree).split("\n")[1:]
tree_str_strip = list(map(str.strip, tree_str))

for tree in tree_str_strip:
assert tree in expected_strip

0 comments on commit a97f855

Please sign in to comment.