




###primer position



setwd ("final")
library(matchprobes)
load ("primer.RData") #from supplemental table 11A, matrix of nc=2, rownames tu.list

primer.pos <- matrix(NA, nrow=nrow(primer), nc=2); rownames(primer.pos) <- rownames(primer)

for (chrom in 1:5)
{
 seq.chr <- scan( paste("../ftp/chr", chrom, ".fas", sep=""), skip=1, what="a" )
 seq.chr <- paste(seq.chr, collapse="")
 
 for (i in grep( paste("AT", chrom, "G", sep=""), rownames(primer) ) )
 {
  primer.pos[i,1] <- regexpr( toupper( primer[i,1] ), seq.chr)
  primer.pos[i,2] <- regexpr( toupper( complementSeq( reverseSeq( primer[i,2] )) ), seq.chr)
 }

 }

 save(primer.pos, file="primer.pos.RData", compress=T)






###

 setwd ("final")

 source("plottu.figure.R")

 load ("primer.pos.RData")

 #tu.list <- rownames(primer.pos)

 tu.list <- "AT1G51350 intron8"


 primer.pos <- matrix(primer.pos[ match( tu.list, rownames(primer.pos) ), ], nc=2)

 plot.tu(tu.list, "validate", primer.pos)










load ( paste("tair7/chr", chrom, ".RData", sep="") )
regexpr( toupper("tctccaagtttgttggcctga"), seq.chr)
regexpr( toupper( complementSeq( reverseSeq("agtggagaaaacaaaacatcaca")) ), seq.chr)
exon[ which(names(exon) == "AT1G29720")]






#########################################################################





 setwd ("final")
 library(geneplotter)


 loci <- scan("validation.loci.txt", what="a", skip=1, sep="\n", nlines=122)
 hit <- scan("validation.loci.txt", what="a", skip=124, sep="\n")

 k <- 1



 pdf ("validation.scatter.pdf", width=6, height=8)
 par (mfrow=c(2, 1), mai=c(0.8, 0.8, 0.2, 0.3))

 
 load ("tmean.main.v2.RData")
 tu.list <- rownames(texpr.main[[1]]) 
 load ("tmean.tgr.RData")
 qcut <- names(tgr)[ tgr <= 0.25 ]    
 load ( paste("Main.tmean.perm.v2.", k, ".RData", sep="") )
 tmain <- texpr.main[[k]] [ which( tu.list %in% qcut), ]
 tperm1  <- texpr.perm[[1]] [ which( tu.list %in% qcut), ]
 tperm2  <- texpr.perm[[2]] [ which( tu.list %in% qcut), ]; rm(texpr.perm); gc()
 s0 <- quantile( tperm2, 0.5)
 exon.d <- tmain[,1]/ (tmain[,2]+s0)
 names (exon.d) <- rownames(tmain)
 exon.e <- tmain[,1]
 names(exon.e) <- rownames(tmain)



 list <- names(sort(exon.d))[1:190]
 list <- c(list, names(sort(exon.d, decreasing=T))[1:287])
 list.select <- loci[ which( loci %in% list )] 
 list.hit <- hit[ which( hit %in% list )]  
 list <- names(sort(exon.d))[1:404]
 list <- c(list, names(sort(exon.d, decreasing=T))[1:457])
 list.select <- loci[ which( loci %in% list )] 
 list.hit <- hit[ which( hit %in% list )] 


 exon <- loci[ which( loci %in% rownames(tmain) )] 
 exon.hit <- hit[ which( hit %in% rownames(tmain) )] 

 col <- densCols( exon.d, exon.e)
 plot(  exon.d, exon.e, "p", pch=".", col=col, xlab="d score", ylab="coef")
 legend ("topleft", "exon", bty="n", cex=1.2)
 legend ("bottomright", c("analyzed", "tested", "validated"), col=c("blue", "yellow", "red"), pch=15, bty="n") 
 points( exon.d[ which(names(exon.d) %in% exon )], exon.e[  which(names(exon.e) %in% exon)], pch=".", col="yellow", cex=3) 
 points(  exon.d[ which(names(exon.d) %in% exon.hit )], exon.e[  which(names(exon.e) %in% exon.hit)], pch=".", col="red", cex=3) 


 exon.q1 <- quantile(exon.d, 190/length(exon.d))
 exon.q2 <- quantile(exon.d, (length(exon.d)- 287 +1)/length(exon.d))
 abline( v=exon.q1, lty=2)
 abline( v=exon.q2, lty=2)


