Mercurial > repos > artbio > cnv_facets
annotate plot_facets_enhanced-v22.R @ 8:e8a8a4910e32 draft default tip
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 2a0f9aee1c61e12ab9f0e25a6ba7db5c08b67fe6
| author | artbio |
|---|---|
| date | Thu, 09 Oct 2025 17:14:30 +0000 |
| parents | d1914f4d9daf |
| children |
| rev | line source |
|---|---|
|
3
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
1 plot_facets_enhanced <- function(x, emfit = NULL, clustered = FALSE, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
2 plot.type = c("em", "naive", "both", "none"), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
3 sname = NULL, add.legend = TRUE) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
4 def.par <- par(no.readonly = TRUE) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
5 plot.type <- match.arg(plot.type) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
6 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
7 # Setup layout |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
8 if (plot.type == "none") { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
9 layout(matrix(1:2, ncol = 1)) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
10 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
11 if (plot.type == "em") { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
12 layout(matrix(rep(1:4, c(9, 9, 6, 1)), ncol = 1)) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
13 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
14 if (plot.type == "naive") { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
15 layout(matrix(rep(1:4, c(9, 9, 6, 1)), ncol = 1)) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
16 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
17 if (plot.type == "both") { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
18 layout(matrix(rep(1:6, c(9, 9, 6, 1, 6, 1)), ncol = 1)) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
19 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
20 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
21 par( |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
22 mar = c(0.25, 3, 0.25, 1), mgp = c(1.75, 0.6, 0), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
23 oma = c(3, 0, 1.25, 0) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
24 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
25 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
26 # Prepare data |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
27 jseg <- x$jointseg |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
28 chrbdry <- which(diff(jseg$chrom) != 0) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
29 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
30 if (missing(emfit)) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
31 out <- x$out |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
32 if (plot.type == "em" | plot.type == "both") { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
33 warning("emfit is missing; plot.type set to naive") |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
34 plot.type <- "naive" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
35 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
36 } else { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
37 out <- emfit$cncf |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
38 out$tcn <- x$out$tcn |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
39 out$lcn <- x$out$lcn |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
40 out$cf <- x$out$cf |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
41 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
42 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
43 if (clustered) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
44 cnlr.median <- out$cnlr.median.clust |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
45 mafR <- out$mafR.clust |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
46 mafR[is.na(mafR)] <- out$mafR[is.na(mafR)] |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
47 } else { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
48 cnlr.median <- out$cnlr.median |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
49 mafR <- out$mafR |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
50 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
51 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
52 mafR <- abs(mafR) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
53 chrcol <- 1 + rep(out$chrom - 2 * floor(out$chrom / 2), out$num.mark) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
54 nn <- cumsum(table(jseg$chrom[is.finite(jseg$cnlr)])) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
55 segbdry <- cumsum(c(0, out$num.mark)) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
56 segstart <- segbdry[-length(segbdry)] |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
57 segend <- segbdry[-1] |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
58 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
59 # Plot 1: log-ratio |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
60 plot(jseg$cnlr[is.finite(jseg$cnlr)], |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
61 pch = ".", cex = 2, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
62 col = c("grey", "lightblue", "azure4", "slateblue")[chrcol], |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
63 ylab = "log-ratio", xaxt = "n" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
64 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
65 abline(v = chrbdry, lwd = 0.25) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
66 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
67 # Calculate reference lines |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
68 global_median <- median(jseg$cnlr, na.rm = TRUE) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
69 diploid_logr <- x$dipLogR |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
70 lines_diff <- abs(global_median - diploid_logr) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
71 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
72 # Only show reference lines if they are sufficiently different (> 0.1) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
73 legend_items <- c("Segments") |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
74 legend_cols <- c(2) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
75 legend_lwd <- c(1.75) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
76 legend_lty <- c(1) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
77 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
78 if (lines_diff > 0.1) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
79 # Lines are different enough to show both |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
80 abline(h = global_median, col = "green2", lwd = 2.5) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
81 abline(h = diploid_logr, col = "magenta4", lwd = 2.5, lty = 2) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
82 legend_items <- c( |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
83 legend_items, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
84 sprintf("Global median (%.3f)", global_median), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
85 sprintf("Diploid LogR (%.3f)", diploid_logr) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
86 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
87 legend_cols <- c(legend_cols, "green2", "magenta4") |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
88 legend_lwd <- c(legend_lwd, 2.5, 2.5) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
89 legend_lty <- c(legend_lty, 1, 2) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
90 } else { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
91 # Lines are too close, show only one with combined label |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
92 abline(h = global_median, col = "green2", lwd = 2.5) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
93 legend_items <- c( |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
94 legend_items, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
95 sprintf("Median/Diploid (%.3f)", global_median) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
96 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
97 legend_cols <- c(legend_cols, "green2") |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
98 legend_lwd <- c(legend_lwd, 2.5) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
99 legend_lty <- c(legend_lty, 1) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
100 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
101 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
102 segments(segstart, cnlr.median, segend, cnlr.median, lwd = 1.75, col = 2) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
103 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
104 # Add legend for log-ratio plot |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
105 if (add.legend) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
106 legend("topright", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
107 legend = legend_items, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
108 col = legend_cols, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
109 lwd = legend_lwd, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
110 lty = legend_lty, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
111 bty = "n", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
112 cex = 0.7 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
113 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
114 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
115 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
116 # Plot 2: log-odds-ratio |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
117 plot(jseg$valor[is.finite(jseg$cnlr)], |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
118 pch = ".", cex = 2.5, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
119 col = c("grey", "lightblue", "azure4", "slateblue")[chrcol], |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
120 ylab = "log-odds-ratio", ylim = c(-4, 4), xaxt = "n" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
121 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
122 abline(v = chrbdry, lwd = 0.25) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
123 segments(segstart, sqrt(mafR), segend, sqrt(mafR), lwd = 1.75, col = 2) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
124 segments(segstart, -sqrt(mafR), segend, -sqrt(mafR), lwd = 1.75, col = 2) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
125 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
126 # Add legend for log-odds-ratio plot |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
127 if (add.legend) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
128 legend("topright", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
129 legend = c("BAF segments"), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
130 col = c(2), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
131 lwd = c(1.75), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
132 bty = "n", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
133 cex = 0.7 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
134 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
135 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
136 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
137 cfpalette <- c(colorRampPalette(c("white", "steelblue"))(10), "bisque2") |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
138 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
139 # Plot 3: copy number (naive) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
140 if (plot.type == "naive" | plot.type == "both") { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
141 out$tcn[out$tcn > 10] <- 9 + log10(out$tcn[out$tcn > 10]) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
142 ii <- which(out$lcn > 5) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
143 if (length(ii) > 0) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
144 out$lcn[ii] <- 5 + log10(out$lcn[ii]) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
145 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
146 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
147 plot(c(0, length(jseg$cnlr)), c(0, max(out$tcn)), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
148 type = "n", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
149 ylab = "copy number (nv)", xaxt = "n" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
150 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
151 abline(v = chrbdry, lwd = 0.25) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
152 segments(segstart, out$lcn, segend, out$lcn, lwd = 1.75, col = 2) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
153 segments(segstart, out$tcn, segend, out$tcn, lwd = 1.75, col = 1) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
154 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
155 # Add legends for copy number plot (including CF legend) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
156 if (add.legend) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
157 # CN legend on top left |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
158 legend("topleft", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
159 legend = c("Total CN (TCN)", "Minor CN (LCN)"), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
160 col = c(1, 2), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
161 lwd = 1.75, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
162 bty = "n", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
163 cex = 0.7 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
164 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
165 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
166 # CF legend on top right |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
167 legend("topright", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
168 legend = c( |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
169 "CF = 0 (normal)", "CF = 0.2 (low tumor)", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
170 "CF = 0.8 (high tumor)", "CF = 1.0 (pure tumor)" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
171 ), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
172 fill = c("white", "lightblue", "steelblue", "tan"), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
173 border = "black", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
174 bty = "o", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
175 box.col = "black", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
176 box.lwd = 1.5, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
177 cex = 0.65, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
178 title = "Cellular Fraction (CF)", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
179 bg = "white" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
180 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
181 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
182 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
183 # CF bar (naive) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
184 plot(c(0, length(jseg$cnlr)), 0:1, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
185 type = "n", ylab = "", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
186 xaxt = "n", yaxt = "n" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
187 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
188 mtext("cf-nv", side = 2, at = 0.5, line = 0.3, las = 2, cex = 0.75) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
189 cfcol <- cfpalette[round(10 * out$cf + 0.501)] |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
190 rect(segstart, 0, segend, 1, col = cfcol, border = NA) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
191 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
192 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
193 # Plot 4: copy number (EM) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
194 if (plot.type == "em" | plot.type == "both") { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
195 out$tcn.em[out$tcn.em > 10] <- 9 + log10(out$tcn.em[out$tcn.em > 10]) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
196 ii <- which(out$lcn.em > 5) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
197 if (length(ii) > 0) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
198 out$lcn.em[ii] <- 5 + log10(out$lcn.em[ii]) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
199 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
200 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
201 plot(c(0, length(jseg$cnlr)), c(0, max(out$tcn.em)), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
202 type = "n", ylab = "copy number (em)", xaxt = "n" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
203 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
204 abline(v = chrbdry, lwd = 0.25) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
205 segments(segstart, out$lcn.em, segend, out$lcn.em, lwd = 1.75, col = 2) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
206 segments(segstart, out$tcn.em, segend, out$tcn.em, lwd = 1.75, col = 1) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
207 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
208 # Add legends for EM copy number plot (including CF legend) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
209 if (add.legend) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
210 # CN legend on top left |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
211 legend("topleft", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
212 legend = c("Total CN (TCN)", "Minor CN (LCN)"), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
213 col = c(1, 2), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
214 lwd = 1.75, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
215 bty = "n", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
216 cex = 0.7 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
217 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
218 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
219 # CF legend on top right |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
220 legend("topright", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
221 legend = c( |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
222 "CF = 0 (normal)", "CF = 0.2 (low tumor)", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
223 "CF = 0.8 (high tumor)", "CF = 1.0 (pure tumor)" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
224 ), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
225 fill = c("white", "lightblue", "steelblue", "tan"), |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
226 border = "black", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
227 bty = "o", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
228 box.col = "black", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
229 box.lwd = 1.5, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
230 cex = 0.65, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
231 title = "Cellular Fraction (CF)", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
232 bg = "white" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
233 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
234 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
235 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
236 # CF bar (EM) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
237 plot(c(0, length(jseg$cnlr)), 0:1, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
238 type = "n", ylab = "", |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
239 xaxt = "n", yaxt = "n" |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
240 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
241 mtext("cf-em", side = 2, at = 0.5, line = 0.2, las = 2, cex = 0.75) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
242 cfcol <- cfpalette[round(10 * out$cf.em + 0.501)] |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
243 rect(segstart, 0, segend, 1, col = cfcol, border = NA) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
244 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
245 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
246 # X-axis with chromosome labels |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
247 chromlevels <- x$chromlevels |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
248 if (is.null(chromlevels)) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
249 chromlevels <- 1:length(nn) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
250 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
251 axis( |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
252 labels = chromlevels, side = 1, |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
253 at = (nn + c(0, nn[-length(nn)])) / 2, cex = 0.65 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
254 ) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
255 mtext(side = 1, line = 1.75, "Chromosome", cex = 0.8) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
256 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
257 # Sample name title |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
258 if (!missing(sname)) { |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
259 mtext(sname, side = 3, line = 0, outer = TRUE, cex = 0.8) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
260 } |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
261 |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
262 par(def.par) |
|
d1914f4d9daf
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/main/tools/facets commit 64ac36125f04497dd51028f307e059fca9ec0503
artbio
parents:
diff
changeset
|
263 } |
