-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from IlyaLab/main
update to the docs branch
- Loading branch information
Showing
4 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import anndata | ||
from gssnng.score_cells import _proc_data | ||
from gssnng.util import error_checking | ||
from typing import Union | ||
|
||
def smooth_anndata( | ||
adata: anndata.AnnData, | ||
groupby: Union[str, list, dict], | ||
smooth_mode: str, | ||
recompute_neighbors: int, | ||
method_params: dict, | ||
cores: int | ||
) -> anndata.AnnData: | ||
|
||
""" | ||
nearest neighbor smoothing of the expression matrix | ||
:param adata | ||
anndata.AnnData containing the cells to be scored | ||
:param groupby | ||
either a column label in adata.obs, and all categories taken, or a dict specifies one group. | ||
:param smooth_mode | ||
`adjacency` or `connectivity`, which representation of the neighborhood graph to use. | ||
`adjacency` weights all neighbors equally, `connectivity` weights close neighbors more | ||
:param recompute_neighbors | ||
should neighbors be recomputed within each group, 0 for no, >0 for yes and specifies N | ||
:param method_params | ||
specific params for each method. | ||
:param cores | ||
number of parallel processes to work through groupby groups | ||
:returns: a list of adatas with smoothed data | ||
""" | ||
|
||
return_data = 1 | ||
noise_trials = 0 ### not used currently | ||
samp_neighbors = None ### also not used | ||
just_smoothing=1 | ||
|
||
error_checking(adata, samp_neighbors, recompute_neighbors, | ||
None, None, None, method_params, just_smoothing) | ||
|
||
if method_params == None: | ||
method_params = dict() | ||
|
||
# score each cell with the list of gene sets | ||
data_list = _proc_data(adata, None, groupby, smooth_mode, recompute_neighbors, | ||
None, method_params, samp_neighbors, | ||
noise_trials, None, cores, return_data) | ||
|
||
print("**done**") | ||
return(data_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
if __name__ == '__main__': | ||
|
||
import scanpy as sc | ||
from gssnng.smooth_anndatas import smooth_anndata | ||
import time | ||
|
||
def test_return_smoothed(adata): | ||
res0 = smooth_anndata(adata=adata, | ||
groupby='louvain', | ||
smooth_mode='adjacency', | ||
recompute_neighbors=32, | ||
method_params={}, | ||
cores=4) | ||
return(res0) | ||
|
||
|
||
def test_score_all_sets(): | ||
q = sc.datasets.pbmc3k_processed() | ||
t0 = time.time() | ||
print('start time: ' + str(t0)) | ||
data_list = test_return_smoothed(q) | ||
print('******DONE*******') | ||
t1 = time.time() | ||
print('end time: ' + str(t1)) | ||
print('TOTAL TIME: ' + str(t1-t0)) | ||
print(len(data_list)) | ||
|
||
test_score_all_sets() | ||
print('test done') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters