# GeoTcgaData

## Authors

Erqiang Hu

Department of Bioinformatics, School of Basic Medical Sciences, Southern Medical University.

## Introduction

GEO and TCGA provide us with a wealth of data, such as RNA-seq, DNA Methylation, single nucleotide Variation and Copy number variation data. It’s easy to download data from TCGA using the gdc tool or `TCGAbiolinks`, and some software provides organized TCGA data, such as UCSC Xena , UCSCXenaTools, and sangerbox, but processing these data into a format suitable for bioinformatics analysis requires more work. This R package was developed to handle these data.

    library(GeoTcgaData)

## Example

This is a basic example which shows you how to solve a common problem:

### RNA-seq data differential expression analysis

It is convenient to use TCGAbiolinks or `GDCRNATools` to download and analysis Gene expression data. `TCGAbiolinks` use `edgeR` package to do differential expression analysis, while `GDCRNATools` can implement three most commonly used methods: limma, edgeR , and DESeq2 to identify differentially expressed genes (DEGs).

Alicia Oshlack et al. claimed that unlike the chip data, the RNA-seq data had one bias[1]: the larger the transcript length / mean read count , the more likely it was to be identified as a differential gene, while there was no such trend in the chip data[2].

However, when we use their chip data for difference analysis (using the limma package), we find that chip data has the same trend as RNA-seq data. And we also found this trend in the difference analysis results given by the data authors[3].

It is worse noting that only technical replicate data, which has small gene dispersions, shows this bias[4]. This is because in technical replicate RNA-seq data a long gene has more reads mapping to it compared to a short gene of similar expression, and most of the statistical methods used to detect differential expression have stronger detection ability for genes with more reads. However, we have not deduced why there is such a bias in the current difference analysis algorithms.

