Skip to content

Commit d3ebc5f

Browse files
authored
Merge pull request #54 from broadinstitute/devel
Devel Former-commit-id: b7c3cf5 Former-commit-id: e2177ca
2 parents dd92b96 + df14e81 commit d3ebc5f

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: infercnv
22
Type: Package
33
Title: Infer Copy Number Variation from Single-Cell RNA-Seq Data
4-
Version: 0.8
4+
Version: 0.8.1
55
Date: 2017-05-25
66
Authors@R: c( person("Timothy", "Tickle", email = "[email protected]", role = c("aut", "cre")), person("Itay", "Tirosh", email = "[email protected]", role = "aut"), person("Christophe", "Georgescu", email = "[email protected]", role = "aut"), person("Maxwell", "Brown", email = "[email protected]", role = "aut"), person("Brian", "Haas", email = "[email protected]", role = "aut"))
77
Author: Timothy Tickle [aut, cre], Itay Tirosh [aut], Christophe Georgescu [aut], Maxwell Brown [aut], Brian Haas [aut]

R/inferCNV.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,23 @@ validate_infercnv_obj <- function(infercnv_obj) {
377377

378378
}
379379

380+
381+
get_cell_name_by_grouping <- function(infercnv_obj) {
382+
383+
cell_name_groupings = list()
384+
385+
groupings = c(infercnv_obj@reference_grouped_cell_indices, infercnv_obj@observation_grouped_cell_indices)
386+
387+
for (group_name in names(groupings)) {
388+
389+
cell_names = colnames(infercnv_obj@expr.data[, groupings[[ group_name ]] ] )
390+
391+
cell_name_groupings[[ group_name ]] = cell_names
392+
393+
}
394+
395+
return(cell_name_groupings)
396+
}
397+
398+
399+

