genomicSimulationC 0.2.6
|
#include "sim-operations.h"
Go to the source code of this file.
Data Structures | |
union | gsc_datastore_make_genotypes |
Macros | |
#define | SIM_OPERATIONS |
Functions | |
static void * | gsc_malloc_wrap (const size_t size, char exitonfail) |
Replace calls to malloc direct with this function. More... | |
gsc_AlleleMatrix * | gsc_create_empty_allelematrix (const unsigned int n_markers, const unsigned int n_labels, const int *labelDefaults, const unsigned int n_genotypes) |
Creator for an empty gsc_AlleleMatrix object of a given size. More... | |
gsc_SimData * | gsc_create_empty_simdata (unsigned int RNGseed) |
Creator for an empty gsc_SimData object on the heap. More... | |
void | gsc_clear_simdata (gsc_SimData *d) |
Clear a gsc_SimData object on the heap. More... | |
int | gsc_randpoi (rnd_pcg_t *rng, double lambda) |
Generates randomly a number from the Poisson distribution with parameter lambda , using the Knuth approach. More... | |
struct gsc_TableSize | gsc_get_file_dimensions (const char *filename, const char sep) |
Opens a table file and reads the number of columns and rows (including headers) separated by sep into a gsc_TableSize struct that is returned. More... | |
unsigned int | gsc_get_from_ordered_pedigree_list (const gsc_PedigreeID target, const unsigned int listLen, const gsc_PedigreeID *list) |
Binary search through list of unsigned integers. More... | |
size_t | gsc_get_from_unordered_str_list (const char *target, const size_t listLen, const char **list) |
Linear search through a list of strings. More... | |
size_t | gsc_get_from_ordered_str_list (const char *target, const size_t listLen, const char **list) |
Binary search through a list of strings. More... | |
void | gsc_shuffle_up_to (rnd_pcg_t *rng, void *sequence, const size_t item_size, const size_t total_n, const size_t n_to_shuffle) |
Produce a random ordering of the first n elements in an array using a (partial) Fisher-Yates shuffle. More... | |
static void | gsc_set_names (gsc_AlleleMatrix *a, const char *prefix, const int suffix, const unsigned int from_index) |
Fills the designated section of the .names array in an gsc_AlleleMatrix with the pattern "`prefix`index". More... | |
gsc_LabelID | gsc_create_new_label (gsc_SimData *d, const int setTo) |
Initialises a new custom label. More... | |
void | gsc_change_label_default (gsc_SimData *d, const gsc_LabelID whichLabel, const int newDefault) |
Set the default value of a custom label. More... | |
void | gsc_change_label_to (gsc_SimData *d, const gsc_GroupNum whichGroup, const gsc_LabelID whichLabel, const int setTo) |
Set the values of a custom label. More... | |
void | gsc_change_label_by_amount (gsc_SimData *d, const gsc_GroupNum whichGroup, const gsc_LabelID whichLabel, const int byValue) |
Increment the values of a custom label. More... | |
void | gsc_change_label_to_values (gsc_SimData *d, const gsc_GroupNum whichGroup, const unsigned int startIndex, const gsc_LabelID whichLabel, const size_t n_values, const int *values) |
Copy a vector of integers into a custom label. More... | |
void | gsc_change_names_to_values (gsc_SimData *d, const gsc_GroupNum whichGroup, const unsigned int startIndex, const size_t n_values, const char **values) |
Copy a vector of strings into the genotype name field. More... | |
void | gsc_change_allele_symbol (gsc_SimData *d, const char *which_marker, const char from, const char to) |
Replace all occurences of a given allele with a different symbol representation. More... | |
int | gsc_get_integer_digits (const int i) |
Count and return the number of digits in i . More... | |
static int | gsc_helper_descending_pdouble_comparer (const void *pp0, const void *pp1) |
Comparator function for qsort. More... | |
static int | gsc_helper_ascending_double_comparer (const void *pp0, const void *pp1) |
Comparator function for qsort. More... | |
static int | gsc_helper_ascending_pdouble_comparer (const void *pp0, const void *pp1) |
Comparator function for qsort. More... | |
static int | gsc_helper_indirect_alphabetical_str_comparer (const void *p0, const void *p1) |
Comparator function for qsort. More... | |
static int | gsc_helper_mapfileunit_ascending_chr_comparer (const void *p0, const void *p1) |
Comparator function for qsort. More... | |
static int | gsc_helper_mapfileunit_ascending_d_comparer (const void *p0, const void *p1) |
Comparator function for qsort. More... | |
void | gsc_move_genotype (gsc_GenoLocation from, gsc_GenoLocation to, int *label_defaults) |
Move all details of the genotype at one gsc_GenoLocation to another gsc_GenoLocation. More... | |
static gsc_GenoLocation | gsc_nextgappy_valid_pos (struct gsc_GappyIterator *it) |
Sets the current cursor position in a gsc_GappyIterator to the next valid position, if the cursor is not already a valid position. More... | |
static gsc_GenoLocation | gsc_nextgappy_get_gap (struct gsc_GappyIterator *it) |
Sets the current cursor position in a gsc_GappyIterator to the next empty position, if the cursor is not already an empty position. More... | |
static gsc_GenoLocation | gsc_nextgappy_get_nongap (struct gsc_GappyIterator *it) |
Sets the current cursor position in a gsc_GappyIterator to the next filled position, if the cursor is not already a filled position. More... | |
void | gsc_condense_allele_matrix (gsc_SimData *d) |
A function to tidy the internal storage of genotypes after addition or deletion of genotypes in the gsc_SimData. More... | |
gsc_BidirectionalIterator | gsc_create_bidirectional_iter (gsc_SimData *d, const gsc_GroupNum group) |
Create a bidirectional iterator. More... | |
gsc_BidirectionalIterator | gsc_create_bidirectional_iter_fromAM (gsc_AlleleMatrix *am, const gsc_GroupNum group) |
gsc_RandomAccessIterator | gsc_create_randomaccess_iter (gsc_SimData *d, const gsc_GroupNum group) |
Create a Random Access Iterator. More... | |
gsc_AlleleMatrix * | gsc_get_nth_AlleleMatrix (gsc_AlleleMatrix *listStart, const unsigned int n) |
Get an gsc_AlleleMatrix by index in the linked list. More... | |
gsc_GenoLocation | gsc_set_bidirectional_iter_to_start (gsc_BidirectionalIterator *it) |
Initialise a Bidirectional iterator to the start of its sequence. More... | |
gsc_GenoLocation | gsc_set_bidirectional_iter_to_end (gsc_BidirectionalIterator *it) |
Initialise a Bidirectional iterator to the end of its sequence. More... | |
gsc_GenoLocation | gsc_next_forwards (gsc_BidirectionalIterator *it) |
Get the next location from a bidirectional iterator. More... | |
gsc_GenoLocation | gsc_next_backwards (gsc_BidirectionalIterator *it) |
Get the previous location from a bidirectional iterator. More... | |
gsc_GenoLocation | gsc_next_get_nth (gsc_RandomAccessIterator *it, const unsigned int n) |
Get a location by index using a gsc_RandomAccessIterator. More... | |
char * | gsc_get_name_of_id (const gsc_AlleleMatrix *start, const gsc_PedigreeID id) |
Returns the name of the genotype with a given id. More... | |
int | gsc_get_parents_of_id (const gsc_AlleleMatrix *start, const gsc_PedigreeID id, gsc_PedigreeID output[static 2]) |
Saves the ids of the parents of a genotype with a particular id to the output array output . More... | |
void | gsc_get_ids_of_names (const gsc_AlleleMatrix *start, const size_t n_names, const char **names, gsc_PedigreeID *output) |
Search for genotypes with certain names in a linked list of gsc_AlleleMatrix and save the ids of those names. More... | |
unsigned int | gsc_get_index_of_child (const gsc_AlleleMatrix *start, const gsc_PedigreeID parent1id, const gsc_PedigreeID parent2id) |
Search for a genotype with parentage matching two given parent ids in a linked list of gsc_AlleleMatrix, and return its index. More... | |
unsigned int | gsc_get_index_of_name (const gsc_AlleleMatrix *start, const char *name) |
Search for a genotype with a particular name in a linked list of gsc_AlleleMatrix, and return its global index in the list. More... | |
gsc_PedigreeID | gsc_get_id_of_index (const gsc_AlleleMatrix *start, const unsigned int index) |
Get the id of a genotype by its index. More... | |
char * | gsc_get_genes_of_index (const gsc_AlleleMatrix *start, const unsigned int index) |
Get the alleles of a genotype by its index. More... | |
gsc_GroupNum | gsc_combine_groups (gsc_SimData *d, const size_t list_len, const gsc_GroupNum *grouplist) |
Combine a set of groups into one group. More... | |
gsc_GroupNum | gsc_make_group_from (gsc_SimData *d, const size_t index_list_len, const unsigned int *genotype_indexes) |
Take a list of indexes and allocate the genotypes at those indexes to a new group. More... | |
gsc_GroupNum | gsc_split_by_label_value (gsc_SimData *d, const gsc_GroupNum group, const gsc_LabelID whichLabel, const int valueToSplit) |
Allocates the genotypes with a particular value of a label to a new group. More... | |
gsc_GroupNum | gsc_split_by_label_range (gsc_SimData *d, const gsc_GroupNum group, const gsc_LabelID whichLabel, const int valueLowBound, const int valueHighBound) |
Allocates the genotypes with values of a label in a particular range to a new group. More... | |
size_t | gsc_scaffold_split_by_somequality (gsc_SimData *d, const gsc_GroupNum group_id, void *somequality_data, gsc_GroupNum(*somequality_tester)(gsc_GenoLocation, void *, size_t, size_t, gsc_GroupNum *), size_t maxentries_results, gsc_GroupNum *results) |
Split by some quality (generic function) More... | |
static gsc_GroupNum | gsc_helper_split_by_quality_halfsibtemplate (gsc_GenoLocation loc, void *datastore, size_t maxgroups, size_t groupsfound, gsc_GroupNum *results, gsc_PedigreeID(*getparent)(gsc_GenoLocation)) |
static gsc_GroupNum | gsc_helper_split_by_quality_halfsib1 (gsc_GenoLocation loc, void *datastore, size_t maxgroups, size_t groupsfound, gsc_GroupNum *results) |
static gsc_GroupNum | gsc_helper_split_by_quality_halfsib2 (gsc_GenoLocation loc, void *datastore, size_t maxgroups, size_t groupsfound, gsc_GroupNum *results) |
size_t | gsc_split_into_halfsib_families (gsc_SimData *d, const gsc_GroupNum group_id, const int parent, size_t maxentries_results, gsc_GroupNum *results) |
Split a group into families of half-siblings by shared first or second parent. More... | |
static gsc_GroupNum | gsc_helper_split_by_quality_family (gsc_GenoLocation loc, void *datastore, size_t maxgroups, size_t groupsfound, gsc_GroupNum *results) |
size_t | gsc_split_into_families (gsc_SimData *d, const gsc_GroupNum group_id, size_t maxentries_results, gsc_GroupNum *results) |
Split a group into families by their pedigrees. More... | |
static gsc_GroupNum | gsc_helper_split_by_quality_individuate (gsc_GenoLocation loc, void *datastore, size_t maxgroups, size_t groupsfound, gsc_GroupNum *results) |
size_t | gsc_split_into_individuals (gsc_SimData *d, const gsc_GroupNum group_id, size_t maxentries_results, gsc_GroupNum *results) |
Split a group into n one-member groups. More... | |
gsc_GroupNum | gsc_split_evenly_into_two (gsc_SimData *d, const gsc_GroupNum group_id) |
Split a group into two groups of equal size (or size differing only by one, if the original group had an odd number of members) using a random permutation of the group members to determine which goes where. More... | |
size_t | gsc_scaffold_split_by_someallocation (gsc_SimData *d, const gsc_GroupNum group_id, void *someallocator_data, gsc_GroupNum(*someallocator)(gsc_GenoLocation, gsc_SimData *, void *, size_t, size_t *, gsc_GroupNum *), size_t n_outgroups, gsc_GroupNum *outgroups) |
Split by some allocator (generic function) More... | |
static gsc_GroupNum | gsc_helper_split_by_allocator_knowncounts (gsc_GenoLocation loc, gsc_SimData *d, void *datastore, size_t n_outgroups, size_t *subgroupsfound, gsc_GroupNum *outgroups) |
size_t | gsc_split_evenly_into_n (gsc_SimData *d, const gsc_GroupNum group_id, const size_t n, gsc_GroupNum *results) |
Split a group into n groups of equal size (or size differing only by one, if n does not perfectly divide the group size.), using a random permutation of the group members to determine which goes where. More... | |
size_t | gsc_split_into_buckets (gsc_SimData *d, const gsc_GroupNum group_id, const size_t n, const unsigned int *counts, gsc_GroupNum *results) |
Split a group into n groups of equal size (or size differing only by one, if n does not perfectly divide the group size), using a random permutation of the group members to determine which goes where. More... | |
gsc_GroupNum | gsc_split_randomly_into_two (gsc_SimData *d, const gsc_GroupNum group_id) |
Flip a coin for each member of the group to decide if it should be moved to the new group. More... | |
static gsc_GroupNum | gsc_helper_split_by_allocator_equalprob (gsc_GenoLocation loc, gsc_SimData *d, void *datastore, size_t n_outgroups, size_t *subgroupsfound, gsc_GroupNum *outgroups) |
size_t | gsc_split_randomly_into_n (gsc_SimData *d, const gsc_GroupNum group_id, const size_t n, gsc_GroupNum *results) |
Allocate each member of the group to one of n groups with equal probability. More... | |
static gsc_GroupNum | gsc_helper_split_by_allocator_unequalprob (gsc_GenoLocation loc, gsc_SimData *d, void *datastore, size_t n_outgroups, size_t *subgroupsfound, gsc_GroupNum *outgroups) |
size_t | gsc_split_by_probabilities (gsc_SimData *d, const gsc_GroupNum group_id, const size_t n, const double *probs, gsc_GroupNum *results) |
Allocate each member of the group to one of n groups with custom probabilities for each group. More... | |
size_t | gsc_get_existing_groups (gsc_SimData *d, gsc_GroupNum *output) |
Identify group numbers that currently have members. More... | |
size_t | gsc_get_existing_group_counts (gsc_SimData *d, gsc_GroupNum *out_groups, unsigned int *out_sizes) |
Identify group numbers that currently have members, and how many members they have. More... | |
gsc_GroupNum | gsc_get_next_free_group_num (const size_t n_existing_groups, const gsc_GroupNum *existing_groups, size_t *cursor, gsc_GroupNum previous) |
Iterator to get the next currently-free group number. More... | |
gsc_GroupNum | gsc_get_new_group_num (gsc_SimData *d) |
Function to identify the next sequential integer that does not identify a group that currently has member(s). More... | |
void | gsc_get_n_new_group_nums (gsc_SimData *d, const size_t n, gsc_GroupNum *result) |
Function to identify the next n sequential integers that do not identify a group that currently has member(s). More... | |
gsc_LabelID | gsc_get_new_label_id (const gsc_SimData *d) |
Function to identify the next sequential integer that is not already allocated to a label in the simulation. More... | |
gsc_EffectID | gsc_get_new_eff_set_id (const gsc_SimData *d) |
Function to identify the next sequential integer that is not already allocated to a marker effect set ID in the simulation. More... | |
gsc_MapID | gsc_get_new_map_id (const gsc_SimData *d) |
Function to identify the next sequential integer that is not already allocated to a map ID in the simulation. More... | |
unsigned int | gsc_get_index_of_label (const gsc_SimData *d, const gsc_LabelID label) |
Function to identify the label lookup index of a label identifier. More... | |
unsigned int | gsc_get_index_of_eff_set (const gsc_SimData *d, const gsc_EffectID eff_set_id) |
Function to identify the lookup index of a marker effect set identifier. More... | |
unsigned int | gsc_get_index_of_map (const gsc_SimData *d, const gsc_MapID map) |
Function to identify the lookup index of a recombination map identifier. More... | |
unsigned int | gsc_get_group_size (const gsc_SimData *d, const gsc_GroupNum group_id) |
Function to count the number of genotypes that currently belong to the specified group. More... | |
unsigned int | gsc_get_group_genes (const gsc_SimData *d, const gsc_GroupNum group_id, unsigned int group_size, char **output) |
Gets a shallow copy of the genes/alleles of each member of the group. More... | |
unsigned int | gsc_get_group_names (const gsc_SimData *d, const gsc_GroupNum group_id, unsigned int group_size, char **output) |
Gets a shallow copy of the names of each member of the group. More... | |
unsigned int | gsc_get_group_ids (const gsc_SimData *d, const gsc_GroupNum group_id, unsigned int group_size, gsc_PedigreeID *output) |
Gets the ids of each member of the group. More... | |
unsigned int | gsc_get_group_indexes (const gsc_SimData *d, const gsc_GroupNum group_id, unsigned int group_size, unsigned int *output) |
Gets the 0-based global indexes of each member of the group. More... | |
unsigned int | gsc_get_group_bvs (const gsc_SimData *d, const gsc_GroupNum group_id, const gsc_EffectID effID, unsigned int group_size, double *output) |
Gets the breeding values/breeding values/fitnesses of each member of the group. More... | |
unsigned int | gsc_get_group_parent_ids (const gsc_SimData *d, const gsc_GroupNum group_id, unsigned int group_size, const int whichParent, gsc_PedigreeID *output) |
Gets the ids of either the first or second parent of each member of the group. More... | |
unsigned int | gsc_get_group_parent_names (const gsc_SimData *d, const gsc_GroupNum group_id, unsigned int group_size, const int whichParent, char **output) |
Gets the names of either the first or second parent of each member of the group. More... | |
unsigned int | gsc_get_group_pedigrees (const gsc_SimData *d, const gsc_GroupNum group_id, unsigned int group_size, char **output) |
Gets the full pedigree string (as per gsc_save_group_full_pedigree() ) of each member of the group. More... | |
gsc_DecimalMatrix | gsc_generate_zero_dmatrix (const size_t r, const size_t c) |
Generates a matrix of c columns, r rows with all 0. More... | |
int | gsc_add_matrixvector_product_to_dmatrix (gsc_DecimalMatrix *result, const gsc_DecimalMatrix *a, const double *b) |
Multiply a gsc_DecimalMatrix to a vector, and add that product to the first column of a provided gsc_DecimalMatrix. More... | |
int | gsc_add_doublematrixvector_product_to_dmatrix (gsc_DecimalMatrix *result, const gsc_DecimalMatrix *amat, const double *avec, const gsc_DecimalMatrix *bmat, const double *bvec) |
Multiply two sets of a gsc_DecimalMatrix and vector, and add both products to the first column of a provided gsc_DecimalMatrix. More... | |
void | gsc_delete_dmatrix (gsc_DecimalMatrix *m) |
Deletes a gsc_DecimalMatrix and frees its memory. More... | |
void | gsc_delete_group (gsc_SimData *d, const gsc_GroupNum group_id) |
Deletes all genotypes belonging to a particular group. More... | |
void | gsc_delete_eff_set (gsc_SimData *d, gsc_EffectID effID) |
Deletes a particular set of marker effects from memory. More... | |
void | gsc_delete_label (gsc_SimData *d, const gsc_LabelID which_label) |
Clears memory of this label from the simulation and all its genotypes. More... | |
void | gsc_delete_genome (gsc_KnownGenome *g) |
Deletes and clears the memory of a gsc_KnownGenome object and its children. More... | |
void | gsc_delete_recombination_map (gsc_SimData *d, const gsc_MapID which_map) |
Deletes a particular recombination map from memory. More... | |
void | gsc_delete_recombination_map_nointegrity (gsc_RecombinationMap *m) |
Deletes and clears the memory of a gsc_RecombinationMap struct. More... | |
void | gsc_delete_allele_matrix (gsc_AlleleMatrix *m) |
Delete the gsc_AlleleMatrix linked list from m onwards and frees its memory. More... | |
void | gsc_delete_effect_matrix (gsc_EffectMatrix *m) |
Deletes an gsc_EffectMatrix object and frees its memory. More... | |
void | gsc_delete_simdata (gsc_SimData *m) |
Deletes a gsc_SimData object and frees its memory. More... | |
void | gsc_delete_markerblocks (gsc_MarkerBlocks *b) |
Delete a gsc_MarkerBlocks struct. More... | |
void | gsc_delete_bidirectional_iter (gsc_BidirectionalIterator *it) |
Deletes a gsc_BidirectionalIterator object. More... | |
void | gsc_delete_randomaccess_iter (gsc_RandomAccessIterator *it) |
Deletes a gsc_RandomAccessIterator object and frees its memory. More... | |
gsc_TableFileReader | gsc_tablefilereader_create (const char *filename) |
Open a file for reading with gsc_TableFileReader. More... | |
void | gsc_tablefilereader_close (gsc_TableFileReader *tbl) |
Close a gsc_TableFileReader's file pointer. More... | |
void | gsc_helper_tablefilereader_refill_buffer (gsc_TableFileReader *tbl) |
Read another buffer's worth of characters from a gsc_TableFileReader's file. More... | |
enum gsc_TableFileCurrentStatus | gsc_helper_tablefilereader_classify_char (gsc_TableFileReader *tbl) |
Classify the character under the cursor of a TableFileReader as cell contents or otherwise. More... | |
void | gsc_tablefilecell_deep_copy (gsc_TableFileCell *c) |
Allocate memory to store a deep copy of a gsc_TableFileCell, if previously only a shallow copy. More... | |
gsc_TableFileCell | gsc_tablefilereader_get_next_cell (gsc_TableFileReader *tbl) |
Read forwards in TableFileReader and return the next cell's contents, as well as how many column gaps and newlines preceeded it. More... | |
_Bool | gsc_get_index_of_genetic_marker (const char *target, gsc_KnownGenome g, unsigned int *out) |
Return whether or not a marker name is present in the tracked markers, and at what index. More... | |
static gsc_TableFileCell | gsc_helper_tablefilereader_get_next_cell_wqueue (gsc_TableFileReader *tf, gsc_TableFileCell **queue, size_t *queuesize) |
Return the next cell from a queue of cells until the queue is exhausted, and thereafter read new cells from a TableFileReader. More... | |
static GSC_LOGICVAL | gsc_helper_parse_3cell_header (gsc_TableFileReader *tf, const char **canonical_titles, int *col_order, gsc_TableFileCell *unprocessedqueue, size_t *queuesize) |
Header row reading and processing for map and effect set files. More... | |
static size_t | gsc_helper_parse_mapfile (const char *filename, struct gsc_MapfileUnit **out) |
Extract the contents of a genetic map file. More... | |
static unsigned int | gsc_helper_str_markerlist_leftjoin (gsc_KnownGenome g, unsigned int n_markers_in_list, struct gsc_MapfileUnit **markerlist) |
Discard markers whose names are not present in a gsc_KnownGenome. More... | |
static gsc_MapID | gsc_helper_insert_recombmap_into_simdata (gsc_SimData *d, gsc_RecombinationMap map) |
Save a RecombinationMap to the SimData and allocate it a mapID. More... | |
static gsc_EffectID | gsc_helper_insert_eff_set_into_simdata (gsc_SimData *d, gsc_EffectMatrix effset) |
Save an EffectMatrix to the SimData and allocate it an EffectID. More... | |
static void | gsc_helper_sort_markerlist (unsigned int n_markers, struct gsc_MapfileUnit *markerlist) |
Sort markerlist by chromosome name, and by position within each chromosome. More... | |
gsc_MapID | gsc_create_recombmap_from_markerlist (gsc_SimData *d, unsigned int n_markers, struct gsc_MapfileUnit *markerlist) |
Parse a list of markers/chrs/positions into a gsc_RecombinationMap and save to SimData. More... | |
gsc_MapID | gsc_create_uniformspaced_recombmap (gsc_SimData *d, unsigned int n_markers, char **markernames, double expected_n_recombinations) |
Create a uniformly-spaced gsc_RecombinationMap from a list of marker names and save to SimData. More... | |
gsc_MapID | gsc_load_mapfile (gsc_SimData *d, const char *filename) |
Load a genetic map to a gsc_SimData object. More... | |
gsc_EffectID | gsc_load_effectfile (gsc_SimData *d, const char *filename) |
Populates a gsc_SimData combination with effect values. More... | |
static enum gsc_GenotypeFileCellStyle | gsc_helper_genotype_matrix_identify_cell_style (gsc_TableFileCell c) |
Identify what formatting a genotype matrix is representing alleles as. More... | |
static void | gsc_helper_genotypecell_to_allelematrix (gsc_GenoLocation loc, unsigned int markerix, enum gsc_GenotypeFileCellStyle style, char *cell, gsc_SimData *forrng) |
Parse a string and save it as the alleles of a genotype at a particular location and genetic marker. More... | |
static struct gsc_EmptyListNavigator | gsc_create_emptylistnavigator (gsc_SimData *d, gsc_GroupNum allocation_group) |
Create a new gsc_EmptyListNavigator, including an empty AlleleMatrix suitable for inserting into the provided SimData once the emptylist is finalised. More... | |
static gsc_GenoLocation | gsc_emptylistnavigator_get_first (struct gsc_EmptyListNavigator *it) |
Reset the cursor of a gsc_EmptyListNavigator to the first genotype. More... | |
static gsc_GenoLocation | gsc_emptylistnavigator_get_next (struct gsc_EmptyListNavigator *it) |
Get the next sequential genotype in an gsc_EmptyListNavigator. More... | |
static void | gsc_emptylistnavigator_finaliselist (struct gsc_EmptyListNavigator *it) |
Push emptylist edited genotypes into the SimData. More... | |
static struct gsc_GenotypeFile_MatrixFormat | gsc_helper_genotypefile_matrix_detect_orientation (const gsc_SimData *d, const gsc_TableFileCell *cellqueue, const size_t firstrowlen, const size_t queuelen, struct gsc_GenotypeFile_MatrixFormat format, const char *filenameforlog) |
Determine whether a genotype matrix is row- or column-oriented. More... | |
static struct gsc_GenotypeFile_MatrixFormat | gsc_helper_genotypefile_matrix_detect_cellstyle (const gsc_TableFileCell *cellqueue, const size_t firstrowlen, const size_t queuelen, struct gsc_GenotypeFile_MatrixFormat format, const char *filenameforlog) |
Determine the style in which alleles are stored in a genotype matrix. More... | |
static struct gsc_GenotypeFile_MatrixFormat | gsc_helper_genotypefile_matrix_detect_header (const gsc_TableFileCell *cellqueue, const size_t firstrowlen, const size_t queuelen, struct gsc_GenotypeFile_MatrixFormat format, const char *filenameforlog) |
Determine whether a genotype matrix has a header row or not. More... | |
static GSC_LOGICVAL | gsc_helper_genotypefile_matrix_detect_cornercell_presence (const size_t ncellsfirstrow, const size_t ncellssecondrow, const _Bool secondrowheaderisempty) |
Determine whether a genotype matrix has a corner cell or not. More... | |
gsc_FileFormatSpec | gsc_define_matrix_format_details (const GSC_LOGICVAL has_header, const GSC_LOGICVAL markers_as_rows, const enum gsc_GenotypeFileCellStyle cell_style) |
Give genomicSimulation hints on the format of a genotype matrix file to be loaded. More... | |
static gsc_GroupNum | gsc_load_genotypefile_matrix (gsc_SimData *d, const char *filename, const gsc_FileFormatSpec format) |
Loads a genotype file, with or without existing genome model in the SimData. More... | |
gsc_GroupNum | gsc_load_genotypefile (gsc_SimData *d, const char *filename, const gsc_FileFormatSpec format) |
Load a set of genotypes to a gsc_SimData object. More... | |
struct gsc_MultiIDSet | gsc_load_data_files (gsc_SimData *d, const char *genotype_file, const char *map_file, const char *effect_file, const gsc_FileFormatSpec format) |
Populates a gsc_SimData object with marker allele data, a genetic map, and (optionally) marker effect values. More... | |
int * | gsc_calculate_min_recombinations_fw1 (gsc_SimData *d, gsc_MapID mapid, char *parent1, unsigned int p1num, char *parent2, unsigned int p2num, char *offspring, int certain) |
Identify markers in the genotype of offspring where recombination from its parents occured. More... | |
int * | gsc_calculate_min_recombinations_fwn (gsc_SimData *d, gsc_MapID mapid, char *parent1, unsigned int p1num, char *parent2, unsigned int p2num, char *offspring, int window_size, int certain) |
Identify markers in the genotype of offspring where recombination from its parents occured, as judged by the marker itself and a short window around it. More... | |
int | gsc_calculate_recombinations_from_file (gsc_SimData *d, const char *input_file, const char *output_file, int window_len, int certain) |
Provides guesses as to the location of recombination events that led to the creation of certain genotypes from certain other genotypes. More... | |
void | gsc_generate_gamete (gsc_SimData *d, const char *parent_genome, char *output, const unsigned int map_index) |
Fills a char* with the simulated result of meiosis (reduction and recombination) from the marker alleles of a given parent. More... | |
void | gsc_generate_doubled_haploid (gsc_SimData *d, const char *parent_genome, char *output, const unsigned int map_index) |
Get the alleles of the outcome of producing a doubled haploid from a gamete from a given parent. More... | |
void | gsc_generate_clone (gsc_SimData *d, const char *parent_genome, char *output) |
Get an identical copy of a given genotype. More... | |
static FILE * | gsc_helper_genoptions_save_pedigrees_setup (const gsc_GenOptions g) |
Opens file for writing save-as-you-go pedigrees in accordance with gsc_GenOptions. More... | |
static FILE * | gsc_helper_genoptions_save_bvs_setup (const gsc_SimData *d, const gsc_GenOptions g, unsigned int *effIndexp) |
Opens file for writing save-as-you-go breeding values in accordance with gsc_GenOptions. More... | |
static FILE * | gsc_helper_genoptions_save_genotypes_setup (const gsc_SimData *d, const gsc_GenOptions g) |
Opens file for writing save-as-you-go genotypes in accordance with gsc_GenOptions. More... | |
static void | gsc_helper_genoptions_save_pedigrees (FILE *fp, gsc_SimData *d, gsc_AlleleMatrix *tosave) |
save-as-you-go (pedigrees) More... | |
static void | gsc_helper_genoptions_save_bvs (FILE *fe, gsc_EffectMatrix *effMatrices, unsigned int effIndex, gsc_AlleleMatrix *tosave) |
save-as-you-go (breeding values) More... | |
static void | gsc_helper_genoptions_save_genotypes (FILE *fg, gsc_AlleleMatrix *tosave) |
save-as-you-go (genotypes/alleles) More... | |
static void | gsc_helper_genoptions_give_names_and_ids (gsc_AlleleMatrix *am, gsc_SimData *d, const gsc_GenOptions g) |
Apply gsc_GenOptions naming scheme and gsc_PedigreeID allocation to a single gsc_AlleleMatrix. More... | |
gsc_GroupNum | gsc_scaffold_make_new_genotypes (gsc_SimData *d, const gsc_GenOptions g, void *parentIterator, union gsc_datastore_make_genotypes *datastore, int(*parentChooser)(void *, union gsc_datastore_make_genotypes *, unsigned int *, gsc_ParentChoice[static 2]), void(*offspringGenerator)(gsc_SimData *, union gsc_datastore_make_genotypes *, gsc_ParentChoice[static 2], gsc_GenoLocation)) |
Make new genotypes (generic function) More... | |
static int | gsc_helper_parentchooser_cross_randomly (void *parentIterator, union gsc_datastore_make_genotypes *datastore, unsigned int *counter, gsc_ParentChoice parents[static 2]) |
parentChooser function parameter for gsc_make_random_crosses. More... | |
static void | gsc_helper_make_offspring_cross (gsc_SimData *d, union gsc_datastore_make_genotypes *datastore, gsc_ParentChoice parents[static 2], gsc_GenoLocation putHere) |
offspringGenerator function parameter for all crossing functions More... | |
static unsigned int | gsc_helper_random_cross_checks (gsc_SimData *d, const gsc_GroupNum from_group, const unsigned int n_crosses, const unsigned int cap) |
Check input parameters of random crossing functions. More... | |
gsc_GroupNum | gsc_make_random_crosses (gsc_SimData *d, const gsc_GroupNum from_group, const unsigned int n_crosses, const unsigned int cap, const gsc_MapID which_map, const gsc_GenOptions g) |
Performs random crosses among members of a group. More... | |
unsigned int | gsc_randomdraw_replacementrules (gsc_SimData *d, unsigned int max, unsigned int cap, unsigned int *member_uses, unsigned int noCollision) |
Randomly pick a number in a range, optionally with a cap on how many times a number can be picked, and optionally required to be different to the last pick. More... | |
static int | gsc_helper_parentchooser_cross_randomly_between (void *parentIterator, union gsc_datastore_make_genotypes *datastore, unsigned int *counter, gsc_ParentChoice parents[static 2]) |
parentChooser function parameter for gsc_make_random_crosses_between. More... | |
gsc_GroupNum | gsc_make_random_crosses_between (gsc_SimData *d, const gsc_GroupNum group1, const gsc_GroupNum group2, const unsigned int n_crosses, const unsigned int cap1, const unsigned int cap2, const gsc_MapID map1, const gsc_MapID map2, const gsc_GenOptions g) |
Performs random crosses where the first parent comes from one group and the second from another. More... | |
static int | gsc_helper_parentchooser_cross_targeted (void *parentIterator, union gsc_datastore_make_genotypes *datastore, unsigned int *counter, gsc_ParentChoice parents[static 2]) |
parentChooser function parameter for gsc_make_targeted_crosses. More... | |
gsc_GroupNum | gsc_make_targeted_crosses (gsc_SimData *d, const size_t n_combinations, const unsigned int *firstParents, const unsigned int *secondParents, const gsc_MapID map1, const gsc_MapID map2, const gsc_GenOptions g) |
Performs the crosses of pairs of parents whose indexes are provided in an array. More... | |
static int | gsc_helper_parentchooser_selfing (void *parentIterator, union gsc_datastore_make_genotypes *datastore, unsigned int *counter, gsc_ParentChoice parents[static 2]) |
parentChooser function parameter for gsc_self_n_times. More... | |
static void | gsc_helper_make_offspring_self_n_times (gsc_SimData *d, union gsc_datastore_make_genotypes *datastore, gsc_ParentChoice parents[static 2], gsc_GenoLocation putHere) |
offspringGenerator function parameter for gsc_self_n_times. More... | |
gsc_GroupNum | gsc_self_n_times (gsc_SimData *d, const unsigned int n, const gsc_GroupNum group, const gsc_MapID which_map, const gsc_GenOptions g) |
Selfs each member of a group for a certain number of generations. More... | |
static void | gsc_helper_make_offspring_doubled_haploids (gsc_SimData *d, union gsc_datastore_make_genotypes *datastore, gsc_ParentChoice parents[static 2], gsc_GenoLocation putHere) |
offspringGenerator function parameter for gsc_make_doubled_haploids. More... | |
gsc_GroupNum | gsc_make_doubled_haploids (gsc_SimData *d, const gsc_GroupNum group, const gsc_MapID which_map, const gsc_GenOptions g) |
Creates a doubled haploid from each member of a group. More... | |
static int | gsc_helper_parentchooser_cloning (void *parentIterator, union gsc_datastore_make_genotypes *datastore, unsigned int *counter, gsc_ParentChoice parents[static 2]) |
parentChooser function parameter for gsc_make_clones. More... | |
static void | gsc_helper_make_offspring_clones (gsc_SimData *d, union gsc_datastore_make_genotypes *datastore, gsc_ParentChoice parents[static 2], gsc_GenoLocation putHere) |
offspringGenerator function parameter for gsc_make_clones. More... | |
gsc_GroupNum | gsc_make_clones (gsc_SimData *d, const gsc_GroupNum group, const _Bool inherit_names, gsc_GenOptions g) |
Creates an identical copy of each member of a group. More... | |
gsc_GroupNum | gsc_make_all_unidirectional_crosses (gsc_SimData *d, const gsc_GroupNum from_group, const gsc_MapID mapID, const gsc_GenOptions g) |
Perform crosses between all pairs of parents in the group from_group and allocates the resulting offspring to a new group. More... | |
gsc_GroupNum | gsc_make_n_crosses_from_top_m_percent (gsc_SimData *d, const int n, const int m, const gsc_GroupNum group, const gsc_MapID mapID, const gsc_EffectID effID, const gsc_GenOptions g) |
gsc_GroupNum | gsc_make_crosses_from_file (gsc_SimData *d, const char *input_file, const gsc_MapID map1, const gsc_MapID map2, const gsc_GenOptions g) |
Perform crosses between pairs of parents identified by name in a file and allocate the resulting offspring to a new group. More... | |
gsc_GroupNum | gsc_make_double_crosses_from_file (gsc_SimData *d, const char *input_file, const gsc_MapID map1, const gsc_MapID map2, const gsc_GenOptions g) |
Perform crosses between previously-generated offspring of pairs of parents identified by name in a file. More... | |
gsc_GroupNum | gsc_split_by_bv (gsc_SimData *d, const gsc_GroupNum group, const gsc_EffectID effID, const unsigned int top_n, const _Bool lowIsBest) |
Takes the top_n individuals in the group with the best breeding values/fitnesses and puts them in a new group. More... | |
gsc_DecimalMatrix | gsc_calculate_bvs (const gsc_SimData *d, const gsc_GroupNum group, const gsc_EffectID effID) |
Calculate the fitness metric/breeding value for every genotype in the simulation or every genotype in a certain group. More... | |
gsc_DecimalMatrix | gsc_calculate_utility_bvs (gsc_BidirectionalIterator *targets, const gsc_EffectMatrix *effset) |
Calculate the fitness metric/breeding value for a set of genotypes. More... | |
gsc_DecimalMatrix | gsc_calculate_allele_counts (const gsc_SimData *d, const gsc_GroupNum group, const char allele) |
Calculates the number of times at each marker that a particular allele appears. More... | |
void | gsc_calculate_utility_allele_counts (const unsigned int n_markers, const unsigned int n_genotypes, const char **const genotypes, const char allele, gsc_DecimalMatrix *counts) |
Calculates the number of times at each marker that a particular allele appears. More... | |
void | gsc_calculate_utility_allele_counts_pair (const unsigned int n_markers, const unsigned int n_genotypes, const char **const genotypes, const char allele, gsc_DecimalMatrix *counts, const char allele2, gsc_DecimalMatrix *counts2) |
Calculates the number of times at each marker that two particular alleles appear. More... | |
gsc_MarkerBlocks | gsc_create_evenlength_blocks_each_chr (const gsc_SimData *d, const gsc_MapID mapid, const unsigned int n) |
Divide the genotype into blocks where each block contains all markers within a 1/n length section of each chromosome in the map, and return the resulting blocks in a struct. More... | |
gsc_MarkerBlocks | gsc_load_blocks (const gsc_SimData *d, const char *block_file) |
Given a file containing definitions of blocks of markers, process that file and return a struct containing the definitions of those blocks. More... | |
void | gsc_calculate_group_local_bvs (const gsc_SimData *d, const gsc_MarkerBlocks b, const gsc_EffectID effID, const char *output_file, const gsc_GroupNum group) |
Given a set of blocks of markers in a file, for each genotype in a group, calculate the local fitness metric/breeding value for the first allele at each marker in the block, and the local fitness metric/breeding value for the second allele at each marker in the block, then save the result to a file. More... | |
void | gsc_calculate_local_bvs (const gsc_SimData *d, const gsc_MarkerBlocks b, const gsc_EffectID effID, const char *output_file) |
Given a set of blocks of markers in a file, for each genotype saved, calculate the local BV for the first allele at each marker in the block, and the local BV for the second allele at each marker in the block, then save the result to a file. More... | |
char * | gsc_calculate_optimal_haplotype (const gsc_SimData *d, const gsc_EffectID effID) |
Takes a look at the currently-loaded effect values and creates a string containing the allele with the highest effect value for each marker as ordered in the gsc_SimData. More... | |
char * | gsc_calculate_optimal_possible_haplotype (const gsc_SimData *d, const gsc_GroupNum group, const gsc_EffectID effID) |
Calculates the highest-breeding-value haplotype that can be created from the alleles present in a given group. More... | |
double | gsc_calculate_optimal_bv (const gsc_SimData *d, const gsc_EffectID effID) |
Takes a look at the currently-loaded effect values and returns the highest possible breeding value any (diploid) genotype could have using those effect values. More... | |
double | gsc_calculate_optimal_possible_bv (const gsc_SimData *d, const gsc_GroupNum group, const gsc_EffectID effID) |
Calculates the breeding value of the highest breeding-value genotype that can be created from the alleles present in a given group. More... | |
double | gsc_calculate_minimal_bv (const gsc_SimData *d, const gsc_EffectID effID) |
Takes a look at the currently-loaded effect values and returns the lowest possible breeding value any (diploid) genotype could score using those effect values. More... | |
void | gsc_save_markerblocks (const char *fname, const gsc_SimData *d, const gsc_MarkerBlocks b, const gsc_MapID labelMapID) |
Prints the markers contained in a set of blocks to a file. More... | |
void | gsc_save_genotypes (const char *fname, const gsc_SimData *d, const gsc_GroupNum groupID, const _Bool markers_as_rows) |
Prints genotypes from the simulation to a file. More... | |
void | gsc_save_allele_counts (const char *fname, const gsc_SimData *d, const gsc_GroupNum groupID, const char allele, const _Bool markers_as_rows) |
Prints allele counts of genotypes from the simulation to a file. More... | |
void | gsc_save_pedigrees (const char *fname, const gsc_SimData *d, const gsc_GroupNum groupID, const _Bool full_pedigree) |
Prints pedigrees of genotypes in the simulation to a file. More... | |
void | gsc_save_bvs (const char *fname, const gsc_SimData *d, const gsc_GroupNum groupID, const gsc_EffectID effID) |
Prints breeding values of genotypes in the simulation to a file. More... | |
static GSC_LOGICVAL | gsc_helper_is_marker_in_chr (const unsigned int markerix, const gsc_LinkageGroup chr, double *pos) |
Check if a marker index is found in a particular LinkageGroup, and provide its distance along the chromosome/linkage group if so. More... | |
void | gsc_save_utility_markerblocks (FILE *f, const gsc_MarkerBlocks b, const unsigned int n_markers, char **const marker_names, const gsc_RecombinationMap *map) |
Prints the markers contained in a set of blocks to a file. More... | |
static void | gsc_scaffold_save_genotype_info (FILE *f, gsc_BidirectionalIterator *targets, unsigned int n_markers, char **const marker_names, const _Bool markers_as_rows, void(*bodycell_printer)(FILE *, gsc_GenoLocation, unsigned int, void *), void *bodycell_printer_data) |
Prints a matrix of genotype information to a file. More... | |
static void | gsc_helper_output_genotypematrix_cell (FILE *f, gsc_GenoLocation loc, unsigned int markerix, void *GSC_NA) |
Kernel for gsc_scaffold_save_genotype_info, when the goal is to save the (phased) allele pairs of each genotype. More... | |
static void | gsc_helper_output_countmatrix_cell (FILE *f, gsc_GenoLocation loc, unsigned int markerix, void *data) |
Kernel for gsc_scaffold_save_genotype_info, when the goal is to save the allele counts of a particular allele for each genetic marker. More... | |
void | gsc_save_utility_genotypes (FILE *f, gsc_BidirectionalIterator *targets, unsigned int n_markers, char **const marker_names, const _Bool markers_as_rows) |
Prints simulated genotypes to a file. More... | |
void | gsc_save_utility_allele_counts (FILE *f, gsc_BidirectionalIterator *targets, unsigned int n_markers, char **const marker_names, const _Bool markers_as_rows, const char allele) |
Prints allele counts of simulated genotypes to a file. More... | |
static void | gsc_scaffold_save_ancestry_of (const gsc_AlleleMatrix *m, gsc_PedigreeID p1, gsc_PedigreeID p2, void(*strprinter)(char *, size_t, void *), void(*intprinter)(long unsigned int, void *), void *printer_data) |
Identifies and saves (recursively) the pedigree of a pair of parents. More... | |
static void | gsc_helper_ancestry_strprinter_file (char *str, size_t strlen, void *data) |
Kernel for scaffold functions that require printing a string to a file (as opposed to saving the string in a different place) More... | |
static void | gsc_helper_ancestry_intprinter_file (long unsigned int i, void *data) |
Kernel for scaffold functions that require printing an integer to a file (as opposed to saving the integer in a different place) More... | |
void | gsc_save_utility_pedigrees (FILE *f, gsc_BidirectionalIterator *targets, const _Bool full_pedigree, const gsc_AlleleMatrix *parent_pedigree_store) |
Prints pedigrees to a file. More... | |
void | gsc_save_utility_bvs (FILE *f, gsc_BidirectionalIterator *targets, const gsc_EffectMatrix *eff) |
Calculate and print breeding values to a file. More... | |
Variables | |
const gsc_GenOptions | GSC_BASIC_OPT |
Default parameter values for GenOptions, to help with quick scripts and prototypes. More... | |
#define SIM_OPERATIONS |
Definition at line 2 of file sim-operations.c.
|
static |
Create a new gsc_EmptyListNavigator, including an empty AlleleMatrix suitable for inserting into the provided SimData once the emptylist is finalised.
Definition at line 6300 of file sim-operations.c.
|
static |
Push emptylist edited genotypes into the SimData.
This is the expected final step in use of gsc_EmptyListNavigator
Definition at line 6375 of file sim-operations.c.
|
static |
Reset the cursor of a gsc_EmptyListNavigator to the first genotype.
Definition at line 6317 of file sim-operations.c.
|
static |
Get the next sequential genotype in an gsc_EmptyListNavigator.
Definition at line 6336 of file sim-operations.c.
|
static |
Kernel for scaffold functions that require printing an integer to a file (as opposed to saving the integer in a different place)
Definition at line 10777 of file sim-operations.c.
|
static |
Kernel for scaffold functions that require printing a string to a file (as opposed to saving the string in a different place)
Definition at line 10770 of file sim-operations.c.
|
static |
Comparator function for qsort.
Used to compare a pair of doubles to sort in ascending order
Sorts lower numbers before higher numbers. If they are equal, their order after comparison is undefined.
Definition at line 1147 of file sim-operations.c.
|
static |
Comparator function for qsort.
Used to compare a pair of doubles* to sort them in ascending order of the doubles they point to.
Sorts lower numbers before higher numbers. If they are equal, their order after comparison is undefined.
Definition at line 1164 of file sim-operations.c.
|
static |
Comparator function for qsort.
Used to compare a pair of doubles* to sort them in descending order of the doubles they point to.
Sorts higher numbers before lower numbers. If they are equal, their order after comparison is undefined.
Definition at line 1131 of file sim-operations.c.
|
static |
Apply gsc_GenOptions naming scheme and gsc_PedigreeID allocation to a single gsc_AlleleMatrix.
Definition at line 7778 of file sim-operations.c.
|
static |
save-as-you-go (breeding values)
Calculates and saves breeding values of genotypes in an gsc_AlleleMatrix to a file. Performs null-checks on file pointer and effIndex, and fails silently if checks do.
Definition at line 7752 of file sim-operations.c.
|
static |
Opens file for writing save-as-you-go breeding values in accordance with gsc_GenOptions.
effIndexp | a location to save the index of the chosen effect set. It will be set to GSC_NA_IDX if the effect set ID in g was invalid. |
Definition at line 7692 of file sim-operations.c.
|
static |
save-as-you-go (genotypes/alleles)
Saves genotypes in an gsc_AlleleMatrix to a file. Performs null-checks on file pointer and fails silently if checks do.
Definition at line 7767 of file sim-operations.c.
|
static |
Opens file for writing save-as-you-go genotypes in accordance with gsc_GenOptions.
Definition at line 7713 of file sim-operations.c.
|
static |
save-as-you-go (pedigrees)
Saves pedigrees in gsc_AlleleMatrix tosave to a file. Performs null-checks on file pointer fp, and fails silently if checks do.
Definition at line 7737 of file sim-operations.c.
|
static |
Opens file for writing save-as-you-go pedigrees in accordance with gsc_GenOptions.
Definition at line 7672 of file sim-operations.c.
|
static |
Identify what formatting a genotype matrix is representing alleles as.
For IUPAC encoding: https://genome.ucsc.edu/goldenPath/help/iupac.html
Definition at line 6149 of file sim-operations.c.
|
static |
Parse a string and save it as the alleles of a genotype at a particular location and genetic marker.
If the style in which the allele string is encoded does not denote phase, linkage phase is randomly chosen.
Definition at line 6208 of file sim-operations.c.
|
static |
Determine the style in which alleles are stored in a genotype matrix.
cellqueue | array of cells read from the matrix. It should contain at least one body cell, if the matrix has any boy cells: that is, at least two cells if format.has_header is false, or an entire first row plus two cells if format.has_header is unknown or true. |
firstrowlen | number of cells in the first row of the matrix. |
queuelen | number of cells saved sequentially in cellqueue. It is assumed that queuelen >= firstrowlen. |
format | established details about the formatting of the genotype matrix |
filenameforlog | The name of the matrix file or other identifier for this matrix that should be used when printing out logging information. |
Definition at line 6496 of file sim-operations.c.
|
static |
Determine whether a genotype matrix has a corner cell or not.
A corner cell is a non-blank value in the first-row/first-column of the matrix, if the matrix has both a header row and header column.
ncellsfirstrow | number of cells in the first row of the matrix. |
ncellssecondrow | number of cells in the second row of the matrix. |
secondrowheaderisempty | truthy if the value in the first column of the second row of the matrix is blank, falsy if there is a non-blank value in the first cell of that second row of the matrix. (note: genomicSimulation's TableFileReader takes any blank space (including spaces at the beginning of a row) as cell dividers. That interface is the assumed input for calculating these parameters). |
Definition at line 6638 of file sim-operations.c.
|
static |
Determine whether a genotype matrix has a header row or not.
It is assumed that, during the detection process,
This function does not guarantee that the returned format has a known (true or false) has_header field. has_header may still be unknown.
The decision as to whether the genotype matrix has a header row is based on:
cellqueue | array of cells read from the matrix. It should contain at least two cells, and ideally the whole of the first row of the matrix. |
firstrowlen | number of cells in the first row of the matrix. |
queuelen | number of cells saved sequentially in cellqueue. It is assumed that queuelen >= firstrowlen. |
format | established details about the formatting of the genotype matrix |
filenameforlog | The name of the matrix file or other identifier for this matrix that should be used when printing out logging information. |
Definition at line 6576 of file sim-operations.c.
|
static |
Determine whether a genotype matrix is row- or column-oriented.
The decision of whether a genotype matrix is storing markers as columns or rows is based on the following factors:
genomicSimulation requires marker names for file loading, so if markers are represented by columns in the matrix, the format specifier returned will also specify that the matrix does have a header row.
d | SimData object the genotype file is assumed to be loaded to. Required because determining matrix orientation requires checking marker names against the markers tracked in the SimData. |
cellqueue | array of cells read from the matrix. Requires at least the first row of the matrix, preferably the first row of the matrix plus the first two cells (header and first body cell) of the second row of the matrix. |
firstrowlen | number of cells in the first row of the matrix. These cells can be accessed at indices 0-{firstrowlen-1} in cellqueue. |
queuelen | number of cells saved sequentially in cellqueue. It is assumed that queuelen >= firstrowlen. |
format | established details about the formatting of the genotype matrix |
filenameforlog | The name of the matrix file or other identifier for this matrix that should be used when printing out logging information. |
Definition at line 6415 of file sim-operations.c.
|
static |
Comparator function for qsort.
Used to compare a pair of pointers to strings to sort them in alphabetical order of the strings.
Definition at line 1177 of file sim-operations.c.
|
static |
Save an EffectMatrix to the SimData and allocate it an EffectID.
Definition at line 5569 of file sim-operations.c.
|
static |
Save a RecombinationMap to the SimData and allocate it a mapID.
Definition at line 5541 of file sim-operations.c.
|
static |
Check if a marker index is found in a particular LinkageGroup, and provide its distance along the chromosome/linkage group if so.
Definition at line 10274 of file sim-operations.c.
|
static |
offspringGenerator function parameter for gsc_make_clones.
Generates new alleles by making a clone of its parent. Only looks at the first parent and does not check it is valid.
Definition at line 8707 of file sim-operations.c.
|
static |
offspringGenerator function parameter for all crossing functions
Generates new alleles from two separate parents. Does not check they are valid parents.
datastore parameter goes unused
Definition at line 8026 of file sim-operations.c.
|
static |
offspringGenerator function parameter for gsc_make_doubled_haploids.
Generates new alleles by making a doubled haploid. Only looks at the first parent and does not check it is valid.
Definition at line 8608 of file sim-operations.c.
|
static |
offspringGenerator function parameter for gsc_self_n_times.
Datastore should be a pointer to an unsigned int containing the number of generations to self for.
Generates new alleles by selfing from one parent. Only looks at the first parent and does not check it is valid.
Definition at line 8510 of file sim-operations.c.
|
static |
Comparator function for qsort.
Used to compare a pair of gsc_MapFileUnits to sort them in ascending order of chromosome number.
Definition at line 1186 of file sim-operations.c.
|
static |
Comparator function for qsort.
Used to compare a pair of gsc_MapFileUnits to sort them in ascending order of position.
Definition at line 1196 of file sim-operations.c.
|
static |
Kernel for gsc_scaffold_save_genotype_info, when the goal is to save the allele counts of a particular allele for each genetic marker.
Definition at line 10569 of file sim-operations.c.
|
static |
Kernel for gsc_scaffold_save_genotype_info, when the goal is to save the (phased) allele pairs of each genotype.
Definition at line 10558 of file sim-operations.c.
|
static |
parentChooser function parameter for gsc_make_clones.
Very similar to gsc_helper_parentchooser_selfing, but also accesses the datastore to see if it needs to inherit the name from its parent.
Locates the next group member. Guarantees parents contains two valid gsc_GenoLocations (which are the same) at the time it returns a truthy value.
Definition at line 8680 of file sim-operations.c.
|
static |
parentChooser function parameter for gsc_make_random_crosses.
Chooses parents randomly without overruning parent usage caps and without permitting selfing. Guarantees parents contains two valid gsc_GenoLocations at the time it returns a truthy value.
Definition at line 7974 of file sim-operations.c.
|
static |
parentChooser function parameter for gsc_make_random_crosses_between.
Chooses parents randomly without overruning parent usage caps and without permitting selfing. First and second parent come from different groups and may have different usage caps. Guarantees parents contains two valid gsc_GenoLocations at the time it returns a truthy value.
Definition at line 8204 of file sim-operations.c.
|
static |
parentChooser function parameter for gsc_make_targeted_crosses.
Locates the next pair of parents in the provided sequence of combinations. Guarantees parents contains two valid gsc_GenoLocations at the time it returns a truthy value.
Definition at line 8361 of file sim-operations.c.
|
static |
parentChooser function parameter for gsc_self_n_times.
Locates the next group member. Guarantees parents contains two valid gsc_GenoLocations (which are the same) at the time it returns a truthy value.
Definition at line 8486 of file sim-operations.c.
|
static |
Header row reading and processing for map and effect set files.
Task 1: identifies if there is a header (in which case the returned queue will not contain the header cells) or there is no header (in which case the returned queue will contain the first row of cells).
The first three cells are identified as a header row if there is a newline after the third cell (and none between the first three cells), and the entries in those three header cells correspond to the strings in the canonical_titles parameter, in any order. If the first row does match the requirements of a header row, the ordering of those canonical_titles in the header row will be saved to col_order.
The function returns the number of cells read but not processed. These cells read but not processed (i.e. not any identified header cells) will be saved to unprocessedqueue. At maximum 4 cells will be read, so unprocessedqueue must be a pointer with a location for space for at least 4 TableFileCells.
canonical_titles | vector of three column titles, which the three potential header cells will be matched against |
col_order | if the first row is determined to be a header row, entry i in this vector will be filled with the column number (1, 2, or 3) that corresponds to the i-th title in canonical_titles |
unprocessedqueue | vector of length at least 4 which will be overwritten with the cells that were read but determined to not be part of the header. |
queuesize | space to save number of entries in the queue unprocessedqueue after execution of this function |
Definition at line 5285 of file sim-operations.c.
|
static |
Extract the contents of a genetic map file.
By default, the file's columns are assumed to be in the order:
Marker names may contain any characters except tabs, spaces, commas, and newlines. Chromosome names must be integers (eg 1) or alphanumeric strings (eg 1A). Positions should be able to be parsed as a floating point number by the compiling computer's C standard library (usually allows integers, decimals, and scientific notation, but not fractions).
Columns may be space-separated or tab-separated. Column separators need not be consistent throughout the file, and may be repeated. That is, any consecutive sequence of spaces and tabs is interpreted as one column separator. Any single or consecutive pair of '
' and '\r' characters are inferred as representing a newline. Like with column separators, there is no requirement for consistency across the file in which character or pair of characters represents the end of a row.
In the current implementation, it attempts to load the entire file into memory at a time, so the system must have enough memory to hold the file if it is to run this function.
filename | name of the file to parse |
out | location to save a heap-allocated vector containing the contents of each line of the file. |
Definition at line 5375 of file sim-operations.c.
|
static |
Check input parameters of random crossing functions.
(helper function)
Definition at line 8040 of file sim-operations.c.
|
static |
Sort markerlist by chromosome name, and by position within each chromosome.
n_markers | length of markerlist |
markerlist | list of MapFileUnits to sort Could return number of unique chromosomes found in the markerlist, but we aren't worried about that level of performance right now. |
Definition at line 5601 of file sim-operations.c.
|
static |
|
static |
|
static |
|
static |
Definition at line 2908 of file sim-operations.c.
|
static |
Definition at line 2827 of file sim-operations.c.
|
static |
Definition at line 2836 of file sim-operations.c.
|
static |
|
static |
|
static |
Discard markers whose names are not present in a gsc_KnownGenome.
All markers in the genome g are retained in the list. All markers not in that genome are freed and deleted from the markerlist. The new length of the marker list after deletions is returned.
Markers without names to join on are discarded.
g | genome object containing the list of markers to compare markers in markerlist against |
n_markers_in_list | length of markerlist |
markerlist | Pointer to a list of name/chromosome/position entries for various markers. Only the names will be read, but for each entry, if its name does not exist in the list of markers to keep, the entry will be deleted and the remainder of the marker list shuffled backwards. Markers without names are automatically discarded. |
Definition at line 5510 of file sim-operations.c.
|
static |
Return the next cell from a queue of cells until the queue is exhausted, and thereafter read new cells from a TableFileReader.
queue | pointer to queue containing queuesize TableFileCells. The pointer will be updated to point one cell forwards (so that it still points to the 'start' of the queue) if the item returned comes from the queue. |
queuesize | number of entries remaining in the queue. Will be updated to be one fewer if the item returned comes from the queue |
Definition at line 5240 of file sim-operations.c.
|
static |
Loads a genotype file, with or without existing genome model in the SimData.
First, it reads the first row to determine if it is a header or not. This, and early information from the second row, can be used to determine:
Definition at line 6706 of file sim-operations.c.
gsc_GroupNum gsc_make_n_crosses_from_top_m_percent | ( | gsc_SimData * | d, |
const int | n, | ||
const int | m, | ||
const gsc_GroupNum | group, | ||
const gsc_MapID | mapID, | ||
const gsc_EffectID | effID, | ||
const gsc_GenOptions | g | ||
) |
Definition at line 8824 of file sim-operations.c.
|
static |
Replace calls to malloc direct with this function.
size | size of space to be allocated. Treat like the parameter of a regular malloc call. |
exitonfail | if truthy, if memory allocation fails it will terminate execution. if falsy, on memory allocation failure it will only print an error message and return NULL (useful, for example, if the calling function wants to add its own error message, or return partial results even if it fails here). |
Definition at line 34 of file sim-operations.c.
|
static |
Sets the current cursor position in a gsc_GappyIterator to the next empty position, if the cursor is not already an empty position.
Empty positions do not contain genotypes. This function does not change the cursor position if the curstor is already on a gap.
Definition at line 1291 of file sim-operations.c.
|
static |
Sets the current cursor position in a gsc_GappyIterator to the next filled position, if the cursor is not already a filled position.
Non-gap positions do contain genotypes. This function does not change the cursor position if the curstor is already on a non-gap.
Definition at line 1320 of file sim-operations.c.
|
static |
Sets the current cursor position in a gsc_GappyIterator to the next valid position, if the cursor is not already a valid position.
Valid positions in the linked list of AlleleMatrices may contain genotypes or not.
Definition at line 1271 of file sim-operations.c.
|
static |
Identifies and saves (recursively) the pedigree of a pair of parents.
This is a generic scaffold for the following functions:
Definition at line 10703 of file sim-operations.c.
|
static |
Prints a matrix of genotype information to a file.
This is a generic scaffold for the following functions:
Definition at line 10437 of file sim-operations.c.
|
static |
Fills the designated section of the .names
array in an gsc_AlleleMatrix with the pattern "`prefix`index".
In future this function could be expanded to allow for different naming formats.
The index is padded with zeros depending on the size of a->n_genotypes
.
a | pointer to the gsc_AlleleMatrix whose .names to modify |
prefix | the prefix to add to the suffix to make the new genotype name |
suffix | suffixes start at this value and increment for each additional name |
from_index | the new names are added to this index and all those following it in this gsc_AlleleMatrix. |
Definition at line 580 of file sim-operations.c.