# BOBaFIT

# Introduction

The R package BoBafit is composed of four functions which allow the refit and the recalibration of copy number profile of tumor sample. In particular, the package was built to check, and possibly correct, the diploid regions. The wrong diploid region is a phenomenon that very often affects the profiles of samples with a very complex karyotype.

The principal and refitting function was named `DRrefit`, which - throughout a chromosome clustering method and a list of unaltered chromosomes (chromosome list) - recalibrates the copy number values. BoBafit also contains three secondary functions: `ComputeNormalChromosome`, which generates the chromosome list; `PlotChrCluster`, where is possible to visualize the cluster; and `Popeye`, which affixes its chromosomal arm to each segment (see in “Data Preparation” vignette).

# Data

The package checks the diploid region assessment working on pre-estimated segment information, as the copy number and their position. We included a data set `TCGA_BRCA_CN_segments` where are showed all the information necessary. The data correspond to segments about 100 breast tumors samples obtained by the project TCGA-BRCA (Tomczak, Czerwińska, and Wiznerowicz 2015). In the “Data Preparation” vingnette is shown how we download and prepare the dataset for the following analysis.

    ## Warning: replacing previous import 'ggplot2::geom_segment' by
    ## 'ggbio::geom_segment' when loading 'BOBaFIT'

# BOBaFIT Workflow

Once the dataset has been prepared, the next step is to generate the chromosome list. The chromosome list is a vector containing all chromosomal arm which are the least affected by SCNAs in the tumor analyzed. Together with the clustering, the chromosome list is one the operating principles to rewrite the diploid region. The list can be manually created or by using the function `ComputeNormalChromosome`. We suggest these two sequential steps to allow the right refit and recalibration of sample’s diploid region:

1. `ComputeNormalChromosome()`

2. `DRrefit()`

Here we performed this analysis workflow on the dataset `TCGA_BRCA_CN_segments` described above.

## ComputeNormalChromosome

The chromosome list is a vector specific for each tumor (type and subtype) . The chromosome arms included in this list must be selected based on how many CNA events they are subject to and how many times their CN falls into a “diploid range”. According to this principle, ComputeNormalChromosome write the chromosome list. The function allows to set the chromosomal alteration rate (`tolerance_val`), which corresponds to a minimum percentage of alterations that one wants to tolerate per arm.

With a little dataframe (less than 200 samples), we suggest an alteration rate of 5% (0.5) ; on the contrary, With a big dataframe (about 1000 samples), we suggest as maximum rate 20-25% (0.20-0.25) . The function input is a sample cohort with their segments.

Here we performed the function in the data set `TCGA_BRCA_CN_segments`, using an alteration rate of 25%.

    chr_list

[1] “10q” “12q” “15q” “2p” “2q” “3p” “4q” “9q”

Storing the result in the variable `chr_list`, it will be a vector containing the chromosomal arms which present an alteration rate under the indicated `tolerance_val` value.

The function also plots in the Viewer a histogram where is possible observe the chromosomal alteration rate of each chromosomal arms and which one have been selected in the chromosome list (blue bars). The tolerance value has been set at 0.25 (dotted line).

\end{kframe}\begin{adjustwidth}{}{0mm} \includegraphics[width=100%]{/tmp/RtmpVMYp2R/Rbuild19a33d3376b9/BOBaFIT/vignettes/BOBaFIT_files/figure-html/chrlist plot-1} \end{adjustwidth} \begin{adjustwidth}{}{0mm} \includegraphics[width=100%]{/tmp/RtmpVMYp2R/Rbuild19a33d3376b9/BOBaFIT/vignettes/BOBaFIT_files/figure-html/DRrefit_plot 1-1} \end{adjustwidth}

\begin{adjustwidth}{}{0mm} \includegraphics[width=100%]{/tmp/RtmpVMYp2R/Rbuild19a33d3376b9/BOBaFIT/vignettes/BOBaFIT_files/figure-html/DRrefit_plot 2-1} \end{adjustwidth}\begin{kframe}

# PlotChrCluster

Another accessory function is `PlotChrCluster`. It can be used to visualize the chromosomal cluster in a single sample or in a sample cohort. The input data is always a .tsv file, as the data frame `TCGA_BRCA_CN_segments`. The option of `clust_method` argument are the same of `DRrefit`(“ward.D”, “ward.D2”, “single”, “complete”, “average”, “mcquitty”, “median”, “centroid” and “kmeans”).

    Cluster <- PlotChrCluster(segs = TCGA_BRCA_CN_segments,
                           clust_method = "ward.D2",
                           plot_output= TRUE)

We suggest to store the output on a variable (in this example we use `Cluster`) to view and possibly save the data frame generated. The `PlotCuster` will automatically save the plot in the folder indicated by the variable `path` of the argument `plot_path`.

In the `PlotChrCluster` plot, the chromosomal arms are labeled and colored according to the cluster they belong to. The y-axis reports the arm CN.

## The Dataframes

The outputs `report` summarizes the outcome of clustering for each sample (fail or succeeded, the number of clusters), similar to DRrefit report output. The second output, `plot tables`, is a list of data frames (one per sample) and reports in which clustering the chromosomes of the sample have been placed.

    head(Cluster$report)

    #select plot table per sample
    head(Cluster$plot_tables$`01428281-1653-4839-b5cf-167bc62eb147`)

    knitr::kable(head(Cluster$report))

