-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCGA_code
362 lines (331 loc) · 19.2 KB
/
TCGA_code
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# ---------------------------------------------------------
# @Author: Yu Liu
# @Date: 2020-02-25 17:21:17
# ---------------------------------------------------------
#---------------------------------------------------
# Filter TCGA Replicate Samples
# ooooooo
# The filter rule following broad institute says:
#
# In many instances there is more than one aliquot for a given combination of individual, platform, and data type. However, only one aliquot may be ingested into Firehose. Therefore, a set of precedence rules are applied to select the most scientifically advantageous one among them. Two filters are applied to achieve this aim: an Analyte Replicate Filter and a Sort Replicate Filter.
#
# Analyte Replicate Filter
# The following precedence rules are applied when the aliquots have differing analytes. For RNA aliquots, T analytes are dropped in preference to H and R analytes, since T is the inferior extraction protocol. If H and R are encountered, H is the chosen analyte. This is somewhat arbitrary and subject to change, since it is not clear at present whether H or R is the better protocol. If there are multiple aliquots associated with the chosen RNA analyte, the aliquot with the later plate number is chosen. For DNA aliquots, D analytes (native DNA) are preferred over G, W, or X (whole-genome amplified) analytes, unless the G, W, or X analyte sample has a higher plate number.
#
# Sort Replicate Filter
# The following precedence rules are applied when the analyte filter still produces more than one sample. The sort filter chooses the aliquot with the highest lexicographical sort value, to ensure that the barcode with the highest portion and/or plate number is selected when all other barcode fields are identical.
# oooooo
# Ref Link: <https://confluence.broadinstitute.org/display/GDAC/FAQ#FAQ-sampleTypesQWhatTCGAsampletypesareFirehosepipelinesexecutedupon>
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# source: https://gist.github.com/ShixiangWang/33b2f9b49b77eaa8f773b428480f9101#file-tcga_replicatefilter-r
#-------------------------------------------------------------------
tcga_replicateFilter = function(tsb, analyte_target=c("DNA","RNA"), decreasing=TRUE,
analyte_position=20, plate=c(22,25), portion=c(18,19), filter_FFPE=FALSE, full_barcode=FALSE) {
# basically, user provide tsb and analyte_target is fine.
# If you want to filter FFPE samples, please set filter_FFPE and full_barcode all to TRUE,
# and tsb must have nchar of 28
analyte_target = match.arg(analyte_target)
# Strings in R are largely lexicographic
# see ??base::Comparison
# filter FFPE samples
# provide by <http://gdac.broadinstitute.org/runs/sampleReports/latest/FPPP_FFPE_Cases.html>
if(full_barcode & filter_FFPE){
ffpe = c("TCGA-44-2656-01B-06D-A271-08", "TCGA-44-2656-01B-06D-A273-01",
"TCGA-44-2656-01B-06D-A276-05", "TCGA-44-2656-01B-06D-A27C-26",
"TCGA-44-2656-01B-06R-A277-07", "TCGA-44-2662-01B-02D-A271-08",
"TCGA-44-2662-01B-02D-A273-01", "TCGA-44-2662-01B-02R-A277-07",
"TCGA-44-2665-01B-06D-A271-08", "TCGA-44-2665-01B-06D-A273-01",
"TCGA-44-2665-01B-06D-A276-05", "TCGA-44-2665-01B-06R-A277-07",
"TCGA-44-2666-01B-02D-A271-08", "TCGA-44-2666-01B-02D-A273-01",
"TCGA-44-2666-01B-02D-A276-05", "TCGA-44-2666-01B-02D-A27C-26",
"TCGA-44-2666-01B-02R-A277-07", "TCGA-44-2668-01B-02D-A271-08",
"TCGA-44-2668-01B-02D-A273-01", "TCGA-44-2668-01B-02D-A276-05",
"TCGA-44-2668-01B-02D-A27C-26", "TCGA-44-2668-01B-02R-A277-07",
"TCGA-44-3917-01B-02D-A271-08", "TCGA-44-3917-01B-02D-A273-01",
"TCGA-44-3917-01B-02D-A276-05", "TCGA-44-3917-01B-02D-A27C-26",
"TCGA-44-3917-01B-02R-A277-07", "TCGA-44-3918-01B-02D-A271-08",
"TCGA-44-3918-01B-02D-A273-01", "TCGA-44-3918-01B-02D-A276-05",
"TCGA-44-3918-01B-02D-A27C-26", "TCGA-44-3918-01B-02R-A277-07",
"TCGA-44-4112-01B-06D-A271-08", "TCGA-44-4112-01B-06D-A273-01",
"TCGA-44-4112-01B-06D-A276-05", "TCGA-44-4112-01B-06D-A27C-26",
"TCGA-44-4112-01B-06R-A277-07", "TCGA-44-5645-01B-04D-A271-08",
"TCGA-44-5645-01B-04D-A273-01", "TCGA-44-5645-01B-04D-A276-05",
"TCGA-44-5645-01B-04D-A27C-26", "TCGA-44-5645-01B-04R-A277-07",
"TCGA-44-6146-01B-04D-A271-08", "TCGA-44-6146-01B-04D-A273-01",
"TCGA-44-6146-01B-04D-A276-05", "TCGA-44-6146-01B-04D-A27C-26",
"TCGA-44-6146-01B-04R-A277-07", "TCGA-44-6146-01B-04R-A27D-13",
"TCGA-44-6147-01B-06D-A271-08", "TCGA-44-6147-01B-06D-A273-01",
"TCGA-44-6147-01B-06D-A276-05", "TCGA-44-6147-01B-06D-A27C-26",
"TCGA-44-6147-01B-06R-A277-07", "TCGA-44-6147-01B-06R-A27D-13",
"TCGA-44-6775-01C-02D-A271-08", "TCGA-44-6775-01C-02D-A273-01",
"TCGA-44-6775-01C-02D-A276-05", "TCGA-44-6775-01C-02D-A27C-26",
"TCGA-44-6775-01C-02R-A277-07", "TCGA-44-6775-01C-02R-A27D-13",
"TCGA-A6-2674-01B-04D-A270-10", "TCGA-A6-2674-01B-04R-A277-07",
"TCGA-A6-2677-01B-02D-A270-10", "TCGA-A6-2677-01B-02D-A274-01",
"TCGA-A6-2677-01B-02D-A27A-05", "TCGA-A6-2677-01B-02D-A27E-26",
"TCGA-A6-2677-01B-02R-A277-07", "TCGA-A6-2684-01C-08D-A270-10",
"TCGA-A6-2684-01C-08D-A274-01", "TCGA-A6-2684-01C-08D-A27A-05",
"TCGA-A6-2684-01C-08D-A27E-26", "TCGA-A6-2684-01C-08R-A277-07",
"TCGA-A6-3809-01B-04D-A270-10", "TCGA-A6-3809-01B-04D-A274-01",
"TCGA-A6-3809-01B-04D-A27A-05", "TCGA-A6-3809-01B-04D-A27E-26",
"TCGA-A6-3809-01B-04R-A277-07", "TCGA-A6-3810-01B-04D-A270-10",
"TCGA-A6-3810-01B-04D-A274-01", "TCGA-A6-3810-01B-04D-A27A-05",
"TCGA-A6-3810-01B-04D-A27E-26", "TCGA-A6-3810-01B-04R-A277-07",
"TCGA-A6-5656-01B-02D-A270-10", "TCGA-A6-5656-01B-02D-A274-01",
"TCGA-A6-5656-01B-02D-A27A-05", "TCGA-A6-5656-01B-02D-A27E-26",
"TCGA-A6-5656-01B-02R-A277-07", "TCGA-A6-5656-01B-02R-A27D-13",
"TCGA-A6-5659-01B-04D-A270-10", "TCGA-A6-5659-01B-04D-A274-01",
"TCGA-A6-5659-01B-04D-A27A-05", "TCGA-A6-5659-01B-04D-A27E-26",
"TCGA-A6-5659-01B-04R-A277-07", "TCGA-A6-6650-01B-02D-A270-10",
"TCGA-A6-6650-01B-02D-A274-01", "TCGA-A6-6650-01B-02D-A27A-05",
"TCGA-A6-6650-01B-02D-A27E-26", "TCGA-A6-6650-01B-02R-A277-07",
"TCGA-A6-6650-01B-02R-A27D-13", "TCGA-A6-6780-01B-04D-A270-10",
"TCGA-A6-6780-01B-04D-A274-01", "TCGA-A6-6780-01B-04D-A27A-05",
"TCGA-A6-6780-01B-04D-A27E-26", "TCGA-A6-6780-01B-04R-A277-07",
"TCGA-A6-6780-01B-04R-A27D-13", "TCGA-A6-6781-01B-06D-A270-10",
"TCGA-A6-6781-01B-06D-A274-01", "TCGA-A6-6781-01B-06D-A27A-05",
"TCGA-A6-6781-01B-06R-A277-07", "TCGA-A6-6781-01B-06R-A27D-13",
"TCGA-A7-A0DB-01C-02D-A272-09", "TCGA-A7-A0DB-01C-02R-A277-07",
"TCGA-A7-A0DB-01C-02R-A27D-13", "TCGA-A7-A13D-01B-04D-A272-09",
"TCGA-A7-A13D-01B-04R-A277-07", "TCGA-A7-A13D-01B-04R-A27D-13",
"TCGA-A7-A13E-01B-06D-A272-09", "TCGA-A7-A13E-01B-06R-A277-07",
"TCGA-A7-A13E-01B-06R-A27D-13", "TCGA-A7-A26E-01B-06D-A272-09",
"TCGA-A7-A26E-01B-06D-A275-01", "TCGA-A7-A26E-01B-06D-A27B-05",
"TCGA-A7-A26E-01B-06R-A277-07", "TCGA-A7-A26E-01B-06R-A27D-13",
"TCGA-A7-A26J-01B-02D-A272-09", "TCGA-A7-A26J-01B-02D-A275-01",
"TCGA-A7-A26J-01B-02D-A27B-05", "TCGA-A7-A26J-01B-02D-A27F-26",
"TCGA-A7-A26J-01B-02R-A277-07", "TCGA-A7-A26J-01B-02R-A27D-13",
"TCGA-B2-3923-01B-10D-A270-10", "TCGA-B2-3923-01B-10R-A277-07",
"TCGA-B2-3923-01B-10R-A27D-13", "TCGA-B2-3924-01B-03D-A270-10",
"TCGA-B2-3924-01B-03D-A274-01", "TCGA-B2-3924-01B-03D-A27A-05",
"TCGA-B2-3924-01B-03D-A27E-26", "TCGA-B2-3924-01B-03R-A277-07",
"TCGA-B2-3924-01B-03R-A27D-13", "TCGA-B2-5633-01B-04D-A270-10",
"TCGA-B2-5633-01B-04D-A274-01", "TCGA-B2-5633-01B-04D-A27A-05",
"TCGA-B2-5633-01B-04D-A27E-26", "TCGA-B2-5633-01B-04R-A277-07",
"TCGA-B2-5633-01B-04R-A27D-13", "TCGA-B2-5635-01B-04D-A270-10",
"TCGA-B2-5635-01B-04D-A274-01", "TCGA-B2-5635-01B-04D-A27A-05",
"TCGA-B2-5635-01B-04D-A27E-26", "TCGA-B2-5635-01B-04R-A277-07",
"TCGA-B2-5635-01B-04R-A27D-13", "TCGA-BK-A0CA-01B-02D-A272-09",
"TCGA-BK-A0CA-01B-02D-A275-01", "TCGA-BK-A0CA-01B-02D-A27B-05",
"TCGA-BK-A0CA-01B-02D-A27F-26", "TCGA-BK-A0CA-01B-02R-A277-07",
"TCGA-BK-A0CA-01B-02R-A27D-13", "TCGA-BK-A0CC-01B-04D-A272-09",
"TCGA-BK-A0CC-01B-04D-A275-01", "TCGA-BK-A0CC-01B-04D-A27B-05",
"TCGA-BK-A0CC-01B-04R-A277-07", "TCGA-BK-A0CC-01B-04R-A27D-13",
"TCGA-BK-A139-01C-08D-A272-09", "TCGA-BK-A139-01C-08D-A275-01",
"TCGA-BK-A139-01C-08D-A27B-05", "TCGA-BK-A139-01C-08D-A27F-26",
"TCGA-BK-A139-01C-08R-A277-07", "TCGA-BK-A139-01C-08R-A27D-13",
"TCGA-BK-A26L-01C-04D-A272-09", "TCGA-BK-A26L-01C-04D-A275-01",
"TCGA-BK-A26L-01C-04D-A27B-05", "TCGA-BK-A26L-01C-04D-A27F-26",
"TCGA-BK-A26L-01C-04R-A277-07", "TCGA-BK-A26L-01C-04R-A27D-13",
"TCGA-BL-A0C8-01B-04D-A271-08", "TCGA-BL-A0C8-01B-04D-A273-01",
"TCGA-BL-A0C8-01B-04D-A276-05", "TCGA-BL-A0C8-01B-04D-A27C-26",
"TCGA-BL-A0C8-01B-04R-A277-07", "TCGA-BL-A0C8-01B-04R-A27D-13",
"TCGA-BL-A13I-01B-04D-A271-08", "TCGA-BL-A13I-01B-04D-A276-05",
"TCGA-BL-A13I-01B-04R-A277-07", "TCGA-BL-A13I-01B-04R-A27D-13",
"TCGA-BL-A13J-01B-04D-A271-08", "TCGA-BL-A13J-01B-04D-A273-01",
"TCGA-BL-A13J-01B-04D-A276-05", "TCGA-BL-A13J-01B-04D-A27C-26",
"TCGA-BL-A13J-01B-04R-A277-07", "TCGA-BL-A13J-01B-04R-A27D-13")
tsb = setdiff(tsb, tsb[which(tsb %in% ffpe)])
}
# find repeated samples
sampleID = substr(tsb, start = 1, stop = 15)
dp_samples = unique(sampleID[duplicated(sampleID)])
if(length(dp_samples)==0){
message("ooo Not find any duplicated barcodes, return original input..")
tsb
}else{
uniq_tsb = tsb[! sampleID %in% dp_samples]
dp_tsb = setdiff(tsb, uniq_tsb)
add_tsb = c()
# analyte = substr(dp_tsb, start = analyte_position, stop = analyte_position)
# if analyte_target = "DNA"
# analyte: D > G,W,X
if(analyte_target == "DNA"){
for(x in dp_samples){
mulaliquots = dp_tsb[substr(dp_tsb,1,15) == x]
analytes = substr(mulaliquots,
start = analyte_position,
stop = analyte_position)
if(any(analytes == "D") & !(all(analytes == "D"))){
aliquot = mulaliquots[which(analytes == "D")]
add_tsb = c(add_tsb, aliquot)
dp_tsb = setdiff(dp_tsb, mulaliquots)
}
}
# if analyte_target = "RNA"
# analyte: H > R > T
}else{
for(x in dp_samples){
mulaliquots = dp_tsb[substr(dp_tsb,1,15) == x]
analytes = substr(mulaliquots,
start = analyte_position,
stop = analyte_position)
if(any(analytes == "H") & !(all(analytes == "H"))){
aliquot = mulaliquots[which(analytes == "H")]
add_tsb = c(add_tsb, aliquot)
dp_tsb = setdiff(dp_tsb, mulaliquots)
}else if(any(analytes == "R") & !(all(analytes == "R"))){
aliquot = mulaliquots[which(analytes == "R")]
add_tsb = c(add_tsb, aliquot)
dp_tsb = setdiff(dp_tsb, mulaliquots)
}else if(any(analytes == "T") & !(all(analytes == "T"))){
aliquot = mulaliquots[which(analytes == "T")]
add_tsb = c(add_tsb, aliquot)
dp_tsb = setdiff(dp_tsb, mulaliquots)
}
}
}
# else{
#
# }
if(length(dp_tsb) == 0){
message("ooo Filter barcodes successfully!")
c(uniq_tsb, add_tsb)
}else{
# filter according to portion number
sampleID_res = substr(dp_tsb, start=1, stop=15)
dp_samples_res = unique(sampleID_res[duplicated(sampleID_res)])
for(x in dp_samples_res){
mulaliquots = dp_tsb[substr(dp_tsb,1,15) == x]
portion_codes = substr(mulaliquots,
start = portion[1],
stop = portion[2])
portion_keep = sort(portion_codes, decreasing = decreasing)[1]
if(!all(portion_codes == portion_keep)){
if(length(which(portion_codes == portion_keep)) == 1){
add_tsb = c(add_tsb, mulaliquots[which(portion_codes == portion_keep)])
dp_tsb = setdiff(dp_tsb, mulaliquots)
}else{
dp_tsb = setdiff(dp_tsb, mulaliquots[which(portion_codes != portion_keep)])
}
}
}
if(length(dp_tsb)==0){
message("ooo Filter barcodes successfully!")
c(uniq_tsb, add_tsb)
}else{
# filter according to plate number
sampleID_res = substr(dp_tsb, start=1, stop=15)
dp_samples_res = unique(sampleID_res[duplicated(sampleID_res)])
for(x in dp_samples_res){
mulaliquots = dp_tsb[substr(dp_tsb,1,15) == x]
plate_codes = substr(mulaliquots,
start = plate[1],
stop = plate[2])
plate_keep = sort(plate_codes, decreasing = decreasing)[1]
add_tsb = c(add_tsb, mulaliquots[which(plate_codes == plate_keep)])
dp_tsb = setdiff(dp_tsb, mulaliquots)
}
if(length(dp_tsb)==0){
message("ooo Filter barcodes successfully!")
c(uniq_tsb, add_tsb)
}else{
message("ooo barcodes ", dp_tsb, " failed in filter process, other barcodes will be returned.")
c(uniq_tsb, add_tsb)
}
}
}
}
}
# 安装相关的包
# if (!requireNamespace("BiocManager", quietly=TRUE))
# install.packages("BiocManager")
# BiocManager::install("TCGAbiolinks")
# BiocManager::install("SummarizedExperiment")
# 打开.Rprofile
file.edit('~/.Rprofile')
# 这是清华源的镜像
options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor")
# BiocManager::install("org.Hs.eg.db")
# chooseBioCmirror()
# install.packages('survival')
# install.packages('survminer')
library(SummarizedExperiment)
library(TCGAbiolinks)
library(survival)
library(survminer)
library("annotate")
library("org.Hs.eg.db")
# Set path
setwd("D:/TCGA/diff/")
# 项目的概括信息,project的名称可以从 https://portal.gdc.cancer.gov/ 上面选择对应的器官,进入之后左侧列表中就会显示。
request_project = "TCGA-PAAD"
# http://www.zxzyl.com/archives/1063
TCGAbiolinks:::getProjectSummary(request_project)
# 获取该项目样本的临床信息
clinical <- GDCquery_clinic(project = request_project, type = "clinical")
write.table(clinical, "PAAD_clinical.txt", sep="\t", quote=F, row.names=F)
View(clinical)
# 下载TCGA-COAD项目的rna-seq的counts数据,构建GDCquery,具体的数据类型的写法可以参考 https://portal.gdc.cancer.gov/repository 左侧列表
query <- GDCquery(project = request_project,
experimental.strategy = "miRNA-Seq",
data.category = "Transcriptome Profiling",
data.type = "miRNA Expression Quantification",
workflow.type = "BCGSC miRNA Profiling")
query <- GDCquery(project = request_project,
experimental.strategy = "RNA-Seq",
data.category = "Transcriptome Profiling",
data.type = "Gene Expression Quantification",
workflow.type = "HTSeq - FPKM")
# 下载数据
GDCdownload(query)
# 导入数据
Rnaseq <- GDCprepare(query)
# 得到样本的基因counts矩阵,每行为一个基因,每列为一个样本
count_matrix <- assay(Rnaseq)
samplename<-colnames(count_matrix)
# TCGA样本的编号以'-'分割,前三列是患者编号,第四列是类型,一般11表示正常样本,01表示肿瘤样本,见https://gdc.cancer.gov/resources-tcga-users/tcga-code-tables/sample-type-codes
# 选出所有正常样本
# NB Blood Derived Normal
# NT Solid Tissue Normal
# NBC Buccal Cell Normal
# NEBV EBV Immortalized Normal
# NBM Bone Marrow Normal
# sampleNormal <- TCGAquery_SampleTypes(barcode = colnames(count_matrix),typesample = c("NB","NT","NBC","NEBV","NBM"))
sampleNormal <- TCGAquery_SampleTypes(barcode = colnames(count_matrix),typesample = c("NT"))
length(sampleNormal)
# selection of tumor samples "TP"
sampleCase <- TCGAquery_SampleTypes(barcode = colnames(count_matrix),typesample = c("TP"))
length(sampleCase)
sampleCase_filtered <- tcga_replicateFilter(tsb = sampleCase, analyte_target = "RNA")
dim(sampleCase_filtered)
#基因相关信息
request_gene = c("ENSG00000136688")
gene_name = c("IL36A")
GSEA.matrix.raw <- count_matrix[,sampleCase]
raw <- GSEA.matrix.raw
gexp <- raw["ENSG00000136688",]
GSEA.sampleinfo <- ""
GSEA.sampleinfo <- data.frame(barcode = sampleCase_filtered, gexp = gexp)
#GSEA.sampleinfo$group<-ifelse(GSEA.sampleinfo$gexp > quantile(GSEA.sampleinfo$gexp, 0.7),'high','medium')
#GSEA.sampleinfo$group<-ifelse(GSEA.sampleinfo$gexp < quantile(GSEA.sampleinfo$gexp, 0.3),'low',GSEA.sampleinfo$group)
GSEA.sampleinfo$group<-ifelse(GSEA.sampleinfo$gexp > median(GSEA.sampleinfo$gexp),'high','medium')
GSEA.sampleinfo$group<-ifelse(GSEA.sampleinfo$gexp <= median(GSEA.sampleinfo$gexp),'low',GSEA.sampleinfo$group)
GSEA.sampleinfo<-subset(GSEA.sampleinfo, group!="medium")
#直接输出ENSG表达矩阵
GSEA.matrix<- GSEA.matrix.raw[,as.character(GSEA.sampleinfo$barcode)]
table(colnames(GSEA.matrix) == as.character(GSEA.sampleinfo$barcode))
GSEA.matrix.raw<- cbind(rownames(GSEA.matrix.raw), GSEA.matrix.raw)
colnames(GSEA.matrix.raw)[1] <- "NAME"
ncol(GSEA.matrix.raw)-1
nrow(GSEA.sampleinfo)
table(colnames(GSEA.matrix[,-1]) == as.character(GSEA.sampleinfo$barcode))
write.table(GSEA.matrix,"TNFRSF12A_50_expression_matrix.txt",row.names=F,sep="\t",quote=F)
write.table(GSEA.sampleinfo,"TNFRSF12A_50_sampleinfo.txt",row.names=F,sep="\t",quote=F)
outfcon <- file("TNFRSF12A_50_sampleinfo.cls", open="wt")
writeLines(paste(nrow(GSEA.sampleinfo),"\t2","\t1"), con=outfcon)
writeLines(paste("#\t",GSEA.sampleinfo$group[1],"\t", c("high","low")[c("high","low")!= GSEA.sampleinfo$group[1]]), con=outfcon)
writeLines(paste(GSEA.sampleinfo$group, collapse="\t"), con=outfcon)
close(outfcon)
#用ensembl100注释
ensg_symbol <- read.table("ensembl_100_gene.txt", sep="\t", header = T)
matrix1 <- merge(GSEA.matrix.raw, ensg_symbol, by.x = "NAME", by.y = "gene_id")
duplicated(matrix1$gene_name)
duplicated_symbol <- matrix1$gene_name[which(duplicated(matrix1$gene_name))]
subset(ensg_symbol, gene_name %in% duplicated_symbol)
#去掉多个ENSG对应一个symbol,也可以选择取平均值
matrix_noduplicated <- subset(matrix1, ! gene_name %in% duplicated_symbol)
GSEA.matrix<- matrix_noduplicated[ ,1:(ncol(matrix_noduplicated)-12)]
GSEA.matrix$NAME <- matrix_noduplicated$gene_name
write.table(GSEA.matrix,"LUAD.txt",row.names=F,sep="\t",quote=F)