###
 load ("iexpr.main.v2.RData")
 load ( paste("Main.iexpr.perm.v2.", k, ".RData", sep="") )  
 s0 <- quantile( iexpr.perm[[2]], 0.5); rm(iexpr.perm); gc()
 intron.d <- iexpr.main[[k]][,1]/ (iexpr.main[[k]][,2]+s0)
 names (intron.d) <- rownames(iexpr.main[[k]])
 intron.e <- iexpr.main[[k]][,1]
 names(intron.e) <- rownames(iexpr.main[[k]])


 
 list <- names(sort(intron.d))[1:220]
 list <- c(list, names(sort(intron.d, decreasing=T))[1:239])
 list.select <- loci[ which( loci %in% list )] 
 list.hit <- hit[ which( hit %in% list )] 



 intron <-  loci[ which( loci %in% rownames(iexpr.main[[k]]) )] 
 intron.hit <- hit[ which( hit %in% rownames(iexpr.main[[k]]) )] 


 col <- densCols( intron.d, intron.e)
 plot( intron.d, intron.e, "p", pch=".",  col=col, xlab="d score", ylab="coef")
 legend ("topleft", "intron", bty="n", cex=1.2)
 legend ("bottomright", c("analyzed", "tested", "validated"), col=c("blue", "yellow", "red"),pch=15, bty="n") 
 points( intron.d[ which(names(intron.d) %in% intron )], intron.e[  which(names(intron.e) %in% intron)], pch=".", col="yellow", cex=3) 
 points(  intron.d[ which(names(intron.d) %in% intron.hit )], intron.e[  which(names(intron.e) %in% intron.hit)], pch=".", col="red", cex=3) 



 intron.q1 <- quantile(intron.d, 220/length(intron.d))
 intron.q2 <- quantile(intron.d, (length(intron.d)- 239 +1)/length(intron.d))
 abline( v=intron.q1, lty=2)
 abline( v=intron.q2, lty=2)

 dev.off()







#### probe density



 setwd ("final")
 load ("tmean.tgr.RData")
 qcut <- names(tgr)[ tgr <= 0.25 ]    

 load ("attile.nonSFP.exon.RData")
 tu.list <-  paste(attile.nonSFP.exon$gene, attile.nonSFP.exon$tu)
 tu.list <- tu.list[ which(tu.list %in% qcut)]
 exon.len <- table(table(tu.list) ) 
 idx <- which(names (exon.len) == "20")
 exon <- exon.len[1:idx] 
 exon[idx] <- sum(exon.len[idx:length(exon.len)]) 

 k <- 1 
 load ("attile.nonSFP.RData")
 attile.nonSFP.intron <- attile.nonSFP[ - which( rownames(attile.nonSFP) %in% rownames(attile.nonSFP.exon) ), ]
 tu.list <-  paste(attile.nonSFP.intron$gene, attile.nonSFP.intron$tu)
 load ("iexpr.main.v2.RData")
 tu.list <- tu.list[ which(tu.list %in% rownames(iexpr.main[[k]]))]
 intron.len <- table(table(tu.list))
 idx <- which(names (intron.len) == "20")
 intron <- intron.len[1:idx] 
 intron[idx] <- sum(intron.len[idx:length(intron.len)]) 


 load ("expr.main.RData")
 gene.list <- as.character(attile.nonSFP.exon$gene)
 gene.list <- gene.list[ which(gene.list %in% rownames(expr.main[[k]]))]
 gene.len <- table(table(gene.list))
 idx <- which(names (gene.len) == "80")
 gene <- gene.len[1:idx] 
 gene[idx] <- sum(gene.len[idx:length(gene.len)]) 

 pdf ("probe.density1.pdf", width=4.5, height=4.5)

 barplot( gene, xlab="probes per gene", ylab="number of genes")
 dev.off()


pdf ("probe.density2.pdf", width=4.5, height=4.5)

 barplot( rbind(exon, intron), beside=T, xlab="probes per exon/intron", ylab="number of exons/introns", space=c(0,1.2), col=c("black", "grey"))
 legend( "top", c("exon", "intron"), col=c("black", "grey"), pch=15)
 
 dev.off()

























