Repository navigation
Expand file tree
/
Copy pathcirclize_plotfuns.R
More file actions
95 lines (67 loc) · 3.32 KB
/
Copy pathcirclize_plotfuns.R
File metadata and controls
95 lines (67 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#----------------
# circlize
# ---------------
library(tidyverse)
library(circlize)
load('data/_circdb.rdata')
test_circle <- 'chr10:13233299-13234568'
snps <- read_tsv('data/common_cRNA_mRNA_SNPS_by_gene.txt')
snps_filtered <- snps %>%
as_tibble() %>%
dplyr::filter(trait_id == test_circle) %>%
mutate(chr=paste0('chr', chr),
pos=as.numeric(pos),
pos2=as.numeric(pos))
snps_filtered <- as.data.frame(snps_filtered)
snps_filtered <- snps_filtered[, c(1,5,19, 2:4, 6:18)]
gene <- gbrowsedf[gbrowsedf$circID == test_circle,]$geneID[1]
chr <- gbrowsedf[gbrowsedf$circID == test_circle,]$chr[1]
junction <- browser_gr[browser_gr$circID == test_circle]
# get the exons with the gene coordinates
# to plot the backsplice
gquery <- genes(TxDb.Hsapiens.UCSC.hg19.knownGene)[which(genes(TxDb.Hsapiens.UCSC.hg19.knownGene)$gene_id == junction$entrez_id),]
tx <- subsetByOverlaps(transcripts(TxDb.Hsapiens.UCSC.hg19.knownGene), gquery)
tx <- as.data.frame(tx)
exons <- subsetByOverlaps(exons(TxDb.Hsapiens.UCSC.hg19.knownGene), gquery)
exons <- as.data.frame(exons)
exons$gene <- as.character(gene)
exons$exon_id <- as.factor(exons$exon_id)
levels(exons$exon_id) <- as.character(1:length(levels(exons$exon_id)))
exons <- exons[, c('gene', 'start', 'end', 'seqnames', 'width', 'strand', 'exon_id')]
bs_exons <- exons[c(junction$Exon1,junction$Exon2),]
crna_exons <- exons[c(junction$Exon1:junction$Exon2),]
bs_exon1 <- bs_exons[1, c(1:3, 5)]
bs_exon2 <- bs_exons[2, c(1:3, 5)]
png('mcm10_circos_with_snps_and_backsplice2.png', width=12, height=12, res=300, units='in')
#colnames(exons)[1] <- 'name'
#gquery <- as.data.frame(gquery)
circos.par(track.height = 0.1, gap.degree=180)
# , chromosome.index = paste0("chr", c(1:22, "X", "Y"))
circos.genomicInitialize(exons)
## important to have enough space for the plots
circos.genomicTrack(snps_filtered, ylim=c(min(snps_filtered$beta) - 0.5, max(snps_filtered$beta) +0.5), panel.fun = function(region, beta, ...) {
circos.genomicPoints(region, beta, col = 'blue', pch = 16, cex = 0.5, ...)
})
circos.genomicTrack(exons, ylim = c(-2.5, 2.5),
panel.fun = function(region, value, ...) {
# for each transcript
current_tx_start = min(region[, 1])
current_tx_end = max(region[, 2])
circos.lines(c(current_tx_start, current_tx_end),
c(0, 0), col = "#CCCCCC")
circos.genomicRect(region, ytop = 1,
ybottom = -1, col = "orange", border = NA)
}, bg.border = NA)
circos.genomicTrack(crna_exons, ylim = c(-2.5, 2.5),
panel.fun = function(region, value, ...) {
# for each transcript
current_tx_start = min(region[, 1])
current_tx_end = max(region[, 2])
circos.lines(c(current_tx_start, current_tx_end),
c(0, 0), col = "#CCCCCC")
circos.genomicRect(region, ytop = 1,
ybottom = -1, col = "red", border = NA)
}, bg.border = NA)
circos.genomicLink(bs_exon1, bs_exon2, col = 'red', border = NA, h=0.1, h2=0.1)
circos.clear()
dev.off()