## Data preprocessing
This is a jupyter version of CLI tutorial that can be found [here](/geniml/tutorials/create-consensus-peaks.md). You will use here python functions instead of CLI to build and assess different universes. Files that you will use here can be downloaded from XXX. In there you will find a compressed folder:

```
consensus:
    - raw
        test_1.bed
        test_2.bed
        test_3.bed
        test_4.bed
    file_list.txt
    chrom.sizes
```

In the raw folder there are example BED files used in this tutorial and in file_list.txt are names of files you will analyze. Additionally there is a file with chromosome sizes, which you will use to preprocess the data. 

Here we assume that you already have files of the genome coverage by the analyzed collection. The example of how to create them can be found [here](/geniml/tutorials/create-consensus-peaks.md).

## Coverage cutoff universe

First, you will create a coverage cutoff universe (CC). This is the simplest type of a universe that only includes genomic positions with coverage greater or equal to cutoff *x*. This cutoff by default is calculated using simple likelihood model that calculates the probability of appearing in a collection. The universe can be build just based on genome coverage:


```python
from geniml.universe.cc_universe import cc_universe
cc_universe("coverage/", file_out="universe_cc.bed")
```

Depending on the task the universe can be smooth by setting ```merge``` option with the distance below witch peaks should be merged together and 
`filter_size` with minimum size of peak that should be part of the universe. Instead of using maximum likelihood cutoff one can also defined cutoff with `cutoff` option. If it is set to 1 the result is union universe, and when to number of files it will produce intersection universe:


```python
cc_universe("coverage/", file_out="universe_union.bed", cutoff=1)
cc_universe("coverage/", file_out="universe_intersection.bed", cutoff=4)
```

## Coverage cutoff flexible universe
A more complex version of coverage cutoff universe is coverage cutoff flexible universe (CCF). In contrast to its' fixed version it produces flexible universes. It uses two cutoffs calculated based on maximum likelihood cutoff, making a confidence interval around the optimal cutoff value. Despite the fact that the CFF universe is more complex it is build using the same input as the CC universe: 



```python
from geniml.universe.ccf_universe import ccf_universe

ccf_universe("coverage/", file_out="universe_ccf.bed")
```

## Maximum likelihood universe
In the previous examples both CC anf CCF universes used simple likelihood model to calculate the cutoff. However, we also developed more complex likelihood model that takes into account the positions of starts and ends of the regions in the collection. This LH model can build based on coverage files:


```python
from geniml.likelihood.build_model import main

main("model.tar", "coverage/",
     "all",
     file_no=4)
```

    Function 'main' executed in 0.0001min


The resulting tar archiver contains LH model. This model can be used as a scoring function that assigns to each position probability of it being a start, core or end of a region. It can be both used for universe assessment and universe building. Combination of LH model and optimization algorithm for building flexible universes results in maximum likelihood universe (ML):


```python
from geniml.universe.ml_universe import ml_universe

ml_universe("model.tar",
     "coverage",
     "all",
     "universe_ml.bed")
```

## HMM 
The forth presented method of creating universes utilizes Hidden Markov Models. In this approach the parts of flexible regions are hidden states of the model, while genome coverage by the collections are emissions. The resulting universe is called Hidden Markov Model universe. It can be build only based on the genome coverage by the collection:


```python
from geniml.universe.hmm_universe import hmm_universe

hmm_universe("coverage/",
             "universe_hmm.bed")
```

# How to assess new universe?

So far you used many different methods for creating new universes. But choosing, which universe represents data the best can be challenging. To help with this we created a tutorial that can be found [here](/geniml/tutorials/assess-universe.md), which presents different  methods that assess universe fit to the collection of files.
