Skip to content

Commit

Permalink
bio.phylo
Browse files Browse the repository at this point in the history
  • Loading branch information
tongzhouxu committed Mar 27, 2024
1 parent 09e9f66 commit 947db6f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mashpit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__author__ = 'Tongzhou Xu'
__email__ = '[email protected]'
__version__ = '0.9.4'
__version__ = '0.9.41'
23 changes: 17 additions & 6 deletions mashpit/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import heapq
import time
import pandas as pd
import matplotlib.pyplot as plt

from phytreeviz import TreeViz
from skbio import DistanceMatrix
from skbio.tree import nj
from Bio import Phylo
from mashpit.build import create_connection
from operator import itemgetter
from sourmash import SourmashSignature, save_signatures, load_one_signature, load_file_as_signatures


def get_query_sig(query_path, query_name,hash_number,kmer_size):
genome = query_path
mh = sourmash.MinHash(n=hash_number, ksize=kmer_size)
Expand Down Expand Up @@ -105,10 +105,21 @@ def generate_mashtree(output_df,min_similarity,query_name,sig_path,added_annotat
newick_str = nj(dm, result_constructor=str)
with open(f'{query_name}_annotated_tree.newick','w') as f:
f.write(newick_str)

tv = TreeViz(f'{query_name}_tree.newick')
tv.set_node_label_props(query_name, color="red")
tv.savefig(f'{query_name}_tree.png', dpi=300)
tree = Phylo.read(f'{query_name}_annotated_tree.newick', "newick")
n = len(tree.get_terminals())
fig = plt.figure(figsize=(10, n*0.35), dpi=300)
axes = fig.add_subplot(1, 1, 1)
# disable the axes and borders
axes.set_frame_on(False)
# remove ticks and labels
axes.set_xticks([])
axes.set_yticks([])
axes.set_xticklabels([])
axes.set_yticklabels([])
# add white background
fig.patch.set_facecolor('white')
Phylo.draw(tree, axes=axes,do_show=False)
plt.savefig(f'{query_name}_tree.png')

def query(args):
t = time.localtime()
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='mashpit',
version='0.9.4',
version='0.9.41',
url='https://github.com/tongzhouxu/mashpit',
author='Tongzhou Xu',
author_email='[email protected]',
Expand All @@ -23,7 +23,6 @@
'pandas',
'biopython',
'scikit-bio',
'python-dotenv',
'tqdm',
'flask',
'dask[dataframe]',
Expand Down

0 comments on commit 947db6f

Please sign in to comment.