Some software, such as CQN , present a normalization algorithm [5] to correct systematic biases(gene length bias and GC-content bias[6]. But they did not provide sufficient evidence to prove that the correction is effective. We use the Marioni dataset[2] to verify the correction effect of CQN and find that there is still a deviation after correction:

GOseq [1]based on Wallenius’ noncentral hypergeometric distribution can effectively correct the gene length deviation in enrichment analysis. However, the current RNA-seq data often have no gene length bias, but only the expression amount(read count) bias, GOseq may overcorrect these data, correcting originally unbiased data into reverse bias.

GOseq also fails to correct for expression bias, therefore, read count bias correction is still a challenge for us.

    # use user-defined data
    df <- matrix(rnbinom(400, mu = 4, size = 10), 25, 16)
    df <- as.data.frame(df)
    rownames(df) <- paste0("gene", 1:25)
    colnames(df) <- paste0("sample", 1:16)
    group <- sample(c("group1", "group2"), 16, replace = TRUE)
    result <- differential_RNA(counts = df, group = group,
        filte = FALSE, method = "Wilcoxon")
    # use SummarizedExperiment object input
    df <- matrix(rnbinom(400, mu = 4, size = 10), 25, 16)
    rownames(df) <- paste0("gene", 1:25)
    colnames(df) <- paste0("sample", 1:16)
    group <- sample(c("group1", "group2"), 16, replace = TRUE)

    nrows <- 200; ncols <- 20
    counts <- matrix(
        runif(nrows * ncols, 1, 1e4), nrows,
        dimnames = list(paste0("cg",1:200),paste0("S",1:20))
    )

    colData <- S4Vectors::DataFrame(
      row.names = paste0("sample", 1:16),
      group = group
    )
    data <- SummarizedExperiment::SummarizedExperiment(
             assays=S4Vectors::SimpleList(counts=df),
             colData = colData)

    result <- differential_RNA(counts = data, groupCol = "group",
        filte = FALSE, method = "Wilcoxon")

### DNA Methylation data integration

use `TCGAbiolinks` data.

The codes may need to be modified if `TCGAbiolinks` updates. So please read its documents.

    # use user defined data
    library(ChAMP)
    cpgData <- matrix(runif(2000), nrow = 200, ncol = 10)
    rownames(cpgData) <- paste0("cpg", seq_len(200))
    colnames(cpgData) <- paste0("sample", seq_len(10))
    sampleGroup <- c(rep("group1", 5), rep("group2", 5))
    names(sampleGroup) <- colnames(cpgData)
    cpg2gene <- data.frame(cpg = rownames(cpgData),
        gene = rep(paste0("gene", seq_len(20)), 10))
    result <- differential_methy(cpgData, sampleGroup,
        cpg2gene = cpg2gene, normMethod = NULL)
    # use SummarizedExperiment object input
    library(ChAMP)
    cpgData <- matrix(runif(2000), nrow = 200, ncol = 10)
    rownames(cpgData) <- paste0("cpg", seq_len(200))
    colnames(cpgData) <- paste0("sample", seq_len(10))
    sampleGroup <- c(rep("group1", 5), rep("group2", 5))
    names(sampleGroup) <- colnames(cpgData)
    cpg2gene <- data.frame(cpg = rownames(cpgData),
        gene = rep(paste0("gene", seq_len(20)), 10))
    colData <- S4Vectors::DataFrame(
        row.names = colnames(cpgData),
        group = sampleGroup
    )
    data <- SummarizedExperiment::SummarizedExperiment(
             assays=S4Vectors::SimpleList(counts=cpgData),
             colData = colData)
    result <- differential_methy(cpgData = data,
        groupCol = "group", normMethod = NULL,
        cpg2gene = cpg2gene)

Note: `ChAMP`has a large number of dependent packages. If you cannot install it successfully, you can download each dependent package separately(Source or Binary) and install it locally.

We provide two models to get methylation difference genes:

if model = “cpg”, step1: calculate difference cpgs; step2: calculate difference genes;

if model = “gene”, step1: calculate the methylation level of genes; step2: calculate difference genes.

We find that only model = “gene” has no deviation of CpG number.

### Copy number variation data integration and differential gene extraction

use TCGAbiolinks to download TCGA data(Gene Level Copy Number Scores)

    # use random data as example
    aa <- matrix(sample(c(0, 1, -1), 200, replace = TRUE), 25, 8)
    rownames(aa) <- paste0("gene", 1:25)
    colnames(aa) <- paste0("sample", 1:8)
    sampleGroup <- sample(c("A", "B"), ncol(aa), replace = TRUE)
    diffCnv <- differential_CNV(aa, sampleGroup)

### Difference analysis of single nucleotide Variation data

We provide SNP_QC function to do quality control of SNP data

    snpDf <- matrix(sample(c("AA", "Aa", "aa"), 100, replace = TRUE), 10, 10)
    snpDf <- as.data.frame(snpDf)
    sampleGroup <- sample(c("A", "B"), 10, replace = TRUE)
    result <- SNP_QC(snpDf)

Then use differential_SNP to do differential analysis.

    #' snpDf <- matrix(sample(c("mutation", NA), 100, replace = TRUE), 10, 10)
    #' snpDf <- as.data.frame(snpDf)
    #' sampleGroup <- sample(c("A", "B"), 10, replace = TRUE)
    #' result <- differential_SNP(snpDf, sampleGroup)

### GEO chip data processing

The function `gene_ave` could average the expression data of different ids for the same gene in the GEO chip data. For example:

    aa <- c("MARCH1","MARC1","MARCH1","MARCH1","MARCH1")
    bb <- c(2.969058399,4.722410064,8.165514853,8.24243893,8.60815086)
    cc <- c(3.969058399,5.722410064,7.165514853,6.24243893,7.60815086)
    file_gene_ave <- data.frame(aa=aa,bb=bb,cc=cc)
    colnames(file_gene_ave) <- c("Gene", "GSM1629982", "GSM1629983")
    result <- gene_ave(file_gene_ave, 1)

Multiple genes symbols may correspond to a same chip id. The result of function `repAssign` is to assign the expression of this id to each gene, and function `repRemove` deletes the expression. For example:

    aa <- c("MARCH1 /// MMA","MARC1","MARCH2 /// MARCH3",
            "MARCH3 /// MARCH4","MARCH1")
    bb <- c("2.969058399","4.722410064","8.165514853","8.24243893","8.60815086")
    cc <- c("3.969058399","5.722410064","7.165514853","6.24243893","7.60815086")
    input_file <- data.frame(aa=aa,bb=bb,cc=cc)
    repAssign_result <- repAssign(input_file," /// ")
    repRemove_result <- repRemove(input_file," /// ")

### Other downstream analyses

1. The function `id_conversion_TCGA` could convert ENSEMBL gene id to gene Symbol in TCGA. For example:

    data(profile)
    result <- id_conversion_TCGA(profile)

The parameter `profile` is a data.frame or matrix of gene expression data in TCGA.

Note: In previous versions(< 1.0.0) the `id_conversion` and `id_conversion_TCGA` used HGNC data to convert human gene id.
In future versions, we will use `clusterProfiler::bitr` for ID conversion.

2. The function `countToFpkm` and `countToTpm` could convert count data to FPKM or TPM data.

    data(gene_cov)
    lung_squ_count2 <- matrix(c(1,2,3,4,5,6,7,8,9),ncol=3)
    rownames(lung_squ_count2) <- c("DISC1","TCOF1","SPPL3")
    colnames(lung_squ_count2) <- c("sample1","sample2","sample3")
    result <- countToFpkm(lung_squ_count2, keyType = "SYMBOL",
        gene_cov = gene_cov)
    #> 'select()' returned 1:1 mapping between keys and columns
    #> Warning in clusterProfiler::bitr(rownames(gene_cov), fromType = "ENTREZID", :
    #> 0.08% of input gene IDs are fail to map...

    data(gene_cov)
    lung_squ_count2 <- matrix(c(0.11,0.22,0.43,0.14,0.875,
        0.66,0.77,0.18,0.29),ncol=3)
    rownames(lung_squ_count2) <- c("DISC1","TCOF1","SPPL3")
    colnames(lung_squ_count2) <- c("sample1","sample2","sample3")
    result <- countToTpm(lung_squ_count2, keyType = "SYMBOL",
        gene_cov = gene_cov)

    sessionInfo()
    #> R version 4.6.0 (2026-04-24)
    #> Platform: x86_64-pc-linux-gnu
    #> Running under: Ubuntu 24.04.4 LTS
    #>
    #> Matrix products: default
    #> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
    #> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
    #>
    #> locale:
    #>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    #>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
    #>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
    #>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
    #>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
    #> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
    #>
    #> time zone: Etc/UTC
    #> tzcode source: system (glibc)
    #>
    #> attached base packages:
    #> [1] parallel  stats4    stats     graphics  grDevices utils     datasets
    #> [8] methods   base
    #>
    #> other attached packages:
    #>  [1] ChAMP_2.42.0
    #>  [2] RPMM_1.25
    #>  [3] cluster_2.1.8.2
    #>  [4] DT_0.34.0
    #>  [5] IlluminaHumanMethylationEPICmanifest_0.3.0
    #>  [6] Illumina450ProbeVariants.db_1.46.0
    #>  [7] DMRcate_3.6.0
    #>  [8] ChAMPdata_2.42.0
    #>  [9] minfi_1.58.0
    #> [10] bumphunter_1.54.0
    #> [11] locfit_1.5-9.12
    #> [12] iterators_1.0.14
    #> [13] foreach_1.5.2
    #> [14] Biostrings_2.80.0
    #> [15] XVector_0.52.0
    #> [16] SummarizedExperiment_1.42.0
    #> [17] Biobase_2.72.0
    #> [18] MatrixGenerics_1.24.0
    #> [19] matrixStats_1.5.0
    #> [20] GenomicRanges_1.64.0
    #> [21] Seqinfo_1.2.0
    #> [22] IRanges_2.46.0
    #> [23] S4Vectors_0.50.0
    #> [24] BiocGenerics_0.58.0
    #> [25] generics_0.1.4
    #> [26] GeoTcgaData_2.12.0
    #> [27] rmarkdown_2.31
    #>
    #> loaded via a namespace (and not attached):
    #>   [1] R.methodsS3_1.8.2
    #>   [2] dichromat_2.0-0.1
    #>   [3] cqn_1.58.0
    #>   [4] progress_1.2.3
    #>   [5] nnet_7.3-20
    #>   [6] shinythemes_1.2.0
    #>   [7] HDF5Array_1.40.0
    #>   [8] vctrs_0.7.3
    #>   [9] ggtangle_0.1.2
    #>  [10] digest_0.6.39
    #>  [11] png_0.1-9
    #>  [12] lumi_2.64.0
    #>  [13] ggrepel_0.9.8
    #>  [14] deldir_2.0-4
    #>  [15] combinat_0.0-8
    #>  [16] permute_0.9-10
    #>  [17] fontLiberation_0.1.0
    #>  [18] MASS_7.3-65
    #>  [19] reshape_0.8.10
    #>  [20] reshape2_1.4.5
    #>  [21] withr_3.0.2
    #>  [22] httpuv_1.6.17
    #>  [23] qvalue_2.44.0
    #>  [24] ggfun_0.2.0
    #>  [25] xfun_0.57
    #>  [26] survival_3.8-6
    #>  [27] doRNG_1.8.6.3
    #>  [28] memoise_2.0.1
    #>  [29] gson_0.1.0
    #>  [30] clusterProfiler_4.20.0
    #>  [31] MatrixModels_0.5-4
    #>  [32] BiasedUrn_2.0.12
    #>  [33] systemfonts_1.3.2
    #>  [34] tidytree_0.4.7
    #>  [35] gtools_3.9.5
    #>  [36] DNAcopy_1.86.0
    #>  [37] R.oo_1.27.1
    #>  [38] Formula_1.2-5
    #>  [39] sys_3.4.3
    #>  [40] prettyunits_1.2.0
    #>  [41] KEGGREST_1.52.0
    #>  [42] promises_1.5.0
    #>  [43] otel_0.2.0
    #>  [44] httr_1.4.8
    #>  [45] restfulr_0.0.16
    #>  [46] IlluminaHumanMethylation450kanno.ilmn12.hg19_0.6.1
    #>  [47] rhdf5filters_1.22.0
    #>  [48] ps_1.9.3
    #>  [49] rhdf5_2.56.0
    #>  [50] rstudioapi_0.18.0
    #>  [51] DOSE_4.6.0
    #>  [52] UCSC.utils_1.8.0
    #>  [53] processx_3.9.0
    #>  [54] base64enc_0.1-6
    #>  [55] curl_7.1.0
    #>  [56] h5mread_1.4.0
    #>  [57] polyclip_1.10-7
    #>  [58] quadprog_1.5-8
    #>  [59] ExperimentHub_3.2.0
    #>  [60] SparseArray_1.12.0
    #>  [61] xtable_1.8-8
    #>  [62] stringr_1.6.0
    #>  [63] doParallel_1.0.17
    #>  [64] evaluate_1.0.5
    #>  [65] S4Arrays_1.12.0
    #>  [66] BiocFileCache_3.2.0
    #>  [67] preprocessCore_1.74.0
    #>  [68] hms_1.1.4
    #>  [69] colorspace_2.1-2
    #>  [70] filelock_1.0.3
    #>  [71] JADE_2.0-4
    #>  [72] IlluminaHumanMethylationEPICanno.ilm10b4.hg19_0.6.0
    #>  [73] marray_1.90.0
    #>  [74] magrittr_2.0.5
    #>  [75] readr_2.2.0
    #>  [76] ggtree_4.2.0
    #>  [77] later_1.4.8
    #>  [78] buildtools_1.0.0
    #>  [79] viridis_0.6.5
    #>  [80] lattice_0.22-9
    #>  [81] genefilter_1.94.0
    #>  [82] SparseM_1.84-2
    #>  [83] XML_3.99-0.23
    #>  [84] maketools_1.3.2
    #>  [85] Hmisc_5.2-5
    #>  [86] pillar_1.11.1
    #>  [87] nlme_3.1-169
    #>  [88] compiler_4.6.0
    #>  [89] beachmat_2.28.0
    #>  [90] stringi_1.8.7
    #>  [91] dendextend_1.19.1
    #>  [92] GenomicAlignments_1.48.0
    #>  [93] plyr_1.8.9
    #>  [94] crayon_1.5.3
    #>  [95] abind_1.4-8
    #>  [96] BiocIO_1.22.0
    #>  [97] gridGraphics_0.5-1
    #>  [98] org.Hs.eg.db_3.22.0
    #>  [99] bit_4.6.0
    #> [100] dplyr_1.2.1
    #> [101] codetools_0.2-20
    #> [102] openssl_2.4.0
    #> [103] bslib_0.10.0
    #> [104] biovizBase_1.60.0
    #> [105] plotly_4.12.0
    #> [106] multtest_2.68.0
    #> [107] mime_0.13
    #> [108] wateRmelon_2.18.0
    #> [109] splines_4.6.0
    #> [110] Rcpp_1.1.1-1.1
    #> [111] quantreg_6.1
    #> [112] tidydr_0.0.6
    #> [113] dbplyr_2.5.2
    #> [114] sparseMatrixStats_1.24.0
    #> [115] IlluminaHumanMethylation450kmanifest_0.4.0
    #> [116] interp_1.1-6
    #> [117] knitr_1.51
    #> [118] blob_1.3.0
    #> [119] clue_0.3-68
    #> [120] BiocVersion_3.23.1
    #> [121] AnnotationFilter_1.36.0
    #> [122] fs_2.1.0
    #> [123] checkmate_2.3.4
    #> [124] DelayedMatrixStats_1.34.0
    #> [125] Gviz_1.56.0
    #> [126] ggplotify_0.1.3
    #> [127] tibble_3.3.1
    #> [128] Matrix_1.7-5
    #> [129] callr_3.7.6
    #> [130] statmod_1.5.1
    #> [131] tzdb_0.5.0
    #> [132] tweenr_2.0.3
    #> [133] pkgconfig_2.0.3
    #> [134] tools_4.6.0
    #> [135] cachem_1.1.0
    #> [136] cigarillo_1.2.0
    #> [137] RSQLite_2.4.6
    #> [138] viridisLite_0.4.3
    #> [139] globaltest_5.66.0
    #> [140] DBI_1.3.0
    #> [141] impute_1.86.0
    #> [142] fastmap_1.2.0
    #> [143] scales_1.4.0
    #> [144] grid_4.6.0
    #> [145] Rsamtools_2.28.0
    #> [146] AnnotationHub_4.2.0
    #> [147] sass_0.4.10
    #> [148] patchwork_1.3.2
    #> [149] BiocManager_1.30.27
    #> [150] VariantAnnotation_1.58.0
    #> [151] scrime_1.3.7
    #> [152] rpart_4.1.27
    #> [153] farver_2.1.2
    #> [154] scatterpie_0.2.6
    #> [155] mgcv_1.9-4
    #> [156] yaml_2.3.12
    #> [157] latticeExtra_0.6-31
    #> [158] foreign_0.8-91
    #> [159] rtracklayer_1.72.0
    #> [160] illuminaio_0.54.0
    #> [161] cli_3.6.6
    #> [162] purrr_1.2.2
    #> [163] siggenes_1.86.0
    #> [164] GEOquery_2.80.0
    #> [165] txdbmaker_1.8.0
    #> [166] lifecycle_1.0.5
    #> [167] askpass_1.2.1
    #> [168] backports_1.5.1
    #> [169] BiocParallel_1.46.0
    #> [170] annotate_1.90.0
    #> [171] methylumi_2.58.0
    #> [172] gtable_0.3.6
    #> [173] rjson_0.2.23
    #> [174] missMethyl_1.46.0
    #> [175] ape_5.8-1
    #> [176] limma_3.68.0
    #> [177] enrichit_0.1.4
    #> [178] jsonlite_2.0.0
    #> [179] edgeR_4.10.0
    #> [180] isva_1.10
    #> [181] bitops_1.0-9
    #> [182] ggplot2_4.0.3
    #> [183] bit64_4.8.0
    #> [184] assertthat_0.2.1
    #> [185] yulab.utils_0.2.4
    #> [186] base64_2.0.2
    #> [187] geneLenDataBase_1.46.0
    #> [188] aisdk_1.1.0
    #> [189] jquerylib_0.1.4
    #> [190] GOSemSim_2.38.0
    #> [191] R.utils_2.13.0
    #> [192] lazyeval_0.2.3
    #> [193] shiny_1.13.0
    #> [194] enrichplot_1.32.0
    #> [195] htmltools_0.5.9
    #> [196] affy_1.90.0
    #> [197] GO.db_3.22.0
    #> [198] rappdirs_0.3.4
    #> [199] ensembldb_2.36.0
    #> [200] glue_1.8.1
    #> [201] ROC_1.88.0
    #> [202] httr2_1.2.2
    #> [203] gdtools_0.5.0
    #> [204] RCurl_1.98-1.18
    #> [205] treeio_1.36.0
    #> [206] mclust_6.1.2
    #> [207] BSgenome_1.80.0
    #> [208] jpeg_0.1-11
    #> [209] gridExtra_2.3
    #> [210] igraph_2.3.0
    #> [211] R6_2.6.1
    #> [212] ggiraph_0.9.6
    #> [213] sva_3.60.0
    #> [214] tidyr_1.3.2
    #> [215] GenomicFeatures_1.64.0
    #> [216] rngtools_1.5.2
    #> [217] Rhdf5lib_2.0.0
    #> [218] beanplot_1.3.1
    #> [219] aplot_0.2.9
    #> [220] GenomeInfoDb_1.48.0
    #> [221] bsseq_1.48.0
    #> [222] DelayedArray_0.38.0
    #> [223] tidyselect_1.2.1
    #> [224] ProtGenerics_1.44.0
    #> [225] nleqslv_3.3.7
    #> [226] htmlTable_2.5.0
    #> [227] ggforce_0.5.0
    #> [228] xml2_1.5.2
    #> [229] fontBitstreamVera_0.1.1
    #> [230] AnnotationDbi_1.74.0
    #> [231] fastICA_1.2-7
    #> [232] KernSmooth_2.23-26
    #> [233] goseq_1.64.0
    #> [234] S7_0.2.2
    #> [235] fontquiver_0.2.1
    #> [236] affyio_1.82.0
    #> [237] nor1mix_1.3-3
    #> [238] data.table_1.18.2.1
    #> [239] htmlwidgets_1.6.4
    #> [240] RColorBrewer_1.1-3
    #> [241] biomaRt_2.68.0
    #> [242] rlang_1.2.0
    #> [243] rentrez_1.2.4
    #> [244] topconfects_1.26.0
    #> [245] ggnewscale_0.5.2

## References

1. Young MD, Wakefield MJ, Smyth GK, Oshlack A (2010) Gene ontology analysis for RNA-seq: accounting for selection bias. Genome Biol 11: R14.
2. Oshlack A, Wakefield MJ (2009) Transcript length bias in RNA-seq data confounds systems biology. Biol Direct 4: 14.
3. Marioni JC, Mason CE, Mane SM, Stephens M, Gilad Y (2008) RNA-seq: an assessment of technical reproducibility and comparison with gene expression arrays. Genome Res 18: 1509-1517.
4. Yoon S, Nam D (2017) Gene dispersion is the key determinant of the read count bias in differential expression analysis of RNA-seq data. BMC Genomics 18: 408.
5. Hansen KD, Irizarry RA, Wu Z (2012) Removing technical variability in RNA-seq data using conditional quantile normalization. Biostatistics 13: 204-216.
6. Risso D, Schwartz K, Sherlock G, Dudoit S (2011) GC-content normalization for RNA-Seq data. BMC Bioinformatics 12: 480.