forked from lkaihua/Bipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baselineBiclustering.R
52 lines (45 loc) · 1.64 KB
/
baselineBiclustering.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
# The function plotKMeans returns a plot of clustered data using k-means
#
# Author: Ricardo Cachucho
# Edited by kai on Mar 2016
###########################################################################################################
library("biclust")
# Ploting the results of Cheng and Church biclustering on a time series
baselineBiclustering <- function(data, segments=NULL, method=BCCC(), ...) {
# if segments are NULL, then skip aggregate part
if(is.null(segments)){
AggregateData <- as.matrix(data)
}
else{
# represent the time series in an aggregated form
aSegStart <- segments$segStart
aSegEnd <- segments$segEnd
Nrow <- length(aSegStart)
Ncol <- ncol(data)
AggregateData <- matrix(data=NA, ncol=Ncol, nrow=Nrow)
for(j in 1:Ncol){
AggregateData[,j] <- sapply(seq(1,Nrow,1), function(i) mean(data[aSegStart[i]:aSegEnd[i],j], na.rm=TRUE))
}
}
fit <- biclust(AggregateData, method=method, ...)
# plot is done in another module
# K <- fit@Number
# # make plot of original time series
# N <- nrow(data)
# par(mfrow=c(1,1))
# plot(x=1:N,y=data[,1], type="l",xlab="time series index",ylab="", main="Biclustering time series.",ylim=c(min(data,na.rm=TRUE), max(data,na.rm=TRUE)))
# if(ncol(data) > 1) {
# for(c in 2:ncol(data))
# lines(x=1:N, y=data[,c], type="l")
# }
# # plot with points the biclusters
# i=1
# for(i in 1:N) {
# if(any(fit@RowxNumber[i,])==TRUE) {
# a <- which(fit@RowxNumber[i,] == TRUE)
# c <- which(fit@NumberxCol[a,] == TRUE)
# temp <- data[i, c]
# points(x=rep(i, length(temp)), y=data[i,c], col=a+1)
# }
# }
}