-
Notifications
You must be signed in to change notification settings - Fork 0
/
tximport&DESeq2-script.R
59 lines (45 loc) · 1.52 KB
/
tximport&DESeq2-script.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
# Load libraries
library(tximport)
library(DESeq2)
library(EnsDb.Hsapiens.v86)
library(tidyverse)
## Get the mapping from transcript IDs to gene symbols ##
# What are the columns in the database?
columns(EnsDb.Hsapiens.v86)
# Get the TXID and SYMBOL columns for all entries in database
tx2gene <- AnnotationDbi::select(EnsDb.Hsapiens.v86,
keys = keys(EnsDb.Hsapiens.v86),
columns = c('TXID', 'SYMBOL'))
# Remove the gene ID column
tx2gene <- dplyr::select(tx2gene, -GENEID)
## Get the quant files and metadata ##
# Collect the sample quant files
samples <- list.dirs('Salmon.out/', recursive = FALSE, full.names = FALSE)
quant_files <- file.path('Salmon.out', samples, 'quant.sf')
names(quant_files) <- samples
print(quant_files)
# Ensure each file actually exists
file.exists(quant_files) # all should be TRUE
# Set up metadata frame
colData <- data.frame(
row.names = samples,
condition = rep(c('untreated', 'dex'), 4)
)
## Compile the tximport counts object and make DESeq dataset ##
# Get tximport counts object
txi <- tximport(files = quant_files,
type = 'salmon',
tx2gene = tx2gene,
ignoreTxVersion = TRUE)
# Make DESeq dataset
dds <- DESeqDataSetFromTximport(txi = txi,
colData = colData,
design = ~condition)
### Do DESeq analysis ! ###
# PCA
vsd <- vst(dds)
plotPCA(vsd)
# DEG analysis
dds <- DESeq(dds)
# Get the results
resdf <- results(dds)