---
title: "04-TE-meth-intersect"
output: html_document
---

test run on one

```{bash}
pwd

```

```{bash}
/home/shared/bedtools2/bin/intersectBed \
-wb \
-a ../data/3F_R1_val_1_10x.bedgraph \
-b ../genome-features/C_virginica-3.0_TE-all.gff \
> ../output/12M_te.tab
```

```{bash}
head ../output/12M_te.tab
```


```{r}
testMte <- read.csv("../output/12M_te.tab", sep = "\t", header = FALSE)
```


```{r}
library(tidyverse)
```


```{r}
group12 <- testMte %>% group_by(V13) %>%
summarize(avg_sq = mean(V4, na.rm=TRUE))
```






# CODE TO GET METHYLATION INTERSECT WITH TE

```{bash}
cd ../data
FILES=$(ls *bedgraph)

for file in ${FILES}
do
   NAME=$(echo ${file} | awk -F "_" '{print $1}')
   echo ${NAME}

  /home/shared/bedtools2/bin/intersectBed \
  -wb \
  -a ${NAME}_R1_val_1_10x.bedgraph \
  -b ../genome-features/C_virginica-3.0_TE-all.gff \
  > ../output/${NAME}mTE.out
done  



```
```{bash}
head ../output/9MmTE.out
```


# Taking TE methylation at each Loci and getting Mean methylation



```{r}
group12 <- testMte %>% group_by(V13) %>%
summarize(avg_sq = mean(V4, na.rm=TRUE))
```






