https://github.com/nmartinkova/diemr
Genome polarization using the diagnostic index expectation maximisation algorithm in R
https://github.com/nmartinkova/diemr
bioinformatics diem diemr genome-admixture genome-polarisation genome-polarization genomics hybridisation hybridization population-genetics population-genomics r r-package speciation
Last synced: 16 days ago
JSON representation
Genome polarization using the diagnostic index expectation maximisation algorithm in R
- Host: GitHub
- URL: https://github.com/nmartinkova/diemr
- Owner: nmartinkova
- License: gpl-3.0
- Created: 2025-09-11T11:19:47.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2026-03-18T07:55:54.000Z (4 months ago)
- Last Synced: 2026-03-18T23:37:02.758Z (4 months ago)
- Topics: bioinformatics, diem, diemr, genome-admixture, genome-polarisation, genome-polarization, genomics, hybridisation, hybridization, population-genetics, population-genomics, r, r-package, speciation
- Language: R
- Homepage: https://CRAN.R-project.org/package=diemr
- Size: 1.26 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE.md
- Citation: CITATION.cff
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# diemr: Genome polarisation in R
[](https://CRAN.R-project.org/package=diemr)
[](https://cran.r-project.org/package=diemr)
[](https://cran.r-project.org/package=diemr)

_diemr_ implements the **Diagnostic Index Expectation Maximization (*diem*) algorithm**
for **genome polarization** in `R`. It estimates which alleles of single nucleotide
variant (SNV) sites belong to
either side of a barrier to gene flow, co-estimates individual assignment,
and infers barrier strength and divergence. These tools are designed for studies
of **hybridization**, **speciation**, and population divergence, and extend the
methods described in Baird et al. (2023) Genome polarisation for detecting barriers to
geneflow. _Methods in Ecology and Evolution 14_, 512-528 .
For the original algorithm description and implementations in `Python` and
`Mathematica`, see the _diem_ repository at https://github.com/StuartJEBaird/diem. For a
step-by-step explanation of the functions and their outputs, see the [documentation](https://nmartinkova.github.io/genome-polarisation/) for the `diemr` package.
## Installation
To start using _diemr_, load the package or install it from CRAN if it is not yet available:
``` {r, eval = FALSE}
if(!require("diemr", character.only = TRUE)){
install.packages("diemr", dependencies = TRUE)
library("diemr", character.only = TRUE)
}
# Loading required package: diemr
```
The developer version can be installed directly from this repository using package `devtools`.
```{r, eval = FALSE}
devtools::install_github("https://github.com/nmartinkova/diemr")
```
Set working directory to a location with read and write privileges.
## Check data format and polarise genotypes
Next, assemble paths to all files containing the data to be used by _diemr_. Here, we will use a tiny example dataset for illustration that is included in the package. A good practice is to check that all files contain data in correct format for all individuals and markers.
```{r, eval = FALSE}
filepaths <- system.file("extdata", "data7x3.txt",
package = "diemr")
CheckDiemFormat(filepaths, ploidy = list(rep(2, 6)), ChosenInds = 1:6)
# File check passed: TRUE
# Ploidy check passed: TRUE
```
If the `CheckDiemFormat()` function fails, work through the error messages and fix the stored input files accordingly. The algorithm repeatedly accesses data from the harddisk, so seeing the passed file check prior to analysis is critical.
```{r, eval = FALSE}
diem.res <- diem(files = filepaths,
ploidy = list(rep(2, 6)),
ChosenInds = 1:6,
nCores = 1)
```
The results including marker polarisation, marker diagnostic index and its support will be included in the list element `diem.res$DI`. Additional elements in the results list contain basic tracking information about the expectation maximisation iterations. The key results are saved in a file *MarkerDiagnosticsWithOptimalPolarities.txt* in the working directory. Check the the `diemr` [documentation](https://nmartinkova.github.io/genome-polarisation/) for further information.