R/LFQDataTransformer.R
LFQDataTransformer.Rd
Decorate LFQData with Methods for transforming Intensities
Decorate LFQData with Methods for transforming Intensities
lfq
LFQData object
log2()
log2 transform data
robscale()
robust scale data
robscale_subset()
log2 transform and robust scale data based on subset
LFQDataTransformer$robscale_subset(
lfqsubset,
preserveMean = TRUE,
colname = "transformedIntensity"
)
intensity_array()
Transforms intensities
intensity_matrix()
pass a function which works with matrices, e.g., vsn::justvsn
istar <- prolfqua_data('data_ionstar')$filtered()
#> Column added : nr_peptide_Id_IN_protein_Id
istar$config <- old2new(istar$config)
data <- istar$data |> dplyr::filter(protein_Id %in% sample(protein_Id, 100))
lfqdata <- LFQData$new(data, istar$config)
lfqcopy <- lfqdata$get_copy()
lfqTrans <- lfqcopy$get_Transformer()
x <- lfqTrans$intensity_array(log2)
#> Column added : log2_peptide.intensity
x$lfq$config$table$is_response_transformed
#> [1] TRUE
x <- x$intensity_matrix(robust_scale)
#> Warning: data already transformed. If you still want to log2 tranform, set force = TRUE
plotter <- x$lfq$get_Plotter()
plotter$intensity_distribution_density()
# transform by asinh root and scale
lfqcopy <- lfqdata$get_copy()
lfqTrans <- lfqcopy$get_Transformer()
x <- lfqTrans$intensity_array(asinh)
#> Column added : asinh_peptide.intensity
mads1 <- mean(x$get_scales()$mads)
x <- lfqTrans$intensity_matrix(robust_scale, force = TRUE)
#> Warning: Expected 2 pieces. Additional pieces discarded in 15520 rows [1, 2, 3, 4, 5, 6,
#> 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
#> Joining with `by = join_by(protein_Id, sampleName, peptide_Id)`
mads2 <- mean(x$get_scales()$mads)
stopifnot(abs(mads1 - mads2) < 1e-8)
stopifnot(abs(mean(x$get_scales()$medians)) < 1e-8)
lfqcopy <- lfqdata$get_copy()
lfqTrans <- lfqcopy$get_Transformer()
lfqTrans$log2()
#> Column added : log2_peptide.intensity
before <- lfqTrans$get_scales()
lfqTrans$robscale()
#> data is : TRUE
#> Warning: Expected 2 pieces. Additional pieces discarded in 15520 rows [1, 2, 3, 4, 5, 6,
#> 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
#> Joining with `by = join_by(protein_Id, sampleName, peptide_Id)`
after <- lfqTrans$get_scales()
stopifnot(abs(mean(before$medians) - mean(after$medians)) < 1e-8)
stopifnot(abs(mean(before$mads) - mean(after$mads)) < 1e-8)
# normalize data using vsn
lfqcopy <- lfqdata$get_copy()
lfqTrans <- lfqcopy$get_Transformer()
lfqTransCheck <- lfqcopy$get_Transformer()
lfqTransCheck$log2()
#> Column added : log2_peptide.intensity
lfqTransCheck$get_scales()
#> $medians
#> a~10 a~11 a~20 a~21 b~02 b~09 b~12 b~19
#> 24.72115 25.15540 25.16233 25.17072 24.83373 24.76536 25.13049 25.13891
#> c~03 c~08 c~13 c~18 d~04 d~07 d~14 d~17
#> 24.90253 24.72028 24.84177 25.19270 24.82138 24.70535 25.06052 25.17819
#> e~05 e~06 e~15 e~16
#> 24.72917 24.72036 25.11136 25.13985
#>
#> $mads
#> a~10 a~11 a~20 a~21 b~02 b~09 b~12 b~19
#> 2.238950 2.243746 2.196464 2.227671 2.212583 2.312846 2.220689 2.214160
#> c~03 c~08 c~13 c~18 d~04 d~07 d~14 d~17
#> 2.275791 2.302519 2.222436 2.234537 2.171028 2.127855 2.126487 2.265475
#> e~05 e~06 e~15 e~16
#> 2.142237 2.196353 2.162166 2.148171
#>
lfqTransCheck$lfq$get_Plotter()$intensity_distribution_density()
if(require("vsn")){
res <- lfqTrans$intensity_matrix( .func = vsn::justvsn)
res$lfq$get_Plotter()$intensity_distribution_density()
res$get_scales()
}
#> Warning: Expected 2 pieces. Additional pieces discarded in 15520 rows [1, 2, 3, 4, 5, 6,
#> 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
#> Joining with `by = join_by(protein_Id, sampleName, peptide_Id)`
#> $medians
#> a~10 a~11 a~20 a~21 b~02 b~09 b~12 b~19
#> 24.89048 24.92424 24.96236 25.00745 24.85800 24.95805 24.91216 24.97514
#> c~03 c~08 c~13 c~18 d~04 d~07 d~14 d~17
#> 24.97357 24.98283 25.01958 25.00426 24.94905 24.94866 24.90674 25.02897
#> e~05 e~06 e~15 e~16
#> 24.94858 24.95029 24.99417 25.00696
#>
#> $mads
#> a~10 a~11 a~20 a~21 b~02 b~09 b~12 b~19
#> 2.238950 2.243746 2.196464 2.227671 2.212583 2.312846 2.220689 2.214160
#> c~03 c~08 c~13 c~18 d~04 d~07 d~14 d~17
#> 2.275791 2.302519 2.222436 2.234537 2.171028 2.127855 2.126487 2.265475
#> e~05 e~06 e~15 e~16
#> 2.142237 2.196353 2.162166 2.148171
#>
if(require("preprocessCore")){
quant <- function(y){
ynorm <- preprocessCore::normalize.quantiles(y)
rownames(ynorm) <- rownames(y)
colnames(ynorm) <- colnames(y)
return(ynorm)
}
res <- lfqTrans$intensity_matrix( .func = quant)
res$lfq$get_Plotter()$intensity_distribution_density()
}
#> Warning: data already transformed. If you still want to log2 tranform, set force = TRUE