---
title: R/GNapi User Guide
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{R/GNapi User Guide}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8](inputenc)
---

```{r knitr_options, include=FALSE}
library(knitr)
opts_chunk$set(fig.width=7, fig.height=4.5,
               dev.args=list(pointsize=16),
               eval=FALSE)
```

[![R-CMD-check](https://github.com/rqtl/GNapi/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rqtl/GNapi/actions/workflows/R-CMD-check.yaml)
[![r-universe badge](https://rqtl.r-universe.dev/GNapi/badges/version)](https://rqtl.r-universe.dev/GNapi)
[![zenodo DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8192582.svg)](https://doi.org/10.5281/zenodo.8192582)

The [R/GNapi](https://github.com/rqtl/GNapi) package provides
access to the [GeneNetwork2](https://genenetwork.org) API; for
details on the API, see [its
documentation](https://github.com/genenetwork/genenetwork2/blob/testing/api_readme.md)
The present vignette simply follows that documenation and shows the
corresponding R facilities.

## Fetch species list

To fetch the list of species available in the GeneNetwork database:

```r
list_species()
```

You can also get the information for a single species:

```r
list_species("mouse")
```

## Fetch Groups/RISets

To get a list of groups (for example, RIL sets) across all species:

```r
list_groups()
```

You can also get the list of groups for a single species:

```r
list_groups("rat")
```

## Fetch genotypes for Group/RIset

```r
g <- get_geno("BXD")
```

## Fetch datasets

List datasets for a particular group.

```r
list_datasets("bxd")
```

List a particular dataset.

```r
list_datasets("bxd", "HC_M2_0606_P")
```


## Fetch sample data for dataset

```r
phe <- get_pheno("HSNIH-PalmerPublish")
```



### Information for mRNA assay/probeset

```r
list_datasets(dataset="HC_M2_0606_P")
```

Or provide group/riset

```r
list_datasets("bxd", "HC_M2_0606_P")
```

### Fetch individual phenotype info

```r
list_datasets("bxd", "10001")
```

## Fetch trait information

This is mostly information about QTL location (LRS score and marker).
You need to provide a group and a trait, such as a probeset on a microarray:

```r
info_pheno("HC_M2_0606_P", "1436869_at")
```

Or a traditional phenotype:

```r
info_pheno("BXD", "10002")
```

You can provide a vector of trait identifiers:

```r
info_pheno("BXD", c("10002", "10010", "10100"))
```


## Fetch sample data for a single trait

```r
ph <- get_pheno("HC_M2_0606_P", "1436869_at")
```

### For mRNA expression/probeset

```r
info_pheno("HC_M2_0606_P", "1436869_at")
```

### For classical phenotypes

```r
info_pheno("BXD", "10001")
```

## Analyses

### Gemma

```r
out <- run_gemma("BXDPublish", "10015", use_loco=TRUE)
```

### R/qtl

```r
out <- run_rqtl("BXDPublish", "10015", method="em", interval_mapping=TRUE)
```

### Correlations

```r
out <- run_correlation("HC_M2_0606_P", "BXDPublish", "1427571_at")
```