R/inferCNV_heatmap.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ plot_cnv <- function(infercnv_obj,
145145

146146
# Row separation based on reference
147147
ref_idx <- unlist(infercnv_obj@reference_grouped_cell_indices)
148-
148+
ref_idx = ref_idx[order(ref_idx)]
149+
149150
# Column seperation by contig and label axes with only one instance of name
150151
contig_tbl <- table(contigs)[unique_contigs]
151152
col_sep <- cumsum(contig_tbl)
@@ -176,13 +177,14 @@ plot_cnv <- function(infercnv_obj,
176177
counter <- counter + 1
177178
}
178179
# restrict to just the obs indices
179-
obs_annotations_groups <- obs_annotations_groups[ unlist(obs_index_groupings) ]
180-
181180

181+
obs_annotations_groups <- obs_annotations_groups[-ref_idx]
182+
182183
grouping_key_coln[1] <- floor(123/(max(nchar(obs_annotations_names)) + 4)) ## 123 is the max width in number of characters, 4 is the space taken by the color box itself and the spacing around it
183184
if (grouping_key_coln[1] < 1) {
184185
grouping_key_coln[1] <- 1
185186
}
187+
186188
name_ref_groups = names(infercnv_obj@reference_grouped_cell_indices)
187189
grouping_key_coln[2] <- floor(123/(max(nchar(name_ref_groups)) + 4)) ## 123 is the max width in number of characters, 4 is the space taken by the color box itself and the spacing around it
188190
if (grouping_key_coln[2] < 1) {
@@ -195,7 +197,7 @@ plot_cnv <- function(infercnv_obj,
195197
# Calculate how much bigger the output needs to be to accodomate for the grouping key
196198
grouping_key_height <- c((grouping_key_rown[2] + 2) * 0.175, (grouping_key_rown[1] + 3) * 0.175)
197199

198-
# Rows observations, Columns CHR
200+
# Rows observations, Columns CHR
199201
if (! is.na(output_format)) {
200202
if (output_format == "pdf") {
201203
pdf(paste(out_dir, paste(output_filename, ".pdf", sep=""), sep="/"),
@@ -219,7 +221,7 @@ plot_cnv <- function(infercnv_obj,
219221
## They are more informative anyway
220222
obs_data <- infercnv_obj@expr.data
221223
if (!is.null(ref_idx)){
222-
obs_data <- plot_data[, -1 * ref_idx, drop=FALSE]
224+
obs_data <- plot_data[, -ref_idx, drop=FALSE]
223225
if (ncol(obs_data) == 1) {
224226
# hack for dealing with single entries
225227
plot_data <- cbind(obs_data, obs_data)
@@ -244,7 +246,7 @@ plot_cnv <- function(infercnv_obj,
244246
current_grp_idx <- current_grp_idx + 1
245247
}
246248
ref_groups <- updated_ref_groups
247-
249+
248250
nb_breaks <- 16
249251
breaksList_t <-
250252
seq(min(min(obs_data_t, na.rm=TRUE), min(ref_data_t, na.rm=TRUE)),

example/example.Rmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,10 @@ plot_cnv(infercnv_obj,
292292

293293
```{r}
294294
knitr::include_graphics("infercnv.finalized_view.png")
295+
```
296+
295297
And that's it. You can experiment with each step to fine-tune your data exploration. See the documentation for uploading the resulting data matrix into the Next Generation Clustered Heatmap Viewer for more interactive exploration of the infercnv-processed data:
296298
<https://github.com/broadinstitute/inferCNV/wiki/Next-Generation-Clustered-Heat-Map>
297299

298300

299-
```
301+

scripts/inferCNV_utils.R

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
library(tidyverse)
3-
3+
library(futile.logger)
44

55
# plot expression density by chromosome for each observation group, reference groups are shown as single 'normal' group.
6-
plot_density_by_chr <- function(infercnv_obj, pdf_filename=NULL, exclude_range=NULL, chrs=NULL) {
6+
plot_density_by_chr <- function(infercnv_obj, pdf_filename=NULL, exclude_range=NULL, include_range = NULL, chrs=NULL) {
77

88
ref_group_cell_indices = infercnv:::get_reference_grouped_cell_indices(infercnv_obj)
99

@@ -15,6 +15,9 @@ plot_density_by_chr <- function(infercnv_obj, pdf_filename=NULL, exclude_range=N
1515
if (! is.null(pdf_filename)) {
1616
pdf(pdf_filename)
1717
}
18+
19+
20+
chr_expr_vals = list()
1821

1922
for (chr in chrs) {
2023

@@ -40,16 +43,25 @@ plot_density_by_chr <- function(infercnv_obj, pdf_filename=NULL, exclude_range=N
4043
excl_range_right = exclude_range[2]
4144

4245
df = df %>% filter(vals < excl_range_left | vals > excl_range_right)
46+
} else if (! is.null(include_range)) {
47+
include_range_left = include_range[1]
48+
include_range_right = include_range[2]
49+
50+
df = df %>% filter(vals >= include_range_left & vals <= include_range_right)
4351
}
44-
52+
4553
p = df %>% ggplot(aes(vals, fill=class)) + geom_density(alpha=0.3) + scale_y_continuous(trans='log10', limits=c(1,NA)) + ggtitle(chr)
4654
plot(p)
55+
56+
chr_expr_vals[[ chr ]] = df
4757

4858
}
4959

5060
if (! is.null(pdf_filename)) {
5161
dev.off()
5262
}
63+
64+
return(chr_expr_vals)
5365

5466
}
5567

@@ -87,6 +99,8 @@ plot_dist_counts_expr_genes_by_chr <- function(infercnv_obj, pdf_filename=NULL,
8799
if (! is.null(pdf_filename)) {
88100
pdf(pdf_filename)
89101
}
102+
103+
gene_counts_dfs = list()
90104

91105
for (chr in chrs) {
92106
gene_idx = which(infercnv_obj@gene_order$chr == chr)
@@ -104,11 +118,15 @@ plot_dist_counts_expr_genes_by_chr <- function(infercnv_obj, pdf_filename=NULL,
104118
}
105119
p = df %>% ggplot(aes(gene_counts, fill=class)) + geom_density(alpha=0.3) + ggtitle(chr)
106120
plot(p)
121+
122+
gene_counts_dfs[[ chr ]] = df
107123
}
108124

109125
if (! is.null(pdf_filename)) {
110126
dev.off()
111127
}
128+
129+
return(gene_counts_dfs)
112130
}
113131

114132

@@ -133,7 +151,9 @@ compare_gene_expr_means_by_group_pair <- function(infercnv_obj, groupA, groupB,
133151
groupA.gene_mean = rowMeans(groupA.expr.data)
134152
groupB.gene_mean = rowMeans(groupB.expr.data)
135153

136-
plot(groupA.gene_mean, groupB.gene_mean)
154+
#plot(groupA.gene_mean, groupB.gene_mean)
155+
smoothScatter(groupA.gene_mean, groupB.gene_mean)
156+
abline(a=0, b=1, col='magenta')
137157

138158
df=data.frame(groupA=groupA.gene_mean, groupB=groupB.gene_mean)
139159

0 commit comments

Comments
 (0)