Human Disease Network

Published by chengjun on September 5th, 2011

This is the result, the codes is attached below.

# disease co-occurrence network
# http://barabasilab.neu.edu/projects/hudine/resource/data/data.html
# chengjun @ common room 2011/9/4
 
#~~~~~~~~~~~load data~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
dis<-read.table("D:/NKS & SFI/AllNet3.txt", header = FALSE, sep = "",  dec = ".")
 
#~~~~~~~~~~~Data Description and rename~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# 1  ICD-9 code disease 1
# 2  ICD-9 code disease 2
# 3  Prevalence disease 1
# 4  Prevalence disease 2
# 5  Co-ocurrence between diseases 1 and 2
# 6  Relative Risk
# 7  Relative Risk 99% Conf. Interval (left)
# 8  Relative Risk 99% Conf. Interval (right)
# 9  Phi-correlation
# 10 t-test value
 
names(dis)<-c("dis1","dis2","prevalence_dis1","prevalence_dis2","co_ocurrence","risk",
     "riskleft","riskright","phi","t" ) 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~distribution~~~~~~~~~~~~~~~~~~~~~~~~#
dis1<-as.data.frame(table(dis[,1]))
names(dis1)<-c("disease","Numbers of combinations of coocurrence with other diseases")
plot(dis1) # this is the number of combinations of coocurrences with other diseases
plot(as.data.frame(table(dis1[,2])))  # distribution of combinations
 
popp<-as.data.frame(dis1)
 
plot(popp[,1],popp[,2],xlab="In-degree",ylab="Frequency",type = "p", col = "black", lwd=2,main = "")
 
powerfit<-lm(log(popp[,2])~log(as.numeric(levels(popp[,1])[popp[,1])))
summary(powerfit)
 
plot(log(as.numeric(levels(popp[,1])[popp[,1]]),log(popp[,2]),
   xlab="In-degree",ylab="Frequency",type = "p", col = "black", lwd=2,main = "")
 
abline(powerfit, col = "grey",lwd=3)
 
#~~~~~~~compute the degree distribution using igraph~~~~~~~~~~~~~~~~~~~~#
library(igraph)# install.packages("igraph")
jj<-graph.data.frame(dis[,1:2], directed=FALSE, vertices=NULL)
class(jj)
dd <- degree(jj, mode="in")
ddd <- degree.distribution(jj, mode="in", cumulative=TRUE)
alpha <- power.law.fit(dd, xmin=20)
alpha
plot(ddd, log="xy", xlab="degree", ylab="cumulative frequency",
     col=1, main="Nonlinear preferential attachment")
lines(10:500, 10*(10:500)^(-coef(alpha)+1))
 
# save data
setwd("D:/NKS & SFI/")
savePlot(filename = "Nonlinear preferential attachment",
         type = c( "png"),
         device = dev.cur(),
         restoreConsole = TRUE)
#####################################################
#
#                               plot the disease graph
#
######################################################
#~~~~~~~~~~~~~~~~subset data~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
backbone<-subset(dis, dis[5]>=100000)
dim(backbone)
 
library(igraph)# install.packages("igraph")
g<-graph.data.frame(backbone[,1:2], directed=FALSE, vertices=NULL)
summary(g)
#------the size of nodes denotes the prevalence of events~~~~~~~~~~~~~~~~~~~~~~~~~~~#
 
prevalence<-data.frame(rbind(cbind(backbone[,1], backbone[,3]), cbind(backbone[,2], backbone[,4])) )
prevalencen<-unique(prevalence, fromLast = F)  ## extract unique elements
 
V(g)$size <- log(prevalencen[,2])-5
 
#------the color of nodes denotes the popularity of events~~~~~~~~~~~~~~~~~~~~------#
V(g)$color <- rainbow(20)[log(prevalencen[,2]+5)]
# V(g)$color <-heat.colors(20, alpha = 1)[log(prevalencen[,2])]
#-------the width of links denots the volume of user traffic on the link------#
E(g)$weight <- log(backbone[,5])/5
 
plot(g, vertex.label= NA,edge.arrow.size=0.2,layout=layout.fruchterman.reingold,edge.width=E(g)$weight+1 )
 
setwd("D:/NKS & SFI/")
savePlot(filename = "Disease Coocurrence plot 100000 prevalence_97nodes_674",
         type = c( "png"),
         device = dev.cur(),
         restoreConsole = TRUE)
    分享到:


12 Responses

  1. admin says:

    < !–wp_twitter_goodies–> haha

  2. Awesome website…

    Hey there fella, This was a excellent webpage for such adifficult subject to talk about….

  3. Greetings! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us valuable information to work on. You have done a marvellous job!

  4. hello,what an excellent article this is,I found it on yahoo and I love it very much,I agree with you, lots of things will be learned form your site,but I am not follw well with the last part,can you explain it for me ?I will appreciate your answer,and I will be back again!

  5. 離婚 says:

    Its great that you Shed light on a few things I didn’t understand. Thank you , hope you can keep writing blog?2

  6. I am not used to wordpress blogging and actually appreciated your blog. My goal is to discover your website along with continue looking at get you started. Thought about have got to say thank you for writing your internet web page.

  7. Your writing has inspired me to totally change the way I write. I have to tell you I appreciate your hard work.

  8. ugg says:

    Does your blog post have got a contact page? IпїЅпїЅm having issues locating it but, IпїЅпїЅd plan to send you an e-mail.

  9. ugg says:

    pretty valuable material, overall I am it’s value a bookmark, thanks

  10. 5linx says:

    Thanks for posting this, very useful.

  11. Wonderful site. Plenty of useful information here. I am sending it to a few friends ans also sharing in delicious. And of course, thanks for your sweat!


Leave a Reply

Your email address will not be published. Required fields are marked *