Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include <Rcpp.h>
//compute variance with bessel correction for a single bin
inline double binValue(int* counts, int len){
long tot = 0;
long tot2 = 0;
double denom = len;
for (int i = 0; i < len; ++i){
int c = counts[i];
tot += c;
tot2 += c*c;
}
double mean = tot/denom;
double var = (tot2 - mean*mean*denom)/(denom-1);
return mean/sqrt(var);
}
// [[Rcpp::export]]
Rcpp::NumericVector stabilizeBins(Rcpp::IntegerVector sig, int binsize){
int* C = sig.begin();
int siglen = sig.length();
int nbins = siglen / binsize;
bool incompleteBin = siglen % binsize != 0;
Rcpp::NumericVector binnedSig(nbins + (incompleteBin?1:0));
//loop on the bins
int bin = 0;
for (; bin < nbins; ++bin){
binnedSig[bin] = binValue(C + bin*binsize, binsize);
}
if (incompleteBin) {
binnedSig[nbins] = binValue(C + nbins*binsize, siglen - nbins*binsize);
}
return binnedSig;
}