# Data preparation using TCGA-BRCA database

# Introduction

The data preparation is an important step before the BOBaFIT analysis. In this vignete we will explain how to download the TCGA-BRCA dataset(Tomczak et al. 2015) the package TCGAbiolink (Colaprico et al. 2015) and how to add information like chromosomal arm and CN value of each segments, which operating principle of the package. Further, here we show the column names of the input file for all the BOBaFIT function.

# Download from TCGA

To download the TCGCA-BRCA(Tomczak et al. 2015), we used the R package TCGAbiolinks (Colaprico et al. 2015)and we construct the query. The query includs Breast Cancer samples analyzed by SNParray method (GenomeWide_SNP6), obtaining their Copy Number (CN) profile.

    BiocManager::install("TCGAbiolinks")
    library(TCGAbiolinks)

    query <- GDCquery(project = "TCGA-BRCA",
                      data.category = "Copy Number Variation",
                      data.type = "Copy Number Segment",
                      sample.type = "Primary Tumor"
                      )

    #Selecting first 100 samples using the TCGA barcode
    subset <- query[[1]][[1]]
    barcode <- subset$cases[1:100]

    TCGA_BRCA_CN_segments <- GDCquery(project = "TCGA-BRCA",
                      data.category = "Copy Number Variation",
                      data.type = "Copy Number Segment",
                      sample.type = "Primary Tumor",
                      barcode = barcode
    )

    GDCdownload(TCGA_BRCA_CN_segments, method = "api", files.per.chunk = 50)

    #prepare a data.frame where working
    data <- GDCprepare(TCGA_BRCA_CN_segments, save = TRUE,
               save.filename= "TCGA_BRCA_CN_segments.txt")

In the last step, a dataframe with the segments of all samples is prepared. However some information are missing, so the dataset is not ready as BOBaFIT input.

# Columns preparation

Further, here we show the column names of the input file for all the BOBaFIT function.

    names(data)
    BOBaFIT_names <- c("ID", "chr", "start", "end", "Num_Probes",
               "Segment_Mean","Sample")
    names(data)<- BOBaFIT_names
    names(data)

# Assign the chromosome arm with Popeye

The arm column is an very important information that support the diploid region check of`DRrefit` and the chromosome list computation of `ComputeNormalChromosome`. As it is lacking in the TCGA-BRCAdataset, the function `Popeye`has been specially designed to calculate which chromosomal arm the segment belongs to. Thanks to this algorithm, not only the TCGA-BRCA dataset, but any database you want to analyze can be analyzed by any function of BOBaFIT.

    library(BOBaFIT)
    segments <- Popeye(data)

chr | start | end | width | strand | ID | Num_Probes | Segment_Mean | Sample | arm | chrarm
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
1 | 62920 | 21996664 | 21933745 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 12088 | -0.4756 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p
1 | 22001786 | 22002025 | 240 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 2 | -7.4436 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p
1 | 22004046 | 22010750 | 6705 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 2 | -2.1226 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p
1 | 22011632 | 25256850 | 3245219 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 1914 | -0.4808 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p
1 | 25266637 | 25320198 | 53562 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 22 | -2.1144 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p
1 | 25320253 | 30316360 | 4996108 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 2434 | -0.4905 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p

# Calculation of the Copy Number

The last step is the computation of the copy number value from the “`Segment_Mean`” column (logR), with the following formula. At this point the data is ready to be analyzed by the whole package.

    #When data coming from SNParray platform are used, the user have to apply the
    #compression factor in the formula (0.55). In case of WGS/WES data, the
    #correction factor is equal to 1.
    compression_factor <- 0.55
    segments$CN <- 2^(segments$Segment_Mean/compression_factor + 1)

chr | start | end | width | strand | ID | Num_Probes | Segment_Mean | Sample | arm | chrarm | CN
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
1 | 62920 | 21996664 | 21933745 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 12088 | -0.4756 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p | 1.0983004
1 | 22001786 | 22002025 | 240 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 2 | -7.4436 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p | 0.0001686
1 | 22004046 | 22010750 | 6705 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 2 | -2.1226 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p | 0.1378076
1 | 22011632 | 25256850 | 3245219 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 1914 | -0.4808 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p | 1.0911264
1 | 25266637 | 25320198 | 53562 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 22 | -2.1144 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p | 0.1392391
1 | 25320253 | 30316360 | 4996108 | * | 01428281-1653-4839-b5cf-167bc62eb147 | 2434 | -0.4905 | TCGA-BH-A18R-01A-11D-A12A-01 | p | 1p | 1.0778690

