+ colors <- col2rgb(V(ng)$color)
+ V(ng)$r <- colors["red", ]
+ V(ng)$g <- colors["green", ]
+ V(ng)$b <- colors["blue", ]
+ ng
+}
+
+merge.graph.proto <- function(graphs) {
+ library(colorspace)
+ ng <- graph.union(graphs, byname=T)
+ V.weight <- V(ng)$weight_1
+ E.weight <- E(ng)$weight_1
+ V.proto.color <- V(ng)$proto.color_1
+ cols <- rainbow(length(graphs))
+ V.color <- rep(cols[1], length(V.weight))
+ for (i in 2:length(graphs)) {
+ tw <- paste('weight_', i, sep='')
+ tocomp <- get.vertex.attribute(ng,tw)
+ totest <- intersect(which(!is.na(V.weight)), which(!is.na(tocomp)))
+ maxmat <- cbind(V.weight[totest], tocomp[totest])
+ resmax <- apply(maxmat, 1, which.max)
+ V.weight[totest] <- apply(maxmat, 1, max)
+ nas <- which(is.na(V.weight))
+ nas2 <- which(is.na(tocomp))
+ fr2 <- setdiff(nas,nas2)
+ V.weight[fr2] <- tocomp[fr2]
+
+ cw <- paste('proto.color_', i, sep='')
+ tocomp.col <- get.vertex.attribute(ng,cw)
+ which.sup <- which(resmax==2)
+ V.proto.color[totest[which.sup]] <- tocomp.col[totest[which.sup]]
+ V.proto.color[fr2] <- tocomp.col[fr2]
+
+ V.color[totest[which.sup]] <- cols[i]
+ V.color[fr2] <- cols[i]
+
+ tocomp <- get.edge.attribute(ng, tw)
+ totest <- intersect(which(!is.na(E.weight)), which(!is.na(tocomp)))
+ maxmat <- cbind(E.weight[totest], tocomp[totest])
+ resmax <- apply(maxmat, 1, which.max)
+ E.weight[totest] <- apply(maxmat, 1, max)
+ nas <- which(is.na(E.weight))
+ nas2 <- which(is.na(tocomp))
+ fr2 <- setdiff(nas,nas2)
+ E.weight[fr2] <- tocomp[fr2]
+ }
+ V(ng)$weight <- V.weight
+ V(ng)$proto.color <- V.proto.color
+ V(ng)$color <- V.proto.color
+ E(ng)$weight <- E.weight
+ V(ng)$ocolor <- V.color
+ colors <- col2rgb(V(ng)$color)
+ V(ng)$r <- colors["red", ]
+ V(ng)$g <- colors["green", ]
+ V(ng)$b <- colors["blue", ]