-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchromosomePlot.R
74 lines (44 loc) · 1.85 KB
/
chromosomePlot.R
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
# ===== Install Stuff =====
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install()
BiocManager::install("karyoploteR")
BiocManager::install("BSgenome", force=TRUE)
library(BiocManager)
install("BSgenome.Hsapiens.UCSC.hg38")
library(karyoploteR)
# ===== Generate Plot =====
regions1 <- regioneR::toGRanges("chromDataForPlot/miscalls_grch38_bwameth_emseq_200ng_4cycles_LB_combined_reps_bed.sorted.bed")
regions2 <- regioneR::toGRanges("chromDataForPlot/grch38_200ng_bwameth_emseq_cleaned_cut.tsv")
chromsToPlot <- c("chr13", "chr14", "chr15", "chr16", "chr17", "chr18", "chr19", "chr20", "chr21", "chr22", "chrX", "chrY")
# chromsToPlot <- c("chr1", "chr2", "chr3", "chr4", "chr5", "chr6", "chr7", "chr8", "chr9", "chr10", "chr11", "chr12")
chromDataX1 = list()
chromDataY1 = list()
chromDataX2 = list()
chromDataY2 = list()
i <- 1
for(chrom in chromsToPlot)
{
kp.tmp <- karyoploteR::plotKaryotype("hg38", chr=chrom)
kp.tmp <- karyoploteR::kpPlotDensity(kp.tmp, data=regions1)
density1 <- kp.tmp$latest.plot$computed.values$density
windows1 <- kp.tmp$latest.plot$computed.values$windows
density1[density1>30000] <- 30000
kp.tmp <- karyoploteR::kpPlotDensity(kp.tmp, data=regions2)
density2 <- kp.tmp$latest.plot$computed.values$density
windows2 <- kp.tmp$latest.plot$computed.values$windows
density2[density2>30000] <- 30000
chromDataY1[[i]] = density1
chromDataX1[[i]] = windows1
chromDataY2[[i]] = density2
chromDataX2[[i]] = windows2
i <- i+1
}
i <- 1
kp <- karyoploteR::plotKaryotype("hg38", chr=chromsToPlot)
for(chrom in chromsToPlot)
{
karyoploteR::kpArea(kp, chromDataX2[[i]], y=chromDataY2[[i]], chr=chrom, col="blue", ymax=max(30000), ymin=0, r0=0.0, r1=0.5)
karyoploteR::kpArea(kp, chromDataX1[[i]], y=chromDataY1[[i]], chr=chrom, col="red", ymax=max(30000), ymin=0, r0=0.5, r1=1.0)
i <- i+1
}