sample | clustering | num_clust
--- | --- | ---
01428281-1653-4839-b5cf-167bc62eb147 | SUCCEDED | 3
01bc5261-bf91-4f7b-a6b4-0e727c5e31d2 | SUCCEDED | 2
05afee4e-9acd-44f1-8a0c-ffa34d772b9c | SUCCEDED | 3
091f70c0-586a-49e8-a0e5-0b60caa72c1b | SUCCEDED | 3
0941a978-c8aa-467b-8464-9f979d1f0418 | SUCCEDED | 2

    #select plot table per sample
    knitr::kable(head(Cluster$plot_tables$`01428281-1653-4839-b5cf-167bc62eb147`))

chr | cluster | CN
--- | --- | ---
1p | cluster1 | 1.670236
1q | cluster2 | 3.140345
2p | cluster1 | 1.906657
2q | cluster1 | 1.911449
3p | cluster1 | 1.996745
3q | cluster2 | 2.624881

# Session info

    ## R version 4.5.2 (2025-10-31)
    ## Platform: x86_64-pc-linux-gnu
    ## Running under: Ubuntu 24.04.3 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=C
    ##  [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.1.4      BOBaFIT_1.14.0   BiocStyle_2.38.0
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] DBI_1.2.3                   bitops_1.0-9
    ##   [3] RBGL_1.86.0                 gridExtra_2.3
    ##   [5] rlang_1.1.7                 magrittr_2.0.4
    ##   [7] biovizBase_1.58.0           matrixStats_1.5.0
    ##   [9] compiler_4.5.2              RSQLite_2.4.5
    ##  [11] GenomicFeatures_1.62.0      png_0.1-8
    ##  [13] vctrs_0.7.1                 reshape2_1.4.5
    ##  [15] ProtGenerics_1.42.0         stringr_1.6.0
    ##  [17] pkgconfig_2.0.3             crayon_1.5.3
    ##  [19] fastmap_1.2.0               backports_1.5.0
    ##  [21] XVector_0.50.0              labeling_0.4.3
    ##  [23] Rsamtools_2.26.0            rmarkdown_2.30
    ##  [25] graph_1.88.1                UCSC.utils_1.6.1
    ##  [27] tinytex_0.58                purrr_1.2.1
    ##  [29] bit_4.6.0                   xfun_0.56
    ##  [31] cachem_1.1.0                cigarillo_1.0.0
    ##  [33] GenomeInfoDb_1.46.2         jsonlite_2.0.0
    ##  [35] blob_1.3.0                  DelayedArray_0.36.0
    ##  [37] tweenr_2.0.3                BiocParallel_1.44.0
    ##  [39] parallel_4.5.2              cluster_2.1.8.1
    ##  [41] plyranges_1.30.1            VariantAnnotation_1.56.0
    ##  [43] R6_2.6.1                    bslib_0.9.0
    ##  [45] stringi_1.8.7               RColorBrewer_1.1-3
    ##  [47] rtracklayer_1.70.1          rpart_4.1.24
    ##  [49] GenomicRanges_1.62.1        jquerylib_0.1.4
    ##  [51] Rcpp_1.1.1                  Seqinfo_1.0.0
    ##  [53] SummarizedExperiment_1.40.0 knitr_1.51
    ##  [55] base64enc_0.1-3             IRanges_2.44.0
    ##  [57] Matrix_1.7-4                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.0.0                  lattice_0.22-7
    ##  [67] tibble_3.3.1                plyr_1.8.9
    ##  [69] withr_3.0.2                 Biobase_2.70.0
    ##  [71] KEGGREST_1.50.0             S7_0.2.1
    ##  [73] evaluate_1.0.5              foreign_0.8-90
    ##  [75] polyclip_1.10-7             Biostrings_2.78.0
    ##  [77] pillar_1.11.1               BiocManager_1.30.27
    ##  [79] MatrixGenerics_1.22.0       checkmate_2.3.3
    ##  [81] stats4_4.5.2                OrganismDbi_1.52.0
    ##  [83] generics_0.1.4              RCurl_1.98-1.17
    ##  [85] ensembldb_2.34.0            S4Vectors_0.48.0
    ##  [87] ggplot2_4.0.1               scales_1.4.0
    ##  [89] ggbio_1.58.0                glue_1.8.0
    ##  [91] Hmisc_5.2-5                 lazyeval_0.2.2
    ##  [93] maketools_1.3.2             tools_4.5.2
    ##  [95] BiocIO_1.20.0               sys_3.4.3
    ##  [97] data.table_1.18.0           BSgenome_1.78.0
    ##  [99] GenomicAlignments_1.46.0    XML_3.99-0.20
    ## [101] buildtools_1.0.0            grid_4.5.2
    ## [103] tidyr_1.3.2                 AnnotationDbi_1.72.0
    ## [105] colorspace_2.1-2            ggforce_0.5.0
    ## [107] restfulr_0.0.16             htmlTable_2.4.3
    ## [109] Formula_1.2-5               cli_3.6.5
    ## [111] NbClust_3.0.1               S4Arrays_1.10.1
    ## [113] AnnotationFilter_1.34.0     gtable_0.3.6
    ## [115] sass_0.4.10                 digest_0.6.39
    ## [117] BiocGenerics_0.56.0         SparseArray_1.10.8
    ## [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.7                  MASS_7.3-65
    ## [127] bit64_4.6.0-1

# Reference

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.