生信实例
rm(list = ls())
> load(file = "01_TCGA_BRCA_exprSet.Rdata")
> ######################################################################
> ## TCGA_id判断是肿瘤还是正常
> metadata <- data.frame(rownames(exprSet)) #转换成数据框,只要行名?
> for (i in 1:length(metadata[,1])) {
+ num <- as.numeric(substring(metadata[i,1],14,15)) #substring直接将
+ if (num %in% seq(1,9)) {
+ metadata[i,2] <- "Tumor"
+ } #如果是肿瘤,就给第2列加上Tumor
+ if (num %in% seq(10,29)) {
+ metadata[i,2] <- "Normal"
+ } #如果是正常组织,就给第2列加上Normal
+ }
>
> names(metadata) <- c("TCGA_id","sample")
> head(metadata)
TCGA_id sample
1 TCGA-AC-A3OD-01B-06R-A22O-07 Tumor
2 TCGA-AR-A251-01A-12R-A169-07 Tumor
3 TCGA-BH-A0B5-11A-23R-A12P-07 Normal
4 TCGA-E2-A1IK-01A-11R-A144-07 Tumor
5 TCGA-E2-A15C-01A-31R-A12D-07 Tumor
6 TCGA-B6-A2IU-01A-32R-A18M-07 Tumor
> ## 上面的事情也可以用ifelse完成
> group <- ifelse(as.numeric(substring(rownames(exprSet),14,15))
+ %in% c(1:9),"Tumor","Normal")
> metadata1 <- data.frame(TCGA_id=rownames(exprSet),
+ sample=group)
> head(metadata1)
TCGA_id sample
1 TCGA-AC-A3OD-01B-06R-A22O-07 Tumor
2 TCGA-AR-A251-01A-12R-A169-07 Tumor
3 TCGA-BH-A0B5-11A-23R-A12P-07 Normal
4 TCGA-E2-A1IK-01A-11R-A144-07 Tumor
5 TCGA-E2-A15C-01A-31R-A12D-07 Tumor
6 TCGA-B6-A2IU-01A-32R-A18M-07 Tumor