-
Notifications
You must be signed in to change notification settings - Fork 1
/
itraq.R
130 lines (114 loc) · 4.11 KB
/
itraq.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
## Labelled (iTRAQ4) Mass Spectometry Protein Quantification
## Docker Package: p3
## Daniel Kristiyanto (daniel.kristiyanto@pnnl.gov)
suppressMessages(library(mzID))
suppressMessages(library(MSnbase))
suppressMessages(library(stringr))
suppressMessages(library(BiocParallel))
BiocParallel::register(BiocParallel::SnowParam(2))
BiocParallel::register(BiocParallel::MulticoreParam(2))
start.time = Sys.time()
args = commandArgs(trailingOnly=TRUE)
if (length(args)!=7) {
stop("Arguments.", call.=FALSE)
} else {
mzml.files = args[1]
mzid.files = args[2]
specvalue_threshold = as.double(args[3])
pNA = as.numeric(args[4])
quant_method = args[5]
combine_by = args[6]
out_file = args[7]
}
print("=======================================")
print(" Quantification")
if(quant_method=="count")
{
print("Spectrum Count Quantification")
if(specvalue_threshold > 0)
{
print(paste("Spec E-Value Threshold:", specvalue_threshold))
}
if(toupper(combine_by) != "SKIP")
{
print(paste("features combined using:", combine_by))
}
}else{
print("iTRAQ4 Quantification")
if(specvalue_threshold > 0)
{
print(paste("Spec E-Value Threshold:", specvalue_threshold))
}
print(paste("pNA:", pNA))
print(paste("quant_method:", quant_method))
if(toupper(combine_by) != "SKIP")
{
print(paste("features combined using:", combine_by))
}
}
print("=======================================")
setwd("/root/data")
####################################### READ FILE ###################################################
# mzid.files <- list.files(path = ".", pattern ="mzid", all.files = F,
# full.names = F, recursive = F, ignore.case = T, include.dirs = F)
# mzml.files <- list.files(path = ".", pattern ="mzML$|mzXML$", all.files = F,
# full.names = F, recursive = F, ignore.case = T, include.dirs = F)
#mzids.raw <- mzID(mzid.files)
msexp.raw <- readMSData(mzml.files)
####################################### IDENTIFICATION & FILTERING ###################################################
print("Identifying...")
msexp.id <- addIdentificationData(msexp.raw, id = mzid.files,verbose=F)
idSummary(msexp.id)
rm(mzid.files)
rm(mzml.files)
rm(msexp.raw)
gc(verbose = FALSE)
if(specvalue_threshold==0)
{
msexp.filter1 <- msexp.id
} else {
print("Filtering...")
k <- (fData(msexp.id)$'ms-gf:specevalue'< specvalue_threshold)
k[is.na(k)] <- FALSE
msexp.filter1 <- removeNoId(msexp.id, keep=k)
}
rm(msexp.id)
gc(verbose = FALSE)
####################################### QUANTIFICATION ###################################################
print("Quantifying...")
if (quant_method=="count")
{
qnt <- quantify(msexp.filter1, method=quant_method)
qnt.filtered <- qnt
} else
{
qnt <- quantify(msexp.filter1, method=quant_method, reporters=iTRAQ4, strict=F, verbose=F)
qnt.filtered <- filterNA(qnt, pNA = pNA)
}
rm(msexp.filter1)
rm(qnt)
gc(verbose = FALSE)
if(toupper(combine_by) == "SKIP")
{
result <- qnt.filtered
} else
{
result <- combineFeatures(qnt.filtered, groupBy = fData(qnt.filtered)$accession, fun=combine_by)
}
save(result, file=out_file)
####################################### OUTPUT ###################################################
print("Writing the output...")
if (quant_method=="count")
{
Cnt=exprs(result)
colnames(Cnt) = "Count"
quantified <- as.data.frame(cbind(Scan=fData(result)$'scan number(s)', Spectrum=fData(result)$spectrum, Spec_Evalue=fData(result)$'ms-gf:specevalue', AccessionID=row.names(result), PepSeq=fData(result)$pepseq, Cnt))
} else
{
quantified <- as.data.frame(cbind(Scan=fData(result)$'scan number(s)', Spectrum=fData(result)$spectrum, Spec_Evalue=fData(result)$'ms-gf:specevalue', AccessionID=row.names(result), PepSeq=fData(result)$pepseq, exprs(result)))
}
write.table(quantified, row.names = F, quote=F, file=str_replace(out_file,".rda",".txt"), sep = "\t")
stop.time = Sys.time()
print(paste("File:", out_file,"Start Time:", start.time," Stop Time:", stop.time, "Elapsed=",stop.time-start.time))
rm(result)
rm(qnt.filtered)