Skip to content

Commit

Permalink
Added python changes to pass arguments for rse
Browse files Browse the repository at this point in the history
  • Loading branch information
cboix committed Apr 14, 2024
1 parent 06d0228 commit fed439f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 7 additions & 1 deletion notebooks/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@
mod.setup() # Setup the object

# For testing graph construction:
# mod.make_graph('rse', method='robust_se')
mod.make_graph('rse', method='robust_se', t_cutoff=4.5, scale=0.75)
graph_id = 'rse'
pl.plot_genes(mod, graph_id, attr="leiden", show_labels=True, width=16)
pl.plot_heatmap_avgexpr(mod, graph_id, cvlist=['leiden'], attr="leiden")
pl.plot_umap_grid(mod, graph_id)


# mod.make_graph('merge', multigraph=True, power=[0,.5,1])
# mod.make_graph('raw', raw=True)
# mod.make_graph('subset', filter_covariate="leiden")
Expand Down
18 changes: 9 additions & 9 deletions scdemon/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def _calculate_covariate_lengths(self):
# TODO: allow passing abs_t and t_cutoff to this function
def _calculate_correlation(self,
indices=None, center=False, power=0,
raw=False, robust_se=False):
raw=False, robust_se=False, t_cutoff=6.5):
"""
Calculate the correlation between the genes.
---
Expand All @@ -266,7 +266,6 @@ def _calculate_correlation(self,
# TODO: add function wrapper that handles indices and power!
# TODO: allow using harmony instead of PCA
# TODO: Separate out the robust_se from the batch correction
t_cutoff = 35
adjacency = robust_se_default(
U=self.U @ np.diag(self.s), V=self.V, B=None,
t_cutoff=t_cutoff, abs_t=True)
Expand Down Expand Up @@ -335,6 +334,7 @@ def _make_single_graph(self, graph_id,
full_graph_only=False,
keep_all_z=False,
layout=True,
t_cutoff=6.5,
**kwargs):
# 3. Select which PCs to keep:
indices = self._select_PCs(filter_covariate=filter_covariate)
Expand All @@ -344,8 +344,8 @@ def _make_single_graph(self, graph_id,
# Options for constructing correlation
indices=indices, power=power, raw=raw,
# Options for thresholding methods:
method=method,
**kwargs)
method=method, t_cutoff=t_cutoff,
**kwargs) # TODO: how to separate out kwargs for this vs. below

# Make graph with adjacency instead of correlation:
self._make_single_graph_object(graph_id, corr=corr, adj=adj, **kwargs)
Expand All @@ -369,7 +369,7 @@ def _construct_adjacency_matrix(self,
# Options for correlation:
indices=None, power=0, raw=False,
# Options for thresholding method:
method='bivariate',
method='bivariate', t_cutoff=6.5,
# TODO: Add adjacency options here:
**kwargs):
"""
Expand All @@ -381,7 +381,8 @@ def _construct_adjacency_matrix(self,
# 4. Calculate the correlation:
robust_se = (method == 'robust_se')
corr, adjacency = self._calculate_correlation(
indices=indices, power=power, raw=raw, robust_se=robust_se)
indices=indices, power=power, raw=raw,
robust_se=robust_se, t_cutoff=t_cutoff)
# sd calculation if needed, but robust_se is highly preferable:
if method == 'sd' and not raw:
# TODO: update function to use correct indices and power!
Expand All @@ -404,9 +405,8 @@ def _construct_adjacency_matrix(self,
# TODO: Simplify inheritance of kwargs params:
def _make_single_graph_object(self, graph_id, corr,
adj=None, graph=None, # Either one needed
edge_weight=None,
min_size=4,
layout_method="fr"):
edge_weight=None, min_size=4,
layout_method="fr", **kwargs):
self.graphs[graph_id] = gene_graph(corr, adj=adj,
graph=graph,
genes=self.genes,
Expand Down

0 comments on commit fed439f

Please sign in to comment.