Skip to content

Commit

Permalink
add color to clustermap
Browse files Browse the repository at this point in the history
  • Loading branch information
raquellewei committed Sep 27, 2023
1 parent 2744f8c commit 2b0ed52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 0 additions & 1 deletion fununifrac/reproducibility/_filter_files_in_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def parsearg():
args = parsearg()
all_files = os.listdir(args.source_dir)
meta_data = pd.read_table(args.metadata_file)
print(all_files[:5])
ids = meta_data['f_uid']
selected_files = [f'sourmash_gather_out_scale1000_k_11_{i}.csv' for i in ids]
for i, file in enumerate(all_files):
Expand Down
27 changes: 19 additions & 8 deletions fununifrac/reproducibility/plot_clustermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@ def parsearg():

if __name__ == "__main__":
args = parsearg()
from sklearn.datasets import load_iris
iris = load_iris()
X, y = iris.data, iris.target
DF = pd.DataFrame(X, index=["iris_%d" % (i) for i in range(X.shape[0])], columns=iris.feature_names)
DF_corr = DF.T.corr()
DF_dism = 1 - DF_corr # distance matrix
linkage = hc.linkage(sp.distance.squareform(DF_dism), method='average')
sns.clustermap(DF_dism, row_linkage=linkage, col_linkage=linkage)
pw_distance = np.load(args.pairwise_distance)
print(pw_distance)
linkage = hc.linkage(pw_distance, method='average')
metadata = pd.read_table(args.metadata_file)

lut = dict(zip(metadata['study_full_name'].unique(), "rbg"))
row_colors = metadata['study_full_name'].map(lut)
sns.clustermap(pw_distance, row_linkage=linkage, col_linkage=linkage)
plt.show()


# from sklearn.datasets import load_iris
# iris = load_iris()
# X, y = iris.data, iris.target
# DF = pd.DataFrame(X, index=["iris_%d" % (i) for i in range(X.shape[0])], columns=iris.feature_names)
# DF_corr = DF.T.corr()
# DF_dism = 1 - DF_corr # distance matrix
# linkage = hc.linkage(sp.distance.squareform(DF_dism), method='average')
# sns.clustermap(DF_dism, row_linkage=linkage, col_linkage=linkage)

0 comments on commit 2b0ed52

Please sign in to comment.