Visualize and cluster one-mode projection of a bi-partite graph

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.

Details in github project

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 &lt;- rownames(dat)[i]
    
    for(j in 1:ncol(dat)){
        b &lt;- colnames(dat)[j]
        pcc.ab &lt;- dat[a,b] - 0.05
        
        conn.pairs.a &lt;- colnames(dat)[which(dat[a,] &gt;= pcc.ab)]
        conn.pairs.b &lt;- rownames(dat)[which(dat[,b] &gt;= pcc.ab)]
        
        conn.pairs.ab &lt;- length(union(conn.pairs.a,conn.pairs.b))
        n &lt;- nrow(dat)
        
        csi &lt;- 1 - (conn.pairs.ab/n)
        mat[i,j] &lt;- 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")

Details in github project

Raunak Shrestha
Assistant Professional Researcher (Computational Biology)