Skip to content

Commit

Permalink
add_dics
Browse files Browse the repository at this point in the history
  • Loading branch information
robinredX committed Jan 15, 2024
1 parent a058c88 commit e8e9cb3
Show file tree
Hide file tree
Showing 12 changed files with 11,080 additions and 3,113 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**/*/tutorial_bulkRNAseq
**/*/tutorial_spatial
**/*/tutorial_tldr
**/*/experiment*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
5,174 changes: 2,371 additions & 2,803 deletions dissect/PropsSimulator/simulator.c

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions dissect/PropsSimulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def generate_props(self):
if not self.config["simulation_params"]["n_samples"]:
self.config["simulation_params"]["n_samples"] = 1000 * self.n_celltypes
if not self.config["simulation_params"]["cells_per_sample"]:
self.config["simulation_params"]["cells_per_sample"] = 1000
self.config["simulation_params"]["cells_per_sample"] = 100
self.n_sparse = int(self.config["simulation_params"]["n_samples"] * self.config["simulation_params"]["prop_sparse"])
self.n_complete = self.config["simulation_params"]["n_samples"] - self.n_sparse

Expand Down Expand Up @@ -111,13 +111,13 @@ def generate_props(self):
plt.savefig(
os.path.join(self.simulation_folder, "boxplot_props_complete.pdf")
)
fig = plt.figure()
ax = plt.boxplot(self.cells_complete, labels=self.celltypes)
plt.ylabel("Count")
plt.title("Counts of cell-types in generated samples")
plt.savefig(
os.path.join(self.simulation_folder, "boxplot_ncells_complete.pdf")
)
# fig = plt.figure()
# ax = plt.boxplot(self.cells_complete, labels=self.celltypes)
# plt.ylabel("Count")
# plt.title("Counts of cell-types in generated samples")
# plt.savefig(
# os.path.join(self.simulation_folder, "boxplot_ncells_complete.pdf")
# )

# fig = plt.figure()
# ax = plt.boxplot(self.props_sparse, labels=self.celltypes) #
Expand Down Expand Up @@ -610,10 +610,10 @@ def simulate(config):
else:
sim.simulate(save=True)
else:
print("Number of batches in single-cell data is 1.")
print("Number of batches in single-cell data is 1. If this is incorrect, please specify name of the batch column as in the single-cell data object (.obs)")
sim.simulate(save=True)
sim.config["simulation_params"]["simulation_folder"] = os.path.join(sim.config["experiment_folder"], "simulation")
sim.config["simulation_params"]["concentration"] = list(sim.config["simulation_params"]["concentration"])
sim.config["deconv_params"]["reference"] = os.path.join(sim.config["simulation_params"]["simulation_folder"], "simulated.h5ad")
save_dict_to_file(sim.config)


2 changes: 1 addition & 1 deletion dissect/PropsSimulator/simulator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def simulate(config):
else:
sim.simulate(save=True)
else:
print("Number of batches in single-cell data is 1.")
print("Number of batches in single-cell data is 1. If this is incorrect, please specify name of the batch column as in the single-cell data object (.obs)")
sim.simulate(save=True)
sim.config["simulation_params"]["simulation_folder"] = os.path.join(sim.config["experiment_folder"], "simulation")
sim.config["simulation_params"]["concentration"] = list(sim.config["simulation_params"]["concentration"])
Expand Down
16 changes: 12 additions & 4 deletions dissect/deconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
from dissect.dissect_expr import run_dissect_expr

def run_dissect(config):
simulate(config)
dataset(config)
run_dissect_frac(config)
run_dissect_expr(config)
print("\033[1mStarting simulations\033[0m")
simulate(config)
print("-----\n")

print("\033[1mPreprocessing datasets\033[0m")
dataset(config)
print("-----\n")
print("\033[1mEstimating cell type fractions\033[0m")
run_dissect_frac(config)
print("-----\n")
print("\033[1mEstimating cell type-specific gene expression per sample\033[0m")
run_dissect_expr(config)
3 changes: 2 additions & 1 deletion dissect/dissect_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@


