### Install cmapR Package Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Install the cmapR package from Bioconductor. Ensure BiocManager is installed first if necessary. ```R if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("cmapR") ``` -------------------------------- ### Display R Session Information Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Call sessionInfo() to get details about the R version, operating system, and loaded packages. This is essential for troubleshooting and reproducibility. ```r sessionInfo() ``` -------------------------------- ### Create GCT Object from Matrix Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Shows how to create a GCT object using the 'new' constructor with a matrix. Row and column names must be assigned to the matrix or passed as arguments. ```r # initialize a matrix object # note that you either must assign values to the rownames and colnames # of the matrix, or pass them, # as the 'rid' and 'cid' arguments to GCT" m <- matrix(stats::rnorm(100), ncol=10) rownames(m) <- letters[1:10] colnames(m) <- LETTERS[1:10] (my_new_ds <- new("GCT", mat=m)) ``` -------------------------------- ### Create GCT Object with Annotations Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Illustrates creating a GCT object with row and column annotations provided as data frames. The 'id' column in annotation data frames is used for matching. ```r # we can also include the row/column annotations as data.frames # note these are just arbitrary annotations used to illustrate the function call rdesc <- data.frame(id=letters[1:10], type=rep(c(1, 2), each=5)) cdesc <- data.frame(id=LETTERS[1:10], type=rep(c(3, 4), each=5)) (my_new_ds <- new("GCT", mat=m, rdesc=rdesc, cdesc=cdesc)) ``` -------------------------------- ### Load cmapR Package Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Load the cmapR package into your R session to begin using its functionalities. ```R library(cmapR) ``` -------------------------------- ### Write GCT Object to GCT Format Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Saves a GCT object to disk in GCT format. Ensure the object and filename are correctly specified. ```r # write 'my_ds' in both GCT and GCTX format write_gct(my_ds, "my_ds") ``` ```text ## Saving file to ./my_ds_n25x50.gct ## Dimensions of matrix: [50x25] ## Setting precision to 4 ## Saved. ``` -------------------------------- ### Convert GCT Object to SummarizedExperiment Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Converts a GCT object to a SummarizedExperiment object. This is useful for integrating GCT data with other Bioconductor analysis workflows. The output shows the dimensions and structure of the resulting SummarizedExperiment object. ```r # ds is an object of class GCT (se <- as(ds, "SummarizedExperiment")) ``` ```text ## class: SummarizedExperiment ## dim: 978 272 ## metadata(0): ## assays(1): exprs ## rownames(978): 200814_at 222103_at ... 203341_at 205379_at ## rowData names(1): x ## colnames(272): CPC006_A549_6H:BRD-U88459701-000-01-8:10 ## CPC020_A375_6H:BRD-A82307304-001-01-8:10 ... ## CPD002_PC3_6H:BRD-A51714012-001-04-9:10 ## CPD002_PC3_24H:BRD-A51714012-001-04-9:10 ## colData names(1): x ``` -------------------------------- ### Write GCT Object to Compressed GCTX Format Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Saves a GCT object to disk in GCTX format with specified compression level. Higher compression levels reduce file size but increase read/write times. The output confirms the compressed file and chunk sizes. ```r # write_gctx can also compress the dataset upon write, # which can be controlled using the 'compression_level' option. # the higher the value, the greater the compression, but the # longer the read/write time write_gctx(my_ds, "my_ds_compressed", compression_level = 9) ``` ```text ## writing ./my_ds_compressed_n25x50.gctx ## chunk sizes: 50 25 ``` -------------------------------- ### Parse GCT with Character IDs Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Demonstrates parsing a GCT file using character vectors of IDs for row and column metadata. Ensure the 'id' column exists in your metadata. ```r # get a vector of character ids, using the id column in col_meta col_ids <- col_meta$id[idx] vemurafenib_ds2 <- parse_gctx(ds_path, cid=col_ids) ``` -------------------------------- ### GCT Object Structure Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Displays the formal class definition and slots of a GCT object, including dimensions and data types of its components. ```R ## Formal class 'GCT' [package "cmapR"] with 7 slots ## ..@ mat : num [1:978, 1:272] 0 0 0 0 0 0 0 0 0 0 ... ## .. ..- attr(*, "dimnames")=List of 2 ## .. .. ..$ : chr [1:978] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## .. .. ..$ : chr [1:272] "CPC006_A549_6H:BRD-U88459701-000-01-8:10" "CPC020_A375_6H:BRD-A82307304-001-01-8:10" "CPC020_HT29_6H:BRD-A82307304-001-01-8:10" "CPC020_PC3_24H:BRD-A82307304-001-01-8:10" ... ## ..@ rid : chr [1:978] "1" "2" "3" "4" ... ## ..@ cid : chr [1:272] "1" "2" "3" "4" ... ## ..@ rdesc :'data.frame': 978 obs. of 1 variable: ## .. ..$ x: chr [1:978] "c" "q" "x" "x" ... ## ..@ cdesc :'data.frame': 272 obs. of 1 variable: ## .. ..$ x: chr [1:272] "o" "s" "n" "q" ... ## ..@ version: chr(0) ## ..@ src : chr "inst/extdata/modzs_n272x978.gctx" ``` -------------------------------- ### Parse First 10 Columns of a GCTX File Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Reads the first 10 columns of a GCTX file using numeric indices. This is useful for initial data exploration or when only a small portion of the data is needed. ```r # read just the first 10 columns, using numeric indices (my_ds_10_columns <- parse_gctx(ds_path, cid=1:10)) ``` ```text ## reading /tmp/Rtmpsjxnwd/Rinstc7d766f1152ef/cmapR/extdata/modzs_n25x50.gctx ## done ## Formal class 'GCT' [package "cmapR"] with 7 slots ## ..@ mat : num [1:50, 1:10] -1.145 -1.165 0.437 0.139 -0.673 ... ## .. ..- attr(*, "dimnames")=List of 2 ## .. .. ..$ : chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## .. .. ..$ : chr [1:10] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## ..@ rid : chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## ..@ cid : chr [1:10] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## ..@ rdesc :'data.frame': 50 obs. of 6 variables: ## .. ..$ id : chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## .. ..$ is_bing : int [1:50] 1 1 1 1 1 1 1 1 1 1 ... ## .. ..$ is_lm : int [1:50] 1 1 1 1 1 1 1 1 1 1 ... ## .. ..$ pr_gene_id : int [1:50] 5720 466 6009 2309 387 3553 427 5898 23365 6657 ... ## .. ..$ pr_gene_symbol: chr [1:50] "PSME1" "ATF1" "RHEB" "FOXO3" ... ## .. ..$ pr_gene_title : chr [1:50] "proteasome (prosome, macropain) activator subunit 1 (PA28 alpha)" "activating transcription factor 1" "Ras homolog enriched in brain" "forkhead box O3" ... ## ..@ cdesc :'data.frame': 10 obs. of 16 variables: ## .. ..$ brew_prefix : chr [1:10] "CPC004_PC3_24H" "BRAF001_HEK293T_24H" "CPC006_HT29_24H" "CVD001_HEPG2_24H" ... ## .. ..$ cell_id : chr [1:10] "PC3" "HEK293T" "HT29" "HEPG2" ... ## .. ..$ distil_cc_q75 : num [1:10] 0.05 0.1 0.17 0.45 0.24 ... ## .. ..$ distil_nsample : int [1:10] 5 9 4 3 4 5 2 3 2 2 ## .. ..$ distil_ss : num [1:10] 2.9 1.88 2.71 4.06 3.83 ... ## .. ..$ id : chr [1:10] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## .. ..$ is_gold : int [1:10] 0 0 0 1 1 0 1 0 0 0 ## .. ..$ ngenes_modulated_dn_lm: int [1:10] 11 3 8 38 36 23 12 11 33 13 ## .. ..$ ngenes_modulated_up_lm: int [1:10] 10 7 25 40 16 17 23 14 37 22 ## .. ..$ pct_self_rank_q25 : num [1:10] 26.904 17.125 7.06 0.229 4.686 ... ## .. ..$ pert_id : chr [1:10] "BRD-A51714012" "BRD-U73308409" "BRD-U88459701" "BRD-U88459701" ... ## .. ..$ pert_idose : chr [1:10] "10 M" "500 nM" "10 M" "10 M" ... ## .. ..$ pert_iname : chr [1:10] "venlafaxine" "vemurafenib" "atorvastatin" "atorvastatin" ... ## .. ..$ pert_itime : chr [1:10] "24 h" "24 h" "24 h" "24 h" ... ## .. ..$ pert_type : chr [1:10] "trt_cp" "trt_cp" "trt_cp" "trt_cp" ... ## .. ..$ pool_id : chr [1:10] "epsilon" "epsilon" "epsilon" "epsilon" ... ## ..@ version: chr(0) ## ..@ src : chr "/tmp/Rtmpsjxnwd/Rinstc7d766f1152ef/cmapR/extdata/modzs_n25x50.gctx" ``` -------------------------------- ### Parse Specific Columns by Metadata Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Reads specific columns from a GCTX file by first extracting column metadata, identifying relevant columns based on a metadata field (e.g., 'pert_iname'), and then parsing only those columns. This is useful for selecting data based on experimental conditions. ```r # read the column metadata col_meta <- read_gctx_meta(ds_path, dim="col") # figure out which signatures correspond to vorinostat by searching the 'pert_iname' column idx <- which(col_meta$pert_iname=="vemurafenib") # read only those columns from the GCTX file by using the 'cid' parameter vemurafenib_ds <- parse_gctx(ds_path, cid=idx) ``` ```text ## reading /tmp/Rtmpsjxnwd/Rinstc7d766f1152ef/cmapR/extdata/modzs_n25x50.gctx ## done ``` -------------------------------- ### GCTX File Parsing Output Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html These messages indicate the progress and completion of reading a GCTX file. They confirm that the file has been successfully processed. ```r ## reading /tmp/Rtmpsjxnwd/Rinstc7d766f1152ef/cmapR/extdata/modzs_n25x50.gctx ``` ```r ## done ``` -------------------------------- ### GCT Object Structure After Annotation Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Displays the formal class structure of a GCT object after column annotations have been applied, showing populated `cdesc` slot with various metadata fields. ```R ## Formal class 'GCT' [package "cmapR"] with 7 slots ## ..@ mat : num [1:50, 1:25] -1.145 -1.165 0.437 0.139 -0.673 ... ## .. ..- attr(*, "dimnames")=List of 2 ## .. .. ..$ : chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## .. .. ..$ : chr [1:25] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## ..@ rid : chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## ..@ cid : chr [1:25] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## ..@ rdesc :'data.frame': 50 obs. of 1 variable: ## .. ..$ id: chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## ..@ cdesc :'data.frame': 25 obs. of 16 variables: ## .. ..$ id : chr [1:25] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## .. ..$ brew_prefix : chr [1:25] "CPC004_PC3_24H" "BRAF001_HEK293T_24H" "CPC006_HT29_24H" "CVD001_HEPG2_24H" ... ## .. ..$ cell_id : chr [1:25] "PC3" "HEK293T" "HT29" "HEPG2" ... ## .. ..$ distil_cc_q75 : num [1:25] 0.05 0.1 0.17 0.45 0.24 ... ## .. ..$ distil_nsample : int [1:25] 5 9 4 3 4 5 2 3 2 2 ... ## .. ..$ distil_ss : num [1:25] 2.9 1.88 2.71 4.06 3.83 ... ## .. ..$ is_gold : int [1:25] 0 0 0 1 1 0 1 0 0 0 ... ## .. ..$ ngenes_modulated_dn_lm: int [1:25] 11 3 8 38 36 23 12 11 33 13 ... ## .. ..$ ngenes_modulated_up_lm: int [1:25] 10 7 25 40 16 17 23 14 37 22 ... ## .. ..$ pct_self_rank_q25 : num [1:25] 26.904 17.125 7.06 0.229 4.686 ... ## .. ..$ pert_id : chr [1:25] "BRD-A51714012" "BRD-U73308409" "BRD-U88459701" "BRD-U88459701" ... ## .. ..$ pert_idose : chr [1:25] "10 M" "500 nM" "10 M" "10 M" ... ## .. ..$ pert_iname : chr [1:25] "venlafaxine" "vemurafenib" "atorvastatin" "atorvastatin" ... ## .. ..$ pert_itime : chr [1:25] "24 h" "24 h" "24 h" "24 h" ... ## .. ..$ pert_type : chr [1:25] "trt_cp" "trt_cp" "trt_cp" "trt_cp" ... ## .. ..$ pool_id : chr [1:25] "epsilon" "epsilon" "epsilon" "epsilon" ... ## ..@ version: chr(0) ## ..@ src : chr "/tmp/Rtmpsjxnwd/Rinstc7d766f1152ef/cmapR/extdata/modzs_n25x50.gctx" ``` -------------------------------- ### GCT Object Formal Class Definition Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html This output shows the detailed structure of the 'GCT' object, including its slots like 'mat' (the data matrix), 'rid' (row IDs), 'cid' (column IDs), 'rdesc' (row descriptors), 'cdesc' (column descriptors), and 'src' (source file path). ```r ## Formal class 'GCT' [package "cmapR"] with 7 slots ## ..@ mat : num [1:50, 1:25] -1.145 -1.165 0.437 0.139 -0.673 ... ## .. ..- attr(*, "dimnames")=List of 2 ## .. .. ..$ : chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## .. .. ..$ : chr [1:25] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## ..@ rid : chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## ..@ cid : chr [1:25] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## ..@ rdesc :'data.frame': 50 obs. of 6 variables: ## .. ..$ id : chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## .. ..$ is_bing : int [1:50] 1 1 1 1 1 1 1 1 1 1 ... ## .. ..$ is_lm : int [1:50] 1 1 1 1 1 1 1 1 1 1 ... ## .. ..$ pr_gene_id : int [1:50] 5720 466 6009 2309 387 3553 427 5898 23365 6657 ... ## .. ..$ pr_gene_symbol: chr [1:50] "PSME1" "ATF1" "RHEB" "FOXO3" ... ## .. ..$ pr_gene_title : chr [1:50] "proteasome (prosome, macropain) activator subunit 1 (PA28 alpha)" "activating transcription factor 1" "Ras homolog enriched in brain" "forkhead box O3" ... ## ..@ cdesc :'data.frame': 25 obs. of 16 variables: ## .. ..$ brew_prefix : chr [1:25] "CPC004_PC3_24H" "BRAF001_HEK293T_24H" "CPC006_HT29_24H" "CVD001_HEPG2_24H" ... ## .. ..$ cell_id : chr [1:25] "PC3" "HEK293T" "HT29" "HEPG2" ... ## .. ..$ distil_cc_q75 : num [1:25] 0.05 0.1 0.17 0.45 0.24 ... ## .. ..$ distil_nsample : int [1:25] 5 9 4 3 4 5 2 3 2 2 ... ## .. ..$ distil_ss : num [1:25] 2.9 1.88 2.71 4.06 3.83 ... ## .. ..$ id : chr [1:25] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## .. ..$ is_gold : int [1:25] 0 0 0 1 1 0 1 0 0 0 ... ## .. ..$ ngenes_modulated_dn_lm: int [1:25] 11 3 8 38 36 23 12 11 33 13 ... ## .. ..$ ngenes_modulated_up_lm: int [1:25] 10 7 25 40 16 17 23 14 37 22 ... ## .. ..$ pct_self_rank_q25 : num [1:25] 26.904 17.125 7.06 0.229 4.686 ... ## .. ..$ pert_id : chr [1:25] "BRD-A51714012" "BRD-U73308409" "BRD-U88459701" "BRD-U88459701" ... ## .. ..$ pert_idose : chr [1:25] "10 M" "500 nM" "10 M" "10 M" ... ## .. ..$ pert_iname : chr [1:25] "venlafaxine" "vemurafenib" "atorvastatin" "atorvastatin" ... ## .. ..$ pert_itime : chr [1:25] "24 h" "24 h" "24 h" "24 h" ... ## .. ..$ pert_type : chr [1:25] "trt_cp" "trt_cp" "trt_cp" "trt_cp" ... ## .. ..$ pool_id : chr [1:25] "epsilon" "epsilon" "epsilon" "epsilon" ... ## ..@ version: chr(0) ## ..@ src : chr "/tmp/Rtmpsjxnwd/Rinstc7d766f1152ef/cmapR/extdata/modzs_n25x50.gctx" ``` -------------------------------- ### Parse Entire GCTX File Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Use `parse_gctx` to load a GCTX file into memory. Ensure the file path is valid. This method is suitable for small files that fit within available memory. ```r # create a variable to store the path to the GCTX file # here we'll use a file that's internal to the cmapR package, but # in practice this could be any valid path to a GCT or GCTX file ds_path <- system.file("extdata", "modzs_n25x50.gctx", package="cmapR") my_ds <- parse_gctx(ds_path) ``` -------------------------------- ### Inspect GCT Object Structure Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Display the structure of a parsed GCT object to understand its contents, including dimensions and metadata. This is useful for verifying the loaded data. ```r my_ds ``` -------------------------------- ### Write GCT Object to GCTX Format Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Saves a GCT object to disk in GCTX format. This format is optimized for large datasets. The output messages indicate the file being written and its chunk sizes. ```r write_gctx(my_ds, "my_ds") ``` ```text ## writing ./my_ds_n25x50.gctx ``` ```text ## chunk sizes: 50 25 ``` -------------------------------- ### GCT Object Structure (Matrix Only) Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html This output shows the structure of a GCT object after parsing with `matrix_only = TRUE`. Note that `rdesc` and `cdesc` slots are minimal, containing only the 'id' column. ```r ## reading /tmp/Rtmpsjxnwd/Rinstc7d766f1152ef/cmapR/extdata/modzs_n25x50.gctx ## done ## Formal class 'GCT' [package "cmapR"] with 7 slots ## ..@ mat : num [1:50, 1:25] -1.145 -1.165 0.437 0.139 -0.673 ... ## .. ..- attr(*, "dimnames")=List of 2 ## .. .. ..$ : chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## .. .. ..$ : chr [1:25] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## ..@ rid : chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## ..@ cid : chr [1:25] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## ..@ rdesc :'data.frame': 50 obs. of 1 variable: ## .. ..$ id: chr [1:50] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## ..@ cdesc :'data.frame': 25 obs. of 1 variable: ## .. ..$ id: chr [1:25] "CPC004_PC3_24H:BRD-A51714012-001-03-1:10" "BRAF001_HEK293T_24H:BRD-U73308409-000-01-9:0.625" "CPC006_HT29_24H:BRD-U88459701-000-01-8:10" "CVD001_HEPG2_24H:BRD-U88459701-000-01-8:10" ... ## ..@ version: chr(0) ## ..@ src : chr "/tmp/Rtmpsjxnwd/Rinstc7d766f1152ef/cmapR/extdata/modzs_n25x50.gctx" ``` -------------------------------- ### Access GCT Object Components Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Retrieve the data matrix, row metadata, column metadata, row IDs, and column IDs from a GCT object. ```R # access the data matrix m <- mat(ds) # access the row and column metadata rdesc <- meta(ds, dimension = "row") cdesc <- meta(ds, dimension = "column") # access the row and column ids rid <- ids(ds, dimension = "row") cid <- ids(ds, dimension = "column") ``` -------------------------------- ### Compute Row and Column Maximums Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Calculates the maximum value for each row and each column of the GCT matrix using the `apply` function. Useful for identifying peak values within rows or columns. ```r # using 'apply', compute the max of each row and column row_max <- apply(m, 1, max) col_max <- apply(m, 2, max) message("maxes:") ``` ```r head(row_max) ``` ```r head(col_max) ``` -------------------------------- ### Display GCT Object Structure in R Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html View the internal structure of a GCT object, including its data matrix, row/column identifiers, and annotations. This is useful for understanding the data organization. ```r ds ``` ```text ## Formal class 'GCT' [package "cmapR"] with 7 slots ## ..@ mat : num [1:978, 1:272] -0.524 -0.372 0.578 0.569 1.48 ... ## .. ..- attr(*, "dimnames")=List of 2 ## .. .. ..$ : chr [1:978] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## .. .. ..$ : chr [1:272] "CPC006_A549_6H:BRD-U88459701-000-01-8:10" "CPC020_A375_6H:BRD-A82307304-001-01-8:10" "CPC020_HT29_6H:BRD-A82307304-001-01-8:10" "CPC020_PC3_24H:BRD-A82307304-001-01-8:10" ... ## ..@ rid : chr [1:978] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## ..@ cid : chr [1:272] "CPC006_A549_6H:BRD-U88459701-000-01-8:10" "CPC020_A375_6H:BRD-A82307304-001-01-8:10" "CPC020_HT29_6H:BRD-A82307304-001-01-8:10" "CPC020_PC3_24H:BRD-A82307304-001-01-8:10" ... ## ..@ rdesc :'data.frame': 978 obs. of 6 variables: ## .. ..$ id : chr [1:978] "200814_at" "222103_at" "201453_x_at" "204131_s_at" ... ## .. ..$ is_bing : int [1:978] 1 1 1 1 1 1 1 1 1 1 ... ## .. ..$ is_lm : int [1:978] 1 1 1 1 1 1 1 1 1 1 ... ## .. ..$ pr_gene_id : int [1:978] 5720 466 6009 2309 387 3553 427 5898 23365 6657 ... ## .. ..$ pr_gene_symbol: chr [1:978] "PSME1" "ATF1" "RHEB" "FOXO3" ... ## .. ..$ pr_gene_title : chr [1:978] "proteasome (prosome, macropain) activator subunit 1 (PA28 alpha)" "activating transcription factor 1" "Ras homolog enriched in brain" "forkhead box O3" ... ## ..@ cdesc :'data.frame': 272 obs. of 16 variables: ## .. ..$ brew_prefix : chr [1:272] "CPC006_A549_6H" "CPC020_A375_6H" "CPC020_HT29_6H" "CPC020_PC3_24H" ... ## .. ..$ cell_id : chr [1:272] "A549" "A375" "HT29" "PC3" ... ## .. ..$ distil_cc_q75 : num [1:272] 0.18 0.46 0.14 0.57 0.2 ... ## .. ..$ distil_nsample : int [1:272] 4 5 4 5 7 5 3 2 2 2 ... ## .. ..$ distil_ss : num [1:272] 2.65 3.21 2.14 4.62 2.27 ... ## .. ..$ id : chr [1:272] "CPC006_A549_6H:BRD-U88459701-000-01-8:10" "CPC020_A375_6H:BRD-A82307304-001-01-8:10" "CPC020_HT29_6H:BRD-A82307304-001-01-8:10" "CPC020_PC3_24H:BRD-A82307304-001-01-8:10" ... ## .. ..$ is_gold : int [1:272] 0 1 0 1 1 1 1 0 0 1 ... ## .. ..$ ngenes_modulated_dn_lm: int [1:272] 15 14 4 67 8 95 42 20 14 80 ... ## .. ..$ ngenes_modulated_up_lm: int [1:272] 10 17 7 50 6 98 19 21 14 36 ... ## .. ..$ pct_self_rank_q25 : num [1:272] 5.526 1.567 9.072 0 0.353 ... ## .. ..$ pert_id : chr [1:272] "BRD-U88459701" "BRD-A82307304" "BRD-A82307304" "BRD-A82307304" ... ## .. ..$ pert_idose : chr [1:272] "10 M" "10 M" "10 M" "10 M" ... ## .. ..$ pert_iname : chr [1:272] "atorvastatin" "atorvastatin" "atorvastatin" "atorvastatin" ... ## .. ..$ pert_itime : chr [1:272] "6 h" "6 h" "6 h" "24 h" ... ## .. ..$ pert_type : chr [1:272] "trt_cp" "trt_cp" "trt_cp" "trt_cp" ... ## .. ..$ pool_id : chr [1:272] "epsilon" "epsilon" "epsilon" "epsilon" ... ## ..@ version: chr(0) ## ..@ src : chr "inst/extdata/modzs_n272x978.gctx" ``` -------------------------------- ### Compute Row and Column Means Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Calculates the mean value for each row and each column of the extracted GCT matrix. Useful for understanding central tendencies of the data. ```r # compute the row and column means row_means <- rowMeans(m) col_means <- colMeans(m) message("means:") ``` ```r head(row_means) ``` ```r head(col_means) ``` -------------------------------- ### Parse GCT Object with Matrix Only Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Use the `matrix_only = TRUE` argument in `parse_gctx` to read only the data matrix, excluding metadata. This is useful when you intend to apply external annotations later. ```r # we'll use the matrix_only argument to extract just the matrix (my_ds_no_meta <- parse_gctx(ds_path, matrix_only = TRUE)) ``` -------------------------------- ### Annotate GCT Object Columns Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Use `annotate_gct` to add column annotations to a GCT object. Specify the dimension to annotate (`dim`) and the key field (`keyfield`) that links annotations to the GCT matrix IDs. ```R # note we need to specifiy which dimension to annotate (dim) # and which column in the annotations corresponds to the column # ids in the matrix (keyfield) (my_ds_no_meta <- annotate_gct(my_ds_no_meta, col_meta, dim="col", keyfield="id")) ``` -------------------------------- ### Rank GCT Matrix and Plot Source: https://www.bioconductor.org/packages/release/bioc/vignettes/cmapR/inst/doc/tutorial.html Converts a GCT object's matrix to ranks, with the 'dim' option controlling the direction of calculation. This snippet also demonstrates plotting the ranked data against the original scores. ```R # converting a GCT object's matrix to ranks # the 'dim' option controls the direction along which the ranks are calculated my_ds_rank_by_column <- rank_gct(my_ds, dim="col") # plot z-score vs rank for the first 25 genes (rows) ranked_m <- mat(my_ds_rank_by_column) plot(ranked_m[1:25, ], m[1:25, ], xlab="rank", ylab="differential expression score", main="score vs. rank") ```