Legofit
infers population history from nucleotide site patterns.
rafreader.h
1#ifndef RAFREADER_INCLUDED
2#define RAFREADER_INCLUDED
3
4#include "typedefs.h"
5#include <stdio.h>
6
7#define RAFSTRSIZE 20
8
9typedef uint64_t bits_t;
10
11struct RAFReader {
12 char *fname;
13 FILE *fp;
14 Tokenizer *tkz;
15 int ispipe; // 1 if fp is a pipe; 0 otherwise
16
17 // properties of current snp
18 long snpid; // 0-based index of current snp
19 char ref[RAFSTRSIZE]; // reference allele
20 char alt[RAFSTRSIZE]; // alternate alleles
21 char chr[RAFSTRSIZE]; // chromosome
22 unsigned long nucpos; // nucleotide position from raf file
23 double raf; // frequency of reference allele
24 double daf; // frequency of derived allele
25};
26
27RAFReader *RAFReader_new(const char *fname);
28void RAFReader_clearChromosomes(int n, RAFReader *r[n]);
29void RAFReader_free(RAFReader * self);
30int RAFReader_next(RAFReader * self);
31double RAFReader_raf(RAFReader * r);
32double RAFReader_daf(RAFReader * r);
33int RAFReader_alleleCheck(int n, RAFReader * r[n]);
34void RAFReader_printHdr(FILE *fp);
35void RAFReader_print(RAFReader *r, FILE *fp);
36void RAFReader_printArray(int n, RAFReader * r[n], FILE *fp);
38int RAFReader_multiNext(int n, RAFReader * r[n]);
39int RAFReader_findDaf(int n, RAFReader * r[n]);
40static inline const char *RAFReader_chr(RAFReader *self);
41static inline unsigned long RAFReader_nucpos(RAFReader *self);
42static inline const char *RAFReader_ref(RAFReader *self);
43static inline const char *RAFReader_alt(RAFReader *self);
44static inline const char *RAFReader_fname(RAFReader *self);
45
47static inline const char *RAFReader_fname(RAFReader *self) {
48 return self->fname;
49}
50
52static inline const char *RAFReader_chr(RAFReader *self) {
53 return self->chr;
54}
55
57static inline const char *RAFReader_ref(RAFReader *self) {
58 return self->ref;
59}
60
62static inline const char *RAFReader_alt(RAFReader *self) {
63 return self->alt;
64}
65
67static inline unsigned long RAFReader_nucpos(RAFReader *self) {
68 return self->nucpos;
69}
70#endif
int RAFReader_multiNext(int n, RAFReader *r[n])
Advance an array of RAFReaders to the next shared position, and set derived allele frequency within e...
Definition: rafreader.c:277
double RAFReader_daf(RAFReader *r)
Return derived allele frequency of current line of raf file.
Definition: rafreader.c:456
void RAFReader_clearChromosomes(int n, RAFReader *r[n])
Clear all chromosome names.
Definition: rafreader.c:94
void RAFReader_print(RAFReader *r, FILE *fp)
Print current line of raf file.
Definition: rafreader.c:429
int RAFReader_next(RAFReader *self)
Read the next site and set derived allele frequency (daf) within each reader.
Definition: rafreader.c:130
int RAFReader_findDaf(int n, RAFReader *r[n])
Set derived allele frequency within each RAFReader.
Definition: rafreader.c:358
void RAFReader_printHdr(FILE *fp)
Print header for raf file.
Definition: rafreader.c:423
RAFReader * RAFReader_new(const char *fname)
RAFReader constructor.
Definition: rafreader.c:27
int RAFReader_alleleCheck(int n, RAFReader *r[n])
Return 0 if ref and alt alleles of all readers match; return REF_MISMATCH if there is a mismatch in R...
Definition: rafreader.c:401
void RAFReader_free(RAFReader *self)
RAFReader destructor.
Definition: rafreader.c:101
double RAFReader_raf(RAFReader *r)
Return reference allele frequency of current line of raf file.
Definition: rafreader.c:451
int RAFReader_rewind(RAFReader *self)
Rewind raf file.
Definition: rafreader.c:237
Definition: rafreader.h:11
Definition: tokenizer.h:28