Post date: Sep 28, 2019 2:5:38 AM
## create genotype distance matrix, based on ibs
gf<-list.files(pattern="g")
NF<-length(gf)
g<-vector("list",NF)
for(i in 1:NF){
g[[i]]<-as.matrix(read.table(gf[i],header=FALSE,sep=","))
}
N<-dim(g[[1]])[1]
gd<-vector("list",NF)
for(i in 1:NF){
gd[[i]]<-matrix(0,nrow=N,ncol=N)
for(j in 1:(N-1)){for(k in (j+1):N){
gd[[i]][j,k]<-mean(abs(g[[i]][j,]-g[[i]][k,]))/2
gdp[[i]][k,j]<-gd[[i]][j,k]
}}
write.table(file="mel_common.diffs",gd[[1]],quote=FALSE,row.names=FALSE,col.names=FALSE)
write.table(file="mel_rare.diffs",gd[[2]],quote=FALSE,row.names=FALSE,col.names=FALSE)
## read ids, connect with coordinates
ids<-read.table("indorder.txt")
pops<-read.table("popdetails.csv",sep=" ",header=TRUE)
idlatlon<-matrix(NA,nrow=N,ncol=2)
for(i in 1:N){
p<-which(as.character(pops[,1])==as.character(ids[i,1]))
idlatlon[i,]<-as.numeric(pops[p,c(3,2)])
}
write.table(file="mel.coord",idlatlon,quote=FALSE,row.names=FALSE,col.names=FALSE)