Skip to content

Commit 1ed3cce

Browse files
Merge pull request #115 from theislab/development
Development
2 parents 9b6d3fb + f309341 commit 1ed3cce

File tree

12 files changed

+160
-43
lines changed

12 files changed

+160
-43
lines changed

.cookietemple.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ full_name: Anna Schaar
1515
1616
project_name: ncem
1717
project_short_description: ncem. Learning cell communication from spatial graphs of cells.
18-
version: 0.1.3
18+
version: 0.1.4
1919
license: BSD-3-Clause

.github/release-drafter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name-template: "0.1.3 🌈" # <<COOKIETEMPLE_FORCE_BUMP>>
2-
tag-template: 0.1.3 # <<COOKIETEMPLE_FORCE_BUMP>>
1+
name-template: "0.1.4 🌈" # <<COOKIETEMPLE_FORCE_BUMP>>
2+
tag-template: 0.1.4 # <<COOKIETEMPLE_FORCE_BUMP>>
33
categories:
44
- title: "🚀 Features"
55
labels:

.github/workflows/run_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
pip install rich
153153
154154
- name: Download coverage data
155-
uses: actions/download-artifact@v2.0.10
155+
uses: actions/download-artifact@v3.0.0
156156
with:
157157
name: coverage-data
158158

cookietemple.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.3
2+
current_version = 0.1.4
33

44
[bumpversion_files_whitelisted]
55
init_file = ncem/__init__.py

docs/conf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
intersphinx_mapping = dict(
4949
anndata=("https://anndata.readthedocs.io/en/latest/", None),
5050
scanpy=("https://scanpy.readthedocs.io/en/latest/", None),
51-
numpy=("https://docs.scipy.org/doc/numpy/", None),
52-
pandas=("http://pandas.pydata.org/pandas-docs/stable/", None),
53-
python=("https://docs.python.org/3", None),
54-
scipy=("https://docs.scipy.org/doc/scipy/reference/", None),
51+
#numpy=("https://docs.scipy.org/doc/numpy/", None),
52+
#pandas=("http://pandas.pydata.org/pandas-docs/stable/", None),
53+
#python=("https://docs.python.org/3", None),
54+
#scipy=("https://docs.scipy.org/doc/scipy/reference/", None),
5555
)
5656

5757
# Add any paths that contain templates here, relative to this directory.
@@ -73,9 +73,9 @@
7373
# the built documents.
7474
#
7575
# The short X.Y version.
76-
version = "0.1.3"
76+
version = "0.1.4"
7777
# The full version, including alpha/beta/rc tags.
78-
release = "0.1.3"
78+
release = "0.1.4"
7979

8080
# The language for content autogenerated by Sphinx. Refer to documentation
8181
# for a list of supported languages.

docs/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
ncem>=0.1.2
12
Sphinx>=4.0.1
23
sphinx_rtd_theme>=0.5.2
34
sphinx-rtd-dark-mode>=1.2.1
45
sphinx-automodapi>=0.13
56
sphinx_click>=3.0.0
6-
click>=8.0.1
7+
click>=7.1.2

ncem/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
__maintainer__ = ", ".join(["Anna C. Schaar", "David S. Fischer"])
99
__author__ = ", ".join(["Anna C. Schaar", "David S. Fischer"])
1010
__email__ = ", ".join(["[email protected]", "[email protected]"])
11-
__version__ = "0.1.3"
11+
__version__ = "0.1.4"

