diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..025bb85 --- /dev/null +++ b/setup.py @@ -0,0 +1,27 @@ +from setuptools import setup, find_packages + +setup(name='tmap', + version='1.0', + description='mapper ', + author='Haokui Zhou', + author_email='zhouhaokui@hotmail.com', + license='GNU', + url='https://github.com/GPZ-Bioinfo/tmap', + packages=find_packages(), + package_data={'': ['test_data/*.csv', + 'test_data/*.tsv', + 'example/*'], + }, + install_requires=['statsmodels>=0.9.0', + 'tqdm', + 'scikit-learn>=0.19.1', + 'matplotlib>=2.2.2', + 'networkx==1.11', + 'pandas>=0.23.0', + 'numpy>=1.10.4', + 'scipy', + + ], + zip_safe=False, + extras_require={'alldeps': ('numpy>=1.10.4', 'scipy',)} + ) diff --git a/netx/__init__.py b/tmap/__init__.py similarity index 100% rename from netx/__init__.py rename to tmap/__init__.py diff --git a/example/Bacteroides_SAFE.pdf b/tmap/example/Bacteroides_SAFE.pdf similarity index 100% rename from example/Bacteroides_SAFE.pdf rename to tmap/example/Bacteroides_SAFE.pdf diff --git a/example/Bacteroides_abd.pdf b/tmap/example/Bacteroides_abd.pdf similarity index 100% rename from example/Bacteroides_abd.pdf rename to tmap/example/Bacteroides_abd.pdf diff --git a/example/FGFP_SAFE_ranking_genus_1000.csv b/tmap/example/FGFP_SAFE_ranking_genus_1000.csv similarity index 100% rename from example/FGFP_SAFE_ranking_genus_1000.csv rename to tmap/example/FGFP_SAFE_ranking_genus_1000.csv diff --git a/netx/SAFE.py b/tmap/netx/SAFE.py similarity index 100% rename from netx/SAFE.py rename to tmap/netx/SAFE.py diff --git a/tda/__init__.py b/tmap/netx/__init__.py similarity index 100% rename from tda/__init__.py rename to tmap/netx/__init__.py diff --git a/test/__init__.py b/tmap/tda/__init__.py similarity index 100% rename from test/__init__.py rename to tmap/tda/__init__.py diff --git a/tda/cover.py b/tmap/tda/cover.py similarity index 100% rename from tda/cover.py rename to tmap/tda/cover.py diff --git a/tda/filter.py b/tmap/tda/filter.py similarity index 99% rename from tda/filter.py rename to tmap/tda/filter.py index 7f4cd01..c3562a4 100644 --- a/tda/filter.py +++ b/tmap/tda/filter.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import numpy as np from sklearn import decomposition, manifold -from tda.metric import Metric +from tmap.tda.metric import Metric _METRIC_BUILT_IN = ["braycurtis", "canberra", "chebyshev", "cityblock", "correlation", "cosine", "dice", "euclidean", diff --git a/tda/mapper.py b/tmap/tda/mapper.py similarity index 98% rename from tda/mapper.py rename to tmap/tda/mapper.py index 80fbf6c..442e840 100644 --- a/tda/mapper.py +++ b/tmap/tda/mapper.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- -from tda.cover import Cover import numpy as np import pandas as pd import itertools -from sklearn import cluster, preprocessing +from sklearn import cluster class Mapper(object): diff --git a/tda/metric.py b/tmap/tda/metric.py similarity index 100% rename from tda/metric.py rename to tmap/tda/metric.py diff --git a/tda/plot.py b/tmap/tda/plot.py similarity index 96% rename from tda/plot.py rename to tmap/tda/plot.py index 23a3f71..174e4dc 100644 --- a/tda/plot.py +++ b/tmap/tda/plot.py @@ -40,7 +40,10 @@ def __init__(self, target, dtype="numerical", target_by="sample"): if target_by not in ["sample", "node"]: raise ValueError("target values must be by 'sample' or 'node'") # target values should be numbers, check and encode categorical labels - if ((type(target[0][0]) != int) and (type(target[0][0]) != float)): + if ((type(target[0][0]) != int) + and (type(target[0][0]) != float) + and (not isinstance(target[0][0],np.number)) + ): self.label_encoder = LabelEncoder() self.target = self.label_encoder.fit_transform(target) else: @@ -165,7 +168,10 @@ def show(data, graph, color=None, fig_size=(10, 10), node_size=10, edge_width=2, if color.dtype == "categorical": for label in set([it[0] for it in color.labels]): if color.label_encoder: - label_color = legend_lookup[color.label_encoder.fit_transform(label)] + try: + label_color = legend_lookup[color.label_encoder.fit_transform(label)] + except: + import pdb;pdb.set_trace() else: label_color = legend_lookup[label] ax.plot([], [], 'o', color=label_color, label=label, markersize=10) diff --git a/tda/utils.py b/tmap/tda/utils.py similarity index 100% rename from tda/utils.py rename to tmap/tda/utils.py diff --git a/tmap/test/__init__.py b/tmap/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/load_data.py b/tmap/test/load_data.py similarity index 100% rename from test/load_data.py rename to tmap/test/load_data.py diff --git a/test/test_FGFP.py b/tmap/test/test_FGFP.py similarity index 79% rename from test/test_FGFP.py rename to tmap/test/test_FGFP.py index a1fff94..b4ba1c2 100644 --- a/test/test_FGFP.py +++ b/tmap/test/test_FGFP.py @@ -1,13 +1,13 @@ -from sklearn.preprocessing import MinMaxScaler, LabelEncoder, Imputer +import os +from sklearn.preprocessing import MinMaxScaler from sklearn.cluster import DBSCAN -import numpy as np -from tda import mapper, filter -from tda.cover import Cover -from tda.plot import show, Color -from tda.metric import Metric -from tda.utils import optimize_dbscan_eps -from netx.SAFE import SAFE_batch, get_SAFE_summary, SAFE_single -from test import load_data +from tmap.tda import mapper, filter +from tmap.tda.cover import Cover +from tmap.tda.plot import show, Color +from tmap.tda.metric import Metric +from tmap.tda.utils import optimize_dbscan_eps +from tmap.netx.SAFE import SAFE_batch, get_SAFE_summary +from tmap.test import load_data # load taxa abundance data, sample metadata and precomputed distance matrix @@ -52,4 +52,4 @@ safe_summary = get_SAFE_summary(graph=graph, meta_data=X, safe_scores=safe_scores, n_iter_value=n_iter, p_value=0.01) -safe_summary.to_csv('../example/FGFP_SAFE_ranking_genus_1000.csv', index=True) +safe_summary.to_csv(os.path.join(os.path.dirname(__file__),'../example/FGFP_SAFE_ranking_genus_1000.csv'), index=True) diff --git a/test/test_circles.py b/tmap/test/test_circles.py similarity index 86% rename from test/test_circles.py rename to tmap/test/test_circles.py index 723f40c..de2e689 100644 --- a/test/test_circles.py +++ b/tmap/test/test_circles.py @@ -1,8 +1,8 @@ from sklearn import datasets from sklearn.cluster import DBSCAN -from tda import mapper, filter -from tda.cover import Cover -from tda.plot import show, Color +from tmap.tda import mapper, filter +from tmap.tda.cover import Cover +from tmap.tda.plot import show, Color X, y = datasets.make_circles(n_samples=5000, noise=0.05, factor=0.3) diff --git a/test/test_data/FGFP_bc_dm.csv b/tmap/test/test_data/FGFP_bc_dm.csv similarity index 100% rename from test/test_data/FGFP_bc_dm.csv rename to tmap/test/test_data/FGFP_bc_dm.csv diff --git a/test/test_data/FGFP_genus_data.csv b/tmap/test/test_data/FGFP_genus_data.csv similarity index 100% rename from test/test_data/FGFP_genus_data.csv rename to tmap/test/test_data/FGFP_genus_data.csv diff --git a/test/test_data/FGFP_metadata.tsv b/tmap/test/test_data/FGFP_metadata.tsv similarity index 100% rename from test/test_data/FGFP_metadata.tsv rename to tmap/test/test_data/FGFP_metadata.tsv diff --git a/test/test_digits.py b/tmap/test/test_digits.py similarity index 87% rename from test/test_digits.py rename to tmap/test/test_digits.py index d3cb748..f067c05 100644 --- a/test/test_digits.py +++ b/tmap/test/test_digits.py @@ -1,9 +1,9 @@ from sklearn import datasets from sklearn.preprocessing import MinMaxScaler -from tda import mapper, filter -from tda.cover import Cover +from tmap.tda import mapper, filter +from tmap.tda.cover import Cover from sklearn.cluster import DBSCAN -from tda.plot import Color, show +from tmap.tda.plot import Color, show digits = datasets.load_digits() diff --git a/test/test_iris.py b/tmap/test/test_iris.py similarity index 88% rename from test/test_iris.py rename to tmap/test/test_iris.py index 34a3093..d19eec8 100644 --- a/test/test_iris.py +++ b/tmap/test/test_iris.py @@ -1,9 +1,9 @@ from sklearn.preprocessing import MinMaxScaler, StandardScaler from sklearn import datasets from sklearn.cluster import DBSCAN -from tda import mapper, filter -from tda.cover import Cover -from tda.plot import show, Color +from tmap.tda import mapper, filter +from tmap.tda.cover import Cover +from tmap.tda.plot import show, Color iris = datasets.load_iris()