a function to determine statistically trait-enriched cell by permutation test.

get_sigcell_simple(
  knn_sparse_mat,
  seed_idx,
  topseed_npscore,
  permutation_times = 1000,
  true_cell_significance = 0.05,
  rda_output = FALSE,
  out_rda = tempfile(fileext = "true_cell_df.rda"),
  mycores = 1,
  rw_gamma = 0.05
)

Arguments

knn_sparse_mat

a sparse matrix used for network propagation, which indicates the adjacent matrix (m x m, where m is the cell number) of cell-to-cell network (M-kNN graph)

seed_idx

a logical vector indicating seed cells (TRUE) and non-seed cells (FALSE) with length of m, where m is the cell number. The length and position are corresponding to knn_sparse_mat

topseed_npscore

a numeric vector of real network propagation score

permutation_times

an integer describe times of permutation test for each cell

true_cell_significance

a numeric value between 0-1 indicating the significant threshold used to determine statistically trait-enriched cell

rda_output

if output details of each permutation as a rda

out_rda

if rda_output=T, an rda will be outputed with path and name specified

mycores

how many cores used for permutation test

rw_gamma

gamma from randomWalk_sparse function. Keep the same with what you used in the real setting

Value

A dataframe with two columns, the first one is seed index (the same with input), the second one is significance from permutation test. In addition, an R data is generated, which contains this dataframe and another dataframe depicting the network propagation score for each cell at each permuation.

Examples

knn_sparse_mat <- example_results$mutualknn30
mono_mat <- example_results$mono_mat
ture_cell_df <- get_sigcell_simple(knn_sparse_mat=knn_sparse_mat,
                                   seed_idx=mono_mat$seed_idx,
                                   topseed_npscore=mono_mat$np_score,
                                   permutation_times=100)
