R/metaAnnotation.R

Defines functions metaAnnotation

Documented in metaAnnotation

#' Decode annotations of samples from the corresponding metadata file
#'
#' use the metaAnnotation() fuction to decode the annotations
#' @import rjson
#' @param dataPath the direction of download Data
#' @param yourjson your downloaded json file
#' @export
metaAnnotation<-function(dataPath,yourjson){
  setwd(dataPath)
  message("处理meta文件,获取注释信息...",appendLF = F)
  #处理metadata文件,也就是上述数据的注释文件
  load(file =".//output//step02.RData")
  x=fromJSON(file=yourjson)
  n=ncol(x_reduce)
  id=rep(0,n)
  sample_id=rep(0,n)
  for(i in 1:n){
    id[i]=x[[i]]$submitter_id
    sample_id[i]=x[[i]]$associated_entities[[1]]$entity_submitter_id
  }
  sample_matrix=data.frame(id=id,sample_id=sample_id)
  sample_info=data.frame(id=substr(id,1,9),sample_id=substr(sample_id,1,15))
  sample_info=sample_info[order(sample_info$id),]
  colnames(x_reduce)=sample_info$sample_id
  #head(x_reduce)
  #提取分组信息
  sample_info$group=as.factor(ifelse(as.numeric(substr(sample_info$sample_id,14,15))<10,"Cancer","Normal"))
  #head(sample_info)
  #table(sample_info$group)
  write.csv(sample_info,"SamplesInformation.csv")
  save(x_reduce,sample_info,file=".//output//step03.RData")
  message("Completed!")
}
dming1024/TCGApackages0226 documentation built on April 9, 2021, 7:48 a.m.