Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format and docstring edits for spatial modules #144

Merged
merged 2 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dance/modules/spatial/cell_type_deconvo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

__all__ = [
"Card",
"DSTGLearner",
"DSTG",
"SpatialDecon",
"SPOTlight",
]
53 changes: 27 additions & 26 deletions dance/modules/spatial/cell_type_deconvo/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,36 @@ def CARDref(Xinput, U, W, phi, max_iter, epsilon, V, b, sigma_e2, Lambda):


class Card:
"""The CARD cell-type deconvolution model.

Parameters
----------
sc_count : pd.DataFrame
Reference single cell RNA-seq counts data.
sc_meta : pd.DataFrame
Reference cell-type label information.
ct_varname : str, optional
Name of the cell-types column.
ct_select : str, optional
Selected cell-types to be considered for deconvolution.
cell_varname : str, optional
Name of the cells column.
sample_varname : str, optional
Name of the samples column.
minCountGene : int
Minimum number of genes required.
minCountSpot : int
Minimum number of spots required.
basis
The basis parameter.
markers
Markers.

"""
"""The CARD cell-type deconvolution model."""

def __init__(self, sc_count, sc_meta, ct_varname=None, ct_select=None, cell_varname=None, sample_varname=None,
minCountGene=100, minCountSpot=5, basis=None, markers=None):
"""Initialize Card.

Parameters
----------
sc_count : pd.DataFrame
Reference single cell RNA-seq counts data.
sc_meta : pd.DataFrame
Reference cell-type label information.
ct_varname : str, optional
Name of the cell-types column.
ct_select : str, optional
Selected cell-types to be considered for deconvolution.
cell_varname : str, optional
Name of the cells column.
sample_varname : str, optional
Name of the samples column.
minCountGene : int
Minimum number of genes required.
minCountSpot : int
Minimum number of spots required.
basis
The basis parameter.
markers
Markers.

"""
self.sc_count = sc_count
self.sc_meta = sc_meta
self.ct_varname = ct_varname
Expand Down
49 changes: 25 additions & 24 deletions dance/modules/spatial/cell_type_deconvo/spatialdecon.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,32 @@ def cell_topic_profile(X, groups, ct_select, axis=0, method='median'):


class SpatialDecon:
"""SpatialDecon.

Parameters
----------
sc_count : pd.DataFrame
Reference single cell RNA-seq counts data.
sc_annot : pd.DataFrame
Reference cell-type label information.
mix_count : pd.DataFrame
Target mixed-cell RNA-seq counts data to be deconvoluted.
ct_varname : str, optional
Name of the cell-types column.
ct_select : str, optional
Selected cell-types to be considered for deconvolution.
sc_profile: numpy array optional
Pre-constructed cell profile matrix.
bias : boolean optional
Include bias term, default False.
init_bias: numpy array optional
Initial bias term (background estimate).

"""
"""SpatialDecon."""

def __init__(self, sc_count, sc_annot, ct_varname, ct_select, sc_profile=None, bias=False, init_bias=None,
device="cpu"):
"""Initialize SpatialDecon.

Parameters
----------
sc_count : pd.DataFrame
Reference single cell RNA-seq counts data.
sc_annot : pd.DataFrame
Reference cell-type label information.
mix_count : pd.DataFrame
Target mixed-cell RNA-seq counts data to be deconvoluted.
ct_varname : str, optional
Name of the cell-types column.
ct_select : str, optional
Selected cell-types to be considered for deconvolution.
sc_profile: numpy array optional
Pre-constructed cell profile matrix.
bias : boolean optional
Include bias term, default False.
init_bias: numpy array optional
Initial bias term (background estimate).

"""
super().__init__()

self.device = device
Expand Down Expand Up @@ -199,9 +200,9 @@ def score(self, pred, true):

Parameters
----------
pred :
pred
Predicted cell-type proportions.
true :
true
True cell-type proportions.

Returns
Expand Down
76 changes: 39 additions & 37 deletions dance/modules/spatial/cell_type_deconvo/spotlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@ def cell_topic_profile(x, groups, ct_select, axis=0, method="median"):


class NNLS(nn.Module):
"""NNLS.
"""NNLS."""

Parameters
----------
in_dim : int
Input dimension.
out_dim : int
Output dimension.
bias : bool
Include bias term, default False.
def __init__(self, in_dim, out_dim, bias=False, init_bias=None, device="cpu"):
"""Initialize NNLS.

"""
Parameters
----------
in_dim : int
Input dimension.
out_dim : int
Output dimension.
bias : bool
Include bias term, default False.

def __init__(self, in_dim, out_dim, bias=False, init_bias=None, device="cpu"):
"""
super().__init__()
self.device = device
self.model = nn.Linear(in_features=in_dim, out_features=out_dim, bias=bias)
Expand Down Expand Up @@ -116,35 +117,36 @@ def fit(self, x, y, max_iter, lr, print_res=False, print_period=100):


