diff --git a/README.md b/README.md index 1945de6..a185614 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ Genomap is an entropy-based cartography strategy to contrive the high dimensional gene expression data into a configured image format with explicit integration of the genomic interactions. This unique cartography casts the gene-gene interactions into a spatial configuration and enables us to extract the deep genomic interaction features and discover underlying discriminative patterns of the data. For a wide variety of applications (cell clustering and recognition, gene signature extraction, single-cell data integration, cellular trajectory analysis, dimensionality reduction, and visualization), genomap drastically improves the accuracy of data analyses as compared to state-of-the-art techniques. -# Required packages +## Required packages scipy, scikit-learn, pot, numpy If you face any issues with packages, please check the environment section of our Code-Ocean capsule (https://doi.org/10.24433/CO.0640398.v1), where you can check the package versions. -# How to use genomap +## How to use genomap The easiest way to start with genomap is to install it from pypi using @@ -17,25 +17,22 @@ pip install genomap ``` The data should be in cell (row) x gene (column) format. Genomap construction needs only one parameter: the size of the genomap (row and column number). The row and column number can be any number starting from 1. You can create square or rectangular genomaps. The number of genes in your dataset should be less than or equal to the number of pixels in the genomap. Genomap construction is very fast and you should get the genomaps within a few seconds. -# Sample data +## Sample data -To run the example code below, you will need to download the required data file. You can download it from [here](https://drive.google.com/file/d/1kkbI9_6zD80Jr5OhMkGlcdMOeWcRfz7b/view?usp=drive_link). +To run the example codes below, you will need to download data files from [here](https://drive.google.com/drive/folders/1xq3bBgVP0NCMD7bGTXit0qRkL8fbutZ6?usp=drive_link). -# Example code +## Example codes + +### Example 1 - Construct a genomap ```python import pandas as pd # Please install pandas and matplotlib before you run this example - import matplotlib.pyplot as plt - import scipy - import genomap as gp data = pd.read_csv('TM_data.csv', header=None, delim_whitespace=False) - colNum=31 # Column number of genomap - rowNum=31 # Row number of genomap dataNorm=scipy.stats.zscore(data,axis=0,ddof=1) # Normalization of the data @@ -45,12 +42,50 @@ genoMaps=gp.construct_genomap(dataNorm,rowNum,colNum) # Construction of genomaps findI=genoMaps[0,:,:,:] plt.figure(1) # Plot the first genomap - plt.imshow(findI, origin = 'lower', extent = [0, 10, 0, 10], aspect = 1) - plt.title('Genomap of a cell from TM dataset') ``` +### Example 2 - Try out genoVis, genoTraj and genoMOI + +```python +import scipy.io as sio +import numpy as np +from genomap.genoVis import compute_genoVis +from genomap.genoTraj import compute_genoTraj +from genomap.genoMOI import compute_genoMOI + +dx = sio.loadmat('reducedData_divseq.mat') +data=dx['X'] +gt_data = sio.loadmat('GT_divseq.mat') +y = np.squeeze(gt_data['GT']) +n_clusters = len(np.unique(y)) + + +resVis=compute_genoVis(data,n_clusters=n_clusters, colNum=33,rowNum=33) + +dx = sio.loadmat('organoidData.mat') +data=dx['X3'] +gt_data = sio.loadmat('cellsPsudo.mat') +Y_time = np.squeeze(gt_data['newGT']) + + +outGenoTraj=compute_genoTraj(data) + +dx = sio.loadmat('MOIdata/dataBaronX.mat') +data=dx['dataBaron'] +dx = sio.loadmat('MOIdata/dataMuraroX.mat') +data2=dx['dataMuraro'] +dx = sio.loadmat('MOIdata/dataScapleX.mat') +data3=dx['dataScaple'] +dx = sio.loadmat('MOIdata/dataWangX.mat') +data4=dx['dataWang'] +dx = sio.loadmat('MOIdata/dataXinX.mat') +data5=dx['dataXin'] + +resVis=compute_genoMOI(data, data2, data3, data4, data5, colNum=44, rowNum=44) +``` + # Citation If you use the genomap code, please cite our Nature Communications paper: https://www.nature.com/articles/s41467-023-36383-6 diff --git a/genomap/genoMOI/genoMOI.py b/genomap/genoMOI/genoMOI.py index 0a64ec6..03f96b4 100644 --- a/genomap/genoMOI/genoMOI.py +++ b/genomap/genoMOI/genoMOI.py @@ -6,14 +6,14 @@ """ from tensorflow.keras.optimizers import Adam -from genomap.ConvIDEC import ConvIDEC +from utils.ConvIDEC import ConvIDEC # from ConvIDEC import ConvIDEC from sklearn.feature_selection import VarianceThreshold from genomap.genomap import construct_genomap import umap -from genomap.gTraj_utils import nearest_divisible_by_four +from utils.gTraj_utils import nearest_divisible_by_four # from gTraj_utils import nearest_divisible_by_four -from genomap.utils_MOI import * +from utils.utils_MOI import * # from utils_MOI import * def compute_genoMOI(*arrays,n_clusters=None, colNum, rowNum): diff --git a/genomap/genoTraj/genoTraj.py b/genomap/genoTraj/genoTraj.py index 7896d5a..e7df2df 100644 --- a/genomap/genoTraj/genoTraj.py +++ b/genomap/genoTraj/genoTraj.py @@ -7,11 +7,11 @@ import phate import numpy as np -from genomap.class_discriminative_opt import ClassDiscriminative_OPT +from utils.class_discriminative_opt import ClassDiscriminative_OPT import scipy -from genomap.gTraj_utils import compute_cluster_distances, nearest_divisible_by_four +from utils.gTraj_utils import compute_cluster_distances, nearest_divisible_by_four from tensorflow.keras.optimizers import Adam -from genomap.ConvIDEC import ConvIDEC +from utils.ConvIDEC import ConvIDEC from sklearn.feature_selection import VarianceThreshold from genomap.genomap import construct_genomap # from gTraj_utils import nearest_divisible_by_four diff --git a/genomap/genoVis/genoVis.py b/genomap/genoVis/genoVis.py index 2def62d..e1a95d0 100644 --- a/genomap/genoVis/genoVis.py +++ b/genomap/genoVis/genoVis.py @@ -6,12 +6,12 @@ """ from tensorflow.keras.optimizers import Adam -from genomap.ConvIDEC import ConvIDEC +from utils.ConvIDEC import ConvIDEC from sklearn.feature_selection import VarianceThreshold from genomap.genomap import construct_genomap import umap # from gTraj_utils import nearest_divisible_by_four -from genomap.gTraj_utils import nearest_divisible_by_four +from utils.gTraj_utils import nearest_divisible_by_four import scanpy as sc import numpy as np import pandas as pd diff --git a/genomap/ConvDEC.py b/genomap/utils/ConvDEC.py similarity index 98% rename from genomap/ConvDEC.py rename to genomap/utils/ConvDEC.py index b739567..91fe193 100644 --- a/genomap/ConvDEC.py +++ b/genomap/utils/ConvDEC.py @@ -9,8 +9,7 @@ from tensorflow.keras.layers import Conv2D, Conv2DTranspose, Dense, Flatten, Reshape, InputLayer from tensorflow.keras.models import Sequential, Model from tensorflow.keras.preprocessing.image import ImageDataGenerator -from FcDEC import FcDEC, ClusteringLayer - +from .FcDEC import FcDEC, ClusteringLayer def CAE(input_shape=(28, 28, 1), filters=[32, 64, 128, 10]): model = Sequential() diff --git a/genomap/ConvIDEC.py b/genomap/utils/ConvIDEC.py similarity index 97% rename from genomap/ConvIDEC.py rename to genomap/utils/ConvIDEC.py index 8b1c0f5..8602521 100644 --- a/genomap/ConvIDEC.py +++ b/genomap/utils/ConvIDEC.py @@ -8,7 +8,7 @@ """ from tensorflow.keras.models import Model -from ConvDEC import ConvDEC +from .ConvDEC import ConvDEC class ConvIDEC(ConvDEC): diff --git a/genomap/FcDEC.py b/genomap/utils/FcDEC.py similarity index 99% rename from genomap/FcDEC.py rename to genomap/utils/FcDEC.py index d0fe6d0..86a4dc8 100644 --- a/genomap/FcDEC.py +++ b/genomap/utils/FcDEC.py @@ -17,7 +17,7 @@ from tensorflow.keras.initializers import VarianceScaling from tensorflow.keras.preprocessing.image import ImageDataGenerator from sklearn.cluster import KMeans -import metrics +from .metrics import * def autoencoder(dims, act='relu'): diff --git a/genomap/FcIDEC.py b/genomap/utils/FcIDEC.py similarity index 97% rename from genomap/FcIDEC.py rename to genomap/utils/FcIDEC.py index 04d38d3..60e5286 100644 --- a/genomap/FcIDEC.py +++ b/genomap/utils/FcIDEC.py @@ -8,7 +8,7 @@ """ from tensorflow.keras.models import Model -from FcDEC import FcDEC +from .FcDEC import FcDEC class FcIDEC(FcDEC): diff --git a/genomap/utils/__init__.py b/genomap/utils/__init__.py new file mode 100644 index 0000000..124bcda --- /dev/null +++ b/genomap/utils/__init__.py @@ -0,0 +1,9 @@ +from .class_discriminative_opt import * +from .ConvDEC import * +from .ConvIDEC import * +from .FcDEC import * +from .FcIDEC import * +from .group_centroid_opt import * +from .gTraj_utils import * +from .metrics import * +from .utils_MOI import * \ No newline at end of file diff --git a/genomap/class_discriminative_opt.py b/genomap/utils/class_discriminative_opt.py similarity index 100% rename from genomap/class_discriminative_opt.py rename to genomap/utils/class_discriminative_opt.py diff --git a/genomap/gTraj_utils.py b/genomap/utils/gTraj_utils.py similarity index 100% rename from genomap/gTraj_utils.py rename to genomap/utils/gTraj_utils.py diff --git a/genomap/group_centroid_opt.py b/genomap/utils/group_centroid_opt.py similarity index 100% rename from genomap/group_centroid_opt.py rename to genomap/utils/group_centroid_opt.py diff --git a/genomap/metrics.py b/genomap/utils/metrics.py similarity index 100% rename from genomap/metrics.py rename to genomap/utils/metrics.py diff --git a/genomap/utils_MOI.py b/genomap/utils/utils_MOI.py similarity index 100% rename from genomap/utils_MOI.py rename to genomap/utils/utils_MOI.py diff --git a/setup.py b/setup.py index 1522f64..ad63704 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="genomap", - version="1.0.5", + version="1.0.6", author="Md Tauhidul Islam", author_email="tauhid@stanford.edu", description="Genomap converts tabular gene expression data into spatially meaningful images.",