Skip to content

Commit

Permalink
Major changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jovoni committed Nov 21, 2023
1 parent e999218 commit 7672904
Show file tree
Hide file tree
Showing 23 changed files with 646 additions and 1,539 deletions.
Binary file modified .DS_Store
Binary file not shown.
1,020 changes: 510 additions & 510 deletions .Rhistory

Large diffs are not rendered by default.

Binary file modified inst/.DS_Store
Binary file not shown.
Binary file modified inst/pydevil/.DS_Store
Binary file not shown.
132 changes: 132 additions & 0 deletions inst/pydevil/.virtual_documents/notebook_test/batch_vs_full.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import scanpy as sc
import patsy as ptsy
import torch
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np
import pandas as pd


data_path = "../../../../../../../Dropbox/2021. CLL CD49/scRNA/data/SevenBridges_counts/Novaseq_SampleTag01_hs_RM238_2/Novaseq_SampleTag01_hs_RM238_2_DBEC_MolsPerCell.csv"
labels_path = "../../../../../../../Dropbox/2021. CLL CD49/scRNA/data/kmeans_labels/Novaseq_SampleTag01_hs_RM238_2_Ab_Labels.tsv"
labels = pd.read_csv(labels_path, sep="\t")
adata = sc.read_csv(data)


adata = adata[:, 5:]
adata.obs["cell_type"] = list(labels['labels'])


adata = adata[:, adata.X.sum(axis=0) > 0]


import sys
sys.path.append("../")
%reload_ext autoreload
%autoreload 2

import pydevil


covariates = ptsy.dmatrix("~ 1", adata.obs)
UMI = np.array(X.sum(1)).squeeze() / np.mean(np.array(X.sum(1)).squeeze())
gene_names = adata.var_names
obs_names = adata.obs_names
X = torch.tensor(adata.X).int()


res = pydevil.run_SVDE(X, covariates, UMI,
gene_names = gene_names,
cell_names = obs_names,
#group_matrix = random_effects,
jit_compile=False,
optimizer_name = "ClippedAdam", lr = 0.5, gamma_lr=0.0001, steps = 20,
full_cov = True, cuda = True, batch_size=X.shape[0])


res_batch = pydevil.run_SVDE(X, covariates, UMI,
gene_names = gene_names,
cell_names = obs_names,
#group_matrix = random_effects,
jit_compile=False,
optimizer_name = "ClippedAdam", lr = 0.5, gamma_lr=0.0001, steps = 20,
full_cov = False, cuda = True, batch_size=int(X.shape[0] / 4.0))


contrast = np.array([1,-1])


betas = res_nocov['params']['beta']
var = res_nocov['params']['variance']


(betas * contrast.reshape([-1,1])).sum(axis = 0), (var**2 * abs(contrast)).sum(axis = 1)


batch_factor = 2
res_no_cov_batch = pydevil.run_SVDE(X, covariates, UMI,
gene_names = gene_names,
cell_names = obs_names,
#group_matrix = random_effects,
jit_compile=False,
optimizer_name = "ClippedAdam", lr = 0.5 / batch_factor, gamma_lr=0.0001, steps = 500,
full_cov = True, cuda = True, batch_size=int(X.shape[1] / batch_factor))


pydevil.test_posterior_null(res, contrast)


pydevil.test_posterior_null(res_batch, contrast)


pydevil.test_posterior_null(res, np.array([1]))
pydevil.test_posterior_null(res_nocov, np.array([1]))
pydevil.test_posterior_null(res_no_cov_batch, np.array([1]))


theta = res['params']['theta']
beta = res['params']['beta'].squeeze(0)
beta_loc = res['params']['variance']

theta_nocov = res_nocov['params']['theta']
beta_nocov = res_nocov['params']['beta'].squeeze(0)
beta_loc_nocov = res_nocov['params']['variance']

theta_batch = res_no_cov_batch['params']['theta']
beta_batch = res_no_cov_batch['params']['beta'].squeeze(0)
beta_loc_bathc = res_no_cov_batch['params']['variance']


fig, (ax1, ax2) = plt.subplots(1, 2)
fig.suptitle('Plot for overdispersion')
ax1.scatter(theta, theta_batch, s = .5)
ax2.scatter([i for i in range(len(theta))], theta / theta_batch, s = .5)
plt.show()


fig, (ax1, ax2) = plt.subplots(1, 2)
fig.suptitle('Plot for overdispersion')
ax1.scatter(theta, theta_batch_nc, s = .5)
ax2.scatter([i for i in range(len(theta))], theta / theta_batch_nc, s = .5)
plt.show()


fig, (ax1, ax2) = plt.subplots(1, 2)
fig.suptitle('Plot for beta')
ax1.scatter(beta, beta_batch, s = .5)
ax2.scatter([i for i in range(len(beta))], beta / beta_batch, s = .5)


fig, (ax1, ax2) = plt.subplots(1, 2)
fig.suptitle('Plot for beta')
ax1.scatter(beta_loc, beta_loc_batch, s = .5)
ax2.scatter([i for i in range(len(beta_loc))], beta_loc_batch / beta_loc, s = .5)


beta_loc_bathc_nc.shape,


fig, (ax1, ax2) = plt.subplots(1, 2)
fig.suptitle('Plot for beta')
ax1.scatter(beta_loc, beta_loc_bathc_nc, s = .5)
ax2.scatter([i for i in range(len(beta_loc))], beta_loc_bathc_nc / beta_loc, s = .5)

This file was deleted.

35 changes: 0 additions & 35 deletions inst/pydevil/pydevil/.ipynb_checkpoints/guide-checkpoint.py

This file was deleted.

Loading

0 comments on commit 7672904

Please sign in to comment.