Skip to content

Commit e8396c5

Browse files
committed
adding missing function
1 parent ebbed60 commit e8396c5

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export(leidenCBI)
4444
export(logNorm)
4545
export(louvainCBI)
4646
export(markMultiPotts)
47+
export(medianFilter)
4748
export(mergeLevels)
4849
export(mock_bincounts)
4950
export(multiPCFcompact)

R/multipcf.R

+49
Original file line numberDiff line numberDiff 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 <[email protected]>
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+
}

0 commit comments

Comments
 (0)