Legofit
infers population history from nucleotide site patterns.
Functions
lblndx.c File Reference

An index of sample labels. More...

#include "error.h"
#include "lblndx.h"
#include "misc.h"
#include "strdblqueue.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>

Functions

int comparePtrs (const void *void_x, const void *void_y)
 Compare pointers to pointers to two tipId_t values. More...
 
tipId_t LblNdx_getTipId_1 (const LblNdx *self, const char *lbl)
 
static int make_map (size_t n, int map[n], tipId_t collapse)
 
static void make_rm_map (size_t n, int map[n], tipId_t remove)
 
void LblNdx_init (LblNdx *self)
 Set everything to zero.
 
void LblNdx_addSamples (LblNdx *self, unsigned nsamples, const char *lbl)
 Add samples for a single population. More...
 
const char * LblNdx_lbl (const LblNdx *self, unsigned i)
 Return the label associated with index i.
 
unsigned LblNdx_size (const LblNdx *self)
 Return number of samples, which equals number of labels.
 
void LblNdx_sanityCheck (const LblNdx *self, const char *file, int line)
 
int LblNdx_equals (const LblNdx *lhs, const LblNdx *rhs)
 Return 1 if the two arguments are equal; 0 otherwise.
 
tipId_t LblNdx_getTipId (const LblNdx *self, const char *lbl)
 Reverse lookup. More...
 
void LblNdx_print (const LblNdx *self, FILE *fp)
 Print a LblNdx.
 
char * patLbl (size_t n, char buff[n], tipId_t tid, const LblNdx *lblndx)
 Generate a label for site pattern tid. More...
 
int compare_tipId (const void *void_x, const void *void_y)
 Compare pointers to two tipId_t values. More...
 
void orderpat (int n, unsigned ord[n], tipId_t pat[n])
 On entry, pat is an array of n tipId_t values. More...
 
int LblNdx_collapse (LblNdx *self, tipId_t collapse, const char *lbl)
 Reduce dimension of LblNdx object by collapsing several entries into a single entry. More...
 
int LblNdx_rmPops (LblNdx *self, tipId_t remove)
 
int LblNdx_from_StrDblQueue (LblNdx *lndx, StrDblQueue *queue)
 Initialize a pre-allocated LblNdx from a StrDblQueue. More...
 

Detailed Description

An index of sample labels.

Author
Alan R. Rogers

Function Documentation

◆ compare_tipId()

int compare_tipId ( const void *  void_x,
const void *  void_y 
)

Compare pointers to two tipId_t values.

Parameters
void_x,void_ypointers to tipId_t values
Returns
<0, 0, or >0 depending on whether the first arg is <, ==, or > the second.

References num1bits().

◆ comparePtrs()

int comparePtrs ( const void *  void_x,
const void *  void_y 
)

Compare pointers to pointers to two tipId_t values.

Parameters
void_x,void_ypointers to pointers to tipId_t values
Returns
<0, 0, or >0 depending on whether the first arg is <, ==, or > the second.

References num1bits().

◆ LblNdx_addSamples()

void LblNdx_addSamples ( LblNdx self,
unsigned  nsamples,
const char *  lbl 
)

Add samples for a single population.

Should be called once for each sampled population.

Referenced by LblNdx_from_StrDblQueue(), and parseSegment().

◆ LblNdx_collapse()

int LblNdx_collapse ( LblNdx self,
tipId_t  collapse,
const char *  lbl 
)

Reduce dimension of LblNdx object by collapsing several entries into a single entry.

The "on" bits of "collapse" indicate the entries to be collapsed. they are collapsed into the entry indicated by the bit in the lowest position. "lbl" is the label assigned to this entry. The dimension of the rewritten LblNdx object is reduced by one less than the number of "on" bits in "collapse". The function returns 0 on success, EDOM if the number of "on" bits in "collapse" exceeds self->n, and BUFFER_OVERFLOW if any of the write operations would overflow.

◆ LblNdx_from_StrDblQueue()

int LblNdx_from_StrDblQueue ( LblNdx lndx,
StrDblQueue queue 
)

Initialize a pre-allocated LblNdx from a StrDblQueue.

On input, each entry of the StrDblQueue refers to a single site pattern. The string in each entry should be of form "a:b:c", where the colons separate fields, and each field is the label of a sample. On return, lndx contains all these labels, indexed in their order of appearance with the queue.

References LblNdx_addSamples(), and LblNdx_getTipId().

◆ LblNdx_getTipId()

tipId_t LblNdx_getTipId ( const LblNdx self,
const char *  lbl 
)

Reverse lookup.

Return tipId_t value corresponding to label, which may be composite. The parts of a composite label are delimited by the ':' character. If label (or any of its parts) is not present in LblNdx, return 0.

Referenced by BranchTab_from_StrDblQueue(), and LblNdx_from_StrDblQueue().

◆ orderpat()

void orderpat ( int  n,
unsigned  ord[n],
tipId_t  pat[n] 
)

On entry, pat is an array of n tipId_t values.

On return, ord[0] is the index of the first value, ord[1] is that of the 2nd, and so on.

◆ patLbl()

char * patLbl ( size_t  n,
char  buff[n],
tipId_t  tid,
const LblNdx lblndx 
)

Generate a label for site pattern tid.

Label goes into buff. Function returns a pointer to buff;