# Inbred Based Populations

#### Statistical Genetics Lab
Department of Genetics
Luiz de Queiroz College of Agriculture
University of São Paulo

#### 2017-10-18

Starting in version 2.0-0, `OneMap` can also deal with inbred-based populations, that is, populations that have homozygous parental lines in the genealogy (F2s, backcrosses and RILs). As a consequence, linkage phases do not need to be estimated.

In this vignette we explain how to proceed the analysis in an F2 population. The same procedure can be used for backcrosses and RILs as well, and therefore users should not have any difficulty in analyzing their data. However, there are a number of differences from genetic mapping in outcrossing species; please read the proper vignette.

If you are not familiar with `R`, we recommend first the reading of vignette Introduction to R. You do not need to be an expert in R to build your linkage map, but some concepts are necessary and will help you through the process.

There is a github `OneMap` version which is constantly improved, we strong recommend all users to try this version. In `augusto-garcia/onemap` github page you can find instructions to install the package from github and also more fancy tutorials.

# Creating the data file

For F2s, backcrosses and RILs, two input formats are accepted. The user can choose between the standard {} file format or the same raw file used by `MAPMAKER/EXP` (Lander et al., 1987). Therefore, one should have no difficulty in using data sets already available for `MAPMAKER/EXP` when deciding to try `OneMap`.

Both types of raw file can contain phenotypic information, but this will not be used during map construction, that requires only genotypic information (made available by molecular markers).

## Creating `MAPMAKER/EXP` data file

The `MAPMAKER/EXP` raw file, combined with the map file produced by `OneMap`, can be readily used for QTL mapping using `R/qtl` (Broman et al., 2008) or `QTL Cartographer` (Wang et al., 2010), among others.

Here, we briefly present how to set up this data file. For more detailed information see the `MAPMAKER/EXP` manual (Lincon et al., 1993), available here.

The first line of your data file should be:

    data type xxxx

where `xxxx` is one of the following data types:

`xxxx` | Population type
--- | ---
`f2 backcross` | Backcross
`f2 intercross` | F2
`ri self` | RIL, produced by selfing
`ri sib` | RIL, produced by sib mating

The second line should contain the number of individuals in the progeny, the number of markers and the number of quantitative traits. So, for example, a valid line would be

    10 5 2

for a data set with 10 individuals (yes, very small, but this is just an example), 5 markers and 2 traits evaluated.

Then, the genotype information is included for each marker. The character `*` indicates the beginning of information of a marker, followed by the marker name. For instance, here is an example of such a file for an F2 population with 10 individuals, 5 markers and 2 quantitative traits:

    data type f2 intercross
    10 5 2

    *M1 A B H H A - B A A B
    *M2 C - C C C - - C C A
    *M3 D B D D - - B D D B
    *M4 C C C - A C C A A C
    *M5 C C C C C C C C C C

    *weight 10.2 - 9.4 11.3 11.9 8.9 - 11.2 7.8 8.1
    *length 1.7 2.1 - 1.8 2.0 1.0 - 1.7 1.0 1.1

The codification for genotypes is the following:

Code | Meaning
--- | ---
`A` | homozygous for allele A (from parent 1 - AA)
`B` | homozygous for allele B (from parent 2 - BB)
`H` | heterozygous carrying both alleles (AB)
`C` | Not homozygous for allele A (Not AA)
`D` | Not homozygous for allele B (Not BB)
`-` | Missing data for the individual at this marker

The `symbols` option (not included in this example), used in `MAPMAKER/EXP` files, is also accepted (please, see its manual for details).

The quantitative trait data should come after the genotypic data and has a similar format, except the trait values for each individual must be separated by at least one space, a tab or a line break. A dash (`-`) indicates missing data.

This file must be saved in plain text format using a simple text editor such as notepad on Microsoft Windows. Historically, `MAPMAKER/EXP` uses the `.raw` extension for this file; however, you can use any other extensions, such as `.txt`.

If you want to see more examples about this file type, open `mapmaker_example_bc.raw` and `mapmaker_example_f2.raw`, both available with `OneMap` and saved in the directory `extdata` on your computer, in the folder where you installed `OneMap` (use `system.file(package="onemap")` to see where it is located on your computer).

Now, let us load `OneMap`:

    library(onemap)

To save your project anytime, type:

    save.image("C:/.../yourfile.RData")

if you are using Windows; otherwise, adapt the code. Notice that you need to specify where to save and the name of the file. You can also use the toolbar, of course.

## Creating `OneMap` data file

The `OneMap` data file has few differences compared to MAPMAKER/EXP format. As MAPMAKER/EXP format, the input `OneMap` file is a text file, where the first line indicates the cross type and the second line provides information about the number of individuals and the number of markers, but, because the format aldo supports to keep physical markers locations informations, the followed numbers indicate the presence/absence (1/0) of chromossome and position informations and, after the presence/absence(1/0) of phenotypic data.

The third line contains sample IDs. Then, the genotype information is included separately for each marker. The character `*` indicates the beginning of information input for a new marker, followed by the marker name. Next, there is a code indicating the marker type according with:

Code | Type
--- | ---
`A.H.B` | Codominant marker
`C.A` | Dominant marker for allele B
`D.B` | Dominant marker for allele A

Finally, after each marker type, comes the genotype data for the segregating population. Missing data are indicated with the character `-` (minus sign) and an empty space separates the information for each individual. Positions and phenotype information, if present, follows genotypic data with a similar structure. Details are found in the help of function `read_onemap`.

Here is an example of such file for 10 individuals and 5 markers (the three zeros in the second line indicate that there is no chromosome information, physical position information or phenotypic data, respectively). It is very similar to a MAPMAKER/EXP file, but has additional information about the crosstype.

    data type f2 intercross
    10 5 1 0 1
    I1 I2 I3 I4 I5 I6 I7 I8 I9 I10
    *M1 A.H.B  ab a - ab b a ab - ab b
    *M2 A.H.B  a - ab ab - b a - a ab
    *M3 C.A    c a a c c - a c a c
    *M4 A.H.B  ab b - ab a b ab b - a
    *M5 D.B    b b d - b d b b b d
    *CHROM 1 1 1 2 2 2 3 3 3 3
    *fen1 10.3 11.2 11.1 - 9.8 8.9 11.0 10.7 - 10.1
    *fen2 42 49 - 45 51 42 28 32 38 40

The input file must be saved in text format, with extensions like `.raw`. It is a good idea to open the text file called `onemap_example_f2.raw` (available in `extdata` with `OneMap` and saved in the directory you installed it) to see how this file should be. You can see where `OneMap` is installed using the command

## Creating `OneMap` data file from `VCF` file

If you are working with biallelic markers, as SNPs and indels (only codominant markers A.H.B), in VCF (Variant Call Format) files, you can use the function `vcf2raw` to convert the genotype information from the VCF file to `OneMap` format `.raw`. Moreover, the function keeps chromosome and position information for each marker at the end of raw file.

To see how the function works, there is a short example of VCF file called `vcf_example_f2.vcf` saved in the directory you installed the `OneMap`. This file is already sorted, compressed and tabix indexed as require by the function. If you need to sort your file, we suggest the `vcf-sort` perl script from `vcftools` program. The functions `bgzip` and `indexTabix` from `Rsamtools` package can be used to compress and add tabix index.

    vcf2raw(input = system.file("extdata/vcf_example_f2.vcf.gz", package = "onemap"),
            output = "vcf_example_f21.raw", parent1 = "P1", parent2 = "P2", cross = "f2 intercross")

The first argument is the path and the name of the data file. You can acess the example data using the function `system.file` as already seen above. For the second argument you can choose a name for the output `.raw` data. At the `parent1` and `parent2` arguments you should specify the parents samples IDs. They could be only one ID or, if there are replicate samples of the parents, multiple IDs for each parent. If you have replicates, you can specify a real number between 0.0 and 1.0 for the argument `min_class` to define the proportion of parents replicates that must have the same genotype for it to be assigned to the corresponding parent. At the `cross` argument you should point the cross type. You can access more information in the help page `?vcf2raw`.

After running the function, the `OneMap` imput file `vcf_example_out.raw` generated will be at your working directory.

The function will not convert non-informative markers (if parents genotypes are not as expected). Therefore, you can have smaller number of markers in your `.raw` file compared to `vcf` file. In our example, there is one non-informative marker, identified as `SNP4`.

# Importing data

## From `MAPMAKER/EXP` file

Once you created your data file with raw data, you can use `OneMap` function `read_mapmaker` to import it to `OneMap`:

    mapmaker_example_f2 <- read_mapmaker(dir="C:/workingdirectory",
                                    file="your_data_file.raw")

The first argument is the directory where the input file is located, so modify it accordingly. The second one is the data file name.

In this example, an object named `mapmaker_example_f2.raw` was created. Notice that if you leave the argument `dir` blank, the file will be read from your current working directory. To set a working directory, see Introduction to R (Importing and Exporting Data).

    mapmaker_example_f2 <- read_mapmaker(file= system.file("extdata/mapmaker_example_f2.raw",
                                                           package = "onemap"))

For this example, we will use a simulated data set from an F2 population which is distributed along with `OneMap`. Because this particular data set is distributed along with the package, you can load it typing

    data("mapmaker_example_f2")

To see what this data set is about, type

    mapmaker_example_f2
    #>   This is an object of class 'onemap'
    #>     Type of cross:      f2
    #>     No. individuals:    200
    #>     No. markers:        66
    #>     CHROM information:  no
    #>     POS information:    no
    #>     Percent genotyped:  85
    #>
    #>     Segregation types:
    #>        AA : AB : BB -->  36
    #>         Not AA : AA -->  15
    #>         Not BB : BB -->  15
    #>
    #>     No. traits:         1
    #>     Missing trait values:
    #>   Trait_1: 0

