Legofit
infers population history from nucleotide site patterns.
Macros | Functions
rafreader.c File Reference

Class RAFReader: read a raf file. More...

#include "rafreader.h"
#include "tokenizer.h"
#include "misc.h"
#include "error.h"
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <unistd.h>

Macros

#define MAXFIELDS   5
 
#define MAX(X, Y)   ((X) > (Y) ? (X) : (Y))
 
#define MIN(X, Y)   ((X) > (Y) ? (Y) : (X))
 

Functions

int iscomment (const char *s)
 Return 1 if first non-white character in string is '#'; 0 otherwise.
 
int RAFReader_cmp (const RAFReader *lhs, const RAFReader *rhs)
 Compare two RAFReader objects. More...
 
void RAFReader_popen (RAFReader *self)
 
RAFReaderRAFReader_new (const char *fname)
 RAFReader constructor.
 
void RAFReader_clearChromosomes (int n, RAFReader *r[n])
 Clear all chromosome names.
 
void RAFReader_free (RAFReader *self)
 RAFReader destructor.
 
int RAFReader_next (RAFReader *self)
 Read the next site and set derived allele frequency (daf) within each reader. More...
 
int RAFReader_rewind (RAFReader *self)
 Rewind raf file. More...
 
int RAFReader_multiNext (int n, RAFReader *r[n])
 Advance an array of RAFReaders to the next shared position, and set derived allele frequency within each RAFReader. More...
 
int RAFReader_findDaf (int n, RAFReader *r[n])
 Set derived allele frequency within each RAFReader. More...
 
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 REF alleles; return MULTIPLE_ALT if there is a mismatch in ALT alleles.
 
void RAFReader_printHdr (FILE *fp)
 Print header for raf file.
 
void RAFReader_print (RAFReader *r, FILE *fp)
 Print current line of raf file.
 
void RAFReader_printArray (int n, RAFReader *r[n], FILE *fp)
 
double RAFReader_raf (RAFReader *r)
 Return reference allele frequency of current line of raf file.
 
double RAFReader_daf (RAFReader *r)
 Return derived allele frequency of current line of raf file.
 

Detailed Description

Class RAFReader: read a raf file.

Function Documentation

◆ RAFReader_cmp()

int RAFReader_cmp ( const RAFReader lhs,
const RAFReader rhs 
)

Compare two RAFReader objects.

If the "chr" fields differ, return positive if lhs->chr > rhs->chr; return negative if the reverse inequality holds. Otherwise return positive, 0, or negative to match the sign of lhs->nucpos - rhs->nucpos.

◆ RAFReader_findDaf()

int RAFReader_findDaf ( int  n,
RAFReader r[n] 
)

Set derived allele frequency within each RAFReader.

Parameters
[in]nnumber of RAFReader objects in array
[in]rarray of RAFReader objects. Last one should be outgroup.
Returns
0 on success, or one of several error codes on failure.

◆ RAFReader_multiNext()

int RAFReader_multiNext ( int  n,
RAFReader r[n] 
)

Advance an array of RAFReaders to the next shared position, and set derived allele frequency within each RAFReader.

Parameters
[in]nnumber of RAFReader objects in array
[in]rarray of RAFReader objects. Last one should be outgroup.
Returns
0 on success, or one of several error codes on failure.

◆ RAFReader_next()

int RAFReader_next ( RAFReader self)

Read the next site and set derived allele frequency (daf) within each reader.

Returns
0 on success, or else EOF, NO_ANCESTRAL_ALLELE, BUFFER_OVERFLOW, BAD_RAF_INPUT, BAD_SORT, MONOMORPHIC_SITE, or an errno code for failure to parse a floating-point number.

References iscomment(), strlowercase(), Tokenizer_print(), Tokenizer_split(), Tokenizer_strip(), and Tokenizer_token().

◆ RAFReader_rewind()

int RAFReader_rewind ( RAFReader self)

Rewind raf file.

Returns
0 on success; -1 on failure