-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from VasudhaJha/feature/export-all-files
Feature/export all files
- Loading branch information
Showing
29 changed files
with
954 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .genoClassification import * |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
""" | ||
Created on Sun Jul 16 21:27:17 2023 | ||
@author: Md Tauhidul Islam, Research Scientist, Dept. of radiation Oncology, Stanford University | ||
""" | ||
|
||
import numpy as np | ||
import os | ||
import torch | ||
from torch.utils.data import DataLoader, Dataset | ||
import scipy | ||
|
||
from genomap.genomap import construct_genomap | ||
from genomap.utils.util_Sig import select_n_features | ||
import genomap.genoNet as gNet | ||
|
||
def genoClassification(training_data, training_labels, test_data, rowNum=32, colNum=32, epoch=100): | ||
|
||
# training_data: numpy array in cellxgene shape | ||
# training_labels: numpy array | ||
# test_data: numpy array in cellxgene shape | ||
# rowNum: row number of genomap | ||
# colNum: column number of genomap | ||
# epoch: epoch number for training | ||
|
||
data = np.concatenate((training_data, test_data), axis=0) | ||
# Construction of genomaps | ||
nump=rowNum*colNum | ||
if nump<data.shape[1]: | ||
data,index=select_n_features(data,nump) | ||
|
||
dataNorm=scipy.stats.zscore(data,axis=0,ddof=1) | ||
genoMaps=construct_genomap(dataNorm,rowNum,colNum,epsilon=0.0,num_iter=200) | ||
|
||
# Split the data for training and testing | ||
dataMat_CNNtrain = genoMaps[:training_labels.shape[0]] | ||
dataMat_CNNtest = genoMaps[training_labels.shape[0]:] | ||
|
||
groundTruthTrain = training_labels | ||
classNum = len(np.unique(groundTruthTrain)) | ||
|
||
# Preparation of training and testing data for PyTorch computation | ||
XTrain = dataMat_CNNtrain.transpose([0,3,1,2]) | ||
XTest = dataMat_CNNtest.transpose([0,3,1,2]) | ||
yTrain = groundTruthTrain | ||
|
||
# Train the network in PyTorch framework | ||
miniBatchSize = 128 | ||
net = gNet.traingenoNet(XTrain, yTrain, maxEPOCH=epoch, batchSize=miniBatchSize, verbose=True) | ||
|
||
# # Process the test data | ||
yTest = np.random.rand(dataMat_CNNtest.shape[0]) | ||
testset = gNet.geneDataset(XTest, yTest) | ||
testloader = gNet.DataLoader(testset, batch_size=miniBatchSize, shuffle=False) | ||
device = gNet.get_device() | ||
|
||
# Perform data classification | ||
prob_test = gNet.predict(net, testloader, device) | ||
pred_test = np.argmax(prob_test, axis=-1) | ||
|
||
return pred_test | ||
|
||
|
||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .genoDimReduction import * |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Wed Jul 12 16:11:15 2023 | ||
@author: Md Tauhidul Islam, Ph.D., Dept. of Radiation Oncology, Stanford University | ||
""" | ||
import numpy as np | ||
import pandas as pd | ||
import scanpy as sc | ||
from sklearn.feature_selection import VarianceThreshold | ||
from tensorflow.keras.optimizers import Adam | ||
import umap | ||
|
||
from genomap.genomap import construct_genomap | ||
from genomap.utils.ConvIDEC import ConvIDEC | ||
from genomap.utils.gTraj_utils import nearest_divisible_by_four | ||
from genomap.utils.util_Sig import select_n_features | ||
|
||
def genoDR(data,n_dim=32, n_clusters=None, colNum=32,rowNum=32,batch_size=64,verbose=1, | ||
pretrain_epochs=100,maxiter=300): | ||
|
||
# Construction of genomap | ||
colNum=nearest_divisible_by_four(colNum) | ||
rowNum=nearest_divisible_by_four(rowNum) | ||
nump=rowNum*colNum | ||
if nump<data.shape[1]: | ||
data,index=select_n_features(data,nump) | ||
|
||
genoMaps=construct_genomap(data,rowNum,colNum,epsilon=0.0,num_iter=200) | ||
|
||
if n_clusters==None: | ||
|
||
adata = convertToAnnData(data) | ||
# Perform Louvain clustering | ||
sc.pp.neighbors(adata) | ||
sc.tl.louvain(adata, resolution=1.0) | ||
# Access the cluster assignments | ||
cluster_labels = adata.obs['louvain'] | ||
n_clusters = len(np.unique(cluster_labels)) | ||
|
||
# Deep learning-based dimensionality reduction and clustering | ||
optimizer = Adam() | ||
model = ConvIDEC(input_shape=genoMaps.shape[1:], filters=[32, 64, 128, n_dim], n_clusters=n_clusters) | ||
model.compile(optimizer=optimizer, loss=['kld', 'mse'], loss_weights=[0.1, 1.0]) | ||
pretrain_optimizer ='adam' | ||
update_interval=50 | ||
model.pretrain(genoMaps, y=None, optimizer=pretrain_optimizer, epochs=pretrain_epochs, batch_size=batch_size, | ||
verbose=verbose) | ||
|
||
y_pred = model.fit(genoMaps, y=None, maxiter=maxiter, batch_size=batch_size, update_interval=update_interval, | ||
) | ||
y_pred = model.predict_labels(genoMaps) | ||
feat_DNN=model.extract_features(genoMaps) | ||
#embedding2D = umap.UMAP(n_neighbors=30,min_dist=0.3,n_epochs=200).fit_transform(feat_DNN) | ||
return feat_DNN | ||
|
||
|
||
def convertToAnnData(data): | ||
# Create pseudo cell names | ||
cell_names = ['Cell_' + str(i) for i in range(1, data.shape[0]+1)] | ||
# Create pseudo gene names | ||
gene_names = ['Gene_' + str(i) for i in range(1, data.shape[1]+1)] | ||
# Create a pandas DataFrame | ||
df = pd.DataFrame(data, index=cell_names, columns=gene_names) | ||
adataMy=sc.AnnData(df) | ||
return adataMy | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .genoNet import * |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .genoNet_regression import * |
Oops, something went wrong.