library(ggplot2) qtl.trans = read.table('./translocations.perms.3000.100samples-old.txt', h = T) qtl.trans = qtl.trans[qtl.trans$qtl_type == 'trans',] pval = ifelse(qtl.trans$total_number_of_trans_reads > 5, 0, 1) #chr.from and transloc.from correspond to the coordinates of the repeated segment #chr.to and transloc.to correspond to the coordinates of the qtl plot.transloc <- function(chr.from, transloc.from, chr.to, transloc.to, p.value, pdffile = './transloc.qtls.map.pdf'){ chr.lengths = c(30427671, 19698289, 23459830, 18585056, 26975502) names(chr.lengths) = c('Chr1', 'Chr2', 'Chr3', 'Chr4', 'Chr5') chr.offset <- c(0, cumsum(chr.lengths[-5])) names(chr.offset) = names(chr.lengths) from = transloc.from + chr.offset[chr.from] to = transloc.to + chr.offset[chr.to] dfr <- data.frame(from = from/1000000, to = to/1000000, p.value = p.value <= 0.05) p <- ggplot(dfr) + geom_point(aes(x = from, y = to, fill = p.value, colour = p.value, alpha = 0.5)) + scale_fill_manual(values = c('black', 'firebrick')) + scale_colour_manual(values = c('black', 'firebrick')) + xlab('Position of heterozygous, short segment (Mb)') + ylab('QTL (Mb)') + theme(legend.position = 'none') p <- p + geom_vline(xintercept = chr.offset/1000000) + geom_hline(yintercept = chr.offset/1000000) dfr.transonly <- dfr[which(dfr$p.value),] p.transonly <- ggplot(dfr.transonly) + geom_point(aes(x = from, y = to, fill = p.value, colour = p.value, alpha = 0.5)) + scale_colour_manual(values = c( 'firebrick')) + xlab('Position of heterozygous, short segment (Mb)') + ylab('QTL (Mb)') + theme(legend.position = 'none') p.transonly <- p.transonly + geom_vline(xintercept = chr.offset/1000000) + geom_hline(yintercept = chr.offset/1000000) pdf(pdffile) print(p) print(p.transonly) dev.off() } plot.transloc(qtl.trans$chr.segment, qtl.trans$start.segment, qtl.trans$chr.full_qtl, qtl.trans$start.full_qtl, pval, './transloc.qtls.map.pdf')