## ----style, echo = FALSE, results = 'asis'------------------------------------
BiocStyle::markdown()

## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
    collapse = TRUE,
    crop = NULL,
    comment = "#>"
)

## ----eval = FALSE-------------------------------------------------------------
# if (!require("BiocManager", quietly = TRUE))
#     install.packages("BiocManager")
# BiocManager::install("TDbasedUFE")

## ----setup--------------------------------------------------------------------
library(TDbasedUFE)

## -----------------------------------------------------------------------------
require(GenomicRanges)
require(rTensor)
f <- system.file("extdata", "quickstart_counts.rds",
    package = "TDbasedUFE", mustWork = TRUE)
example <- readRDS(f)
counts <- example$counts
samples <- example$samples
dim(counts)

## -----------------------------------------------------------------------------
Z <- PrepareSummarizedExperimentTensor(matrix(samples$sample,c(3,2)),
    rownames(counts),array(counts,c(dim(counts)[1],3,2)))
dim(attr(Z,"value"))
HOSVD <- computeHosvd(Z)

## -----------------------------------------------------------------------------
input_all <- selectSingularValueVectorSmall(HOSVD,input_all= c(1,2)) #batch mode

## -----------------------------------------------------------------------------
index <- selectFeature(HOSVD,input_all)

## -----------------------------------------------------------------------------
head(tableFeatures(Z,index))

## -----------------------------------------------------------------------------
require(MOFAdata)
data("CLL_data")
data("CLL_covariates")
help(CLL_data)

## -----------------------------------------------------------------------------
Z <- PrepareSummarizedExperimentTensorSquare(
    sample=matrix(colnames(CLL_data$Drugs),1),
    feature=list(Drugs=rownames(CLL_data$Drugs),
    Methylation=rownames(CLL_data$Methylation),
    mRNA=rownames(CLL_data$mRNA),Mutations=rownames(CLL_data$Mutations)),
    value=convertSquare(CLL_data),sampleData=list(CLL_covariates[,1]))
HOSVD <- computeHosvdSqure(Z)

## -----------------------------------------------------------------------------
table(CLL_covariates[,1])
cond <- list(attr(Z,"sampleData")[[1]],attr(Z,"sampleData")[[1]],seq_len(4))

## -----------------------------------------------------------------------------
input_all <- selectSingularValueVectorLarge(HOSVD,cond,input_all=c(8,1))

## -----------------------------------------------------------------------------
index <- selectFeatureSquare(HOSVD,input_all,CLL_data,
    de=c(0.3,0.03,0.1,0.1),interact=FALSE) #for batch mode

## -----------------------------------------------------------------------------
for (id in seq_len(4)){print(head(tableFeaturesSquare(Z,index,id)))}

## -----------------------------------------------------------------------------
sessionInfo()

