-
Notifications
You must be signed in to change notification settings - Fork 0
/
grange_to_bed.R
27 lines (27 loc) · 1.06 KB
/
grange_to_bed.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
grange_to_bed = function(gr, write_spot, names_col = "",scores_col = ""){
# allow there to either be empty names or if you fill someting out
if(names_col == ""){
write_names = c(rep(".", length(gr)))
# then the name is taken fromt he metadata
}else(
write_names = gr@elementMetadata %>%
as.data.frame() %>% dplyr::select(!!names_col)
)
# similar concept with scores
# allow there to either be empty names or if you fill someting out
if(scores_col == ""){
write_scores = c(rep(".", length(gr)))
# then the name is taken fromt he metadata
}else(
write_scores = gr@elementMetadata %>%
as.data.frame() %>% dplyr::select(!!scores_col)
)
df <- data.frame(seqnames=seqnames(gr),
starts=start(gr)-1,
ends=end(gr),
names=write_names,
scores=write_scores,
strands=strand(gr))
write.table(df, file=write_spot, quote=F, sep="\t", row.names=F, col.names=F)
return(df)
}