-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeaksBed2IRanges.R
executable file
·49 lines (35 loc) · 1.3 KB
/
peaksBed2IRanges.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/local/bin/Rscript
options(stringsAsFactors = FALSE);
library(IRanges)
qw <- function(...) {
as.character(sys.call()[-1])
}
args <- commandArgs(trailingOnly=TRUE)
filename = args[1]
data <- read.csv(filename, header=T, sep="\t", comment.char = "#")
colnames(data) <- qw(Chr, Start, End, Length, Summit, nTags, neg10log10pVal, FoldEnrichment)
values <- qw(Length, Summit, nTags, neg10log10pVal, FoldEnrichment)
#sometimes they have FDR
if(ncol(data)==9){
colnames(data)[9] <- "FDR"
values<-c(values,"FDR")
}
#we have to give them names to avoid a bug in ChIPpeakAnnot if we want to use it later
data[,"Name"]<-paste(paste(data[,"Chr"],data[,"Start"],sep=":"),data[,"End"], sep="-")
#note - this fails if chr position is undefined, which can happen
#if we've mapped over from somewhere else, so:
ids <- which(is.na(data[,"Chr"]) | is.na(data[,"Start"]) | is.na(data[,"End"]) )
if(length(ids)>0){
data <- data[-ids,]
}
rd <- RangedData(ranges = IRanges(
start= data$Start,
end = data$End,
names = as.character(data$Name),
),
space = as.character(data$Chr),
values = data[,values]
)
outfile=sub('.xls','.RangedData.RData',filename)
#And save the result
save(rd, file=outfile)