Skip to content

Commit

Permalink
help functionality on report now works
Browse files Browse the repository at this point in the history
  • Loading branch information
harmsm committed Dec 25, 2022
1 parent 9a5c1f2 commit 7038612
Show file tree
Hide file tree
Showing 18 changed files with 4,508 additions and 4,056 deletions.
2 changes: 1 addition & 1 deletion docs/badges/coverage-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/badges/tests-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 119 additions & 2 deletions tests/io/test_io_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,133 @@
from topiary.io.tree import read_tree
from topiary.io.tree import _map_tree_to_tree
from topiary.io.tree import load_trees
from topiary.io.tree import write_trees

import os
import re

def test_read_tree():

pass


def test__map_tree_to_tree():

pass

def test_load_trees():

pass
pass

def test_write_trees(small_phylo,tmpdir):

cwd = os.getcwd()
os.chdir(tmpdir)

# Reconciled trees
T = load_trees(small_phylo["06_reconciled-tree-bootstraps/output"],prefix="reconciled")
newick = write_trees(T)
split_trees = newick.split(";")[:-1]
assert len(split_trees) == 4

expected = ["100","S","a5","0.999999"]
for i in range(4):
last_value = split_trees[i].split(")")[-2].split(":")[0]
assert last_value == expected[i]

# gene trees
T = load_trees(small_phylo["06_reconciled-tree-bootstraps/output"],prefix="gene")
newick = write_trees(T)
split_trees = newick.split(";")[:-1]
assert len(split_trees) == 3

expected = ["100","a10","0.997959"]
for i in range(3):
last_value = split_trees[i].split(")")[-2].split(":")[0]
assert last_value == expected[i]

# Only anc_pp
T = load_trees(small_phylo["06_reconciled-tree-bootstraps/output"],prefix="reconciled")
newick = write_trees(T,
anc_pp=True,
anc_label=False,
bs_support=False,
event=False)
split_trees = newick.split(";")[:-1]
assert len(split_trees) == 1
last_value = split_trees[0].split(")")[-2].split(":")[0]
assert last_value == "0.999999"

# Only anc_label
T = load_trees(small_phylo["06_reconciled-tree-bootstraps/output"],prefix="reconciled")
newick = write_trees(T,
anc_pp=False,
anc_label=True,
bs_support=False,
event=False)
split_trees = newick.split(";")[:-1]
assert len(split_trees) == 1
last_value = split_trees[0].split(")")[-2].split(":")[0]
assert last_value == "a5"

# Only bs_support
T = load_trees(small_phylo["06_reconciled-tree-bootstraps/output"],prefix="reconciled")
newick = write_trees(T,
anc_pp=False,
anc_label=False,
bs_support=True,
event=False)
split_trees = newick.split(";")[:-1]
assert len(split_trees) == 1
last_value = split_trees[0].split(")")[-2].split(":")[0]
assert last_value == "100"

# Only event
T = load_trees(small_phylo["06_reconciled-tree-bootstraps/output"],prefix="reconciled")
newick = write_trees(T,
anc_pp=False,
anc_label=False,
bs_support=False,
event=True)
split_trees = newick.split(";")[:-1]
assert len(split_trees) == 1
last_value = split_trees[0].split(")")[-2].split(":")[0]
assert last_value == "S"

# Write to file
T = load_trees(small_phylo["06_reconciled-tree-bootstraps/output"],prefix="reconciled")
newick = write_trees(T,out_file="test.newick")
f = open("test.newick","r")
lines = f.readlines()
f.close()
assert len(lines) == 4
assert sum([line.strip()[-1] == ";" for line in lines]) == 4

# Try to write to existing
with pytest.raises(FileExistsError):
newick = write_trees(T,out_file="test.newick")

# Overwrite
newick = write_trees(T,out_file="test.newick",overwrite=True)

# Try to write onto a directory
os.mkdir("test")
with pytest.raises(FileExistsError):
newick = write_trees(T,out_file="test",overwrite=True)

# name_dict
T = load_trees(small_phylo["06_reconciled-tree-bootstraps/output"],prefix="reconciled")

# Build simple name_dict
name_dict = {}
for n in T.traverse():
if n.is_leaf():
name_dict[n.name] = re.sub("x","Y",n.name)

# Make sure replacement happened
newick = write_trees(T,name_dict=name_dict)
found = re.search("Y",newick)
assert found is not None
found = re.search("x",newick)
assert found is None

os.chdir(cwd)
Empty file removed tests/io/test_tree.py
Empty file.
14 changes: 14 additions & 0 deletions tests/reports/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,20 @@ def test_create_icon_row():
assert np.array_equal(parser.tag_dict["a"][0][1]["title"],["some","words"])
assert parser.tag_dict["img"][0][1]["src"][0] == ".assets/pdf_icon.svg"

out = create_icon_row(["stupid.newick"],["some words"])
parser = _load_check_html(out)

assert parser.tag_dict["a"][0][1]["href"][0] == "stupid.newick"
assert np.array_equal(parser.tag_dict["a"][0][1]["title"],["some","words"])
assert parser.tag_dict["img"][0][1]["src"][0] == ".assets/newick_icon.svg"

out = create_icon_row(["stupid.fasta"],["some words"])
parser = _load_check_html(out)

assert parser.tag_dict["a"][0][1]["href"][0] == "stupid.fasta"
assert np.array_equal(parser.tag_dict["a"][0][1]["title"],["some","words"])
assert parser.tag_dict["img"][0][1]["src"][0] == ".assets/fasta_icon.svg"

out = create_icon_row(["stupid.doc"],["some words"])
parser = _load_check_html(out)

Expand Down
120 changes: 0 additions & 120 deletions topiary/_private/check/paralog_patterns.py

This file was deleted.

15 changes: 7 additions & 8 deletions topiary/draw/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def create_name_dict(df,tip_columns=None,separator="|",disambiguate=True):
tip_columns : list, optional
columns in dataframe to use to create human-readable names for tips on
tree. For example, :code:`tip_columns = ["species","nickname"]` would
give names like :code:`"Homo sapiens|LY96"`. If None, try
:code:`["species","nickname"]`. If nickname is not in dataframe,
fall back to :code:`["species",f"{name[:10]}..."]`.
give names like :code:`"Homo sapiens|LY96"`. If None, try
:code:`["species","recip_paralog"], then :code:`["species","nickname"]`,
then :code:`["species",f"{name[:10]}..."]`.
separator : str
separator to use between pretty names. Cannot be "#,;:'\")(" as these
are used in newick format.
Expand All @@ -181,12 +181,11 @@ def create_name_dict(df,tip_columns=None,separator="|",disambiguate=True):

local_df = df.loc[df.keep,:]
if tip_columns is None:

try:
local_df.nickname
if "recip_paralog" in df.columns:
tip_columns = ["species","recip_paralog"]
elif "nickname" in df.columns:
tip_columns = ["species","nickname"]
except AttributeError:

else:
local_df = df.copy()
trunc_name = []
for i in range(len(local_df)):
Expand Down
8 changes: 0 additions & 8 deletions topiary/draw/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,6 @@ def tree(calculation,
if df is None:
df = supervisor.df

if tip_columns is None:
if "recip_paralog" in df.columns:
recip_columns = ["species","recip_paralog"]
elif "nickname" in df.columns:
recip_columns = ["species","nickname"]
else:
recip_columns = ["species","name"]

# Create dictionary mapping between uid and pretty name format
name_dict = create_name_dict(df=df,
tip_columns=tip_columns,
Expand Down
Loading

0 comments on commit 7038612

Please sign in to comment.