# Session info

    ## 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] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] dplyr_1.2.1      BOBaFIT_1.16.0   BiocStyle_2.40.0
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] DBI_1.3.0                   bitops_1.0-9
    ##   [3] RBGL_1.88.0                 gridExtra_2.3
    ##   [5] rlang_1.2.0                 magrittr_2.0.5
    ##   [7] biovizBase_1.60.0           matrixStats_1.5.0
    ##   [9] compiler_4.6.0              RSQLite_2.4.6
    ##  [11] GenomicFeatures_1.64.0      png_0.1-9
    ##  [13] vctrs_0.7.3                 reshape2_1.4.5
    ##  [15] ProtGenerics_1.44.0         stringr_1.6.0
    ##  [17] pkgconfig_2.0.3             crayon_1.5.3
    ##  [19] fastmap_1.2.0               backports_1.5.1
    ##  [21] XVector_0.52.0              labeling_0.4.3
    ##  [23] Rsamtools_2.28.0            rmarkdown_2.31
    ##  [25] graph_1.90.0                UCSC.utils_1.8.0
    ##  [27] tinytex_0.59                purrr_1.2.2
    ##  [29] bit_4.6.0                   xfun_0.57
    ##  [31] cachem_1.1.0                cigarillo_1.2.0
    ##  [33] GenomeInfoDb_1.48.0         jsonlite_2.0.0
    ##  [35] blob_1.3.0                  DelayedArray_0.38.0
    ##  [37] tweenr_2.0.3                BiocParallel_1.46.0
    ##  [39] parallel_4.6.0              cluster_2.1.8.2
    ##  [41] plyranges_1.32.0            VariantAnnotation_1.58.0
    ##  [43] R6_2.6.1                    bslib_0.10.0
    ##  [45] stringi_1.8.7               RColorBrewer_1.1-3
    ##  [47] rtracklayer_1.72.0          rpart_4.1.27
    ##  [49] GenomicRanges_1.64.0        jquerylib_0.1.4
    ##  [51] Rcpp_1.1.1-1.1              Seqinfo_1.2.0
    ##  [53] SummarizedExperiment_1.42.0 knitr_1.51
    ##  [55] base64enc_0.1-6             IRanges_2.46.0
    ##  [57] Matrix_1.7-5                nnet_7.3-20
    ##  [59] tidyselect_1.2.1            rstudioapi_0.18.0
    ##  [61] dichromat_2.0-0.1           abind_1.4-8
    ##  [63] yaml_2.3.12                 codetools_0.2-20
    ##  [65] curl_7.1.0                  lattice_0.22-9
    ##  [67] tibble_3.3.1                plyr_1.8.9
    ##  [69] withr_3.0.2                 Biobase_2.72.0
    ##  [71] KEGGREST_1.52.0             S7_0.2.2
    ##  [73] evaluate_1.0.5              foreign_0.8-91
    ##  [75] polyclip_1.10-7             Biostrings_2.80.0
    ##  [77] pillar_1.11.1               BiocManager_1.30.27
    ##  [79] MatrixGenerics_1.24.0       checkmate_2.3.4
    ##  [81] stats4_4.6.0                OrganismDbi_1.54.0
    ##  [83] generics_0.1.4              RCurl_1.98-1.18
    ##  [85] ensembldb_2.36.0            S4Vectors_0.50.0
    ##  [87] ggplot2_4.0.3               scales_1.4.0
    ##  [89] ggbio_1.60.0                glue_1.8.1
    ##  [91] Hmisc_5.2-5                 lazyeval_0.2.3
    ##  [93] maketools_1.3.2             tools_4.6.0
    ##  [95] BiocIO_1.22.0               sys_3.4.3
    ##  [97] data.table_1.18.2.1         BSgenome_1.80.0
    ##  [99] GenomicAlignments_1.48.0    XML_3.99-0.23
    ## [101] buildtools_1.0.0            grid_4.6.0
    ## [103] tidyr_1.3.2                 AnnotationDbi_1.74.0
    ## [105] colorspace_2.1-2            ggforce_0.5.0
    ## [107] restfulr_0.0.16             htmlTable_2.5.0
    ## [109] Formula_1.2-5               cli_3.6.6
    ## [111] NbClust_3.0.1               S4Arrays_1.12.0
    ## [113] AnnotationFilter_1.36.0     gtable_0.3.6
    ## [115] sass_0.4.10                 digest_0.6.39
    ## [117] BiocGenerics_0.58.0         SparseArray_1.12.0
    ## [119] rjson_0.2.23                htmlwidgets_1.6.4
    ## [121] farver_2.1.2                memoise_2.0.1
    ## [123] htmltools_0.5.9             lifecycle_1.0.5
    ## [125] httr_1.4.8                  MASS_7.3-65
    ## [127] bit64_4.8.0

Colaprico, Antonio, Tiago C. Silva, Catharina Olsen, et al. 2015. “TCGAbiolinks: An r/Bioconductor Package for Integrative Analysis of TCGA Data.” Nucleic Acids Research 44 (8): e71–71. https://doi.org/10.1093/nar/gkv1507.
Tomczak, Katarzyna, Patrycja Czerwińska, and Maciej Wiznerowicz. 2015. “Review the Cancer Genome Atlas (TCGA): An Immeasurable Source of Knowledge.” Współczesna Onkologia 1A: 68–77. https://doi.org/10.5114/wo.2014.47136.