| 1 |
## Generate freebayes params ## |
| 2 |
# make bed for parallelising freebayes |
| 3 |
|
| 4 |
#' This script reads a .fai index and a set of chroms and outputs a series of BED files |
| 5 |
#' which split the genome into separate regions. |
| 6 |
|
| 7 |
library(dplyr) |
| 8 |
library(data.table) |
| 9 |
library(glue) |
| 10 |
|
| 11 |
# read inputs |
| 12 |
chroms = snakemake@params[['chroms']] |
| 13 |
chunks = snakemake@params[['chunks']] |
| 14 |
fai = fread(snakemake@input[['index']]) |
| 15 |
|
| 16 |
# select chroms we want, and start, end columns |
| 17 |
fai = fai[fai$V1 %in% chroms, c(1,2)] |
| 18 |
|
| 19 |
# for each chromsome |
| 20 |
for (chrom in chroms){ |
| 21 |
#subset index to desired chrom |
| 22 |
f = fai[fai$V1 == chrom] |
| 23 |
#get sequence of n chunks from 0 to length of chrom |
| 24 |
bedseq = round(seq(0, f$V2, length.out = chunks)) |
| 25 |
|
| 26 |
#for each chunk |
| 27 |
for (i in 1:(chunks-1)){ |
| 28 |
#write bed file, one for each chunk/interval, which will be passed as input to freebayes |
| 29 |
row = c(chrom, bedseq[i], bedseq[i+1]) |
| 30 |
data.frame(row) %>% t() %>% fwrite(., glue("resources/regions/genome.{chrom}.region.{i}.bed"), sep="\t", col.names = FALSE) |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
sessionInfo() |