---
title: "teeth signal results"
author: "Keren Xu"
date: "09/12/2021"
output: html_document
---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = T)
knitr::opts_chunk$set(warning = FALSE)
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(fig.width= 7, fig.height=5) 
```



# Load packages  
```{r}
library(tidyverse)
require(dplyr)
require(data.table)
library(pals)
library(colorblindr)
theme_set(theme_light()) 

list.dirs(path = "/DIR/signal.out", full.names = F, recursive = F) %>% dput()
```


## R Markdown
```{r}
mydir <- c() # a vector of paths to each individual samples

# read file path
all_paths <- paste0(mydir, "/kataegis_regions.csv")

# read file content
all_content <-
  all_paths %>%
  lapply(read.csv,
         header = TRUE)
 
# read file name
all_filenames <- all_paths %>%
  as.list()
 
# combine file content list and file name list
all_lists <- mapply(c, all_content, all_filenames, SIMPLIFY = FALSE)
 
# unlist all lists and change column name
all_result <- rbindlist(all_lists, fill = T)
# change column name
names(all_result)[4] <- "File.Path"

all_result$sample_id <- gsub("/kataegis_regions.csv", "", all_result$File.Path) 

all_result$sample_id <- gsub("/dir/signal.out/","",all_result$sample_id)

all_result <- all_result %>% select(-File.Path)

all_result <- all_result %>% filter(!is.na(chr))

all_result %>% count(sample_id)

all_result %>% fwrite("signal_kataegis_regions.txt")
```

