Skip to content

Commit

Permalink
update show_cn_distribution()
Browse files Browse the repository at this point in the history
  • Loading branch information
ShixiangWang committed Oct 20, 2022
1 parent 8ca5978 commit f0c050b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: sigminer
Title: Extract, Analyze and Visualize Mutational Signatures for Genomic
Variations
Version: 2.1.7
Version: 2.1.8
Authors@R: c(
person("Shixiang", "Wang", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9855-7357")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# sigminer 2.1.8

- Fixed the bug about plotting CN chromosome distribution (#420).

# sigminer 2.1.7

- Updated COSMIC latest version from v3.2 to v3.3.
Expand Down
27 changes: 19 additions & 8 deletions R/show_cn_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ show_cn_distribution <- function(data,
data$location <- factor(sub("[0-9X]*", "", data$location),
levels = c("p", "pq", "q")
)
# if (sum(!(data$location %in% c("p", "pq", "q"))) > 0){
# message("Discarding segments which located in centromere region...")
# data = subset(data, location %in% c("p", "pq", "q"))
# }
data$location = droplevels(data$location)
loc_level = levels(data$location)

if (scale_chr) {
chrlen <- get_genome_annotation(
Expand All @@ -105,9 +103,22 @@ show_cn_distribution <- function(data,


q <- ggplot_build(p)$data[[1]][, c("x", "count", "fill")]
q$x <- as.integer(q$x)

q$x <- factor(q$x, levels = c(1:23), labels = c(1:22, "X"))
q$fill <- factor(q$fill, levels = c("#F8766D", "#00BA38", "#619CFF"))
cr <- data.frame(
chromosome = unique(data$chromosome[order(data$chromosome)])
)
cr$x <- 1:nrow(cr)

q <- dplyr::full_join(q, cr, by = "x")

q$x <- q$chromosome
if (length(table(q$fill)) < 3) {
q$fill <- factor(q$fill)
q$fill <- relevel(q$fill, ref = "#F8766D")
} else {
q$fill <- factor(q$fill, levels = c("#F8766D", "#00BA38", "#619CFF"))
}

chrlen$chrom <- gsub(
pattern = "chr",
Expand All @@ -122,15 +133,15 @@ show_cn_distribution <- function(data,
geom_bar(stat = "identity") +
scale_fill_discrete(
name = "location",
labels = c("p", "pq", "q")
labels = loc_level
) +
labs(x = "Chromosome", y = "Normalized count (per Mb)")
} else {
ggplot(q, aes(x, y = count, fill = fill)) +
geom_bar(stat = "identity", position = "fill") +
scale_fill_discrete(
name = "location",
labels = c("p", "pq", "q")
labels = loc_level
) +
labs(x = "Chromosome", y = "Percentage")
}
Expand Down

0 comments on commit f0c050b

Please sign in to comment.