Causal Inference for QTL Networks with R/qtlnet

Elias Chaibub Neto and Brian S. Yandell

This vignette briefly describes the qtlnet R package. It incorporates the legacy qdg package and includes code corresponding to Chaibub Neto et al. (2008) and Chaibub Neto et al. (2010). Not all routines are described here, and parallel processing routines using Condor are documented separately in inst/parallel/.

Installation

qtlnet depends on Bioconductor packages graph and RBGL (via pcalg) as well as CRAN packages qtl, igraph, pcalg, and lavaan. You can install the Bioconductor dependencies and CRAN dependencies from within R as follows:

if (!requireNamespace("BiocManager", quietly = TRUE)) {
  install.packages("BiocManager")
}
BiocManager::install(c("graph", "RBGL"))
install.packages(c("qtl", "igraph", "pcalg", "lavaan"))

QTLNET routines

Load qtlnet and inspect the bundled Pscdbp.qtlnet MCMC network example (from Ghazalpour et al. 2006 / Chaibub Neto et al. 2010):

library(qtlnet)
data(Pscdbp.qtlnet)
summary(Pscdbp.qtlnet)
#> 
#> Model-averaged network: (min.prob = 0.5)
#>    cause effect      prob
#> 1 Pscdbp   Ctss 0.9988901
#> 2 Pscdbp    Abr 1.0000000
#> 3 Pscdbp Dock10 0.9600444
#> 4    Abr   Ctss 0.9622642
#> 5 Dock10   Ctss 0.9733629
#> 6   Ctss  Stk10 0.9855716
#> 7    Abr Dock10 0.9988901
#> 
#> Posterior probabilities by direction:
#>     node1  node2   -->   <--    no
#> 1  Pscdbp   Ctss 0.999 0.000 0.001
#> 2  Pscdbp    Abr 1.000 0.000 0.000
#> 3  Pscdbp Dock10 0.960 0.000 0.040
#> 4  Pscdbp  Stk10 0.407 0.000 0.593
#> 5    Ctss    Abr 0.000 0.962 0.038
#> 6    Ctss Dock10 0.022 0.973 0.005
#> 7    Ctss  Stk10 0.986 0.014 0.000
#> 8     Abr Dock10 0.999 0.000 0.001
#> 9     Abr  Stk10 0.192 0.003 0.805
#> 10 Dock10  Stk10 0.194 0.004 0.802
#> 
#> Acceptance frequency for MCMC: 0.0887
pscdbp_graph <- igraph.qtlnet(Pscdbp.qtlnet)
plot(pscdbp_graph)

Additional bundled simulation and data examples can be explored interactively via example() (note that full network simulations and MCMC runs are wrapped in \dontrun{} in their help pages):

## Acyclic and cyclic graph simulations (Chaibub Neto et al. 2008)
example(acyclic)
example(cyclica)
example(cyclicb)
example(cyclicc)

## GLX network example (Chaibub Neto et al. 2008; Ferrara et al. 2008)
example(glxnet)

QDG routines

The QDG (QTL-driven Directed Graph) routines are incorporated into qtlnet. Below we generate synthetic data, infer a QDG model, and plot the inferred graph. We focus on a simple acyclic graph (y1 -> y3, y2 -> y3, and y3 -> y4) with QTLs affecting each of the four phenotypes.

Simulate a genetic map (20 autosomes, 10 unevenly spaced markers per chromosome) and an F2 cross with 200 individuals:

set.seed(1234)
mymap <- qtl::sim.map(len = rep(100, 20), n.mar = 10, eq.spacing = FALSE, include.x = FALSE)
n.ind <- 200
mycross <- qtl::sim.cross(map = mymap, n.ind = n.ind, type = "f2")

Produce genotype imputations using qtl::sim.geno(). The qtl::makeqtl() function requires it, though a single imputation suffices here because there is no missing data and we use marker genotypes directly:

mycross <- qtl::sim.geno(mycross, n.draws = 1)

Sample 2 markers per phenotype from the cross and simulate the four phenotypes:

genotypes <- qtl::pull.geno(mycross)
geno.names <- dimnames(genotypes)[[2]]
m1 <- sample(geno.names, 2, replace = FALSE)
m2 <- sample(geno.names, 2, replace = FALSE)
m3 <- sample(geno.names, 2, replace = FALSE)
m4 <- sample(geno.names, 2, replace = FALSE)

