Genomic knowledge are often curated in the form of Genes. For example, a geneset of genes mapping to the chromosome locus chr8q24; a geneset of genes known to involve in DNA Repair Module, etc. Similarly, this data structure is also representative of patient-Genes data.
This can be thought of as a bipartite graph representing relation between individual Module to a gene. Often bioinformaticians are interested to visualize if there is any kind of relation between the Modules. This problem can be modeled as the conversion of two-mode network (bipartite graph) to one-mode network of Modules and visualize the resulting one-mode network. Here, I attempt to demonstrate how this can be achieved using R.
bip <- matrix(0, nrow=length(ids), ncol=length(genes), dimnames=list(ids, genes))
list.genes <- str_split(df$Genes, ":") list.gene.index <- lapply(list.genes, function(x) which(colnames(bip) %in% x))
for(i in 1:length(list.gene.index)){ bip[i,list.gene.index[[i]]] <- 1 } return(bip) }
bip <- get.bip(dat)
bip[1:5,1:5]
for(i in 1:nrow(dat)){
a <- rownames(dat)[i]
for(j in 1:ncol(dat)){
b <- colnames(dat)[j]
pcc.ab <- dat[a,b] - 0.05
conn.pairs.a <- colnames(dat)[which(dat[a,] >= pcc.ab)]
conn.pairs.b <- rownames(dat)[which(dat[,b] >= pcc.ab)]
conn.pairs.ab <- length(union(conn.pairs.a,conn.pairs.b))
n <- nrow(dat)
csi <- 1 - (conn.pairs.ab/n)
mat[i,j] <- csi
}
}
return(mat)
}
dat.csi <- get.csi(dat.pcc) dat.csi[1:5,1:5]
Set vertex attributes
V(g)$label <- V(g)$name V(g)$label.color <- "black" V(g)$label.cex <- .8 V(g)$label.dist <- 0.3 V(g)$label.family <- "Helvetica" V(g)$frame.color <- "grey"
E(g)$color <- rgb(.6,.6,0,E(g)$weight) E(g)$width <- E(g)$weight * 5
Generate Graph Output File
file.graph.output <- "graph_projection.gml" write_graph(graph=g, file=file.graph.output, format="gml")