class SPOTlight:
"""SPOTlight class.

Parameters
----------
ref_count : pd.DataFrame
Reference single cell RNA-seq counts data (cell x gene).
ref_annot : pd.DataFrame
Reference cell-type label information.
mix_count : pd.DataFrame
Target mixed-cell RNA-seq counts data to be deconvoluted.
ct_varname : str
Name of the cell-types column.
ct_select : str
Selected cell-types to be considered for deconvolution.
rank : int
Rank of the matrix factorization.
sc_profile: np.ndarray
Pre-constructed cell profile matrix.
bias : bool
Include bias term, default False.
init_bias: np.ndarray
Initial bias term (background estimate).
init : str
Initialization method for matrix factorization solver (see NMF from sklearn).

"""
"""SPOTlight."""

def __init__(self, ref_count, ref_annot, ct_varname, ct_select, rank=2, sc_profile=None, bias=False, init_bias=None,
init="random", device="cpu"):
"""Initialize SPOTlight.

Parameters
----------
ref_count : pd.DataFrame
Reference single cell RNA-seq counts data (cell x gene).
ref_annot : pd.DataFrame
Reference cell-type label information.
mix_count : pd.DataFrame
Target mixed-cell RNA-seq counts data to be deconvoluted.
ct_varname : str
Name of the cell-types column.
ct_select : str
Selected cell-types to be considered for deconvolution.
rank : int
Rank of the matrix factorization.
sc_profile: np.ndarray
Pre-constructed cell profile matrix.
bias : bool
Include bias term, default False.
init_bias: np.ndarray
Initial bias term (background estimate).
init : str
Initialization method for matrix factorization solver (see NMF from sklearn).

"""
super().__init__()
self.device = device
self.bias = bias
Expand Down
44 changes: 18 additions & 26 deletions dance/modules/spatial/spatial_domain/louvain.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def modularity(partition, graph, weight="weight"):
and values the communities
graph : networkx.Graph
the networkx graph which is decomposed
weight : str, optional
weight : str
the key in graph to use as weight. Default to "weight"


Expand Down Expand Up @@ -245,20 +245,20 @@ def best_partition(graph, partition=None, weight="weight", resolution=1., random
----------
graph : networkx.Graph
the networkx graph which is decomposed
partition : dict, optional
partition : dict
the algorithm will start using this partition of the nodes.
It's a dictionary where keys are their nodes and values the communities
weight : str, optional
weight : str
the key in graph to use as weight. Default to "weight"
resolution : double, optional
resolution : double
Will change the size of the communities, default to 1.
represents the time described in
"Laplacian Dynamics and Multiscale Modular Structure in Networks",
R. Lambiotte, J.-C. Delvenne, M. Barahona
randomize : boolean, optional
randomize : boolean
Will randomize the node evaluation order and the community evaluation
order to get different partitions at each call
random_state : int, RandomState instance or None, optional (default=None)
random_state : int, RandomState instance or None
If int, random_state is the seed used by the random number generator;
If RandomState instance, random_state is the random number generator;
If None, the random number generator is the RandomState instance used
Expand Down Expand Up @@ -335,21 +335,21 @@ def __init__(self, resolution: float = 1):
self.resolution = resolution

def fit(self, adj, partition=None, weight="weight", randomize=None, random_state=None):
"""fit function for model training.
"""Fit function for model training.

Parameters
----------
adj :
adjacent matrix.
partition : dict optional
partition : dict
a dictionary where keys are graph nodes and values the part the node
belongs to
weight : str, optional
weight : str
the key in graph to use as weight. Default to "weight"
randomize : boolean, optional
randomize : boolean
Will randomize the node evaluation order and the community evaluation
order to get different partitions at each call
random_state : int, RandomState instance or None, optional (default=None)
random_state : int, RandomState instance or None
If int, random_state is the seed used by the random number generator;
If RandomState instance, random_state is the random number generator;
If None, the random number generator is the RandomState instance used
Expand All @@ -368,31 +368,23 @@ def fit(self, adj, partition=None, weight="weight", randomize=None, random_state
print("fit over ")

def predict(self):
"""prediction function.
Parameters
----------

Returns
-------
self.predict_result :
predicted label.

"""
"""Prediction function."""
self.predict_result = partition_at_level(self.dendo, len(self.dendo) - 1)
self.y_pred = self.predict_result
return self.predict_result

def score(self, y_true):
"""score function to get score of prediction.
"""Score function to evaluate the prediction performance.

Parameters
----------
y_true :
ground truth label.
y_true
Ground truth label.

Returns
-------
score : float
metric eval score.
float
Evaluation score.

"""
pred_val = []
Expand Down
Loading