---
title: "04-tiles"
output: html_document
---

```{r}
library(methylKit)
```

```{r}
cov.list=list('../data/1_ATCACG.CpG_report.merged_CpG_evidence.cov',
                 '../data/2_CGATGT.CpG_report.merged_CpG_evidence.cov',
                 '../data/3_TTAGGC.CpG_report.merged_CpG_evidence.cov',
                 '../data/4_TGACCA.CpG_report.merged_CpG_evidence.cov',
                 '../data/5_ACAGTG.CpG_report.merged_CpG_evidence.cov',
                 '../data/6_GCCAAT.CpG_report.merged_CpG_evidence.cov',
                 '../data/7_CAGATC.CpG_report.merged_CpG_evidence.cov',
                 '../data/8_ACTTGA.CpG_report.merged_CpG_evidence.cov'
)
```


```{r}
myobj_lowCov = methRead(cov.list,
           sample.id = list("1","2","3","4","5","6","7","8"),
           assembly="v081",
           treatment = c(0,0,0,0,1,1,1,1),
           pipeline = "bismarkCoverage",
           context="CpG",
           mincov = 3
           )

```



```{r}
tiles = tileMethylCounts(myobj_lowCov,win.size=1000,step.size=1000,cov.bases = 10)
head(tiles[[1]],3)
```


```{r}
save(tiles, file = "../analyses/tiles_01")
```



```{r}
load ("../analyses/tiles_01")
```

```{r}
filtered.myobj=filterByCoverage(tiles,lo.count=5,lo.perc=NULL,
                                      hi.count=NULL,hi.perc=99.9)

meth_filter=unite(filtered.myobj, destrand=TRUE)

clusterSamples(meth_filter, dist="correlation", method="ward", plot=TRUE)


PCASamples(meth_filter)

```

```{r}
myDiff=calculateDiffMeth(meth_filter,mc.cores=8)

```




```{r}
# get hyper methylated bases
myDiff25p.hyper=getMethylDiff(myDiff,difference=25,qvalue=0.01,type="hyper")
#
# get hypo methylated bases
myDiff25p.hypo=getMethylDiff(myDiff,difference=25,qvalue=0.01,type="hypo")
#
#
# get all differentially methylated bases
myDiff10p=getMethylDiff(myDiff,difference=10,qvalue=.01)





```
