-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrna_seq_Functions.R
95 lines (83 loc) · 3.36 KB
/
rna_seq_Functions.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
############################ Functions RNA-Seq #########################
source(file ="./RNA-seq_Sara_MPNSTcl_treatments/utils.R")
source(file = "./RNA-seq_Sara_MPNSTcl_treatments/gsea_functions.R")
source(file ="./RNA-seq_Sara_MPNSTcl_treatments/annotationBioMart.R")
source (file = "./RNA-seq_Sara_MPNSTcl_treatments/plotfunctions.R")
source(file = "./RNA-seq_Sara_MPNSTcl_treatments/deg_result_functions.R")
### salmonAlignment
salmonAlignment <- function(sample.name, salmonDir,
file1.suffix, file2.suffix,
fastqdir,
transcript.index,
output.suffix,
output.quants,
libtype = "IU",
threads = 4,
verbose = TRUE){
now.msg("Salmon starting...")
file.name <- file.path(output.quants, paste0(sample.name, output.suffix))
if (!file.exists(file.name)){
message("missing file", file.name)
full.command <- paste0(salmonDir, " quant -i",
transcript.index," -l ",
libtype, " -1 ",
fastqdir,
sample.name,
file1.suffix, " -2 ",
fastqdir, sample.name,
file2.suffix, " --validateMappings -p ",
as.character(threads),
" -o ",
output.quants,
sample.name, output.suffix )
system(full.command, wait = TRUE)
}
}
####importQuantData
importQuantsData <- function(quant.files, orgdb, orgdb.keytype, org.columns, tximpot.type= "salmon", verbose = TRUE, ...){
now.msg("Tximport starting...", verbose = verbose)
#translating transctipts to gene symbol
k <- keys(orgdb, keytype = org.keytype)
tx2gene <- AnnotationDbi::select(x = orgdb,
keys = k,
columns = org.columns,
keytype = org.keytype)
#importing qunats data
txi.salmon <- tximport(files = salmonquants.fl,
type = "salmon",
tx2gene = tx2gene, ...)
now.msg(" Tximport done", verbose = verbose)
return(txi.salmon)
}
###selectDataFromTximport
selectDataFromTximport <- function(tximport, sample_names){
tximport$abundance <- data.matrix(data.frame(tximport$abundance)[colnames(tximport$abundance) %in% sample_names])
colnames(tximport$abundance)<- sample_names
tximport$counts <-data.matrix(data.frame(tximport$counts)[colnames(tximport$counts) %in% sample_names])
colnames(tximport$counts)<- sample_names
tximport$length <- data.matrix(data.frame(tximport$length)[colnames(tximport$length) %in% sample_names])
colnames(tximport$length)<- sample_names
return(tximport)
}
#we create a function to calculate z-score
cal_z_score <- function(x){
(x - mean(x)) / sd(x)
}
#Functions to wrap labels of barplot
## Core wrapping function
wrap.it <- function(x, len)
{
sapply(x, function(y) paste(strwrap(y, len),
collapse = "\n"),
USE.NAMES = FALSE)
}
## Call this function with a list or vector
wrap.labels <- function(x, len)
{
if (is.list(x))
{
lapply(x, wrap.it, len)
} else {
wrap.it(x, len)
}
}