|
C/C++ version of SNP-HWE
The C/C++ version of SNP-HWE can be downloaded by following the link below and right clicking on the source code.
Once this function has been incorporated into your program, it can be called by passing observed counts for each of the three
SNP genotypes (heterozygote, homozygote_1, and homozygote_2) as function arguments. The code snippet below illustrates a typical calling sequence
to read in genotype counts listed in a text file ("genotype_counts_c.txt") and perform the exact test of Hardy-Weinberg on each marker:
genotype_counts_c.txt:
MARKER_1 100 3 5
MARKER_2 57 14 50
MARKER_3 31 32 51
MARKER_4 47 3 5
MARKER_5 150 32 55
MARKER_6 122 7 32
MARKER_7 99 3 14
MARKER_8 146 13 54
MARKER_9 177 100 57
MARKER_10 184 57 155
main() from run_marker_tests.c:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double SNPHWE(int obs_hets, int obs_hom1, int obs_hom2);
int main(int argc, char * argv[])
{
FILE * test_file = fopen("genotype_counts_c.txt", "rt");
if (test_file == NULL)
{
printf("Unable to open test file");
exit(EXIT_FAILURE);
}
int hets, homs1, homs2;
double p_value;
char name[100];
while (!feof(test_file))
{
fscanf(test_file, "%s %d %d %d\n", name, &hets, &homs1, &homs2);
p_value = SNPHWE(hets, homs1, homs2);
printf("P-value for %s: %lg\n", name, p_value);
}
}
Source distribution
SNP-HWE (C/C++)
| |