## Get marker genotypes
g11 <- genotypes[, m1[1]]; g12 <- genotypes[, m1[2]]
g21 <- genotypes[, m2[1]]; g22 <- genotypes[, m2[2]]
g31 <- genotypes[, m3[1]]; g32 <- genotypes[, m3[2]]
g41 <- genotypes[, m4[1]]; g42 <- genotypes[, m4[2]]

## Generate phenotypes
y1 <- runif(3, 0.5, 1)[g11] + runif(3, 0.5, 1)[g12] + rnorm(n.ind)
y2 <- runif(3, 0.5, 1)[g21] + runif(3, 0.5, 1)[g22] + rnorm(n.ind)
y3 <- runif(1, 0.5, 1) * y1 + runif(1, 0.5, 1) * y2 +
  runif(3, 0.5, 1)[g31] + runif(3, 0.5, 1)[g32] + rnorm(n.ind)
y4 <- runif(1, 0.5, 1) * y3 +
  runif(3, 0.5, 1)[g41] + runif(3, 0.5, 1)[g42] + rnorm(n.ind)

mycross$pheno <- data.frame(y1, y2, y3, y4)

Create the markers list and qtl objects for each phenotype:

markers <- list(y1 = m1, y2 = m2, y3 = m3, y4 = m4)

allqtls <- lapply(markers, function(m) {
  m.pos <- qtl::find.markerpos(mycross, m)
  qtl::makeqtl(mycross, chr = m.pos[, "chr"], pos = m.pos[, "pos"])
})

Infer the QDG object:

out <- qdg(
  cross = mycross,
  phenotype.names = c("y1", "y2", "y3", "y4"),
  marker.names = markers,
  QTL = allqtls,
  alpha = 0.005,
  n.qdg.random.starts = 10,
  skel.method = "pcskel"
)
out
#> 
#>  Number of solutions:
#> [1] 1
#> 
#> Best solution:
#>   node1 direction node2       lod
#> 1    y1     ---->    y3  8.237770
#> 2    y2     ---->    y3  8.480152
#> 3    y3     ---->    y4 11.314181
#> 
#> BIC:
#>       lm 
#> 2375.647 
#> 
#> Best solution is solution number:
#> [1] 1
#> 
#> Caution:
#> [1] "If one of the solutions is a cyclic graph you should run qdg.sem in order to score the networks using SEM."

Plot the inferred graph. graph.qdg() returns an igraph object that can be plotted with plot() (or interactively with igraph::tkplot()):

gr <- graph.qdg(out)
plot(gr)

Scoring Directed Graphs with SEM (lavaan)

For directed graphs—and especially when candidate solutions include cyclic graphs where QDG’s unnormalized log-likelihood cannot compare cyclic and acyclic structures—qdg.sem() fits structural equation models to the phenotype network using lavaan:

out_sem <- qdg.sem(out, cross = mycross)
out_sem
#> 
#> Best SEM solution:
#>   node1 direction node2       lod
#> 1    y1     ---->    y3  8.237770
#> 2    y2     ---->    y3  8.480152
#> 3    y3     ---->    y4 11.314181
#> 
#> BIC:
#>      sem 
#> 2293.885 
#> 
#> Best SEM solution is solution number:
#> [1] 1
out_sem$BIC.SEM
#>          sem.BIC posterior prob
#> model.1 2293.885              1
out_sem$path.coeffs
#> [1] 0.6188715 0.8961851 0.6079770

The scored qdg.sem object can also be converted to an igraph object and plotted:

gr_sem <- graph.qdg(out_sem)
plot(gr_sem)

For cyclic networks, qdg.sem() scores the candidate cyclic solutions returned by qdg(). Here we illustrate this on the bundled cyclica dataset:

data(cyclica)
cyclic_qdg <- qdg(
  cross = cyclica.data,
  phenotype.names = paste0("y", 1:6),
  marker.names = cyclica.qtl$markers,
  QTL = cyclica.qtl$allqtl,
  alpha = 0.005,
  n.qdg.random.starts = 10,
  skel.method = "pcskel"
)
cyclic_sem <- qdg.sem(cyclic_qdg, cross = cyclica.data)
cyclic_sem
#> 
#> Best SEM solution:
#>   node1 direction node2        lod
#> 1    y1     ---->    y2   5.526215
#> 2    y2     ---->    y4  38.041997
#> 3    y2     <----    y5 -31.994703
#> 4    y3     ---->    y4  15.859835
#> 5    y4     ---->    y5  42.607942
#> 6    y5     ---->    y6  28.170211
#> 
#> BIC:
#>       sem 
#> -277.5297 
#> 
#> Best SEM solution is solution number:
#> [1] 1

References