## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE, cache = TRUE, cache.path = "c/", fig.path = "fig/")

## ----cache=TRUE,eval=FALSE----------------------------------------------------
# library("dtangle")
# names(shen_orr_ex)

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# head(shen_orr_ex$annotation$mixture)

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# Y <- shen_orr_ex$data$log
# Y[1:4, 1:4]

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# ?dtangle2

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# library("dtangle")
# data <- shen_orr_ex$data$log[, c(1:10, 201:210, 401:410)]
# mixture_proportions <- shen_orr_ex$annotation$mixture

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# mixture_proportions

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# pure_samples <- list(Liver = c(1, 2, 3), Brain = c(4, 5, 6), Lung = c(7, 8, 9))
# 
# dt_out <- dtangle2(Y = data, pure_samples = pure_samples)

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# true_proportions <- mixture_proportions[-(1:9), ]
# matplot(true_proportions, dt_out$estimates, xlim = c(0, 1), ylim = c(0, 1), xlab = "Truth", ylab = "Estimates")

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# mixture_samples <- data[-(1:9), ]
# reference_samples <- data[1:9, ]

## ----eval=FALSE---------------------------------------------------------------
# dt_out <- dtangle2(Y = mixture_samples, reference = reference_samples, pure_samples = pure_samples)
# 
# matplot(true_proportions, dt_out$estimates, xlim = c(0, 1), ylim = c(0, 1), xlab = "Truth", ylab = "Estimates")

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# ref_reduced <- t(sapply(pure_samples, function(x) colMeans(reference_samples[x, , drop = FALSE])))

## ----eval=FALSE---------------------------------------------------------------
# dt_out <- dtangle2(Y = mixture_samples, reference = ref_reduced)
# 
# matplot(true_proportions, dt_out$estimates, xlim = c(0, 1), ylim = c(0, 1), xlab = "Truth", ylab = "Estimates")

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# dt_out <- dtangle2(Y = mixture_samples, references = ref_reduced)

## ----eval=FALSE---------------------------------------------------------------
# dt_out <- dtangle2(Y = mixture_samples, references = ref_reduced, marker_method = "diff")

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# dt_out$n_markers

## ----eval=FALSE---------------------------------------------------------------
# dt_out <- dtangle2(Y = mixture_samples, references = ref_reduced, marker_method = "diff", n_markers = 3)
# 
# dt_out$n_markers

## ----eval=FALSE---------------------------------------------------------------
# dt_out <- dtangle2(Y = mixture_samples, references = ref_reduced, marker_method = "diff", n_markers = c(1, 2, 3))
# 
# dt_out$n_markers

## ----eval=FALSE---------------------------------------------------------------
# dt_out <- dtangle2(Y = mixture_samples, references = ref_reduced, marker_method = "diff", n_markers = .075)
# 
# dt_out$n_markers
# 
# dt_out <- dtangle2(Y = mixture_samples, references = ref_reduced, marker_method = "diff", n_markers = c(.1, .15, .05))
# 
# dt_out$n_markers

## ----eval=FALSE---------------------------------------------------------------
# marker_genes <- list(
#   c(1, 2, 3),
#   c(4, 5, 6),
#   c(7, 8, 9)
# )
# 
# dt_out <- dtangle2(Y = mixture_samples, references = ref_reduced, markers = marker_genes)
# dt_out$n_markers

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# mrkrs <- find_markers(Y = mixture_samples, references = ref_reduced)
# names(mrkrs)

## ----eval=FALSE---------------------------------------------------------------
# dt_out <- dtangle2(Y = mixture_samples, references = ref_reduced, markers = mrkrs, n_markers = .1)

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# lin_scale_mix <- 2^mixture_samples
# lin_scale_ref <- 2^ref_reduced

## ----cache=TRUE, eval=FALSE---------------------------------------------------
# dt_out <- dtangle2(
#   Y = lin_scale_mix, references = lin_scale_ref, inv_scale = base::identity,
#   seed = 1234, markers = mrkrs$L
# )
# head(dt_out$estimates)

## ----eval=FALSE---------------------------------------------------------------
# ahs_scale_mix <- asinh(lin_scale_mix)
# ahs_scale_ref <- asinh(lin_scale_ref)
# 
# dt_out <- dtangle2(
#   Y = ahs_scale_mix, references = ahs_scale_ref, inv_scale = base::sinh,
#   seed = 1234, markers = mrkrs$L
# )
# head(dt_out$estimates)

