-
Notifications
You must be signed in to change notification settings - Fork 18
/
biclust.R
executable file
·57 lines (41 loc) · 1.54 KB
/
biclust.R
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Detect biclusters
library(biclust)
# Generate random example data matrix
set.seed(233452)
cmat <- matrix(rnorm(600), 20, 30)
cmat[2:4, 3:6] <- 10 # artifical bicluster
rownames(cmat) <- paste0("Sample", 1:nrow(cmat))
colnames(cmat) <- paste0("Feature", 1:ncol(cmat))
bc <- biclust(cmat, method=BCPlaid(), fit.model = y ~ m,
background = TRUE, shuffle = 100, back.fit = 0, max.layers = 10,
iter.startup = 10, iter.layer = 100, verbose = TRUE)
# y ~ m + a + b
# Investigate biclusters
bicluster.list <- list()
if (bc@Number>0) {
for (bci in seq(bc@Number)) {
# Row and col inds for the bci'th bicluster
rinds <- which(bc@RowxNumber[, bci])
cinds <- which(bc@NumberxCol[bci, ])
rnams <- rownames(cmat)[rinds]
cnams <- colnames(cmat)[cinds]
bicluster.list[[bci]] <- list(rnams, cnams)
}
}
print("bicluster sizes")
print(t(sapply(bicluster.list, function (x) {sapply(x, length)})))
##################################################################
bicl.file="tmp.txt"
if (bc@Number > 0) {
for (bci in 1:bc@Number) {
rnams <- bicluster.list[[bci]][[1]]
cnams <- bicluster.list[[bci]][[2]]
write(paste("BICLUSTER ", bci, sep = ""), file = bicl.file, append = TRUE)
write("\n", file = bicl.file, append = TRUE)
write(rnams, file = bicl.file, append = TRUE)
write("\n", file = bicl.file, append = TRUE)
write(cnams, file = bicl.file, append = TRUE)
write("\n", file = bicl.file, append = TRUE)
write("------------------------------\n", file = bicl.file, append = TRUE)
}
}