As you can see, the data consists of a sample of 200 individuals genotyped for 66 markers (36 co-dominant (`AA`, `AB` or `BB`), 15 dominant in one parent (`Not AA` or `AA`) and 15 dominant in the other parent (`Not BB` or `BB`) with 15% of missing data. You can also see that there is phenotypic information for one trait in the data set, that can be used for QTL mapping.

## From `OneMap` raw file

The same procedure is made for `OneMap` raw file, but, instead of using the function `read_mapmaker` we use `read_onemap` to read the `OneMap` format.

    onemap_example_f2 <- read_onemap(dir="C:/workingdirectory",
                                    inputfile = "your_data_file.raw")

In this example, an object named `onemap_example_f2.raw` was created. The data set containg the same markers and individual of the `mapmaker_example_f2.raw` file. Would be a good idea to open this two files in a text editor and compare them to better understand the differences between the two kinds of input files. We can read the `onemap_example_f2.raw` using:

    onemap_example_f2 <- read_onemap(inputfile= system.file("extdata/onemap_example_f2.raw",
                                                           package = "onemap"))

Or, because this particular data are available together with `OneMap` package:

    data("onemap_example_f2")

To see what this data set is about, type

    onemap_example_f2
    #>   This is an object of class 'onemap'
    #>     Type of cross:      f2
    #>     No. individuals:    200
    #>     No. markers:        66
    #>     CHROM information:  no
    #>     POS information:    no
    #>     Percent genotyped:  85
    #>
    #>     Segregation types:
    #>        AA : AB : BB -->  36
    #>         Not AA : AA -->  15
    #>         Not BB : BB -->  15
    #>
    #>     No. traits:         1
    #>     Missing trait values:
    #>   NA: 200

As you can see, the mean difference in the output object is that `read_onemap` function keeps chromossome and position informations. Because the objetcs `mapmaker_example_f2` and `onemap_example_f2` are pratically the same, from now we will use only `onemap_example_f2`.

`OneMap` data sets from `VCF` file can also be read by `read_onemap` function, once the file have the `OneMap` format:

    vcf_example_f2 <- read_onemap(inputfile= system.file("extdata/vcf_example_f2.raw",
                                                           package = "onemap"))

This data is also available together with `OneMap` package:

    data("vcf_example_f2")

This file contains 25 other markers for 192 of the individuals in `onemap_example_f2`:

    vcf_example_f2
    #>   This is an object of class 'onemap'
    #>     Type of cross:      f2
    #>     No. individuals:    192
    #>     No. markers:        25
    #>     CHROM information:  yes
    #>     POS information:    yes
    #>     Percent genotyped:  86
    #>
    #>     Segregation types:
    #>        AA : AB : BB -->  25
    #>
    #>     No. traits:         0

# Visualization of raw data

Before building your linkage map, you should take a look at your data set. First, notice that by reading the raw data into `OneMap`, an object of classes `onemap` and `f2` was produced:

    class(onemap_example_f2)
    #> [1] "onemap" "f2"
    class(vcf_example_f2)
    #> [1] "onemap" "f2"

In fact, functions `read_mapmaker` and `read_onemap` will produce objects of classes `backcross`, `riself`, `risib` or `f2`, according to the information in the data file for inbred-based populations. Therefore, you can use `OneMap`’s version of function `plot` to produce a graphic with information about the raw data. It will automatically recognize the class of the object and produce the graphic. To see it in action, try:

    plot(onemap_example_f2)

    plot(vcf_example_f2)

The graphic is self-explanatory. If you want to save it, see the help for function `plot.onemap`:

    ?plot.onemap

This graphic shows that missing data is somehow randomly distributed; also, the proportion of dominant markers is relatively high for this data set. In Onemap’s notation, co-dominant markers are classified as of B type; dominant ones, by C type (for details about this notation, see the vignette for outcrossing species). You can see the number of loci within each type using funcion `plot_by_segreg_type`:

    plot_by_segreg_type(onemap_example_f2)

    plot_by_segreg_type(vcf_example_f2)

So, as shown before, the object `onemap_example_f2` has 36 codominant markers and 30 dominant ones and the `vcf_example_f2`has only codominant markers.

# Combining `OneMap` objects

If you have more than one dataset of markers, all from the same cross type, you can use the function `combine_onemap` to merge them into only one `onemap` object.

In our example, we have two `onemap` objects:

- first: `onemap_example_f2` (equivalent to `mapmaker_example_f2`) with 66 markers and 200 individuals
- second: `vcf_example_f2` with 25 biallelic markers and 192 individuals.

The `combine_function` recognizes the correspondent individuals by the ID, thus, it is important define exactly same IDs to respective individuals in both `raw` files. Compared with the first file, the second file do not have markers informations for 8 individuals. The `combine_onemap` will complete those informations with NA.

In our examples, we have only genotypic information, but the function can also merge the phenotipic information if it exists.

    comb_example <- combine_onemap(onemap_example_f2, vcf_example_f2)
    comb_example
    #>   This is an object of class 'onemap'
    #>     Type of cross:      f2
    #>     No. individuals:    200
    #>     No. markers:        91
    #>     CHROM information:  yes
    #>     POS information:    yes
    #>     Percent genotyped:  84
    #>
    #>     Segregation types:
    #>        AA : AB : BB -->  61
    #>         Not AA : AA -->  15
    #>         Not BB : BB -->  15
    #>
    #>     No. traits:         1
    #>     Missing trait values:
    #>   NA: 200

The function arguments are the names of the `onemap` objects you want to combine.

Plotting markers genotypes from the outputted `onemap` object, we can see that there are more missing data `-` (black vertical lines) for some individuals, because they were missing in the second file.

    plot(comb_example)

# Segregation tests

Now, it should be interesting to see if markers are segregating following what is expected by Mendel’s law. You first need to use function `test_segregation` using as argument an object of class `onemap`.

    f2_test <- test_segregation(comb_example)

This will produce an object of class `onemap_segreg_test`:

    class(f2_test)
    #> [1] "onemap_segreg_test"

You cannot see the results if you simply type the object name; use Onemap’s version of the `print` function for objects of class `onemap_segreg_test`:

    f2_test

(Nothing is shown!)

    print(f2_test)
    #>    Marker    H0  Chi-square     p-value % genot.
    #> 1      M1 1:2:1 0.206896552 0.901722662     87.0
    #> 2      M2   3:1 0.292682927 0.588506355     82.0
    #> 3      M3   3:1 0.124031008 0.724703003     86.0
    #> 4      M4   3:1 0.292682927 0.588506355     82.0
    #> 5      M5   3:1 0.159763314 0.689374522     84.5
    #> 6      M6   3:1 0.620689655 0.430791121     87.0
    #> 7      M7 1:2:1 3.185185185 0.203397600     81.0
    #> 8      M8   3:1 0.165644172 0.684012345     81.5
    #> 9      M9   3:1 0.126984127 0.721579725     84.0
    #> 10    M10 1:2:1 1.721893491 0.422761645     84.5
    #> 11    M11   3:1 1.390946502 0.238245323     81.0
    #> 12    M12 1:2:1 1.678160920 0.432107681     87.0
    #> 13    M13   3:1 0.154285714 0.694472964     87.5
    #> 14    M14 1:2:1 5.337209302 0.069348924     86.0
    #> 15    M15   3:1 0.403292181 0.525393917     81.0
    #> 16    M16 1:2:1 2.036144578 0.361290733     83.0
    #> 17    M17 1:2:1 1.000000000 0.606530660     81.0
    #> 18    M18 1:2:1 3.413793103 0.181427972     87.0
    #> 19    M19   3:1 0.279069767 0.597311573     86.0
    #> 20    M20   3:1 4.462626263 0.034644194     82.5
    #> 21    M21 1:2:1 4.892857143 0.086602329     84.0
    #> 22    M22 1:2:1 2.862068966 0.239061489     87.0
    #> 23    M23   3:1 0.008032129 0.928587488     83.0
    #> 24    M24   3:1 8.649325626 0.003271824     86.5
    #> 25    M25 1:2:1 0.686746988 0.709373215     83.0
    #> 26    M26 1:2:1 7.022598870 0.029858091     88.5
    #> 27    M27 1:2:1 0.108433735 0.947226662     83.0
    #> 28    M28 1:2:1 3.319526627 0.190183989     84.5
    #> 29    M29 1:2:1 0.161676647 0.922342801     83.5
    #> 30    M30 1:2:1 0.607142857 0.738177160     84.0
    #> 31    M31   3:1 0.007843137 0.929430415     85.0
    #> 32    M32   3:1 0.016949153 0.896416968     88.5
    #> 33    M33 1:2:1 0.640718563 0.725888192     83.5
    #> 34    M34   3:1 0.235867446 0.627206926     85.5
    #> 35    M35   3:1 0.606741573 0.436017310     89.0
    #> 36    M36   3:1 0.272727273 0.601508134     88.0
    #> 37    M37 1:2:1 3.169491525 0.204999905     88.5
    #> 38    M38 1:2:1 3.055555556 0.217017393     90.0
    #> 39    M39   3:1 0.163636364 0.685830434     82.5
    #> 40    M40 1:2:1 4.872093023 0.087506123     86.0
    #> 41    M41 1:2:1 4.253012048 0.119253235     83.0
    #> 42    M42   3:1 0.124031008 0.724703003     86.0
    #> 43    M43 1:2:1 0.927272727 0.628992237     82.5
    #> 44    M44 1:2:1 2.000000000 0.367879441     86.0
    #> 45    M45   3:1 0.008032129 0.928587488     83.0
    #> 46    M46 1:2:1 0.740112994 0.690695307     88.5
    #> 47    M47 1:2:1 0.758620690 0.684333200     87.0
    #> 48    M48 1:2:1 2.122807018 0.345969898     85.5
    #> 49    M49   3:1 1.190476190 0.275233524     87.5
    #> 50    M50   3:1 1.068686869 0.301242240     82.5
    #> 51    M51   3:1 0.031746032 0.858586201     84.0
    #> 52    M52 1:2:1 2.684848485 0.261211660     82.5
    #> 53    M53   3:1 0.017142857 0.895830102     87.5
    #> 54    M54 1:2:1 0.772455090 0.679615865     83.5
    #> 55    M55 1:2:1 0.655172414 0.720661163     87.0
    #> 56    M56 1:2:1 2.310734463 0.314941859     88.5
    #> 57    M57 1:2:1 6.159763314 0.045964696     84.5
    #> 58    M58   3:1 2.050847458 0.152121494     88.5
    #> 59    M59   3:1 0.074074074 0.785494747     81.0
    #> 60    M60   3:1 0.050505051 0.822186767     82.5
    #> 61    M61 1:2:1 0.655172414 0.720661163     87.0
    #> 62    M62 1:2:1 1.047337278 0.592343463     84.5
    #> 63    M63 1:2:1 2.147928994 0.341651353     84.5
    #> 64    M64   3:1 0.238658777 0.625176499     84.5
    #> 65    M65 1:2:1 4.571428571 0.101701392     84.0
    #> 66    M66 1:2:1 0.452513966 0.797513128     89.5
    #> 67   SNP1 1:2:1 1.278787879 0.527612092     82.5
    #> 68   SNP2 1:2:1 1.559523810 0.458515169     84.0
    #> 69   SNP3 1:2:1 0.503105590 0.777592404     80.5
    #> 70   SNP4 1:2:1 0.165644172 0.920514905     81.5
    #> 71   SNP5 1:2:1 4.450000000 0.108067419     80.0
    #> 72   SNP6 1:2:1 2.641975309 0.266871595     81.0
    #> 73   SNP7 1:2:1 3.745341615 0.153712576     80.5
    #> 74   SNP8 1:2:1 4.164705882 0.124636604     85.0
    #> 75   SNP9 1:2:1 2.578313253 0.275503037     83.0
    #> 76  SNP10 1:2:1 3.359281437 0.186440949     83.5
    #> 77  SNP11 1:2:1 2.395061728 0.301938820     81.0
    #> 78  SNP12 1:2:1 4.731707317 0.093869134     82.0
    #> 79  SNP13 1:2:1 2.963855422 0.227199291     83.0
    #> 80  SNP14 1:2:1 7.123456790 0.028389714     81.0
    #> 81  SNP15 1:2:1 3.109090909 0.211285400     82.5
    #> 82  SNP16 1:2:1 2.751552795 0.252643368     80.5
    #> 83  SNP17 1:2:1 5.850299401 0.053656659     83.5
    #> 84  SNP18 1:2:1 3.108433735 0.211354837     83.0
    #> 85  SNP19 1:2:1 3.335403727 0.188680181     80.5
    #> 86  SNP20 1:2:1 3.867469880 0.144607090     83.0
    #> 87  SNP21 1:2:1 3.238095238 0.198087264     84.0
    #> 88  SNP22 1:2:1 4.455621302 0.107764105     84.5
    #> 89  SNP23 1:2:1 2.847058824 0.240862412     85.0
    #> 90  SNP24 1:2:1 1.778443114 0.410975549     83.5
    #> 91  SNP25 1:2:1 1.981595092 0.371280460     81.5

This shows the results of the Chi-square test for the expected Mendelian segregation pattern of each marker locus. This depends of course on marker type, because co-dominant markers can show heterozygous genotypes. The appropriate null hypothesis is selected by the function. The proportion of individuals genotyped is also shown.

To declare statistical significance, remember that you should consider that multiple tests are being performed. To guide you in the analysis, function `Bonferroni_alpha` shows the alpha value that should be considered for this number of loci if applying Bonferroni’s correction with global alpha of 0.05:

    Bonferroni_alpha(f2_test)
    #> [1] 0.0005494505

You can subset object `f2_test` to see which markers are distorted under Bonferroni’s criterion, but it is easier to see the proportion of markers that are distorted by drawing a graphic using OneMap’s version of the function `plot` for objects of class `onemap_segreg_test`:

    plot(f2_test)

The graphic is self-explanatory: p-values were transformed by using `-log10(p-values)` for better visualization. A vertical line shows the threshold for tests if Bonferroni’s correction is applied. Significant and non-significant tests are identified. In this particular example, no test was statistically significant, so none will be discarded.

Please, remember that Bonferroni’s correction is conservative, and also that discarding marker data might not be a good approach to your analysis. This graphic is just to suggest a criterion, so use it with caution.

You can see a list of markers with non-distorted segregation using function `select_segreg`:

    select_segreg(f2_test)
    #>  [1] "M1"    "M2"    "M3"    "M4"    "M5"    "M6"    "M7"    "M8"
    #>  [9] "M9"    "M10"   "M11"   "M12"   "M13"   "M14"   "M15"   "M16"
    #> [17] "M17"   "M18"   "M19"   "M20"   "M21"   "M22"   "M23"   "M24"
    #> [25] "M25"   "M26"   "M27"   "M28"   "M29"   "M30"   "M31"   "M32"
    #> [33] "M33"   "M34"   "M35"   "M36"   "M37"   "M38"   "M39"   "M40"
    #> [41] "M41"   "M42"   "M43"   "M44"   "M45"   "M46"   "M47"   "M48"
    #> [49] "M49"   "M50"   "M51"   "M52"   "M53"   "M54"   "M55"   "M56"
    #> [57] "M57"   "M58"   "M59"   "M60"   "M61"   "M62"   "M63"   "M64"
    #> [65] "M65"   "M66"   "SNP1"  "SNP2"  "SNP3"  "SNP4"  "SNP5"  "SNP6"
    #> [73] "SNP7"  "SNP8"  "SNP9"  "SNP10" "SNP11" "SNP12" "SNP13" "SNP14"
    #> [81] "SNP15" "SNP16" "SNP17" "SNP18" "SNP19" "SNP20" "SNP21" "SNP22"
    #> [89] "SNP23" "SNP24" "SNP25"

To get a list of distorted ones (none in this example):

    select_segreg(f2_test, distorted = TRUE)
    #> character(0)

For the next steps will be useful to know the numbers of each markers with segregation distortion, so then you can keep those out of your map building analysis. These numbers refer to the lines where markers are located on the data file.

To access the corresponding number for of this markers you can change the `numbers` argument:

    no_dist <- select_segreg(f2_test, distorted = FALSE, numbers = TRUE) #to show the markers numbers without segregation distortion
    no_dist
    #>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
    #> [24] 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    #> [47] 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    #> [70] 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

    dist <- select_segreg(f2_test, distorted = TRUE, numbers = TRUE) #to show the markers numbers with segregation distortion
    dist
    #> integer(0)

# Estimating two-point recombination fractions

After visualizing raw data and checking for segregation distortion, let us now estimate recombination fractions between all pairs of markers (two-point tests). This is necessary to allow us to test which markers are linked. At this point, you should pay no attention if markers show segregation distortion or not, that is, simply use all of them.

    twopts_f2 <- rf_2pts(comb_example)

There are two optional arguments in function `rf_2pts`: `LOD` and `max.rf` which indicate the minimum LOD Score and the maximum recombination fraction to declare linkage (they default to 3.0 and 0.5, respectively).

The default for the recombination fraction is easy to understand, because if `max.rf < 0.5` we could state that markers are linked. The LOD Score is the statistic used to evaluate the significance of the test for `max.rf = 0.50`. This needs to take into consideration the number of tests performed, which of course depends on the number of markers. Function `suggest_lod` can help users to find an initial value to use for their linkage test. For this example:

    (LOD_sug <- suggest_lod(comb_example))
    #> [1] 4.155071

Thus, one should consider using `LOD = 4.155` for the tests. Please, notice that this is just a guide, not a value to take without any further consideration. For now, we will keep the default values, but later will show that results do not change in our example by using `LOD = 3` or `LOD = 4.155`.

If you want to see the results for a single pair of markers, say `M12` and `M42`, use:

    print(twopts_f2, c("M12", "M42"))
    #>   Results of the 2-point analysis for markers: M12 and M42
    #>   Criteria: LOD =  3 , Maximum recombination fraction =  0.5
    #>
    #>        rf       LOD
    #> 0.3575533 1.9430940

This was possible because `OneMap` has a version of the `print` function that can be applied to objects of class `rf_2pts`:

    class(twopts_f2)
    #> [1] "rf_2pts" "f2"

However, objects of this type are too complex to print if you do not specify a pair of markers:

    print(twopts_f2)
    #>   This is an object of class 'rf_2pts'
    #>
    #>   Criteria: LOD = 3 , Maximum recombination fraction = 0.5
    #>
    #>   This object is too complex to print
    #>   Type 'print(object, c(mrk1=marker, mrk2=marker))' to see
    #>     the analysis for two markers
    #>     mrk1 and mrk2 can be the names or numbers of both markers

# Strategies for this tutorial example

In this example we follow two different strategies:

- Using only recombinations informations.

- Using the recombinations and also the reference genome informations, once our example have `CHROM` and `POS` informations for some of the markers.

First, we will apply the strategy using only recombinations informations. In a second part of this tutorial we show a way to use also reference genome informations. At the and of our analysis we will be able to compare this two strategies drawing the resulted genetic maps.

## Using only recombinations informations

### Assigning markers to linkage groups

To assign markers to linkage groups, first use the function `make_seq` to create a (un-ordered) sequence with all markers:

    mark_all_f2 <- make_seq(twopts_f2, "all")

Function `make_seq` is used to create sequences from objects of several different classes. Here, the first argument is of class `rf_2pts` and the second argument specifies which markers one wants to use (`"all"` indicates that all markers will be analyzed). The object `mark_all_f2` is of class `sequence`:

    class(mark_all_f2)
    #> [1] "sequence"

If you want to form groups with a subset of markers, say `M1`, `M3` and `M7`, use:

    mrk_subset <- make_seq(twopts_f2, c(1, 3, 7))

In this case, it was easy because marker names and order in the objects (indicated in vector `c(1, 3, 7)`) are closed related, that is, you can easily know the position of markers in the object once you know their names. However, this is not true for real data sets, where markers do not have simple names such as `M1` or `M2`.

A good example is to use the vector of markers without segregation distortion that we selected when applying the Chi-square tests.

    mark_no_dist_f2 <- make_seq(twopts_f2, no_dist)

In our example, there are no markers with segretion distortion, then the object `mark_no_dist_f2` is equivalent to `mark_all_f2`.

### Forming the groups

You can assign markers to linkage groups using the function `group`:

    LGs_f2 <- group(mark_all_f2)
    #>    Selecting markers:
    #>    group    1
    #>     .....................................
    #>    group    2
    #>     ..................
    #>    group    3
    #>     ....................................
    LGs_f2
    #>   This is an object of class 'group'
    #>   It was generated from the object "mark_all_f2"
    #>
    #>   Criteria used to assign markers to groups:
    #>     LOD = 3 , Maximum recombination fraction = 0.5
    #>
    #>   No. markers:            91
    #>   No. groups:             3
    #>   No. linked markers:     91
    #>   No. unlinked markers:   0
    #>
    #>   Printing groups:
    #>   Group 1 : 37 markers
    #>     M1 M3 M4 M6 M7 M9 M12 M13 M17 M23 M26 M27 M29 M30 M31 M34 M35 M36 M40 M42 M44 M46 M53 M55 M58 M60 M63 SNP1 SNP2 SNP3 SNP4 SNP5 SNP6 SNP7 SNP8 SNP9 SNP10
    #>
    #>   Group 2 : 18 markers
    #>     M2 M5 M8 M10 M11 M25 M32 M33 M37 M41 M43 M45 M51 M54 M61 M66 SNP24 SNP25
    #>
    #>   Group 3 : 36 markers
    #>     M14 M15 M16 M18 M19 M20 M21 M22 M24 M28 M38 M39 M47 M48 M49 M50 M52 M56 M57 M59 M62 M64 M65 SNP11 SNP12 SNP13 SNP14 SNP15 SNP16 SNP17 SNP18 SNP19 SNP20 SNP21 SNP22 SNP23

This will show the linkage groups that are formed if criteria defined by `max.rf` and `LOD` are applied to define thresholds to be used when assigning markers to linkage groups. If not modified, the same values used for the object `twopts` (from two-point analysis) will be maintained (so, `LOD = 3.0` and `max.rf = 0.5` in this example).

Users can easily change the default values. For example, using LOD suggested by `suggest_lod` (rounded up):

    (LGs_f2 <- group(mark_all_f2, LOD = LOD_sug, max.rf = 0.5))
    #>    Selecting markers:
    #>    group    1
    #>     .....................................
    #>    group    2
    #>     ..................
    #>    group    3
    #>     ....................................
    #>   This is an object of class 'group'
    #>   It was generated from the object "mark_all_f2"
    #>
    #>   Criteria used to assign markers to groups:
    #>     LOD = 4.155071 , Maximum recombination fraction = 0.5
    #>
    #>   No. markers:            91
    #>   No. groups:             3
    #>   No. linked markers:     91
    #>   No. unlinked markers:   0
    #>
    #>   Printing groups:
    #>   Group 1 : 37 markers
    #>     M1 M3 M4 M6 M7 M9 M12 M13 M17 M23 M26 M27 M29 M30 M31 M34 M35 M36 M40 M42 M44 M46 M53 M55 M58 M60 M63 SNP1 SNP2 SNP3 SNP4 SNP5 SNP6 SNP7 SNP8 SNP9 SNP10
    #>
    #>   Group 2 : 18 markers
    #>     M2 M5 M8 M10 M11 M25 M32 M33 M37 M41 M43 M45 M51 M54 M61 M66 SNP24 SNP25
    #>
    #>   Group 3 : 36 markers
    #>     M14 M15 M16 M18 M19 M20 M21 M22 M24 M28 M38 M39 M47 M48 M49 M50 M52 M56 M57 M59 M62 M64 M65 SNP11 SNP12 SNP13 SNP14 SNP15 SNP16 SNP17 SNP18 SNP19 SNP20 SNP21 SNP22 SNP23

No difference was obtained in this example. (The parentheses above are just to avoid typing `LGs_f2` in a new row to have the object printed).

We can see that the markers were assigned to three linkage groups with 27, 16 and 23 markers, with no unlinked markers.

Notice the class of object `LGs_f2`:

    class(LGs_f2)
    #> [1] "group"

### Ordering markers within linkage groups

After assignin markers to linkage groups, the next step is to order the markers within each group.

First, let us choose the mapping function used to display the genetic map. We can choose between Kosambi or Haldane mapping functions. To use Haldane, type

    set_map_fun(type = "haldane")

To use Kosambi’s function:

    set_map_fun(type = "kosambi")

#### Linkage group 2

We will start our analysis using the smallest linkage group (group 2). To do so, you must `extract` it from the object of class `group`. Let us extract the group 2 using function `make_seq`:

    LG2_f2 <- make_seq(LGs_f2, 2)

The first argument is an object of class `group` and the second is a number indicating which linkage group will be extracted. In this case, the object `LGs_f2`, generated by function `group`, is of class `group`. In fact, this function can handle different classes of objects.

If you type

    LG2_f2
    #>
    #> Number of markers: 18
    #> Markers in the sequence:
    #> M2 M5 M8 M10 M11 M25 M32 M33 M37 M41 M43 M45 M51 M54 M61 M66 SNP24 SNP25
    #>
    #> Parameters not estimated.

you will see which markers are comprised in the sequence. But notice that no parameters have been estimated so far (the function says Parameters not estimated). This refers to the fact that so far we only attributed markers to linkage groups, but we did not perform any analysis for them as a group - only as pairs. (Does it seem complicated? Do not worry, you will understand details in a moment).

Notice the class of object `LG2_f2`:

    class(LG2_f2)
    #> [1] "sequence"

To order markers in this group, you can use a two-point based algorithm such as Seriation (Buetow and Chakravarti, 1987), Rapid Chain Delineation (Doerge, 1996), Recombination Counting and Ordering (Van Os et al., 2005) and Unidirectional Growth (Tan and Fu, 2006):

    LG2_ser_f2 <- seriation(LG2_f2)
    LG2_rcd_f2 <- rcd(LG2_f2)
    LG2_rec_f2 <- record(LG2_f2)
    LG2_ug_f2 <- ug(LG2_f2)

For this particular data set, the algorithms provided different results (results not printed in this vignette). For an evaluation and comparison of these methods, see Mollinari et al. (2009).

When possible (i.e., when groups have a small number of markers, in general up to 10 or 11), one should select the best order by comparing the multipoint likelihood of all possible orders between markers (exhaustive search). This procedure is implemented in the function `compare`. Although feasible for up to 10 or 11 markers, with 7 or more markers it will take a couple of hours until you see the results (depending of course on the computational resources available).

Linkage group 2 has 18 markers, so using function `compare` is infeasible. Thus we will apply a heuristic that shows reliable results. First, we will choose a moderate number of markers, say 6, to create a framework using the function `compare`, and then we will position the remaining markers into this framework using function `try_seq`. The way we choose these initial markers in inbred-based populations is somewhat different from what we did for outcrossing populations, where there is a mixture of segregation patterns (see the vignette for details).

In our scenario, we recommend two methods:

1. Randomly choose a number of markers and calculate the multipoint likelihood of all possible orders (using the function `compare`). If the LOD Score of the second best order is greater than a given threshold, say, 3, then take the best order to proceed with the next step. If not, repeat the procedure.
2. Use some two-point based algorithm to construct a map; then, take equally spaced markers from this map. Then, create a framework of ordered markers using the function `compare`. Next, try to map the remaining markers, one at a time, beginning with co-dominant ones (most informative ones), then add the dominant ones.

You can do this procedure manually, in a similar way as done for outcrossing species (see the vignette for details). However, this procedure is automated in function `order_seq`, which we will use here:

    LG2_f2_ord <- order_seq(input.seq = LG2_f2, n.init = 5,
                            subset.search = "twopt",
                            twopt.alg = "rcd", THRES = 3)
    #>
    #> Cross type:  f2
    #> Choosing initial subset using 'two-point' approach
    #>
    #> order obtained using RCD algorithm:
    #>
    #>  41 10 43 11 2 32 45 54 66 61 25 5 51 33 91 37 8 90
    #>
    #> calculating multipoint map using tol =  0.1 .
    #>
    #>
    #> Comparing 60 orders:
    #>
    #>
      |
      |                                                                 |   0%
      |
      |=                                                                |   2%
      |
      |==                                                               |   3%
      |
      |===                                                              |   5%
      |
      |====                                                             |   7%
      |
      |=====                                                            |   8%
      |
      |======                                                           |  10%
      |
      |========                                                         |  12%
      |
      |=========                                                        |  13%
      |
      |==========                                                       |  15%
      |
      |===========                                                      |  17%
      |
      |============                                                     |  18%
      |
      |=============                                                    |  20%
      |
      |==============                                                   |  22%
      |
      |===============                                                  |  23%
      |
      |================                                                 |  25%
      |
      |=================                                                |  27%
      |
      |==================                                               |  28%
      |
      |====================                                             |  30%
      |
      |=====================                                            |  32%
      |
      |======================                                           |  33%
      |
      |=======================                                          |  35%
      |
      |========================                                         |  37%
      |
      |=========================                                        |  38%
      |
      |==========================                                       |  40%
      |
      |===========================                                      |  42%
      |
      |============================                                     |  43%
      |
      |=============================                                    |  45%
      |
      |==============================                                   |  47%
      |
      |===============================                                  |  48%
      |
      |================================                                 |  50%
      |
      |==================================                               |  52%
      |
      |===================================                              |  53%
      |
      |====================================                             |  55%
      |
      |=====================================                            |  57%
      |
      |======================================                           |  58%
      |
      |=======================================                          |  60%
      |
      |========================================                         |  62%
      |
      |=========================================                        |  63%
      |
      |==========================================                       |  65%
      |
      |===========================================                      |  67%
      |
      |============================================                     |  68%
      |
      |==============================================                   |  70%
      |
      |===============================================                  |  72%
      |
      |================================================                 |  73%
      |
      |=================================================                |  75%
      |
      |==================================================               |  77%
      |
      |===================================================              |  78%
      |
      |====================================================             |  80%
      |
      |=====================================================            |  82%
      |
      |======================================================           |  83%
      |
      |=======================================================          |  85%
      |
      |========================================================         |  87%
      |
      |=========================================================        |  88%
      |
      |==========================================================       |  90%
      |
      |============================================================     |  92%
      |
      |=============================================================    |  93%
      |
      |==============================================================   |  95%
      |
      |===============================================================  |  97%
      |
      |================================================================ |  98%
      |
      |=================================================================| 100%
    #>
    #>
    #>
    #> Running try algorithm
    #> 66 --> M66   : ......
    #> 37 --> M37   : ......
    #> 10 --> M10   : ......
    #> 54 --> M54   : .......
    #> 25 --> M25   : ........
    #> 43 --> M43   : .........
    #> 91 --> SNP25 : ..........
    #> 32 --> M32   : ..........
    #>  5 --> M5    : ..........
    #> 51 --> M51   : ...........
    #> 45 --> M45   : ............
    #>  8 --> M8    : .............
    #> 11 --> M11   : ..............
    #>
    #> LOD threshold = 3
    #>
    #> Positioned markers: 2 10 41 43 45 54 61 25 5 51 33 90 8
    #>
    #> Markers not placed on the map: 11 32 37 66 91
    #>
    #>
    #> Calculating LOD-Scores
    #> 11 --> M11   : ..............
    #> 32 --> M32   : ..............
    #> 37 --> M37   : ..............
    #> 66 --> M66   : ..............
    #> 91 --> SNP25 : ..............
    #>
    #>
    #> Placing remaining marker(s) at most likely position
    #> 37 --> M37   : ..............
    #> 66 --> M66   : ...............
    #> 11 --> M11   : ................
    #> 91 --> SNP25 : .................
    #> 32 --> M32   : ..................
    #>
    #> Estimating final genetic map using tol = 10E-5.

The first argument is an object of class `sequence` (LG2_f2). `n.init = 5` means that five markers will be used in the `compare` step. The argument `subset.search = "twopt"` indicates that these five markers should be chosen by using a two point method, which will be Rapid Chain Delineation, as indicated by the argument `twopt.alg = "rcd"`. `THRES = 3` indicates that the `try_seq` step will only add markers to the sequence which can be mapped with LOD Score greater than 3.

Check the order obtained by this procedure:

    LG2_f2_ord
    #>
    #> Best sequence found.
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #>  2 M2                 0.00
    #> 10 M10                7.06
    #> 41 M41               14.96
    #> 43 M43               31.26
    #> 45 M45               38.96
    #> 54 M54               41.02
    #> 61 M61               49.73
    #> 25 M25               55.66
    #>  5 M5                59.81
    #> 51 M51               64.09
    #> 33 M33               70.24
    #> 90 SNP24             75.07
    #>  8 M8                92.65
    #>
    #>  13 markers            log-likelihood: -1005.635
    #>
    #>
    #>
    #> The following markers could not be uniquely positioned.
    #> Printing most likely positions for each unpositioned marker:
    #>
    #> ------------------------------------
    #> |    |  11 |  32 |  37 |  66 |  91 |
    #> |----|-----|-----|-----|-----|-----|
    #> |    |     |     |     |     |     |
    #> |  2 |     |     |     |     |     |
    #> |    | *   |     |     |     |     |
    #> | 10 |     |     |     |     |     |
    #> |    |     |     |     |     |     |
    #> | 41 |     |     |     |     |     |
    #> |    | *** | *   |     |     |     |
    #> | 43 |     |     |     |     |     |
    #> |    |     | *** |     |     |     |
    #> | 45 |     |     |     |     |     |
    #> |    |     | **  |     |     |     |
    #> | 54 |     |     |     |     |     |
    #> |    |     |     |     | *** |     |
    #> | 61 |     |     |     |     |     |
    #> |    |     |     |     |     |     |
    #> | 25 |     |     |     |     |     |
    #> |    |     |     |     |     |     |
    #> |  5 |     |     |     |     |     |
    #> |    |     |     |     |     |     |
    #> | 51 |     |     |     |     |     |
    #> |    |     |     |     |     | *** |
    #> | 33 |     |     |     |     |     |
    #> |    |     |     |     |     | *   |
    #> | 90 |     |     |     |     |     |
    #> |    |     |     | *** |     |     |
    #> |  8 |     |     |     |     |     |
    #> |    |     |     |     |     |     |
    #> ------------------------------------
    #>
    #> '***' indicates the most likely position(s) (LOD = 0.0)
    #>
    #> '**' indicates very likely positions (LOD > -1.0)
    #>
    #> '*' indicates likely positions (LOD > -2.0)

Note that markers `11`, `32`, `37`, `66` and `91` could not be safely mapped to a single position (`LOD Score > THRES` in absolute value). The output displays the `safe` order and the most likely positions for markers not mapped, where `***` indicates the most likely position, and `*` corresponds to other plausible positions. (If you are familiar with MAPMAKER/EXP, you will recognize the representation).

To get the `safe` order, use

    LG2_f2_safe <- make_seq(LG2_f2_ord, "safe")

and to get the order with all markers (i.e., including the ones not mapped to a single position), use:

    (LG2_f2_all <- make_seq(LG2_f2_ord, "force"))
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #>  2 M2                 0.00
    #> 10 M10                7.06
    #> 41 M41               14.75
    #> 11 M11               27.41
    #> 43 M43               32.04
    #> 32 M32               35.93
    #> 45 M45               41.52
    #> 54 M54               43.89
    #> 66 M66               50.91
    #> 61 M61               52.58
    #> 25 M25               58.29
    #>  5 M5                62.26
    #> 51 M51               66.71
    #> 91 SNP25             74.56
    #> 33 M33               75.93
    #> 90 SNP24             80.81
    #> 37 M37               89.22
    #>  8 M8                95.02
    #>
    #>  18 markers            log-likelihood: -1170.482

which places markers `11`, `32`, `37`, `66` and `91` into their most likely positions.

Although some old publications presented maps with only `safe` orders, we see no reason not to use option `force`, and recommend it for users.

The `order_seq` function can perform two rounds of the `try_seq` step, first using `THRES` and then `THRES - 1` as the threshold. This generally results in safe orders with more markers mapped, but takes longer to run. To do this, type:

    LG2_f2_ord <- order_seq(input.seq = LG2_f2, n.init = 5,
                            subset.search = "twopt",
                            twopt.alg = "rcd", THRES = 3,
                            touchdown = TRUE)
    #>
    #> Cross type:  f2
    #> Choosing initial subset using 'two-point' approach
    #>
    #> order obtained using RCD algorithm:
    #>
    #>  41 10 43 11 2 32 45 54 66 61 25 5 51 33 91 37 8 90
    #>
    #> calculating multipoint map using tol =  0.1 .
    #>
    #>
    #> Comparing 60 orders:
    #>
    #>
      |
      |                                                                 |   0%
      |
      |=                                                                |   2%
      |
      |==                                                               |   3%
      |
      |===                                                              |   5%
      |
      |====                                                             |   7%
      |
      |=====                                                            |   8%
      |
      |======                                                           |  10%
      |
      |========                                                         |  12%
      |
      |=========                                                        |  13%
      |
      |==========                                                       |  15%
      |
      |===========                                                      |  17%
      |
      |============                                                     |  18%
      |
      |=============                                                    |  20%
      |
      |==============                                                   |  22%
      |
      |===============                                                  |  23%
      |
      |================                                                 |  25%
      |
      |=================                                                |  27%
      |
      |==================                                               |  28%
      |
      |====================                                             |  30%
      |
      |=====================                                            |  32%
      |
      |======================                                           |  33%
      |
      |=======================                                          |  35%
      |
      |========================                                         |  37%
      |
      |=========================                                        |  38%
      |
      |==========================                                       |  40%
      |
      |===========================                                      |  42%
      |
      |============================                                     |  43%
      |
      |=============================                                    |  45%
      |
      |==============================                                   |  47%
      |
      |===============================                                  |  48%
      |
      |================================                                 |  50%
      |
      |==================================                               |  52%
      |
      |===================================                              |  53%
      |
      |====================================                             |  55%
      |
      |=====================================                            |  57%
      |
      |======================================                           |  58%
      |
      |=======================================                          |  60%
      |
      |========================================                         |  62%
      |
      |=========================================                        |  63%
      |
      |==========================================                       |  65%
      |
      |===========================================                      |  67%
      |
      |============================================                     |  68%
      |
      |==============================================                   |  70%
      |
      |===============================================                  |  72%
      |
      |================================================                 |  73%
      |
      |=================================================                |  75%
      |
      |==================================================               |  77%
      |
      |===================================================              |  78%
      |
      |====================================================             |  80%
      |
      |=====================================================            |  82%
      |
      |======================================================           |  83%
      |
      |=======================================================          |  85%
      |
      |========================================================         |  87%
      |
      |=========================================================        |  88%
      |
      |==========================================================       |  90%
      |
      |============================================================     |  92%
      |
      |=============================================================    |  93%
      |
      |==============================================================   |  95%
      |
      |===============================================================  |  97%
      |
      |================================================================ |  98%
      |
      |=================================================================| 100%
    #>
    #>
    #>
    #> Running try algorithm
    #> 66 --> M66   : ......
    #> 37 --> M37   : ......
    #> 10 --> M10   : ......
    #> 54 --> M54   : .......
    #> 25 --> M25   : ........
    #> 43 --> M43   : .........
    #> 91 --> SNP25 : ..........
    #> 32 --> M32   : ..........
    #>  5 --> M5    : ..........
    #> 51 --> M51   : ...........
    #> 45 --> M45   : ............
    #>  8 --> M8    : .............
    #> 11 --> M11   : ..............
    #>
    #> LOD threshold = 3
    #>
    #> Positioned markers: 2 10 41 43 45 54 61 25 5 51 33 90 8
    #>
    #> Markers not placed on the map: 11 32 37 66 91
    #>
    #>
    #>
    #> Trying to map remaining markers with LOD threshold  2
    #> 11 --> M11   : ..............
    #> 32 --> M32   : ..............
    #> 37 --> M37   : ..............
    #> 66 --> M66   : ...............
    #> 91 --> SNP25 : ................
    #>
    #> LOD threshold = 2
    #>
    #> Positioned markers: 2 10 41 43 45 54 66 61 25 5 51 33 90 37 8
    #>
    #> Markers not placed on the map: 11 32 91
    #>
    #>
    #> Calculating LOD-Scores
    #> 11 --> M11   : ................
    #> 32 --> M32   : ................
    #> 91 --> SNP25 : ................
    #>
    #>
    #> Placing remaining marker(s) at most likely position
    #> 11 --> M11   : ................
    #> 91 --> SNP25 : .................
    #> 32 --> M32   : ..................
    #>
    #> Estimating final genetic map using tol = 10E-5.

The output is too big to be included here, so please try it to see what happens. In short, for this particular sequence, the `touchdown` step could additionally map two of the five markers (`37` and `66`), but this depends on the dataset. Let us continue our analysis using the order with all markers as suggested by the function `order_seq`:

    (LG2_f2_final <- make_seq(LG2_f2_ord, "force"))
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #>  2 M2                 0.00
    #> 10 M10                7.06
    #> 41 M41               14.75
    #> 11 M11               27.41
    #> 43 M43               32.04
    #> 32 M32               35.93
    #> 45 M45               41.52
    #> 54 M54               43.89
    #> 66 M66               50.91
    #> 61 M61               52.58
    #> 25 M25               58.29
    #>  5 M5                62.26
    #> 51 M51               66.71
    #> 91 SNP25             74.56
    #> 33 M33               75.93
    #> 90 SNP24             80.81
    #> 37 M37               89.22
    #>  8 M8                95.02
    #>
    #>  18 markers            log-likelihood: -1170.482

Finally, to check for alternative orders, use the `ripple_seq` function:

    ripple_seq(LG2_f2_final, ws = 5, LOD = 3)

The second argument, `ws = 5`, means that subsets (windows) of five markers will be permutated sequentially (5! orders for each window), to search for other plausible orders. The `LOD` argument means that only orders with LOD Score smaller than 3 will be printed.

The output shows sequences of five numbers, because `ws = 5`. They can be followed by an `OK`, if there are no alternative orders with LOD Scores smaller than `LOD = 3` in absolute value, or by a list of alternative orders.

In this example, the first seven windows showed alternative orders with LOD smaller than `LOD = 3`. However, the best order was that obtained with the `order_seq` function (LOD = 0.00). If there were an alternative order more likely than the original, one should check the difference between them and, if necessary, change the order with (for example) functions `drop_marker` (see Section about using an arbitrary order) and `try_seq`, or simply by typing the new order. For that, use `LG2_f2_final$seq.num` to obtain the original order; then make the necessary changes (by copying and pasting) and use the function `map` to reestimate the genetic map for the new order.

The final estimated map can then be printed using

    LG2_f2_final
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #>  2 M2                 0.00
    #> 10 M10                7.06
    #> 41 M41               14.75
    #> 11 M11               27.41
    #> 43 M43               32.04
    #> 32 M32               35.93
    #> 45 M45               41.52
    #> 54 M54               43.89
    #> 66 M66               50.91
    #> 61 M61               52.58
    #> 25 M25               58.29
    #>  5 M5                62.26
    #> 51 M51               66.71
    #> 91 SNP25             74.56
    #> 33 M33               75.93
    #> 90 SNP24             80.81
    #> 37 M37               89.22
    #>  8 M8                95.02
    #>
    #>  18 markers            log-likelihood: -1170.482

This is based on multipoint estimation of recombination fractions, using hidden Markov models.

#### Linkage group 1

Let us analyze linkage group 1. Extract markers from object `LGs`:

    LG1_f2 <- make_seq(LGs_f2, 1)

Construct the linkage map, by automatic usage of the `try` algorithm:

    LG1_f2_ord <- order_seq(input.seq = LG1_f2, n.init = 5,
                            subset.search = "twopt",
                            twopt.alg = "rcd", THRES = 3,
                            touchdown = TRUE)

The second round of `try_seq` added markers `9`, `12`, `29`, `35`, `58`, `71` and `72` (try it; results not shown).

Get the order with all markers:

    (LG1_f2_final <- make_seq(LG1_f2_ord, "force"))
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 55 M55                0.00
    #> 27 M27                7.69
    #>  9 M9                10.16
    #>  3 M3                21.27
    #>  4 M4                23.59
    #> 42 M42               30.05
    #> 53 M53               31.58
    #> 46 M46               35.89
    #>  1 M1                44.68
    #> 69 SNP3              50.50
    #> 30 M30               53.66
    #> 70 SNP4              56.30
    #> 71 SNP5              69.40
    #>  7 M7                71.82
    #> 73 SNP7              73.59
    #> 72 SNP6              78.44
    #>  6 M6                87.45
    #> 13 M13               92.62
    #> 35 M35               97.08
    #> 58 M58              104.80
    #> 75 SNP9             115.63
    #> 74 SNP8             121.94
    #> 12 M12              123.60
    #> 76 SNP10            125.48
    #> 17 M17              131.02
    #> 31 M31              134.53
    #> 34 M34              143.64
    #> 63 M63              143.64
    #> 26 M26              151.82
    #> 40 M40              155.42
    #> 36 M36              163.42
    #> 67 SNP1             166.30
    #> 44 M44              168.84
    #> 68 SNP2             171.48
    #> 29 M29              180.72
    #> 60 M60              184.04
    #> 23 M23              192.44
    #>
    #>  37 markers            log-likelihood: -2307.371

Check the final map (results not shown):

    ripple_seq(LG1_f2_final, ws = 5)

No alternative order was found (please, try it).

Print it:

    LG1_f2_final
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 55 M55                0.00
    #> 27 M27                7.69
    #>  9 M9                10.16
    #>  3 M3                21.27
    #>  4 M4                23.59
    #> 42 M42               30.05
    #> 53 M53               31.58
    #> 46 M46               35.89
    #>  1 M1                44.68
    #> 69 SNP3              50.50
    #> 30 M30               53.66
    #> 70 SNP4              56.30
    #> 71 SNP5              69.40
    #>  7 M7                71.82
    #> 73 SNP7              73.59
    #> 72 SNP6              78.44
    #>  6 M6                87.45
    #> 13 M13               92.62
    #> 35 M35               97.08
    #> 58 M58              104.80
    #> 75 SNP9             115.63
    #> 74 SNP8             121.94
    #> 12 M12              123.60
    #> 76 SNP10            125.48
    #> 17 M17              131.02
    #> 31 M31              134.53
    #> 34 M34              143.64
    #> 63 M63              143.64
    #> 26 M26              151.82
    #> 40 M40              155.42
    #> 36 M36              163.42
    #> 67 SNP1             166.30
    #> 44 M44              168.84
    #> 68 SNP2             171.48
    #> 29 M29              180.72
    #> 60 M60              184.04
    #> 23 M23              192.44
    #>
    #>  37 markers            log-likelihood: -2307.371

This is the final version of the map for this linkage group.

#### Linkage group 3

Extract markers from object `LGs_f2`:

    LG3_f2 <- make_seq(LGs_f2, 3)

Construct the linkage map, by automatic usage of try algorithm.

    LG3_f2_ord <- order_seq(input.seq = LG3_f2, n.init = 5,
                            subset.search = "twopt",
                            twopt.alg = "rcd", THRES = 3,
                            touchdown = TRUE)

We can see that in the second round of `try_seq` markers `50`, `64`, `78` and `86` were added (please, try it). A careful examination of the graphics can be a good source of information about how markers where placed.

Now, get the order with all markers:

    (LG3_f2_final <- make_seq(LG3_f2_ord, "force"))
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 47 M47                0.00
    #> 19 M19                7.56
    #> 39 M39                8.94
    #> 38 M38               15.81
    #> 49 M49               23.71
    #> 59 M59               24.88
    #> 79 SNP13             35.91
    #> 28 M28               39.40
    #> 77 SNP11             41.34
    #> 81 SNP15             45.45
    #> 86 SNP20             55.98
    #> 84 SNP18             61.10
    #> 14 M14               62.67
    #> 83 SNP17             64.90
    #> 16 M16               70.87
    #> 80 SNP14             80.95
    #> 65 M65               86.12
    #> 78 SNP12             91.55
    #> 62 M62              101.24
    #> 15 M15              104.96
    #> 21 M21              108.67
    #> 24 M24              112.05
    #> 20 M20              118.55
    #> 64 M64              119.07
    #> 82 SNP16            128.75
    #> 85 SNP19            134.28
    #> 52 M52              136.53
    #> 48 M48              141.80
    #> 57 M57              147.83
    #> 22 M22              151.20
    #> 87 SNP21            158.16
    #> 89 SNP23            163.24
    #> 18 M18              164.72
    #> 88 SNP22            167.97
    #> 56 M56              179.82
    #> 50 M50              182.43
    #>
    #>  36 markers            log-likelihood: -2400.784

Check the final map (not shown):

    ripple_seq(LG3_f2_final, ws = 5)

No better alternative order was observed.

Print it:

    LG3_f2_final
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 47 M47                0.00
    #> 19 M19                7.56
    #> 39 M39                8.94
    #> 38 M38               15.81
    #> 49 M49               23.71
    #> 59 M59               24.88
    #> 79 SNP13             35.91
    #> 28 M28               39.40
    #> 77 SNP11             41.34
    #> 81 SNP15             45.45
    #> 86 SNP20             55.98
    #> 84 SNP18             61.10
    #> 14 M14               62.67
    #> 83 SNP17             64.90
    #> 16 M16               70.87
    #> 80 SNP14             80.95
    #> 65 M65               86.12
    #> 78 SNP12             91.55
    #> 62 M62              101.24
    #> 15 M15              104.96
    #> 21 M21              108.67
    #> 24 M24              112.05
    #> 20 M20              118.55
    #> 64 M64              119.07
    #> 82 SNP16            128.75
    #> 85 SNP19            134.28
    #> 52 M52              136.53
    #> 48 M48              141.80
    #> 57 M57              147.83
    #> 22 M22              151.20
    #> 87 SNP21            158.16
    #> 89 SNP23            163.24
    #> 18 M18              164.72
    #> 88 SNP22            167.97
    #> 56 M56              179.82
    #> 50 M50              182.43
    #>
    #>  36 markers            log-likelihood: -2400.784

# Plotting the recombination fraction matrix

It is possible to plot the recombination fraction matrix and LOD Scores based on a color scale using the function `rf_graph_table`. This matrix can be useful to make some diagnostics about the map.

Just as an example, let us place `M38` at the end of linkage group 3 (wrong position) to check how we can see that in the graphic. First, let us to remove it from the linkage group:

    temp_seq <- drop_marker(LG3_f2_final, 38)

Now, we will force it to be positioned at the end of the linkage group:

    (temp_seq <- add_marker(temp_seq, 38))
    #>
    #> Number of markers: 36
    #> Markers in the sequence:
    #> M47 M19 M39 M49 M59 SNP13 M28 SNP11 SNP15 SNP20 SNP18 M14 SNP17 M16 SNP14
    #> M65 SNP12 M62 M15 M21 M24 M20 M64 SNP16 SNP19 M52 M48 M57 M22 SNP21 SNP23
    #> M18 SNP22 M56 M50 M38
    #>
    #> Parameters not estimated.
    (LG3_f2_wrong <- map(temp_seq))
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 47 M47                0.00
    #> 19 M19                7.44
    #> 39 M39                9.14
    #> 49 M49               22.83
    #> 59 M59               25.17
    #> 79 SNP13             35.49
    #> 28 M28               39.01
    #> 77 SNP11             40.95
    #> 81 SNP15             45.06
    #> 86 SNP20             55.58
    #> 84 SNP18             60.69
    #> 14 M14               62.27
    #> 83 SNP17             64.49
    #> 16 M16               70.47
    #> 80 SNP14             80.54
    #> 65 M65               85.71
    #> 78 SNP12             91.14
    #> 62 M62              100.84
    #> 15 M15              104.55
    #> 21 M21              108.27
    #> 24 M24              111.65
    #> 20 M20              118.15
    #> 64 M64              118.66
    #> 82 SNP16            128.34
    #> 85 SNP19            133.87
    #> 52 M52              136.13
    #> 48 M48              141.39
    #> 57 M57              147.42
    #> 22 M22              150.80
    #> 87 SNP21            157.76
    #> 89 SNP23            162.83
    #> 18 M18              164.32
    #> 88 SNP22            167.56
    #> 56 M56              179.42
    #> 50 M50              181.94
    #> 38 M38              239.62
    #>
    #>  36 markers            log-likelihood: -2527.534

Examining the results, we can see there is a big gap at the end of linkage group 3 (between markers `M50` and `M38`, as expected.

Let us now plot the recombination fraction matrix:

    rf_graph_table(LG3_f2_wrong, inter = FALSE)

The recombination fractions are plotted below the diagonal and the LOD Scores are plotted above the diagonal. The color scale varies from red (small distances and big LODs) to dark blue.

You can also plot an interactive version of this graphic, changing option `inter` to `TRUE` (the default):

    rf_graph_table(LG3_f2_wrong)

An interactive version of the graphic will pop up (not shown here). Clicking on the cell corresponding to two markers, you can see some useful information about them. For example, clicking on the cell corresponding to markers `M47` and `M19` you can see their names, types (co-dominant and dominant), recombination fraction (`rf = 0.074`) and LOD Score (`LOD = 23`). Clicking on a cell on the diagonal, some information about the corresponding marker is shown, including percentage of missing data. We found this to be very useful when evaluating the results of the ordering algorithms.

We clearly see a different pattern for marker `M38`. The blue cell, corresponding to markers `M50` and `M38`, indicates a big recombination fraction between these markers as seen before (by clicking, `rf = 0.4049`). Moreover, we can see a group of red cells corresponding to marker `M38` and other markers as `M47`, `M19`, `M39` and `M49`. This pattern indicates small recombination fractions between marker `M38` and these other markers. Hence, `M38` is supposed to be close to them on the map.

Because we have enough evidence that marker `M38` is misplaced, let us drop this marker and try to map it using the function `try_seq`:

    temp_seq <- drop_marker(LG3_f2_wrong, 38)
    temp_map <- map(temp_seq)
    (temp_try <- try_seq(temp_map, 38))
    #> 38 --> M38   : ....................................
    #>
    #> LOD scores correspond to the best linkage phase combination
    #> for each position
    #>
    #> The symbol "*" outside the box indicates that more than one
    #> linkage phase is possible for the corresponding position
    #>
    #>
    #>        Marker tested: 38
    #>
    #>        Markers      LOD
    #>      ======================
    #>      |                    |
    #>      |            -27.70  |  1
    #>      |  47                |
    #>      |            -24.58  |  2
    #>      |  19                |
    #>      |             -9.72  |  3
    #>      |  39                |
    #>      |              0.00  |  4
    #>      |  49                |
    #>      |            -17.43  |  5
    #>      |  59                |
    #>      |            -27.50  |  6
    #>      |  79                |
    #>      |            -68.03  |  7
    #>      |  28                |
    #>      |            -72.63  |  8
    #>      |  77                |
    #>      |            -68.45  |  9
    #>      |  81                |
    #>      |            -53.97  |  10
    #>      |  86                |
    #>      |            -69.71  |  11
    #>      |  84                |
    #>      |            -82.70  |  12
    #>      |  14                |
    #>      |            -79.77  |  13
    #>      |  83                |
    #>      |            -69.78  |  14
    #>      |  16                |
    #>      |            -71.51  |  15
    #>      |  80                |
    #>      |            -92.91  |  16
    #>      |  65                |
    #>      |            -93.17  |  17
    #>      |  78                |
    #>      |            -80.94  |  18
    #>      |  62                |
    #>      |            -96.11  |  19
    #>      |  15                |
    #>      |            -97.12  |  20
    #>      |  21                |
    #>      |            -98.70  |  21
    #>      |  24                |
    #>      |            -94.17  |  22
    #>      |  20                |
    #>      |            -89.13  |  23
    #>      |  64                |
    #>      |            -87.60  |  24
    #>      |  82                |
    #>      |            -98.60  |  25
    #>      |  85                |
    #>      |           -110.51  |  26
    #>      |  52                |
    #>      |            -97.67  |  27
    #>      |  48                |
    #>      |           -100.08  |  28
    #>      |  57                |
    #>      |           -109.84  |  29
    #>      |  22                |
    #>      |            -95.03  |  30
    #>      |  87                |
    #>      |           -104.05  |  31
    #>      |  89                |
    #>      |           -120.57  |  32
    #>      |  18                |
    #>      |           -110.57  |  33
    #>      |  88                |
    #>      |            -84.52  |  34
    #>      |  56                |
    #>      |            -87.05  |  35
    #>      |  50                |
    #>      |            -71.32  |  36
    #>      |                    |
    #>      ======================

We can see that the most likely position for marker `M38` is between markers `M39` and `M49` (position 4). The patterns on the color matrix are now better. Therefore, you should do

    (LG3_f2_final <- make_seq(temp_try, 4))
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 47 M47                0.00
    #> 19 M19                7.73
    #> 39 M39                7.98
    #> 38 M38               15.25
    #> 49 M49               23.40
    #> 59 M59               23.59
    #> 79 SNP13             35.25
    #> 28 M28               38.84
    #> 77 SNP11             40.76
    #> 81 SNP15             44.87
    #> 86 SNP20             55.63
    #> 84 SNP18             61.02
    #> 14 M14               62.77
    #> 83 SNP17             65.38
    #> 16 M16               71.87
    #> 80 SNP14             82.29
    #> 65 M65               87.62
    #> 78 SNP12             93.25
    #> 62 M62              103.57
    #> 15 M15              107.44
    #> 21 M21              111.33
    #> 24 M24              114.57
    #> 20 M20              121.30
    #> 64 M64              121.47
    #> 82 SNP16            131.43
    #> 85 SNP19            137.55
    #> 52 M52              140.24
    #> 48 M48              145.48
    #> 57 M57              151.43
    #> 22 M22              154.83
    #> 87 SNP21            161.82
    #> 89 SNP23            166.93
    #> 18 M18              168.41
    #> 88 SNP22            171.68
    #> 56 M56              183.61
    #> 50 M50              186.22
    #>
    #>  36 markers            log-likelihood: -2401.428

We can also check the heatmap matrix for the other groups ordered. This is a good map diagnostic and can be used during the map building procedure:

    rf_graph_table(LG1_f2_final)

    rf_graph_table(LG2_f2_final)

## Using the recombinations and the reference genome informations

In our example, we have reference genome chromosome and position informations for some of the markers, here we will examplify one method of using this informations to help build the genetic map.

With the `CHROM` informations in the input file, you can identify markers belonging to some chromosome using the function `make_seq` with the `rf_2pts` object. For example, assign the string `"1"` for the second argument to get chromosome 1 makers. The output sequence will be automatically ordered by `POS` informations.

    CHR1 <- make_seq(twopts_f2, "1")
    CHR1
    #>
    #> Number of markers: 10
    #> Markers in the sequence:
    #> SNP1 SNP2 SNP3 SNP4 SNP5 SNP6 SNP7 SNP8 SNP9 SNP10
    #>
    #> Parameters not estimated.
    CHR2 <- make_seq(twopts_f2, "2")
    CHR3 <- make_seq(twopts_f2, "3")

### Adding markers with no reference genome informations

According to `CHROM` informations we have three defined linkage groups, now we can try to group the markers without chromossome informations to them using recombination informations. For this, we can use the function `group_seq`:

    CHR_mks <- group_seq(input.2pts = twopts_f2, seqs = "CHROM", unlink.mks = mark_all_f2,
                          rm.repeated = TRUE)
    #>    Selecting markers:
    #>    group    1
    #>     .....................................
    #>    group    2
    #>     ................
    #>    group    3
    #>     .......................
    #>    Selecting markers:
    #>    group    1
    #>     ....................................
    #>    group    2
    #>     ...........................
    #>    group    3
    #>     ................
    #>    Selecting markers:
    #>    group    1
    #>     ..................
    #>    group    2
    #>     ...........................
    #>    group    3
    #>     .......................

The function works as the function `group`, but considering preexisting sequences. Setting `seqs` argument with the string `"CHROM"`, it will considered the preexisting sequences according to `CHROM` information. You can also indicate others preexisting sequences if it make sense for your study. For that, you should inform a list with objects of class `sequences`, as the example:

    CHR_mks <- group_seq(input.2pts = twopts_f2, seqs = list(CHR1=CHR1, CHR2=CHR2, CHR3=CHR3),
                          unlink.mks = mark_all_f2, rm.repeated = TRUE)

In this case, the command had the same effect of the previous, because we indicate chromossome sequences, but others sequences can be used.

The `unlink.mks` argument receive a object of class `sequence`, this define which markers will be tested to group with the sequences in `seqs`. In our example, we will indicate only the markers with no segregation distortion, using the sequence `mark_no_dist`. It is also possible to use the string `"all"` to test all the remining markers at the `rf_2pts` object.

In some cases, the same marker can group to more than one sequence, those markers will be considered `repeated`. We can choose if we want to remove or not (`TRUE/FALSE`) them of the output sequences, with the argument `rm.repeated`. Anyway, their numbers will be informed at the list `repeateds` in the output object. In the example case, there are no repeated markers. However, if they exists, it could indicate that their groups actually constitute the same group. Also, genotyping erros can generate repeated markers. Anyway, they deserves better investigations.

We can access detailed information about the results just printing:

    CHR_mks
    #>   This is an object of class 'group_seq'
    #>   It was generated from the object "comb_example"
    #>
    #>   Criteria used to assign markers to groups:
    #>     LOD = 3 , Maximum recombination fraction = 0.5
    #>
    #>   No. markers in input sequences:
    #>                        CHR1 :   10 markers
    #>                        CHR2 :   13 markers
    #>                        CHR3 :   2 markers
    #>
    #>   No. unlinked input markers:   66 markers
    #>
    #>   No. markers in output sequences:
    #>                        CHR1 :   37 markers
    #>                        CHR2 :   36 markers
    #>                        CHR3 :   18 markers
    #>   No. unlinked:                 0 markers
    #>   No. repeated:                 0 markers
    #>
    #>   Printing output sequences:
    #>   Group CHR1 : 37 markers
    #>
    #>
    #>   Group CHR2 : 36 markers
    #>
    #>
    #>   Group CHR3 : 18 markers
    #>
    #>
    #>   Unlinked markers: 0 markers
    #>
    #>
    #>   Repeated markers: 0  markers
    #>

Also, we can access the numbers of repeated markers with:

    CHR_mks$repeated
    #> [1] NA

The same way, we can access the output sequences:

    CHR_mks$sequences$CHR1
    #>
    #> Number of markers: 37
    #> Markers in the sequence:
    #> SNP1 SNP2 SNP3 SNP4 SNP5 SNP6 SNP7 SNP8 SNP9 SNP10 M1 M3 M4 M6 M7 M9 M12
    #> M13 M17 M23 M26 M27 M29 M30 M31 M34 M35 M36 M40 M42 M44 M46 M53 M55 M58
    #> M60 M63
    #>
    #> Parameters not estimated.
    # or
    CHR_mks$sequences[[1]]
    #>
    #> Number of markers: 37
    #> Markers in the sequence:
    #> SNP1 SNP2 SNP3 SNP4 SNP5 SNP6 SNP7 SNP8 SNP9 SNP10 M1 M3 M4 M6 M7 M9 M12
    #> M13 M17 M23 M26 M27 M29 M30 M31 M34 M35 M36 M40 M42 M44 M46 M53 M55 M58
    #> M60 M63
    #>
    #> Parameters not estimated.

For this function, optional arguments are `LOD` and `max.rf`, which define thresholds to be used when assigning markers to linkage groups. If none provided (default), criteria previously defined for the object `rf_2pts` are used.

Now we can order the markers in each group as we made before (Ordering markers within linkage groups). As showed, we can choose different approaches to order the markers.

To order those groups, first we will use `order_seq` function to access a preliminary order and after, we will edit some markers position or remove some of them according with they color pattern in `rf_graph_table` graphic, and other parameters as likelihood and map size.

#### Linkage group 1

    CHR1_ord <- order_seq(CHR_mks$sequences$CHR1)
    CHR1_frame <- make_seq(CHR1_ord, "force")

    rf_graph_table(CHR1_frame) # graphic not showed

The group is similar to that builded before with only recombinations informations. We will better explore differences in a latter step. Only marker `58` do not follow exactly the expected color pattern, then we will try to repositioned it.

    CHR1_test_seq <- drop_marker(CHR1_frame, 58)
    CHR1_test_map <- map(CHR1_test_seq)
    CHR1_add58_seq <- try_seq(CHR1_test_map, 58)
    #> 58 --> M58   : .....................................
    CHR1_add58 <- make_seq(CHR1_add58_seq, 20) # marker 58 was placed at the same position as before

Comparing with and without marker 58:

    CHR1_test_map
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 23 M23                0.00
    #> 55 M55               48.14
    #> 27 M27               55.87
    #>  9 M9                58.35
    #>  3 M3                69.44
    #>  4 M4                71.76
    #> 42 M42               78.21
    #> 53 M53               79.74
    #> 46 M46               84.06
    #>  1 M1                92.84
    #> 69 SNP3              98.66
    #> 30 M30              101.83
    #> 70 SNP4             104.47
    #> 71 SNP5             117.58
    #>  7 M7               119.99
    #> 73 SNP7             121.76
    #> 72 SNP6             126.58
    #>  6 M6               135.20
    #> 13 M13              140.19
    #> 35 M35              147.46
    #> 75 SNP9             162.25
    #> 74 SNP8             168.71
    #> 12 M12              170.42
    #> 76 SNP10            172.32
    #> 17 M17              177.96
    #> 31 M31              181.47
    #> 34 M34              190.58
    #> 63 M63              190.58
    #> 26 M26              198.75
    #> 40 M40              202.36
    #> 36 M36              210.30
    #> 67 SNP1             213.20
    #> 44 M44              215.75
    #> 68 SNP2             218.41
    #> 29 M29              227.63
    #> 60 M60              230.93
    #>
    #>  36 markers            log-likelihood: -2313.984

    rf_graph_table(CHR1_test_map) # graphic not showed

    CHR1_add58
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 23 M23                0.00
    #> 55 M55               46.18
    #> 27 M27               53.75
    #>  9 M9                56.21
    #>  3 M3                67.51
    #>  4 M4                67.77
    #> 42 M42               75.68
    #> 53 M53               75.91
    #> 46 M46               80.67
    #>  1 M1                89.39
    #> 69 SNP3              95.50
    #> 30 M30               98.92
    #> 70 SNP4             101.62
    #> 71 SNP5             114.95
    #>  7 M7               117.43
    #> 73 SNP7             120.19
    #> 72 SNP6             126.09
    #>  6 M6               135.90
    #> 13 M13              141.86
    #> 58 M58              142.15
    #> 35 M35              149.78
    #> 75 SNP9             162.34
    #> 74 SNP8             169.30
    #> 12 M12              171.40
    #> 76 SNP10            173.28
    #> 17 M17              178.98
    #> 31 M31              182.74
    #> 34 M34              191.93
    #> 63 M63              191.94
    #> 26 M26              200.12
    #> 40 M40              203.75
    #> 36 M36              211.78
    #> 67 SNP1             214.54
    #> 44 M44              217.15
    #> 68 SNP2             219.83
    #> 29 M29              228.90
    #> 60 M60              231.97
    #>
    #>  37 markers            log-likelihood: -2357.171

    rf_graph_table(CHR1_add58)

Based in those results, we decide to keep marker 58 in our map.

    CHR1_final <- CHR1_add58

Checking for better orders:

    ripple_seq(CHR1_final)
    #> 23-55-27-9-|-3-...
    #>   Alternative orders:
    #>    23 55 27 9 ... :    0.00
    #>    23 55 9 27 ... :   -2.81
    #>
    #> ...-23-|-55-27-9-3-|-4-...
    #>   Alternative orders:
    #>    55 27 9 3 ... :    0.00
    #>    55 9 27 3 ... :   -2.81
    #>
    #> ...-55-|-27-9-3-4-|-42-...
    #>   Alternative orders:
    #>   ... 27 9 3 4 ... :    0.00
    #>   ... 9 27 3 4 ... :   -2.81
    #>
    #> ...-27-|-9-3-4-42-|-53-... OK
    #>
    #> ...-9-|-3-4-42-53-|-46-...
    #>   Alternative orders:
    #>   ... 3 4 42 53 ... :    0.00
    #>   ... 3 4 53 42 ... :   -1.63
    #>   ... 3 53 4 42 ... :   -1.86
    #>
    #> ...-3-|-4-42-53-46-|-1-...
    #>   Alternative orders:
    #>   ... 4 42 53 46 ... :    0.00
    #>   ... 4 53 42 46 ... :   -1.63
    #>   ... 53 4 42 46 ... :   -1.86
    #>
    #> ...-4-|-42-53-46-1-|-69-...
    #>   Alternative orders:
    #>   ... 42 53 46 1 ... :    0.00
    #>   ... 53 42 46 1 ... :   -1.63
    #>
    #> ...-42-|-53-46-1-69-|-30-... OK
    #>
    #> ...-53-|-46-1-69-30-|-70-... OK
    #>
    #> ...-46-|-1-69-30-70-|-71-... OK
    #>
    #> ...-1-|-69-30-70-71-|-7-... OK
    #>
    #> ...-69-|-30-70-71-7-|-73-... OK
    #>
    #> ...-30-|-70-71-7-73-|-72-...
    #>   Alternative orders:
    #>   ... 70 71 7 73 ... :    0.00
    #>   ... 70 73 7 71 ... :   -1.09
    #>   ... 70 73 71 7 ... :   -1.38
    #>
    #> ...-70-|-71-7-73-72-|-6-...
    #>   Alternative orders:
    #>   ... 71 7 73 72 ... :    0.00
    #>   ... 72 73 7 71 ... :   -0.26
    #>   ... 73 7 71 72 ... :   -1.09
    #>   ... 73 71 7 72 ... :   -1.38
    #>   ... 73 72 7 71 ... :   -2.29
    #>
    #> ...-71-|-7-73-72-6-|-13-... OK
    #>
    #> ...-7-|-73-72-6-13-|-58-... OK
    #>
    #> ...-73-|-72-6-13-58-|-35-... OK
    #>
    #> ...-72-|-6-13-58-35-|-75-...
    #>   Alternative orders:
    #>   ... 6 13 35 58 ... :    0.00
    #>   ... 35 6 13 58 ... :   -2.58
    #>   ... 6 35 13 58 ... :   -2.73
    #>
    #> ...-6-|-13-58-35-75-|-74-...
    #>   Alternative orders:
    #>   ... 13 35 58 75 ... :    0.00
    #>   ... 35 13 58 75 ... :   -2.73
    #>
    #> ...-13-|-58-35-75-74-|-12-... OK
    #>
    #> ...-58-|-35-75-74-12-|-76-...
    #>   Alternative orders:
    #>   ... 35 75 74 12 ... :    0.00
    #>   ... 35 75 12 74 ... :   -1.75
    #>
    #> ...-35-|-75-74-12-76-|-17-...
    #>   Alternative orders:
    #>   ... 75 74 12 76 ... :    0.00
    #>   ... 75 12 74 76 ... :   -1.75
    #>   ... 75 76 12 74 ... :   -2.20
    #>
    #> ...-75-|-74-12-76-17-|-31-...
    #>   Alternative orders:
    #>   ... 74 12 76 17 ... :    0.00
    #>   ... 12 74 76 17 ... :   -1.75
    #>   ... 76 12 74 17 ... :   -2.20
    #>
    #> ...-74-|-12-76-17-31-|-34-... OK
    #>
    #> ...-12-|-76-17-31-34-|-63-... OK
    #>
    #> ...-76-|-17-31-34-63-|-26-...
    #>   Alternative orders:
    #>   ... 17 31 34 63 ... :    0.00
    #>   ... 17 31 63 34 ... :   -0.01
    #>
    #> ...-17-|-31-34-63-26-|-40-...
    #>   Alternative orders:
    #>   ... 31 34 63 26 ... :    0.00
    #>   ... 31 63 34 26 ... :   -0.01
    #>
    #> ...-31-|-34-63-26-40-|-36-...
    #>   Alternative orders:
    #>   ... 34 63 26 40 ... :    0.00
    #>   ... 63 34 26 40 ... :   -0.01
    #>
    #> ...-34-|-63-26-40-36-|-67-... OK
    #>
    #> ...-63-|-26-40-36-67-|-44-... OK
    #>
    #> ...-26-|-40-36-67-44-|-68-... OK
    #>
    #> ...-40-|-36-67-44-68-|-29-...
    #>   Alternative orders:
    #>   ... 36 68 44 67 ... :    0.00
    #>   ... 36 67 44 68 ... :   -0.23
    #>
    #> ...-36-|-67-44-68-29-|-60-...
    #>   Alternative orders:
    #>   ... 68 44 67 29 :    0.00
    #>   ... 67 44 68 29 :   -0.23
    #>
    #> 67-|-44-68-29-60 OK

#### Linkage group 2

    CHR2_ord <- order_seq(CHR_mks$sequences$CHR2)
    CHR2_frame <- make_seq(CHR2_ord, "force")

    rf_graph_table(CHR2_frame) # graphic not showed

The marker `20` presented a color pattern different of expected.

    CHR2_test_seq <- drop_marker(CHR2_frame, 20)
    CHR2_test_map <- map(CHR2_test_seq)
    CHR2_add20_seq <- try_seq(CHR2_test_map, 20)
    #> 20 --> M20   : ....................................
    CHR2_add20 <- make_seq(CHR2_add20_seq, 20) # marker 20 was placed at the same position as before

Comparing with and without marker 58:

    CHR2_test_map
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 47 M47                0.00
    #> 19 M19                7.56
    #> 39 M39                8.94
    #> 38 M38               15.81
    #> 49 M49               23.70
    #> 59 M59               24.88
    #> 79 SNP13             35.91
    #> 28 M28               39.40
    #> 77 SNP11             41.34
    #> 81 SNP15             45.45
    #> 86 SNP20             55.98
    #> 84 SNP18             61.10
    #> 14 M14               62.67
    #> 83 SNP17             64.90
    #> 16 M16               70.87
    #> 80 SNP14             80.95
    #> 65 M65               86.12
    #> 78 SNP12             91.55
    #> 62 M62              101.25
    #> 15 M15              104.96
    #> 21 M21              108.67
    #> 24 M24              112.12
    #> 64 M64              118.31
    #> 82 SNP16            127.51
    #> 85 SNP19            133.23
    #> 52 M52              135.56
    #> 48 M48              140.97
    #> 57 M57              146.98
    #> 22 M22              150.36
    #> 87 SNP21            157.20
    #> 18 M18              160.62
    #> 89 SNP23            162.17
    #> 88 SNP22            167.09
    #> 56 M56              178.98
    #> 50 M50              181.59
    #>
    #>  35 markers            log-likelihood: -2369.779

    rf_graph_table(CHR1_test_map)

    CHR2_add20
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 47 M47                0.00
    #> 19 M19                7.73
    #> 39 M39                7.98
    #> 38 M38               15.25
    #> 49 M49               23.40
    #> 59 M59               23.59
    #> 79 SNP13             35.25
    #> 28 M28               38.84
    #> 77 SNP11             40.76
    #> 81 SNP15             44.87
    #> 86 SNP20             55.63
    #> 84 SNP18             61.02
    #> 14 M14               62.77
    #> 83 SNP17             65.38
    #> 16 M16               71.88
    #> 80 SNP14             82.35
    #> 65 M65               87.70
    #> 78 SNP12             93.38
    #> 62 M62              104.30
    #> 20 M20              117.45
    #> 15 M15              130.08
    #> 21 M21              133.59
    #> 24 M24              138.74
    #> 64 M64              139.02
    #> 82 SNP16            150.70
    #> 85 SNP19            156.94
    #> 52 M52              159.69
    #> 48 M48              165.01
    #> 57 M57              170.97
    #> 22 M22              174.37
    #> 87 SNP21            181.28
    #> 18 M18              184.76
    #> 89 SNP23            186.30
    #> 88 SNP22            191.21
    #> 56 M56              203.16
    #> 50 M50              205.77
    #>
    #>  36 markers            log-likelihood: -2476.901

    rf_graph_table(CHR2_add20)  # graphic not showed

Based in those results, we decide to not include marker 20 in our map.

    CHR2_final <- CHR2_test_map

Checking for better orders:

    ripple_seq(CHR2_final)
    #> 47-19-39-38-|-49-...
    #>   Alternative orders:
    #>    47 19 39 38 ... :    0.00
    #>    47 39 19 38 ... :   -0.05
    #>
    #> ...-47-|-19-39-38-49-|-59-...
    #>   Alternative orders:
    #>    19 39 38 49 ... :    0.00
    #>    39 19 38 49 ... :   -0.05
    #>
    #> ...-19-|-39-38-49-59-|-79-...
    #>   Alternative orders:
    #>   ... 39 38 49 59 ... :    0.00
    #>   ... 39 38 59 49 ... :   -0.09
    #>
    #> ...-39-|-38-49-59-79-|-28-...
    #>   Alternative orders:
    #>   ... 38 49 59 79 ... :    0.00
    #>   ... 38 59 49 79 ... :   -0.09
    #>
    #> ...-38-|-49-59-79-28-|-77-...
    #>   Alternative orders:
    #>   ... 49 59 79 28 ... :    0.00
    #>   ... 59 49 79 28 ... :   -0.09
    #>
    #> ...-49-|-59-79-28-77-|-81-... OK
    #>
    #> ...-59-|-79-28-77-81-|-86-...
    #>   Alternative orders:
    #>   ... 81 77 28 79 ... :    0.00
    #>   ... 77 81 28 79 ... :   -1.26
    #>
    #> ...-79-|-28-77-81-86-|-84-...
    #>   Alternative orders:
    #>   ... 28 77 81 86 ... :    0.00
    #>   ... 28 81 77 86 ... :   -2.46
    #>
    #> ...-28-|-77-81-86-84-|-14-...
    #>   Alternative orders:
    #>   ... 77 81 86 84 ... :    0.00
    #>   ... 81 77 86 84 ... :   -2.46
    #>
    #> ...-77-|-81-86-84-14-|-83-...
    #>   Alternative orders:
    #>   ... 81 86 84 14 ... :    0.00
    #>   ... 81 84 14 86 ... :   -2.53
    #>
    #> ...-81-|-86-84-14-83-|-16-...
    #>   Alternative orders:
    #>   ... 86 84 14 83 ... :    0.00
    #>   ... 86 83 14 84 ... :   -1.63
    #>   ... 84 14 86 83 ... :   -2.53
    #>
    #> ...-86-|-84-14-83-16-|-80-...
    #>   Alternative orders:
    #>   ... 84 14 83 16 ... :    0.00
    #>   ... 83 14 84 16 ... :   -1.63
    #>
    #> ...-84-|-14-83-16-80-|-65-... OK
    #>
    #> ...-14-|-83-16-80-65-|-78-...
    #>   Alternative orders:
    #>   ... 83 16 80 65 ... :    0.00
    #>   ... 83 16 65 80 ... :   -2.19
    #>
    #> ...-83-|-16-80-65-78-|-62-...
    #>   Alternative orders:
    #>   ... 16 80 65 78 ... :    0.00
    #>   ... 16 65 80 78 ... :   -2.19
    #>   ... 16 65 78 80 ... :   -2.34
    #>   ... 16 80 78 65 ... :   -2.50
    #>   ... 16 78 65 80 ... :   -2.96
    #>
    #> ...-16-|-80-65-78-62-|-15-...
    #>   Alternative orders:
    #>   ... 80 65 78 62 ... :    0.00
    #>   ... 65 80 78 62 ... :   -2.19
    #>   ... 65 78 80 62 ... :   -2.34
    #>   ... 80 78 65 62 ... :   -2.50
    #>   ... 78 65 80 62 ... :   -2.96
    #>
    #> ...-80-|-65-78-62-15-|-21-...
    #>   Alternative orders:
    #>   ... 65 78 62 15 ... :    0.00
    #>   ... 78 65 62 15 ... :   -2.50
    #>
    #> ...-65-|-78-62-15-21-|-24-... OK
    #>
    #> ...-78-|-62-15-21-24-|-64-... OK
    #>
    #> ...-62-|-15-21-24-64-|-82-...
    #>   Alternative orders:
    #>   ... 15 21 24 64 ... :    0.00
    #>   ... 15 21 64 24 ... :   -0.38
    #>
    #> ...-15-|-21-24-64-82-|-85-...
    #>   Alternative orders:
    #>   ... 21 24 64 82 ... :    0.00
    #>   ... 21 64 24 82 ... :   -0.38
    #>
    #> ...-21-|-24-64-82-85-|-52-...
    #>   Alternative orders:
    #>   ... 24 64 82 85 ... :    0.00
    #>   ... 64 24 82 85 ... :   -0.38
    #>
    #> ...-24-|-64-82-85-52-|-48-...
    #>   Alternative orders:
    #>   ... 64 82 85 52 ... :    0.00
    #>   ... 64 52 85 82 ... :   -1.54
    #>
    #> ...-64-|-82-85-52-48-|-57-...
    #>   Alternative orders:
    #>   ... 82 85 52 48 ... :    0.00
    #>   ... 52 85 82 48 ... :   -1.54
    #>
    #> ...-82-|-85-52-48-57-|-22-... OK
    #>
    #> ...-85-|-52-48-57-22-|-87-... OK
    #>
    #> ...-52-|-48-57-22-87-|-18-... OK
    #>
    #> ...-48-|-57-22-87-18-|-89-... OK
    #>
    #> ...-57-|-22-87-18-89-|-88-...
    #>   Alternative orders:
    #>   ... 22 87 18 89 ... :    0.00
    #>   ... 22 87 89 18 ... :    0.00
    #>   ... 22 89 18 87 ... :   -0.02
    #>   ... 22 18 89 87 ... :   -0.78
    #>
    #> ...-22-|-87-18-89-88-|-56-...
    #>   Alternative orders:
    #>   ... 87 18 89 88 ... :    0.00
    #>   ... 87 89 18 88 ... :    0.00
    #>   ... 89 18 87 88 ... :   -0.02
    #>   ... 87 88 18 89 ... :   -0.61
    #>   ... 89 18 88 87 ... :   -0.69
    #>   ... 18 89 87 88 ... :   -0.78
    #>   ... 18 89 88 87 ... :   -1.76
    #>
    #> ...-87-|-18-89-88-56-|-50-...
    #>   Alternative orders:
    #>   ... 18 89 88 56 :    0.00
    #>   ... 89 18 88 56 :    0.00
    #>   ... 88 18 89 56 :   -0.61
    #>
    #> 18-|-89-88-56-50
    #>   Alternative orders:
    #>    89 88 56 50 ... :    0.00
    #>    89 88 50 56 ... :   -2.27

#### Linkage group 3

    CHR3_ord <- order_seq(CHR_mks$sequences$CHR3)
    CHR3_frame <- make_seq(CHR3_ord, "force")

    rf_graph_table(CHR3_frame) # graphic not showed

Here, marker `32` have color pattern too different of the expected, removing it could influentiate in other markers ordering. Then, we will remove it and search for a new order.

    CHR3_test_seq <- drop_marker(CHR3_frame, 32)
    CHR3_test_ord <- order_seq(CHR3_test_seq)
    CHR3_test_map <- make_seq(CHR3_test_ord, "force")

The order did not change.

Trying to add the marker again.

    CHR3_add32_seq <- try_seq(CHR3_test_map, 32)
    CHR3_add32 <- make_seq(CHR3_add32_seq, 13) # Marker 32 keeped in the map

    CHR3_final <- CHR3_add32
    rf_graph_table(CHR3_final, inter = FALSE)

Checking for better orders:

    ripple_seq(CHR3_final)
    #> 8-37-91-33-|-90-...
    #>   Alternative orders:
    #>    8 37 91 33 ... :    0.00
    #>    8 37 33 91 ... :   -0.79
    #>
    #> ...-8-|-37-91-33-90-|-51-...
    #>   Alternative orders:
    #>    37 90 33 91 ... :    0.00
    #>    37 91 33 90 ... :   -0.84
    #>    37 90 91 33 ... :   -1.04
    #>    37 33 91 90 ... :   -1.62
    #>
    #> ...-37-|-91-33-90-51-|-5-...
    #>   Alternative orders:
    #>   ... 90 33 91 51 ... :    0.00
    #>   ... 91 33 90 51 ... :   -0.84
    #>   ... 90 91 33 51 ... :   -1.04
    #>   ... 33 91 90 51 ... :   -1.62
    #>
    #> ...-91-|-33-90-51-5-|-25-... OK
    #>
    #> ...-33-|-90-51-5-25-|-61-... OK
    #>
    #> ...-90-|-51-5-25-61-|-66-... OK
    #>
    #> ...-51-|-5-25-61-66-|-54-... OK
    #>
    #> ...-5-|-25-61-66-54-|-45-... OK
    #>
    #> ...-25-|-61-66-54-45-|-32-...
    #>   Alternative orders:
    #>   ... 61 66 54 45 ... :    0.00
    #>   ... 61 66 45 54 ... :   -2.68
    #>
    #> ...-61-|-66-54-45-32-|-43-...
    #>   Alternative orders:
    #>   ... 66 54 45 32 ... :    0.00
    #>   ... 66 54 32 45 ... :   -0.34
    #>   ... 66 45 54 32 ... :   -2.68
    #>
    #> ...-66-|-54-45-32-43-|-11-...
    #>   Alternative orders:
    #>   ... 54 45 32 43 ... :    0.00
    #>   ... 54 32 45 43 ... :   -0.34
    #>   ... 54 45 43 32 ... :   -1.94
    #>   ... 45 54 32 43 ... :   -2.68
    #>
    #> ...-54-|-45-32-43-11-|-2-...
    #>   Alternative orders:
    #>   ... 45 32 43 11 ... :    0.00
    #>   ... 32 45 43 11 ... :   -0.34
    #>   ... 45 43 32 11 ... :   -1.94
    #>   ... 45 43 11 32 ... :   -2.68
    #>
    #> ...-45-|-32-43-11-2-|-10-...
    #>   Alternative orders:
    #>   ... 32 43 11 2 ... :    0.00
    #>   ... 32 43 2 11 ... :   -0.73
    #>   ... 43 32 11 2 ... :   -1.94
    #>   ... 43 11 32 2 ... :   -2.68
    #>   ... 43 11 2 32 ... :   -2.75
    #>   ... 43 32 2 11 ... :   -2.78
    #>
    #> ...-32-|-43-11-2-10-|-41-...
    #>   Alternative orders:
    #>   ... 43 11 2 10 :    0.00
    #>   ... 43 2 11 10 :   -0.73
    #>
    #> 43-|-11-2-10-41
    #>   Alternative orders:
    #>    11 2 10 41 ... :    0.00
    #>    2 11 10 41 ... :   -0.73

# Map estimation for an arbitrary order

If you have some information about the order of the markers, for example, from a reference genome or previously published paper, you can define a sequence of those markers in a specific order (using the function `make_seq`) and then use the function `map` to estimate the final genetic map (based on multipoint analysis). For example, let us assume that we know that the following markers are ordered in this sequence: `M47`, `M38`, `M59`, `M16`, `M62`, `M21`, `M20`, `M48` and `M22`. In this case, select them from the two point analysis, and use function `map`:

    LG3seq_f2 <- make_seq(twopts_f2, c(47, 38, 59, 16, 62, 21, 20, 48, 22))
    (LG3seq_f2_map <- map(LG3seq_f2))
    #>
    #> Printing map:
    #>
    #> Markers           Position
    #>
    #> 47 M47                0.00
    #> 38 M38               14.49
    #> 59 M59               23.99
    #> 16 M16               40.13
    #> 62 M62               50.60
    #> 21 M21               57.84
    #> 20 M20               67.16
    #> 48 M48               75.76
    #> 22 M22               84.62
    #>
    #>  9 markers            log-likelihood: -947.1229

To see the correspondence between marker names and numbers, use function `marker_type`:

    marker_type(LG3seq_f2_map)
    #>   Marker 47 ( M47 ) --> AA : AB : BB (1:2:1)
    #>   Marker 38 ( M38 ) --> AA : AB : BB (1:2:1)
    #>   Marker 59 ( M59 ) --> Not  AA : AA (3:1)
    #>   Marker 16 ( M16 ) --> AA : AB : BB (1:2:1)
    #>   Marker 62 ( M62 ) --> AA : AB : BB (1:2:1)
    #>   Marker 21 ( M21 ) --> AA : AB : BB (1:2:1)
    #>   Marker 20 ( M20 ) --> Not  BB : BB (3:1)
    #>   Marker 48 ( M48 ) --> AA : AB : BB (1:2:1)
    #>   Marker 22 ( M22 ) --> AA : AB : BB (1:2:1)

If one needs to add or drop markers from a predefined sequence, functions `add_marker` and `drop_marker` can be used. For example, to add markers `M18`, `M56` and `M50` at the end of `LG3seq_f2_map`:

    (LG3seq_f2_map <- add_marker(LG3seq_f2_map, c(18, 56, 50)))
    #>
    #> Number of markers: 12
    #> Markers in the sequence:
    #> M47 M38 M59 M16 M62 M21 M20 M48 M22 M18 M56 M50
    #>
    #> Parameters not estimated.

Removing markers `M59` and `21` from `LG3seq_f2_map`:

    (LG3seq_f2_map <- drop_marker(LG3seq_f2_map, c(59, 21)))
    #>
    #> Number of markers: 10
    #> Markers in the sequence:
    #> M47 M38 M16 M62 M20 M48 M22 M18 M56 M50
    #>
    #> Parameters not estimated.

# Drawing the genetic map

We can draw a genetic map for all linkage groups using the function `draw_map`. First we have to create a list of ordered linkage groups:

    maps_list <- list(LG1_f2_final, LG2_f2_final, LG3_f2_final)

Then use function `draw_map` for this list:

    draw_map(maps_list, names = TRUE, grid = TRUE, cex.mrk = 0.7)

We also can draw a map for a specific linkage group:

    draw_map(LG1_f2_final, names = TRUE, grid = TRUE, cex.mrk = 0.7)

Let’s use this function to overview the maps builded by different strategies in this tutorial:

    map_list_all <- list(LG1_f2_final, CHR1_final, LG2_f2_final, CHR3_final, CHR2_final, LG3_f2_final)
    draw_map(map_list_all, names = TRUE, grid = TRUE, cex.mrk = 0.7)

Function `draw_map` draws a very simple graphic representation of the genetic map. However, once the distances are estimated, better map figures can be drawn by the user with any appropriate software. There are several free software that can be used, such as MapChart (Voorrips, 2002).

# Final remarks

At this point it should be clear that any potential `OneMap` user must have some knowledge about genetic mapping and also the R language, because the analysis is not done with only one mouse click. In the future, perhaps a graphical interface will be made available to make this software a lot easier to use.

We do hope that `OneMap` is useful to researchers interested in genetic mapping in outcrossing or inbred-based populations. Any suggestions and critics are welcome.

# Session Info

    sessionInfo()
    #> R version 3.4.0 (2017-04-21)
    #> Platform: x86_64-pc-linux-gnu (64-bit)
    #> Running under: Ubuntu 16.04 LTS
    #>
    #> Matrix products: default
    #> BLAS: /usr/lib/libblas/libblas.so.3.6.0
    #> LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
    #>
    #> locale:
    #>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    #>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C
    #>  [5] LC_MONETARY=pt_BR.UTF-8    LC_MESSAGES=en_US.UTF-8
    #>  [7] LC_PAPER=pt_BR.UTF-8       LC_NAME=C
    #>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
    #> [11] LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C
    #>
    #> attached base packages:
    #> [1] stats     graphics  grDevices utils     datasets  methods   base
    #>
    #> other attached packages:
    #> [1] onemap_2.1.1  rmarkdown_1.6 knitr_1.17
    #>
    #> loaded via a namespace (and not attached):
    #>  [1] Rcpp_0.12.13     magrittr_1.5     maps_3.1.1       munsell_0.4.3
    #>  [5] colorspace_1.3-2 rlang_0.1.1      stringr_1.2.0    plyr_1.8.4
    #>  [9] tcltk_3.4.0      fields_9.0       tools_3.4.0      grid_3.4.0
    #> [13] tkrplot_0.0-23   spam_1.4-0       gtable_0.2.0     htmltools_0.3.6
    #> [17] yaml_2.1.14      lazyeval_0.2.0   rprojroot_1.2    digest_0.6.12
    #> [21] tibble_1.3.3     reshape2_1.4.2   ggplot2_2.2.1    codetools_0.2-15
    #> [25] evaluate_0.10.1  labeling_0.3     stringi_1.1.5    compiler_3.4.0
    #> [29] scales_0.4.1     backports_1.1.0

# References

Adler, J. R in a Nutshell A Desktop Quick Reference, 2009.

Broman, K. W., Wu, H., Churchill, G., Sen, S., Yandell, B. qtl: Tools for analyzing QTL experiments R package version 1.09-43, 2008.

Buetow, K. H., Chakravarti, A. Multipoint gene mapping using seriation. I. General methods. American Journal of Human Genetics 41, 180-188, 1987.

Doerge, R.W. Constructing genetic maps by rapid chain delineation. Journal of Agricultural Genomics 2, 1996.

Garcia, A.A.F., Kido, E.A., Meza, A.N., Souza, H.M.B., Pinto, L.R., Pastina, M.M., Leite, C.S., Silva, J.A.G., Ulian, E.C., Figueira, A. and Souza, A.P. Development of an integrated genetic map of a sugarcane Saccharum spp. commercial cross, based on a maximum-likelihood approach for estimation of linkage and linkage phases. Theoretical and Applied Genetics 112, 298-314, 2006.

Haldane, J. B. S. The combination of linkage values and the calculation of distance between the loci of linked factors. Journal of Genetics 8, 299-309, 1919.

Jiang, C. and Zeng, Z.-B. Mapping quantitative trait loci with dominant and missing markers in various crosses from two inbred lines. Genetica 101, 47-58, 1997.

Kosambi, D. D. The estimation of map distance from recombination values. Annuaire of Eugenetics 12, 172-175, 1944.

Lander, E. S. and Green, P. Construction of multilocus genetic linkage maps in humans. Proc. Natl. Acad. Sci. USA 84, 2363-2367, 1987.

Lander, E.S., Green, P., Abrahanson, J., Barlow, A., Daly, M.J., Lincoln, S.E. and Newburg, L. MAPMAKER, An interactive computing package for constructing primary genetic linkage maps of experimental and natural populations. Genomics 1, 174-181, 1987.

Lincoln, S. E., Daly, M. J. and Lander, E. S. Constructing genetic linkage maps with MAPMAKER/EXP Version 3.0: a tutorial and reference manual. A Whitehead Institute for Biomedical Research Technical Report 1993.

Matloff, N. The Art of R Programming. 2011. 1st ed. San Francisco, CA: No Starch Press, Inc., 404 pages.

Margarido, G. R. A., Souza, A.P. and Garcia, A. A. F. OneMap: software for genetic mapping in outcrossing species. Hereditas 144, 78-79, 2007.

Mollinari, M., Margarido, G. R. A., Vencovsky, R. and Garcia, A. A. F. Evaluation of algorithms used to order markers on genetics maps. Heredity 103, 494-502, 2009.

Oliveira, K.M., Pinto, L.R., Marconi, T.G., Margarido, G.R.A., Pastina, M.M., Teixeira, L.H.M., Figueira, A.M., Ulian, E.C., Garcia, A.A.F., Souza, A.P. Functional genetic linkage map on EST-markers for a sugarcane (Saccharum spp.) commercial cross. Molecular Breeding 20, 189-208, 2007.

Oliveira, E. J., Vieira, M. L. C., Garcia, A. A. F., Munhoz, C. F.,Margarido, G. R.A., Consoli, L., Matta, F. P., Moraes, M. C., Zucchi, M. I., and Fungaro,M. H. P. An Integrated Molecular Map of Yellow Passion Fruit Based on Simultaneous Maximum-likelihood Estimation of Linkage and Linkage Phases J. Amer. Soc. Hort. Sci. 133, 35-41, 2008.

Tan, Y., Fu, Y. A novel method for estimating linkage maps. Genetics 173, 2383-2390, 2006.

Van Os H, Stam P, Visser R.G.F., Van Eck H.J. RECORD: a novel method for ordering loci on a genetic linkage map. Theor Appl Genet 112, 30-40, 2005.

Voorrips, R.E. MapChart: software for the graphical presentation of linkage maps and QTLs. Journal of Heredity 93, 77-78, 2002.

Wang S., Basten, C. J. and Zeng Z.-B. Windows QTL Cartographer 2.5. Department of Statistics, North Carolina State University, Raleigh, NC, 2010. http://statgen.ncsu.edu/qtlcart/WQTLCart.htm

Wu, R., Ma, C.X., Painter, I. and Zeng, Z.-B. Simultaneous maximum likelihood estimation of linkage and linkage phases in outcrossing species. Theoretical Population Biology 61, 349-363, 2002a.

Wu, R., Ma, C.-X., Wu, S. S. and Zeng, Z.-B. Linkage mapping of sex-specific differences. Genetical Research 79, 85-96, 2002b.