smfishHmrf.hmrfem.multi.it: Perform HMRF for multivariate normal distribution. Accepts R...

Description Usage Arguments More information References Examples

View source: R/smfishHmrf.hmrfem.R

Description

This function performs HMRF model \insertCiteZhu2018smfishHmrf on inputs which are directly R data structures. Different from smfishHmrf.hmrfem.multi, this function iterates over multiple betas rather than a single beta. Different from smfishHmrf.hmrfem.multi.it.min, this function accepts R data structures (i.e. parameters y, nei, blocks) as inputs to the function rather than accepting file names. This function will save the results of HMRF to the output directory. It will return void.

This function exists for legacy and compatibility reason. User should use smfishHmrf.hmrfem.multi.it.min function.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
smfishHmrf.hmrfem.multi.it(
  name,
  outdir,
  k,
  y,
  nei,
  beta = 0,
  beta_increment = 1,
  beta_num_iter = 10,
  numnei,
  blocks,
  mu,
  sigma,
  damp
)

Arguments

name

name for this run (eg test)

outdir

output directory

k

number of clusters

y

gene expression matrix

nei

adjacency matrix between cells

beta

initial beta

beta_increment

beta increment

beta_num_iter

number of betas to try

numnei

a vector containing number of neighbors per cell

blocks

a list of cell colors for deciding the order of cell update

mu

a 2D matrix (i,j) of cluster mean (initialization)

sigma

a 3D matrix (i,j,k) where (i,j) is the covariance of cluster k (initialization)

damp

a list of dampening factors (length = k)

More information

Arguments mu and sigma refer to the cluster centroids from running kmeans algorithm. They serve as initialization of HMRF. Users should refer to smfishHmrf.hmrfem.multi.it.min for more information about function parameters and the requirements.

References

\insertRef

Zhu2018smfishHmrf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
y<-as.matrix(read.table(system.file("extdata", "ftest.expression.txt", 
    package="smfishHmrf"), header=FALSE, row.names=1))
nei<-as.matrix(read.table(system.file("extdata", "ftest.adjacency.txt", 
    package="smfishHmrf"), header=FALSE, row.names=1))
colnames(nei)<-NULL; rownames(nei)<-NULL
blocks<-c(t(read.table(system.file("extdata", "ftest.blocks.txt", 
    package="smfishHmrf"), header=FALSE, row.names=1)))
blocks<-lapply(1:max(blocks), function(x) which(blocks == x))
numnei<-apply(nei, 1, function(x) sum(x!=-1))
k<-9
kmeans_results = system.file("extdata", package="smfishHmrf")
kk = smfishHmrf.generate.centroid.use.exist(name="test", input_dir=kmeans_results, k)
numcell<-dim(y)[1]; m<-dim(y)[2]
mu<-t(kk$centers) #should be dimension (m,k)
lclust<-lapply(1:k, function(x) which(kk$cluster == x))
damp<-array(0, c(k)); sigma<-array(0, c(m,m,k))
for(i in 1:k){
    sigma[, , i] <- cov(y[lclust[[i]], ])
    di<-findDampFactor(sigma[,,i], factor=1.05, d_cutoff=1e-5, startValue=0.0001)
    damp[i]<-ifelse(is.null(di), 0, di)
} 
smfishHmrf.hmrfem.multi.it(name="test", outdir=tempdir(), k=k, y=y, nei=nei, 
    beta=28, beta_increment=2, beta_num_iter=1, numnei=numnei, blocks=blocks, 
    mu=mu, sigma=sigma, damp=damp)

## Not run: 
# alternatively, to test a larger set of betas:
smfishHmrf.hmrfem.multi.it(name="test", outdir=tempdir(), k=k, y=y, nei=nei, 
    beta=0, beta_increment=2, beta_num_iter=20, numnei=numnei, blocks=blocks, 
    mu=mu, sigma=sigma, damp=damp)

## End(Not run)

smfishHmrf documentation built on Jan. 13, 2021, 12:54 p.m.