File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ export(leidenCBI)
4444export(logNorm)
4545export(louvainCBI)
4646export(markMultiPotts)
47+ export(medianFilter)
4748export(mergeLevels)
4849export(mock_bincounts)
4950export(multiPCFcompact)
Original file line number Diff line number Diff line change @@ -1114,3 +1114,52 @@ pullOutContent <- function(res,what="segments"){
11141114 return (res )
11151115
11161116}
1117+
1118+ # ###################################################################
1119+ # # Author: Gro Nilsen, Knut Liest?l and Ole Christian Lingj?rde.
1120+ # # Maintainer: Gro Nilsen <gronilse@ifi.uio.no>
1121+ # # License: Artistic 2.0
1122+ # # Part of the copynumber package
1123+ # # Reference: Nilsen and Liest?l et al. (2012), BMC Genomics
1124+ # ###################################################################
1125+
1126+
1127+ # Function to calculate running median for a given a window size
1128+
1129+ # #Input:
1130+ # ## x: vector of numeric values
1131+ # ## k: window size to be used for the sliding window (actually half-window size)
1132+
1133+ # # Output:
1134+ # ## runMedian : the running median corresponding to each observation
1135+
1136+ # #Required by:
1137+ # ## getMad
1138+ # ## medianFilter
1139+
1140+
1141+ # #Requires:
1142+ # ## none
1143+
1144+ # ' @export
1145+ medianFilter <- function (x ,k ){
1146+ n <- length(x )
1147+ filtWidth <- 2 * k + 1
1148+
1149+ # Make sure filtWidth does not exceed n
1150+ if (filtWidth > n ){
1151+ if (n == 0 ){
1152+ filtWidth <- 1
1153+ }else if (n %% 2 == 0 ){
1154+ # runmed requires filtWidth to be odd, ensure this:
1155+ filtWidth <- n - 1
1156+ }else {
1157+ filtWidth <- n
1158+ }
1159+ }
1160+
1161+ runMedian <- runmed(x ,k = filtWidth ,endrule = " median" )
1162+
1163+ return (runMedian )
1164+
1165+ }
You can’t perform that action at this time.
0 commit comments