ncem/api/train/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Initializes a train object in api."""
2+
import numpy as np
23
from ncem.estimators import (Estimator, EstimatorCVAE, EstimatorCVAEncem,
34
EstimatorED, EstimatorEDncem, EstimatorEdNcemNeighborhood, EstimatorGraph,
45
EstimatorInteractions, EstimatorLinear,

ncem/data.py

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from tqdm import tqdm
2222

2323

24-
def get_data_custom(interpreter, n_eval_nodes_per_graph: int=10):
24+
def get_data_custom(interpreter, deconvolution: bool = False, n_eval_nodes_per_graph: int=10):
2525
interpreter.undefined_node_types = None
2626
interpreter.img_to_patient_dict = interpreter.data.celldata.uns["img_to_patient_dict"]
2727
interpreter.complete_img_keys = list(interpreter.data.img_celldata.keys())
@@ -64,8 +64,10 @@ def get_data_custom(interpreter, n_eval_nodes_per_graph: int=10):
6464
interpreter.split_data_node(0.1, 0.1)
6565
interpreter.n_eval_nodes_per_graph = n_eval_nodes_per_graph
6666
interpreter.cell_names = list(interpreter.data.celldata.uns['node_type_names'].values())
67+
if deconvolution:
68+
interpreter.proportions = {k: adata.obsm["proportions"] for k, adata in interpreter.data.img_celldata.items()}
69+
6770

68-
6971
class GraphTools:
7072
"""GraphTools class."""
7173

@@ -1921,6 +1923,109 @@ def _register_graph_features(self, label_selection):
19211923
}
19221924
self.celldata.uns["graph_covariates"] = graph_covariates
19231925

1926+
1927+
class customLoaderDeconvolution(DataLoader):
1928+
1929+
def __init__(
1930+
self,
1931+
adata,
1932+
patient,
1933+
library_id,
1934+
radius,
1935+
coord_type='generic',
1936+
n_rings=1,
1937+
n_top_genes=None,
1938+
label_selection=None
1939+
):
1940+
self.adata = adata.copy()
1941+
self.patient = patient
1942+
self.library_id = library_id
1943+
1944+
print("Loading data from raw files")
1945+
self.register_celldata(n_top_genes=n_top_genes)
1946+
self.register_img_celldata()
1947+
self.register_graph_features(label_selection=label_selection)
1948+
self.compute_adjacency_matrices(radius=radius, coord_type=coord_type, n_rings=n_rings)
1949+
self.radius = radius
1950+
1951+
print(
1952+
"Loaded %i images with complete data from %i patients "
1953+
"over %i cells with %i cell features and %i distinct celltypes."
1954+
% (
1955+
len(self.img_celldata),
1956+
len(self.patients),
1957+
self.celldata.shape[0],
1958+
self.celldata.shape[1],
1959+
len(self.celldata.uns["node_type_names"]),
1960+
)
1961+
)
1962+
1963+
def _register_celldata(self, n_top_genes):
1964+
1965+
metadata = {
1966+
#"cluster_col_preprocessed": self.cluster,
1967+
"image_col": self.library_id
1968+
}
1969+
1970+
celldata = self.adata.copy()
1971+
celldata.uns["metadata"] = metadata
1972+
1973+
if self.patient:
1974+
img_to_patient_dict = {}
1975+
for p in np.unique(celldata.obs[self.patient]):
1976+
for i in np.unique(celldata.obs[celldata.obs[self.patient] == p][self.library_id]):
1977+
img_to_patient_dict[i] = p
1978+
else:
1979+
if self.library_id:
1980+
img_to_patient_dict = {}
1981+
for img in np.unique(celldata.obs[self.library_id]):
1982+
img_to_patient_dict[str(img)] = "patient"
1983+
else:
1984+
img_to_patient_dict = {"image": "patient"}
1985+
celldata.uns["img_to_patient_dict"] = img_to_patient_dict
1986+
self.img_to_patient_dict = img_to_patient_dict
1987+
1988+
self.celldata = celldata
1989+
1990+
def _register_img_celldata(self):
1991+
"""Load dictionary of of image-wise celldata objects with {imgage key : anndata object of image}."""
1992+
img_celldata = {}
1993+
if self.library_id:
1994+
for k in np.unique(self.celldata.obs[self.library_id]):
1995+
img_celldata[str(k)] = self.celldata[self.celldata.obs[self.library_id] == k].copy()
1996+
self.img_celldata = img_celldata
1997+
else:
1998+
self.img_celldata = {"image": self.celldata}
1999+
2000+
def _register_graph_features(self, label_selection):
2001+
"""Load graph level covariates.
2002+
2003+
Parameters
2004+
----------
2005+
label_selection
2006+
Label selection.
2007+
"""
2008+
# Save processed data to attributes.
2009+
for adata in self.img_celldata.values():
2010+
graph_covariates = {
2011+
"label_names": {},
2012+
"label_tensors": {},
2013+
"label_selection": [],
2014+
"continuous_mean": {},
2015+
"continuous_std": {},
2016+
"label_data_types": {},
2017+
}
2018+
adata.uns["graph_covariates"] = graph_covariates
2019+
2020+
graph_covariates = {
2021+
"label_names": {},
2022+
"label_selection": [],
2023+
"continuous_mean": {},
2024+
"continuous_std": {},
2025+
"label_data_types": {},
2026+
}
2027+
self.celldata.uns["graph_covariates"] = graph_covariates
2028+
19242029

19252030
class DataLoaderZhang(DataLoader):
19262031
"""DataLoaderZhang class. Inherits all functions from DataLoader."""

ncem/interpretation/interpreter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ def get_sender_receiver_effects(
19381938
interaction_shape = np.int(self.n_features_0**2)
19391939
interactions = np.asarray(dmatrix("target:proportions-1", data))
19401940

1941-
y = self.data.celldata.X[self.nodes_idx_all['1'],:]
1941+
y = self.data.celldata.X
19421942

19431943
print('using ols parameters.')
19441944
if params_type == 'ols':

0 commit comments

Comments
 (0)