# TCGAbiolinks (二) 获取生存分析数据

## 来源

https://www.yisu.com/zixun/572908.html

https://j11.fun/tcgaclinical

## 慢更新数据（不推荐）

    1
    2
    3
    4
    5
    6
    7
    8
    9

    library(TCGAbiolinks)
    PRAD <- GDCquery(project = 'TCGA-PRAD',
                      data.category = "Clinical",
                      file.type = "xml")
    GDCdownload(query = PRAD)
    clinical <- GDCprepare_clinic(PRAD, clinical.info = 'patient')
    saveRDS(clinical, 'prad_clinical.rds')
    df <- clinical[,c('bcr_patient_barcode','vital_status', 'days_to_death', 'days_to_last_followup', 'biochemical_recurrence', 'days_to_first_biochemical_recurrence', 'patient_death_reason')]
    df[['os_time']] <- with(df, ifelse(vital_status == 'Dead', days_to_death, days_to_last_followup))

## 快更新数据

    1
    2
    3
    4
    5
    6
    7

    library(TCGAbiolinks)
    cl_new <- GDCquery_clinic(project = 'TCGA-PRAD', type = 'clinical')
    df <- cl_new[,c('bcr_patient_barcode', 'days_to_last_follow_up', 'days_to_death', 'vital_status',
             'days_to_last_known_disease_status', 'last_known_disease_status',
             'days_to_recurrence', 'progression_or_recurrence')]
    df[['os_time']] <- with(df, ifelse(vital_status == 'Dead', days_to_death, days_to_last_follow_up))
    write.csv(df, 'prad_survival.csv')

- os_time为总体生存时间，单位：天
- vital_status为结局，Dead or Alive

## 补丁

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

    f_rm_duplicated <- function(NameL, reverse=F){
        tmp <- data.frame(table(NameL))
        if(reverse){
            tmp <- tmp$NameL[tmp$Freq > 1]
        }else{
            tmp <- tmp$NameL[tmp$Freq == 1]
        }
        which(NameL %in% as.character(tmp))
    }
    patch <- readRDS('prad_clinical.rds')
    patch <- patch[f_rm_duplicated(patch$bcr_patient_barcode),]
    patch <- patch[patch$patient_death_reason != '',]
    patch[,c('bcr_patient_barcode','patient_death_reason')]
    df <- df[f_rm_duplicated(df$bcr_patient_barcode),]
    df[['os_status']]  <- with(df, ifelse(vital_status == 'Dead', 0, 1))
    df[df$bcr_patient_barcode %in% with(patch,
                                        bcr_patient_barcode[patient_death_reason == 'Other, non-malignant disease']),
       'os_status']  <- 1
    df[df$os_status==0,]
    write.csv(df, 'prad_survival.csv')

数据库
TCGAbiolinks (二) 获取生存分析数据
https://occdn.limour.top/1945.html
Author
Limour
Posted on
July 3, 2022
Licensed under
生存分析的基本流程 Previous
STAR：一键脚本 Next

#### Search

Keyword