calc_freq

C++ Function Reference

1 Signature

double BigDataStatMeth::calc_freq(Rcpp::NumericVector x)

2 Description

Calculates the Minor Allele Frequency (MAF) from binary genotype data.

3 Parameters

  • x (Rcpp::NumericVector): NumericVector containing binary genotype data (0/1 encoded)

4 Returns

double MAF value between 0 and 0.5

5 Details

xNumericVector containing binary genotype data (0/1 encoded) double MAF value between 0 and 0.5 This function calculates MAF for a vector of binary genotypes:Counts occurrences of reference (0) and alternate (1) allelesCalculates frequency as (n0 + 0.5*n1)/total_lengthEnsures MAF is ≤ 0.5 by taking complement if necessary

6 Call Graph

Function dependencies

7 Source Code

File: inst/include/hdf5Omics/hdf5OmicsUtils.hppLines 61-79

inline double calc_freq(Rcpp::NumericVector x)
    {
        
        int len = x.size();
        
        std::vector<double> xc = Rcpp::as<std::vector<double> >(x);
        
        int n0 = std::count (xc.begin(), xc.end(), 0);
        int n1 = std::count (xc.begin(), xc.end(), 1);
        
        double maf = (double(n0)/len) + 0.5*(double(n1)/len);
        
        if( maf > 0.5 ) { 
            maf = 1 - maf;
        }
        
        return maf;
        
    }

8 Usage Example

#include "BigDataStatMeth.hpp"

// Example usage
auto result = calc_freq(...);