def run_dissect_expr(config):
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
test_format = config["deconv_params"]["test_dataset_format"]
real_path = config["deconv_params"]["test_dataset"]

Expand Down Expand Up @@ -449,4 +450,4 @@ def call(self, inputs, labels):

if __name__ == "__main__":
from configs.main_config import config
run_dissect_expr(config)
run_dissect_expr(config)
14 changes: 8 additions & 6 deletions dissect/dissect_frac.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import random
from dissect.utils.utils_fn import normalize_per_batch, reproducibility, ccc_fn
from sklearn.metrics import mean_squared_error

import logging

def run_dissect_frac(config):
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
logging.getLogger('tensorflow').setLevel(logging.FATAL)
dataset_path = os.path.join(config["experiment_folder"], "datasets")
if not os.path.exists(dataset_path):
sys.exit(
Expand Down Expand Up @@ -216,7 +218,7 @@ def run_dissect_frac(config):

model_p = tf.keras.models.load_model(model_path)

print("Running deconvolution")
# print("Running deconvolution")
y_hat = model_p.predict(normalize_per_batch(X_real_test, n_features))
df_y_hat = pd.DataFrame(y_hat, columns=celltypes)
df_y_hat.index = sample_names
Expand All @@ -234,7 +236,7 @@ def run_dissect_frac(config):
# df_metrics.to_csv(os.path.join(config["experiment_folder"], "per_step_metrics_{}.txt".format(j)),
# sep="\t")

print("Estimated proportions are saved at {}.".format(results_path))
# print("Estimated proportions are saved at {}.".format(results_path))
if i < 5:
print("Starting training model {}".format(i))
j += 1
Expand All @@ -243,7 +245,7 @@ def run_dissect_frac(config):
experiment_path = os.path.join(config["experiment_folder"])

i = 0
for i in range(len(config["models"])):
for i in range(len(config["deconv_params"]["models"])):
df_curr = pd.read_table(
os.path.join(
config["experiment_folder"], "dissect_fractions_{}.txt".format(i)
Expand All @@ -254,9 +256,9 @@ def run_dissect_frac(config):
df_ens = df_curr
else:
df_ens = df_ens + df_curr
df_ens = df_ens / len(config["models"])
df_ens = df_ens / len(config["deconv_params"]["models"])
savepath = os.path.join(config["experiment_folder"], "dissect_fractions.txt")
print("Final predictions are saved to {}".format(savepath))
print("Predictions are saved to {}".format(savepath))
df_ens.to_csv(savepath, sep="\t")

if __name__ == "__main__":
Expand Down
19 changes: 19 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DISSECT v0.1.1</title>
</head>
<body>
<h1>DISSECT v0.1.1</h1>
<nav>
<ul>
<li><a href="installation.md">Installation</a></li>
<!--- <li><a href="expanded_tutorial.html">Step by step tutorial</a></li> -->
<li><a href="minimal_tutorial.html">Minimal tutorial</a></li>
</ul>
</nav>
</body>
</html>

37 changes: 37 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# DISSECT

DISSECT is a deep semi-supervised learning framework that performs complete deconvolution of gene expression mixtures such as bulk RNAseq, proteomics and spatial transcriptomics

## Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. Folder tutorials include notebooks to get started.

## Prerequisites

conda >= v22 through [Anaconda](https://docs.anaconda.com/free/anaconda/install/index.html) or [miniconda](https://docs.conda.io/projects/miniconda/en/latest/miniconda-install.html).


## Installing
```
## Installation
# Create and activate virtual environment
conda create -y -n dissect python=3.8
conda activate dissect
# Clone DISSECT
git clone https://github.com/imsb-uke/DISSECT
# Install dependencies and DISSECT
pip install -r DISSECT/requirements.txt --use-deprecated=legacy-resolver
pip install DISSECT/.
# Install jupyter lab
conda install -y jupyter
## Tutorials to get started
# Go to tutorials directory within DISSECT
cd DISSECT/tutorials
```
Loading

0 comments on commit e8e9cb3

Please sign in to comment.