-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstandardizeSites.R
22 lines (17 loc) · 972 Bytes
/
standardizeSites.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
standardizeSites <- function(unstandardizedSites){
dereplicated <- dereplicateSites(unstandardizedSites)
dereplicated$dereplicatedSiteID <- seq(length(dereplicated))
#expand, keeping the newly standardized starts
standardized <- unname(dereplicated[rep(dereplicated$dereplicatedSiteID, dereplicated$counts)])
#order the original object to match
unstandardizedSites <- unstandardizedSites[unlist(dereplicated$revmap)]
#graft over the widths and metadata
trueBreakpoints <- start(flank(unstandardizedSites, -1, start=F))
standardizedStarts <- start(flank(standardized, -1, start=T))
standardized <- GRanges(seqnames=seqnames(standardized),
ranges=IRanges(start=pmin(standardizedStarts, trueBreakpoints),
end=pmax(standardizedStarts, trueBreakpoints)),
strand=strand(standardized))
mcols(standardized) <- mcols(unstandardizedSites)
standardized
}