#> Get started!
#> Stationary step: 92
#> Stationary Delta: 9.45632919118456e-06
#> Stationary step: 93
#> Stationary Delta: 9.71290384588767e-06
#> Stationary step: 90
#> Stationary Delta: 9.48199274814611e-06
#> Stationary step: 90
#> Stationary Delta: 9.97175177467018e-06
#> Stationary step: 91
#> Stationary Delta: 9.98759110632374e-06
#> Stationary step: 90
#> Stationary Delta: 9.46852338952327e-06
#> Stationary step: 87
#> Stationary Delta: 9.41144355949104e-06
#> Stationary step: 89
#> Stationary Delta: 9.37255968110855e-06
#> Stationary step: 92
#> Stationary Delta: 9.59316775090101e-06
#> Stationary step: 88
#> Stationary Delta: 9.8640259330918e-06
#> Stationary step: 89
#> Stationary Delta: 9.9262707946485e-06
#> Stationary step: 90
#> Stationary Delta: 9.56951869897007e-06
#> Stationary step: 87
#> Stationary Delta: 9.49154371777896e-06
#> Stationary step: 85
#> Stationary Delta: 9.41875924167909e-06
#> Stationary step: 87
#> Stationary Delta: 9.80855434464696e-06
#> Stationary step: 90
#> Stationary Delta: 9.48188599976491e-06
#> Stationary step: 89
#> Stationary Delta: 9.67477317218308e-06
#> Stationary step: 89
#> Stationary Delta: 9.54285967277709e-06
#> Stationary step: 85
#> Stationary Delta: 9.97084310225345e-06
#> Stationary step: 90
#> Stationary Delta: 9.53401380447074e-06
#> Stationary step: 88
#> Stationary Delta: 9.44684620642019e-06
#> Stationary step: 88
#> Stationary Delta: 9.95569627806256e-06
#> Stationary step: 86
#> Stationary Delta: 9.96985765201148e-06
#> Stationary step: 86
#> Stationary Delta: 9.70490363209244e-06
#> Stationary step: 88
#> Stationary Delta: 9.90200449757346e-06
#> Stationary step: 92
#> Stationary Delta: 9.3483761374772e-06
#> Stationary step: 91
#> Stationary Delta: 9.93034564453803e-06
#> Stationary step: 91
#> Stationary Delta: 9.44076056869193e-06
#> Stationary step: 91
#> Stationary Delta: 9.97419716126154e-06
#> Stationary step: 89
#> Stationary Delta: 9.55677705281597e-06
#> Stationary step: 87
#> Stationary Delta: 9.99781434085317e-06
#> Stationary step: 86
#> Stationary Delta: 9.82107216134682e-06
#> Stationary step: 90
#> Stationary Delta: 9.60657507029344e-06
#> Stationary step: 87
#> Stationary Delta: 9.55756693944863e-06
#> Stationary step: 86
#> Stationary Delta: 9.78404693544706e-06
#> Stationary step: 90
#> Stationary Delta: 9.3965602085074e-06
#> Stationary step: 87
#> Stationary Delta: 9.66028720502431e-06
#> Stationary step: 85
#> Stationary Delta: 9.57072750603428e-06
#> Stationary step: 90
#> Stationary Delta: 9.40052111477878e-06
#> Stationary step: 84
#> Stationary Delta: 9.99039382107494e-06
#> Stationary step: 89
#> Stationary Delta: 9.91982469832219e-06
#> Stationary step: 90
#> Stationary Delta: 9.30197567994223e-06
#> Stationary step: 88
#> Stationary Delta: 9.62557109531391e-06
#> Stationary step: 91
#> Stationary Delta: 9.98665041749028e-06
#> Stationary step: 92
#> Stationary Delta: 9.7273031701608e-06
#> Stationary step: 86
#> Stationary Delta: 9.85574164270798e-06
#> Stationary step: 92
#> Stationary Delta: 9.87135666443036e-06
#> Stationary step: 91
#> Stationary Delta: 9.39812463063808e-06
#> Stationary step: 90
#> Stationary Delta: 9.71360615088011e-06
#> Stationary step: 86
#> Stationary Delta: 9.9421170654968e-06
#> Stationary step: 84
#> Stationary Delta: 9.59832477199909e-06
#> Stationary step: 93
#> Stationary Delta: 9.70556357684714e-06
#> Stationary step: 89
#> Stationary Delta: 9.91233626645347e-06
#> Stationary step: 91
#> Stationary Delta: 9.73000908726349e-06
#> Stationary step: 90
#> Stationary Delta: 9.58407162319895e-06
#> Stationary step: 90
#> Stationary Delta: 9.44888726600745e-06
#> Stationary step: 89
#> Stationary Delta: 9.82027052053869e-06
#> Stationary step: 91
#> Stationary Delta: 9.69437299473405e-06
#> Stationary step: 84
#> Stationary Delta: 9.36874472504733e-06
#> Stationary step: 88
#> Stationary Delta: 9.89171408898114e-06
#> Stationary step: 90
#> Stationary Delta: 9.79715435915764e-06
#> Stationary step: 90
#> Stationary Delta: 9.72891640775495e-06
#> Stationary step: 89
#> Stationary Delta: 9.61268997237085e-06
#> Stationary step: 89
#> Stationary Delta: 9.61074664350517e-06
#> Stationary step: 91
#> Stationary Delta: 9.78578551260486e-06
#> Stationary step: 90
#> Stationary Delta: 9.3881224671878e-06
#> Stationary step: 88
#> Stationary Delta: 9.93678661053265e-06
#> Stationary step: 91
#> Stationary Delta: 9.83234866126217e-06
#> Stationary step: 87
#> Stationary Delta: 9.52291724353064e-06
#> Stationary step: 85
#> Stationary Delta: 9.9379077392915e-06
#> Stationary step: 92
#> Stationary Delta: 9.46571542865881e-06
#> Stationary step: 87
#> Stationary Delta: 9.73872727662524e-06
#> Stationary step: 92
#> Stationary Delta: 9.60856999652232e-06
#> Stationary step: 89
#> Stationary Delta: 9.41878050409961e-06
#> Stationary step: 88
#> Stationary Delta: 9.32775127743112e-06
#> Stationary step: 88
#> Stationary Delta: 9.79672334690214e-06
#> Stationary step: 88
#> Stationary Delta: 9.92893961585693e-06
#> Stationary step: 91
#> Stationary Delta: 9.55729371029184e-06
#> Stationary step: 87
#> Stationary Delta: 9.63326979925932e-06
#> Stationary step: 81
#> Stationary Delta: 9.92622940615314e-06
#> Stationary step: 91
#> Stationary Delta: 9.50012592941941e-06
#> Stationary step: 89
#> Stationary Delta: 9.39458695894055e-06
#> Stationary step: 87
#> Stationary Delta: 9.57015356226691e-06
#> Stationary step: 86
#> Stationary Delta: 9.41907152739605e-06
#> Stationary step: 87
#> Stationary Delta: 9.6133379056049e-06
#> Stationary step: 90
#> Stationary Delta: 9.96566683299764e-06
#> Stationary step: 84
#> Stationary Delta: 9.99754255960383e-06
#> Stationary step: 89
#> Stationary Delta: 9.79312918613006e-06
#> Stationary step: 89
#> Stationary Delta: 9.45195197150962e-06
#> Stationary step: 89
#> Stationary Delta: 9.71088698958359e-06
#> Stationary step: 85
#> Stationary Delta: 9.60711397078585e-06
#> Stationary step: 90
#> Stationary Delta: 9.42835264614969e-06
#> Stationary step: 91
#> Stationary Delta: 9.44300730061616e-06
#> Stationary step: 88
#> Stationary Delta: 9.94719366785684e-06
#> Stationary step: 91
#> Stationary Delta: 9.67390147933832e-06
#> Stationary step: 83
#> Stationary Delta: 9.6378585792759e-06
#> Stationary step: 89
#> Stationary Delta: 9.45965914829667e-06
#> Stationary step: 88
#> Stationary Delta: 9.40014867204744e-06
#> Stationary step: 87
#> Stationary Delta: 9.79382582674249e-06
#> Stationary step: 89
#> Stationary Delta: 9.35692890973818e-06
#> 100
#> cells passed 0.001 threshold: 13.28%
#> cells passed 0.01 threshold: 16.77%
#> cells passed 0.05 threshold: 26.39%
#> your emprical P value threshold: 0.05
#> what propertion of enriched cells over all cells: 26.39%
#> what propertion of seed cells that are enriched cells: 98.25%
#> fold of true cell over seed: 5.25