本文整理汇总了Python中skbio.tree.TreeNode.from_linkage_matrix方法的典型用法代码示例。如果您正苦于以下问题:Python TreeNode.from_linkage_matrix方法的具体用法?Python TreeNode.from_linkage_matrix怎么用?Python TreeNode.from_linkage_matrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.tree.TreeNode
的用法示例。
在下文中一共展示了TreeNode.from_linkage_matrix方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_clusters
# 需要导入模块: from skbio.tree import TreeNode [as 别名]
# 或者: from skbio.tree.TreeNode import from_linkage_matrix [as 别名]
def get_clusters(x_original, axis='row'):
"""Performs UPGMA clustering using euclidean distances"""
x = x_original.copy()
if axis == 'column':
x = x.T
nr = x.shape[0]
row_dissims = pw_distances(x, ids=map(str, range(nr)), metric='euclidean')
# do upgma - rows
# Average in SciPy's cluster.hierarchy.linkage is UPGMA
linkage_matrix = linkage(row_dissims.condensed_form(), method='average')
tree = TreeNode.from_linkage_matrix(linkage_matrix, row_dissims.ids)
return [int(tip.name) for tip in tree.tips()]
示例2: get_clusters
# 需要导入模块: from skbio.tree import TreeNode [as 别名]
# 或者: from skbio.tree.TreeNode import from_linkage_matrix [as 别名]
def get_clusters(x_original, axis=['row', 'column'][0]):
"""Performs UPGMA clustering using euclidean distances"""
x = x_original.copy()
if axis == 'column':
x = x.T
nr = x.shape[0]
metric_f = get_nonphylogenetic_metric('euclidean')
row_dissims = DistanceMatrix(metric_f(x), map(str, range(nr)))
# do upgma - rows
# Average in SciPy's cluster.heirarchy.linkage is UPGMA
linkage_matrix = linkage(row_dissims.condensed_form(), method='average')
tree = TreeNode.from_linkage_matrix(linkage_matrix, row_dissims.ids)
row_order = [int(tip.name) for tip in tree.tips()]
return row_order
示例3: write_tree
# 需要导入模块: from skbio.tree import TreeNode [as 别名]
# 或者: from skbio.tree.TreeNode import from_linkage_matrix [as 别名]
def write_tree(cluster_method):
import scipy.spatial.distance as ssd
dmx = pd.read_csv("distance_matrix", index_col=0, sep="\t")
ids = dmx.index.tolist()
#triu = np.square(dmx.as_matrix())
triu = np.square(dmx.values)
distArray = ssd.squareform(triu)
if cluster_method == "average":
hclust = average(distArray)
elif cluster_method == "weighted":
hclust = weighted(distArray)
else:
print("invalid cluster method chosen")
sys.exit()
t = TreeNode.from_linkage_matrix(hclust, ids)
nw = t.__str__().replace("'", "")
outfile = open("bsr_matrix.tree", "w")
outfile.write(nw)
outfile.close()
示例4: single_file_upgma
# 需要导入模块: from skbio.tree import TreeNode [as 别名]
# 或者: from skbio.tree.TreeNode import from_linkage_matrix [as 别名]
def single_file_upgma(input_file, output_file):
# read in dist matrix
dist_mat = DistanceMatrix.read(input_file)
# SciPy uses average as UPGMA:
# http://docs.scipy.org/doc/scipy/reference/generated/
# scipy.cluster.hierarchy.linkage.html#scipy.cluster.hierarchy.linkage
linkage_matrix = linkage(dist_mat.condensed_form(), method='average')
tree = TreeNode.from_linkage_matrix(linkage_matrix, dist_mat.ids)
# write output
f = open(output_file, 'w')
try:
f.write(tree.to_newick(with_distances=True))
except AttributeError:
if c is None:
raise RuntimeError("""input file %s did not make a UPGMA tree.
Ensure it has more than one sample present""" % (str(input_file),))
raise
f.close()