# Dockerized mvMAPIT

In order to enable users to work with mvMAPIT without having to install all dependencies and libraries on their local, we provide a docker build with all dependencies and an installed R package `mvMAPIT`. Learn how to build your own version of the docker image.

## Docker Setup

Follow the official guide to learn how to Get Docker. This is required for being able to follow this tutorial.

## Build an Image with mvMAPIT

The github repository of mvMAPIT already comes with a `Dockerfile`. To build the image, clone the github repository and run the following commands.

    cd mvMAPIT
    docker build -t mvmapit .

This will produce an image named `mvmapit` that contains `Rstudio`, `mvMAPIT`, and all dependencies.

## Run the mvMAPIT Image

With a local copy of the docker image `mvmapit` available, run the following code.

    docker run --rm -ti \
        -e DISABLE_AUTH=true \
        -p 8787:8787 \
        --name my_container \
        mvmapit

This will start the docker container that serves an RStudio application at `localhost:8787`. In this container, `mvMAPIT` is already installed and can be imported and run in the R console via the following code.

    library(mvMAPIT)
    mvmapit(t(simulated_data$genotype[1:100,1:10]),
            t(simulated_data$trait[1:100,]),
            cores = 2, logLevel = "DEBUG")

    ## 2023-02-06 12:07:09 DEBUG:mvmapit:Running in normal test mode.
    ## 2023-02-06 12:07:09 DEBUG:mvmapit:Genotype matrix: 10 x 100
    ## 2023-02-06 12:07:09 DEBUG:mvmapit:Phenotype matrix: 2 x 100
    ## 2023-02-06 12:07:09 DEBUG:mvmapit:Number of zero variance variants: 0
    ## 2023-02-06 12:07:09 DEBUG:mvmapit:Genotype matrix after removing zero variance variants: 10 x 100
    ## 2023-02-06 12:07:09 DEBUG:mvmapit:Scale X matrix appropriately.
    ## 2023-02-06 12:07:09 DEBUG:mvmapit:Calculated mean time of execution. Return list.

    ## $pvalues
    ## # A tibble: 30 × 3
    ##    id        trait         p
    ##    <chr>     <chr>     <dbl>
    ##  1 snp_00001 p_01*p_01 0.435
    ##  2 snp_00001 p_02*p_01 0.476
    ##  3 snp_00001 p_02*p_02 0.909
    ##  4 snp_00002 p_01*p_01 0.510
    ##  5 snp_00002 p_02*p_01 0.606
    ##  6 snp_00002 p_02*p_02 0.326
    ##  7 snp_00003 p_01*p_01 0.452
    ##  8 snp_00003 p_02*p_01 0.536
    ##  9 snp_00003 p_02*p_02 0.140
    ## 10 snp_00004 p_01*p_01 0.688
    ## # … with 20 more rows
    ##
    ## $pves
    ## # A tibble: 30 × 3
    ##    id        trait          PVE
    ##    <chr>     <chr>        <dbl>
    ##  1 snp_00001 p_01*p_01  0.0615
    ##  2 snp_00001 p_02*p_01  0.0663
    ##  3 snp_00001 p_02*p_02 -0.00451
    ##  4 snp_00002 p_01*p_01 -0.0215
    ##  5 snp_00002 p_02*p_01 -0.0239
    ##  6 snp_00002 p_02*p_02 -0.0287
    ##  7 snp_00003 p_01*p_01  0.0579
    ##  8 snp_00003 p_02*p_01  0.0493
    ##  9 snp_00003 p_02*p_02 -0.0400
    ## 10 snp_00004 p_01*p_01 -0.0146
    ## # … with 20 more rows
    ##
    ## $duration
    ##       process duration_ms
    ## 1         cov         0.0
    ## 2 projections         0.0
    ## 3   vectorize         0.0
    ## 4           q         0.0
    ## 5           S         0.0
    ## 6          vc         1.1