

#Manhattan-style plot
par(mar=c(5, 5, 1.5, 2),oma=c(2,2,2,2),mfrow=c(1,2))
x=read.table('genes_position_pvalues.txt')
mhtplot2(x,usepos=TRUE,cutoffs=c(),pch=1,col=rep(c('black','cyan'),11),cex.lab=2,cex=0.5,lwd=2,cex.axis=2)
axis(2)
title(main='Gene P-values')

# Gene-P-value vs. number of affecteds that are carriers of novel, non-synonymous variants for each gene.
y=x[,3];
x=read.table('results.txt')
m=max(x[,4])
p=max(-log10(y))
plot(x[,4],-log10(y),xlim=c(0,m+1),ylim=c(0,max(7,p)),ylab='-log10(P)',xlab='# Carriers',cex.lab=2,cex=0.5,lwd=2,cex.axis=2,type='p',col='black',pch=1,axes=FALSE)
axis(2)
axis(1)
title(main='P vs. # Carriers')



# Joint-Rank calculation
# joint_rank[k]=the joint-rank of gene k


n=dim(x)[1];
t1=vector('numeric',length=n)
t2=vector('numeric',length=n)
joint_rank=vector('numeric',length=n)

for (i in 1:n)
{
	t1[i]=rank(x[,3])[i];
	t2[i]=rank(-x[,4])[i];
	joint_rank[i]=(t1[i]+t2[i])/2;
}

# print the first 20 genes according to Joint-Rank
x=read.table('results.txt')
z=order(joint_rank)
x[z[1:20],1]