Guest User

Untitled

a guest
Jan 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. library(data.table)
  2. small_indels<-read.table("~/gdr/assoc/pcaFiltered/indels/summary_stats/summary.indelReport.txt")
  3. bed<-read.table("genes.bed")
  4. big_dels<-read.table("big_indels.txt")
  5. if(!exists("snps")){snps<-as.data.frame(fread("snps.window.txt"))}
  6.  
  7. plotLocus<-function(gene,window=5000){
  8. gene_start <- bed[match(gene,bed$V4),2]
  9. gene_end <- bed[match(gene,bed$V4),3]
  10. lw <- gene_start-window
  11. rw <- gene_end+window
  12. temp_bed <- subset(bed,V2>lw & V3<rw)
  13. xmax <- max(temp_bed$V3)
  14. xmin <- min(temp_bed$V2)
  15. xlims <- c(xmin,xmax)
  16. ylims <- c(0,3)
  17. plot(0,yaxt="n",type="n",xlim=xlims,ylim=ylims,ylab="Large Deletions",xlab="Genome position (Mb)")
  18. arrow_coords <- t(apply(temp_bed,1,function(x){if (x[5]=="+"){c(as.numeric(x[2]),as.numeric(x[3]))} else {c(as.numeric(x[3]),as.numeric(x[2]))}}))
  19. arrows(as.numeric(arrow_coords[,1]),c(0,0.5),arrow_coords[,2],c(0,0.5),lwd=5,col="blue",length=0.1)
  20. xmid <- (temp_bed$V2+temp_bed$V3)/2
  21. text(xmid,c(0.25,0.75),temp_bed$V4)
  22.  
  23. temp_snps <- subset(snps, V1>lw & V1<rw)
  24. max_snps <- max(temp_snps$V2)
  25. points(scale(temp_snps$V2,F,max_snps)+2 ~ temp_snps$V1,type="l")
  26. points(scale(temp_snps$V3,F,max_snps)+2 ~ temp_snps$V1,type="l",col="dark green")
  27. points(small_indels$V2,rep(2,dim(small_indels)[1]),col="red",pch=4)
  28. abline(h=c(1,2))
  29. axis(side=2,at=scale(seq(0,round(max_snps,-1),50),F,max_snps)+2,labels=seq(0,round(max_snps,-1),50))
  30. mtext(text="SNPs/KB",side=2,line=3,at=2.5)
  31. mtext(text="Genes",side=2,line=3,at=0.5)
  32. temp_big_dels<-subset(big_dels,V3>lw-10000 & V4<rw+10000)
  33. num_dels <- dim(temp_big_dels)[1]
  34. if (num_dels>0){for (i in 1:num_dels){
  35. yh <- scale(i,F,num_dels+1)+1
  36. segments(temp_big_dels[i,3],yh,temp_big_dels[i,4],yh,col="dark green")
  37. }
  38. }
  39. }
  40.  
  41. #plotLocus("pncA")
Add Comment
Please, Sign In to add comment