Skip to content

Commit e7bb5a8

Browse files
committed
Fix reordering for nonstandard sample names
1 parent 734ac81 commit e7bb5a8

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

bin/diffexpr.R

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ contrast_tab$Condition2 <- gsub("\\-", ".", contrast_tab$Condition2)
8686
meta_tab$group <- as.factor(as.character(meta_tab$group))
8787

8888
## order rows to match counts columns
89-
meta_tab <- meta_tab[match(colnames(counts_tab), meta_tab$sample), ]
90-
89+
meta_tab <- meta_tab[match(
90+
colnames(counts_tab), make.names(meta_tab$sample)
91+
), ]
92+
rownames(meta_tab) <- make.names(meta_tab$sample)
9193

9294
## ------------------------------------------------------------------------------
9395
## Differential gene expression
@@ -130,7 +132,9 @@ contrast_list <- lapply(comb_list, function(x) {
130132
## export tables of genes with log2FC and p-values:
131133
lapply(seq_along(contrast_list), function(x) {
132134
contrast_name <- names(contrast_list)[x]
133-
res_df <- tibble::rownames_to_column(as.data.frame(contrast_list[x]), "feature_id")
135+
res_df <- tibble::rownames_to_column(
136+
as.data.frame(contrast_list[x]), "feature_id"
137+
)
134138
colnames(res_df) <- gsub(contrast_name, "", colnames(res_df))
135139
colnames(res_df) <- gsub("\\.", "", colnames(res_df))
136140
write.table(
@@ -171,7 +175,10 @@ set1pal <- brewer.pal(9, "Set1")
171175
lapply(seq_along(contrast_list), function(x) {
172176
ymin <- 0
173177
ymax <- max(-log10(
174-
subset(contrast_list[[x]], padj < p_thresh & log2FoldChange > l2fc_thresh)$padj
178+
subset(
179+
contrast_list[[x]],
180+
padj < p_thresh & log2FoldChange > l2fc_thresh
181+
)$padj
175182
))
176183
xmin <- round_any(
177184
min(unlist(subset(
@@ -193,18 +200,27 @@ lapply(seq_along(contrast_list), function(x) {
193200

194201
## show gene labels where the log2FoldChange exceeds a certain threshold:
195202
keepLabs <- rownames(
196-
subset(contrast_list[[x]], padj < p_thresh & (abs(log2FoldChange) > xmax * 0.9))
203+
subset(
204+
contrast_list[[x]],
205+
padj < p_thresh & (abs(log2FoldChange) > xmax * 0.9)
206+
)
197207
)
198208
keepLabs <- c(keepLabs, rownames(
199-
subset(contrast_list[[x]], padj < p_thresh & (abs(-log10(padj)) > ymax * 0.5))
209+
subset(
210+
contrast_list[[x]],
211+
padj < p_thresh & (abs(-log10(padj)) > ymax * 0.5)
212+
)
200213
))
201214

202215
## Custom colour scheme
203216
keyvals <- ifelse(
204-
contrast_list[[x]]$log2FoldChange < (l2fc_thresh * -1) & contrast_list[[x]]$padj < p_thresh,
217+
contrast_list[[x]]$log2FoldChange < (
218+
l2fc_thresh * -1) & contrast_list[[x]]$padj < p_thresh,
205219
set1pal[3],
206220
ifelse(
207-
contrast_list[[x]]$log2FoldChange > l2fc_thresh & contrast_list[[x]]$padj < p_thresh,
221+
contrast_list[[x]]$log2FoldChange > l2fc_thresh & contrast_list[[
222+
x
223+
]]$padj < p_thresh,
208224
set1pal[1], "grey45"
209225
)
210226
)
@@ -246,7 +262,9 @@ lapply(seq_along(contrast_list), function(x) {
246262

247263
ggsave(
248264
volcano_plot,
249-
file = file.path(outdir, paste0("volcano_plot_", names(contrast_list)[x], ".png")),
265+
file = file.path(outdir, paste0("volcano_plot_", names(
266+
contrast_list
267+
)[x], ".png")),
250268
device = "png", units = "in",
251269
width = 8, height = 7, dpi = 300
252270
)

0 commit comments

Comments
 (0)