Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
czheluo committed Apr 6, 2019
1 parent 3a39ade commit 55f68c8
Show file tree
Hide file tree
Showing 22 changed files with 25,833 additions and 0 deletions.
155 changes: 155 additions & 0 deletions R/CHEKALL.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@

chr<-unique(snp[,1])

nc<-NULL
for (i in 1:length(chr)){

nc[i]<-length(snp[which(snp[,1] %in% chr[i]),1])

}


chr<-unique(indel[,1])

ncl<-NULL
for (i in 1:length(chr)){

ncl[i]<-length(indel[which(indel[,1] %in% chr[i]),1])

}

snpname<-phased.maplist

for (i in 1: length(snpname)){
snpname[[i]][,1]<-paste("LG",i,"_",paste("SNP",c(1:length(snpname[[i]][,1])),sep=""),sep="")
}


SNP_SSR<-list()

for (i in 1:length(phased.maplist)){

SNP_SSR[[i]]<-ALL_dosages_a[which(phased.maplist[[i]][,1] %in% rownames(ALL_dosages_a)),]

}


capture.output(for (i in 0:45) for (j in 0:45) print(i/j),
file = "foo.txt")

for (i in 1: length(SNP_SSR)){
rownames(SNP_SSR[[i]])<-paste("LG",i,"_",paste("SNP",c(1:length(rownames(SNP_SSR[[i]]))),sep=""),sep="")
}

N<-dim(SNPALL)[1]
M<-dim(SNPALL)[1]


for (i in 1: length(SNP_SSR)){
write.csv(SNP_SSR[[i]],file=paste("LGGEN",i,".csv",sep=""))
}



nsnp<-NULL
for (i in 1:length(phased.maplist)) {
nsnp[i]<-dim(phased.maplist[[i]])[1]
}
print(paste("Total Number of SNP Markers:",sum(nsnp)))


nsnp<-NULL
for (i in 1:length(phased.maplist_P1)) {
nsnp[i]<-dim(phased.maplist_P1[[i]])[1]
}
print(paste("Total Number of SNP Markers:",sum(nsnp)))

nsnp<-NULL
for (i in 1:length(phased.maplist_P2)) {
nsnp[i]<-dim(phased.maplist_P2[[i]])[1]
}
print(paste("Total Number of SNP Markers:",sum(nsnp)))



##write the name and map

load("polymap_tetra.RData")

SNP_SSR<-list()

for (i in 1:length(phased.maplist)){
SNP_SSR[[i]]<-ALL_dosages_a[match(phased.maplist[[i]][,1],rownames(ALL_dosages_a)),]


}

names(SNP_SSR)<-paste("LG",c(1:7),sep="")

snpnameall<-phased.maplist

for (i in 1: length(snpnameall)){
for (j in 1:length(snpnameall[[i]][,1])) {
if (is.na(match(snpnameall[[i]][j,1],rownames(polymap_tetra[[1]])))) {
next
} else {
new<-polymap_tetra[[2]][match(snpnameall[[i]][j,1],rownames(polymap_tetra[[1]])),]
rownames(SNP_SSR[[i]])[j]<-paste("c",new[,1],"_",new[,2],sep="")
snpnameall[[i]][j,1]<-paste("c",new[,1],"_",new[,2],sep="")
}
}
snpnameall[[i]][,1]<-rownames(SNP_SSR[[i]])
}



for (i in 1: length(SNP_SSR)){
write.csv(SNP_SSR[[i]],file=paste("LGGEN",i,".csv",sep=""))
}

for (i in 1: length(SNP_SSR)){
SNP_SSR[[i]]<-paste("LG",i,sep="")
}



SNP_SSR<-list()

for (i in 1:length(phased.maplist)){
for (j in 1:length(phased.maplist[[i]][,1])){
SNP_SSR[[i]]<-ALL_dosages_a[which(phased.maplist[[i]][j,1] %in% rownames(ALL_dosages_a)),]
}


}

names(SNP_SSR)<-paste("LG",c(1:7),sep="")

snpnameall<-phased.maplist

for (i in 1: length(snpnameall)){
for (j in 1:length(snpnameall[[i]][,1])) {
if (length(which(snpnameall[[i]][j,1] %in% rownames(polymap_tetra[[1]])))) {
next
} else {
new<-polymap_tetra[[2]][which(snpnameall[[i]][j,1] %in% rownames(polymap_tetra[[1]])),]
rownames(SNP_SSR[[i]])[j]<-paste("c",new[,1],"_",new[,2],sep="")
#snpnameall[[i]][j,1]<-paste("c",new[,1],"_",new[,2],sep="")
}
}
snpnameall[[i]][,1]<-rownames(SNP_SSR[[i]])

}



for (i in 1: length(SNP_SSR)){
SNP_SSR[[i]][is.na(SNP_SSR[[i]])]<-9
write.table(SNP_SSR[[i]],file=paste("LGGEN",i,".txt",sep=""),quote=F,row.names=T,col.names=T)
}






234 changes: 234 additions & 0 deletions R/OUPUT_MAP.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@


for(i in 1:7){
if(i==1){
integrated.maplist_P1[[i]] <- integrated.maplist_P1[[i]][-1046,]
} else if (i==4){
integrated.maplist_P1[[i]] <- integrated.maplist_P1[[i]][-659,]
}else{
integrated.maplist_P1[[i]] <- integrated.maplist_P1[[i]]
}

}



for(i in 1:7){
if(i==2){
integrated.maplist_P2[[i]] <- integrated.maplist_P2[[i]][-1,]
} else if (i==4){
integrated.maplist_P2[[i]] <- integrated.maplist_P2[[i]][-1137,]
}else{
integrated.maplist_P2[[i]] <- integrated.maplist_P2[[i]]
}

}



for(i in 1:7){
if(i==1){
integrated.maplist[[i]] <- integrated.maplist[[i]][-1909,]
} else if (i==2){
integrated.maplist[[i]] <- integrated.maplist[[i]][-1,]
}else if (i==4){
integrated.maplist[[i]] <- integrated.maplist[[i]][-c(1,2,1399),]
}else {
integrated.maplist[[i]] <- integrated.maplist[[i]]
}

}



alldt<-getwd()


for(i in 1:7){
if (i==1){
#dir.create(paste("integrated.maplist_P1"))
#setwd(paste(alldt,"/integrated.maplist_P1",sep = ""))
write.csv(integrated.maplist_P1[[i]],
file=paste("integrated.maplist_P1_LG",i,".cvs",sep = ""),quote = F,row.names = F)
#dir.create(paste("integrated.maplist_P2"))
#setwd(paste(alldt,"/integrated.maplist_P2",sep = ""))
write.csv(integrated.maplist_P2[[i]],
file=paste("integrated.maplist_P2_LG",i,".csv",sep = ""),quote = F,row.names = F)
#dir.create(paste("integrated.maplist_all"))
# setwd(paste(alldt,"/integrated.maplist_all",sep = ""))
write.csv(integrated.maplist_P1[[i]],
file=paste("integrated.maplist_LG",i,".csv",sep = ""),quote = F,row.names = F)
}else {
#dir.create(paste("integrated.maplist_P1"))
#setwd(paste(alldt,"/integrated.maplist_P1",sep = ""))
write.csv(integrated.maplist_P1[[i]],
file=paste("integrated.maplist_P1_LG",i,".csv",sep = ""),quote = F,row.names = F)
#dir.create(paste("integrated.maplist_P2"))
#setwd(paste(alldt,"/integrated.maplist_P2",sep = ""))
write.csv(integrated.maplist_P2[[i]],
file=paste("integrated.maplist_P2_LG",i,".csv",sep = ""),quote = F,row.names = F)
#dir.create(paste("integrated.maplist_all"))
#setwd(paste(alldt,"/integrated.maplist_all",sep = ""))
write.csv(integrated.maplist_P1[[i]],
file=paste("integrated.maplist_LG",i,".csv",sep = ""),quote = F,row.names = F)

}

}


#dir.create(paste("integrated.maplist_P1"))
#setwd(paste(getwd(),"/integrated.maplist_P1",sep = ""))
all_P1<-do.call(rbind,integrated.maplist_P1)
write.csv(all_P1,
file= "integrated.maplist_P1_all.csv",quote = F,row.names = F)

#dir.create(paste("integrated.maplist_P2"))
#setwd(paste(getwd(),"/integrated.maplist_P2",sep = ""))
all_P2<-do.call(rbind,integrated.maplist_P2)
write.csv(all_P1,
file= "integrated.maplist_P2_all.csv",quote = F,row.names = F)
#dir.create(paste("integrated.maplist_all"))
#setwd(paste(getwd(),"/integrated.maplist",sep = ""))
all<-do.call(rbind,integrated.maplist_P2)
write.csv(all,
file= "integrated.maplist_all.csv",quote = F,row.names = F)



####output genetype
map<-read.csv("polymap.map.tetra.csv",header=T)
ALL_dos<-read.csv("polymap.20k.tetra.csv",header=T)

ALL_dos<-read.csv("dosage_10x_snp.csv",header=T)
map<-read.csv("dosage_10x_pos.csv",header=T)

integrated.maplist_P1<-integrated.maplist_P1_chr1new

###FATHER MAP
MarN<-NULL;MapD<-NULL;AvD<-NULL;MaxG<-NULL;#Gap5cM<-NULL
Position_P1<-list();Genetype_P1<-list()
for(i in 1:7){
MarN[i]<-dim(integrated.maplist_P1[[i]])[1]
MapD[i]<-max(integrated.maplist_P1[[i]][,2])
AvD[i]<-max(integrated.maplist_P1[[i]][,2])/dim(integrated.maplist_P1[[i]])[1]
MaxG[i]<-max(integrated.maplist_P1[[i]][,2])-min(integrated.maplist_P1[[i]][,2])
#Gap5cM
Position_P1[[i]]<-map[which(ALL_dos$SNP %in% integrated.maplist_P1[[i]][,1]),]
Genetype_P1[[i]]<-ALL_dos[which(ALL_dos$SNP %in% integrated.maplist_P1[[i]][,1]),]
}

phymap<-do.call(rbind,Position_P1)
write.table(phymap,file="phymap_P1.txt",
quote = F,row.names = F,col.names = T)

Genetype<-do.call(rbind,Genetype_P1)

write.table(Genetype,file="Genetype_P1.txt",
quote = F,row.names = F,col.names = T)


all_stats<-as.matrix(cbind(MarN,MapD,AvD,MaxG))

colnames(all_stats)<-c("Mar Num","Map Distance","Aver Distance","Max Gap")

for(i in 1:7){
rownames(all_stats)[i]<-paste("LG",i,sep = "")
}
write.csv(all_stats,file = "stats_P1.csv",quote=F,row.names=T)

integrated.maplist_P2<-integrated.maplist_P2_chr1new

####MOTHER MAP
MarN<-NULL;MapD<-NULL;AvD<-NULL;MaxG<-NULL;#Gap5cM<-NULL
Position_P2<-list();Genetype_P2<-list()
for(i in 1:7){
MarN[i]<-dim(integrated.maplist_P2[[i]])[1]
MapD[i]<-max(integrated.maplist_P2[[i]][,2])
AvD[i]<-max(integrated.maplist_P2[[i]][,2])/dim(integrated.maplist_P2[[i]])[1]
MaxG[i]<-max(integrated.maplist_P2[[i]][,2])-min(integrated.maplist_P2[[i]][,2])
#Gap5cM
Position_P2[[i]]<-map[which(ALL_dos$SNP %in% integrated.maplist_P2[[i]][,1]),]
Genetype_P2[[i]]<-ALL_dos[which(ALL_dos$SNP %in% integrated.maplist_P2[[i]][,1]),]
}

phymap<-do.call(rbind,Position_P2)
write.table(phymap,file="phymap_P2.txt",
quote = F,row.names = F,col.names = T)

Genetype<-do.call(rbind,Genetype_P2)

write.table(Genetype,file="Genetype_P2.txt",
quote = F,row.names = F,col.names = T)


all_stats<-as.matrix(cbind(MarN,MapD,AvD,MaxG))

colnames(all_stats)<-c("Mar Num","Map Distance","Aver Distance","Max Gap")

for(i in 1:7){
rownames(all_stats)[i]<-paste("LG",i,sep = "")
}
write.csv(all_stats,file = "stats_P2.csv",quote=F,row.names=T)

integrated.maplist<-integrated.maplist_chr1
###INTEGRATE MAP
MarN<-NULL;MapD<-NULL;AvD<-NULL;MaxG<-NULL;#Gap5cM<-NULL
Position_PP<-list();Genetype_PP<-list()
for(i in 1:7){
MarN[i]<-dim(integrated.maplist[[i]])[1]
MapD[i]<-max(integrated.maplist[[i]][,2])
AvD[i]<-max(integrated.maplist[[i]][,2])/dim(integrated.maplist[[i]])[1]
MaxG[i]<-max(integrated.maplist[[i]][,2])-min(integrated.maplist[[i]][,2])
#Gap5cM
Position_PP[[i]]<-map[which(ALL_dos$SNP %in% integrated.maplist[[i]][,1]),]
Genetype_PP[[i]]<-ALL_dos[which(ALL_dos$SNP %in% integrated.maplist[[i]][,1]),]
}

phymap<-do.call(rbind,Position_PP)
write.table(phymap,file="phymap_PP.txt",
quote = F,row.names = F,col.names = T)

Genetype<-do.call(rbind,Genetype_PP)

write.table(Genetype,file="Genetype_PP.txt",
quote = F,row.names = F,col.names = T)


all_stats<-as.matrix(cbind(MarN,MapD,AvD,MaxG))

colnames(all_stats)<-c("Mar Num","Map Distance","Aver Distance","Max Gap")

for(i in 1:7){
rownames(all_stats)[i]<-paste("LG",i,sep = "")
}
write.csv(all_stats,file = "stats_PP.csv",quote=F,row.names=T)













chr<-unique(dis[,1])
gap<-NULL

for (i in 1:length(chr)){gap[i]<-max(dis[which(dis[,1] %in% chr[i]),2])-min(dis[which(dis[,1] %in% chr[i]),2])}












Loading

0 comments on commit 55f68c8

Please sign in to comment.