Created
April 27, 2021 09:56
-
-
Save fredyr/5bff0d4a3fdc7fc41512791351b2da51 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
from io import StringIO | |
import pandas | |
from Bio.Phylo.TreeConstruction import DistanceMatrix | |
def distance_matrix(snp_tab): | |
df = pandas.read_csv(snp_tab, sep='\t', header=0) | |
cols = list(df.columns)[1:] | |
matrix = [[int(f) for f in df[c].values][: i + 1] for i, c in enumerate(cols)] | |
distmat = DistanceMatrix(cols, matrix=matrix) | |
phylip = StringIO() | |
distmat.format_phylip(phylip) | |
print(phylip.getvalue()) | |
distance_matrix(sys.stdin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment