Skip to content

Commit

Permalink
tskit update to C_1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
petrelharp committed Nov 8, 2023
1 parent 5e8f2e9 commit 25199ac
Show file tree
Hide file tree
Showing 11 changed files with 2,328 additions and 507 deletions.
1 change: 1 addition & 0 deletions treerec/_README
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The code in `tskit/kastore` is from [kastore/c](https://github.com/tskit-dev/kas

**Changelog:**

- *7 November 2023*: updated to tskit C_1.1.2 (=0.5.5) and kastore 0.3.2)
- *2 June 2022*: updated to tskit C_1.0.0 and kastore C_2.1.1
- *5 September 2020*: updated to tskit C_0.99.5
- *27 August 2020*: updated to tskit C_0.99.5
Expand Down
41 changes: 36 additions & 5 deletions treerec/tskit/core.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019-2022 Tskit Developers
* Copyright (c) 2019-2023 Tskit Developers
* Copyright (c) 2015-2018 University of Oxford
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -222,6 +222,10 @@ tsk_strerror_internal(int err)
case TSK_ERR_SEEK_OUT_OF_BOUNDS:
ret = "Tree seek position out of bounds. (TSK_ERR_SEEK_OUT_OF_BOUNDS)";
break;
case TSK_ERR_KEEP_ROWS_MAP_TO_DELETED:
ret = "One of the kept rows in the table refers to a deleted row. "
"(TSK_ERR_KEEP_ROWS_MAP_TO_DELETED)";
break;

/* Edge errors */
case TSK_ERR_NULL_PARENT:
Expand Down Expand Up @@ -265,7 +269,8 @@ tsk_strerror_internal(int err)
break;
case TSK_ERR_BAD_EDGES_CONTRADICTORY_CHILDREN:
ret = "Bad edges: contradictory children for a given parent over "
"an interval. (TSK_ERR_BAD_EDGES_CONTRADICTORY_CHILDREN)";
"an interval, or indexes need to be rebuilt. "
"(TSK_ERR_BAD_EDGES_CONTRADICTORY_CHILDREN)";
break;
case TSK_ERR_CANT_PROCESS_EDGES_WITH_METADATA:
ret = "Can't squash, flush, simplify or link ancestors with edges that have "
Expand Down Expand Up @@ -336,7 +341,7 @@ tsk_strerror_internal(int err)
ret = "Duplicate sample value. (TSK_ERR_DUPLICATE_SAMPLE)";
break;
case TSK_ERR_BAD_SAMPLES:
ret = "Bad sample configuration provided. (TSK_ERR_BAD_SAMPLES)";
ret = "The nodes provided are not samples. (TSK_ERR_BAD_SAMPLES)";
break;

/* Table errors */
Expand All @@ -350,8 +355,13 @@ tsk_strerror_internal(int err)
case TSK_ERR_TABLES_NOT_INDEXED:
ret = "Table collection must be indexed. (TSK_ERR_TABLES_NOT_INDEXED)";
break;
case TSK_ERR_TABLES_BAD_INDEXES:
ret = "Table collection indexes inconsistent: do they need to be rebuilt? "
"(TSK_ERR_TABLES_BAD_INDEXES)";
break;
case TSK_ERR_TABLE_OVERFLOW:
ret = "Table too large; cannot allocate more than 2**31 rows. "
ret = "Table too large; cannot allocate more than 2**31 rows. This error "
"is often caused by a lack of simplification when simulating. "
"(TSK_ERR_TABLE_OVERFLOW)";
break;
case TSK_ERR_COLUMN_OVERFLOW:
Expand Down Expand Up @@ -408,6 +418,14 @@ tsk_strerror_internal(int err)
ret = "A tree sequence can't take ownership of tables with "
"TSK_NO_EDGE_METADATA. (TSK_ERR_CANT_TAKE_OWNERSHIP_NO_EDGE_METADATA)";
break;
case TSK_ERR_UNDEFINED_NONBINARY:
ret = "Operation undefined for nonbinary trees. "
"(TSK_ERR_UNDEFINED_NONBINARY)";
break;
case TSK_ERR_UNDEFINED_MULTIROOT:
ret = "Operation undefined for trees that are not singly-rooted. "
"(TSK_ERR_UNDEFINED_MULTIROOT)";
break;

/* Stats errors */
case TSK_ERR_BAD_NUM_WINDOWS:
Expand Down Expand Up @@ -500,7 +518,8 @@ tsk_strerror_internal(int err)
break;
case TSK_ERR_NO_SAMPLE_LISTS:
ret = "The sample_lists option must be enabled on the tree to perform this "
"operation. (TSK_ERR_NO_SAMPLE_LISTS)";
"operation. Pass the option to the constructor or method that created "
"the tree. (TSK_ERR_NO_SAMPLE_LISTS)";
break;

/* Haplotype matching errors */
Expand Down Expand Up @@ -571,6 +590,18 @@ tsk_strerror_internal(int err)
ret = "Individuals cannot be their own ancestor. "
"(TSK_ERR_INDIVIDUAL_PARENT_CYCLE)";
break;

case TSK_ERR_INDIVIDUAL_POPULATION_MISMATCH:
ret = "Individual populations cannot be returned "
"if an individual has nodes from more than one population. "
"(TSK_ERR_INDIVIDUAL_POPULATION_MISMATCH)";
break;

case TSK_ERR_INDIVIDUAL_TIME_MISMATCH:
ret = "Individual times cannot be returned "
"if an individual has nodes from more than one time. "
"(TSK_ERR_INDIVIDUAL_TIME_MISMATCH)";
break;
}
return ret;
}
Expand Down
62 changes: 50 additions & 12 deletions treerec/tskit/core.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019-2022 Tskit Developers
* Copyright (c) 2019-2023 Tskit Developers
* Copyright (c) 2015-2018 University of Oxford
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -123,6 +123,15 @@ specify options to API functions.
typedef uint32_t tsk_flags_t;
#define TSK_FLAGS_STORAGE_TYPE KAS_UINT32

/**
@brief Boolean type.
@rst
Fixed-size (1 byte) boolean values.
@endrst
*/
typedef uint8_t tsk_bool_t;

// clang-format off
/**
@defgroup API_VERSION_GROUP API version macros.
Expand All @@ -138,12 +147,12 @@ sizes and types of externally visible structs.
The library minor version. Incremented when non-breaking backward-compatible changes
to the API or ABI are introduced, i.e., the addition of a new function.
*/
#define TSK_VERSION_MINOR 0
#define TSK_VERSION_MINOR 1
/**
The library patch version. Incremented when any changes not relevant to the
to the API or ABI are introduced, i.e., internal refactors of bugfixes.
*/
#define TSK_VERSION_PATCH 0
#define TSK_VERSION_PATCH 2
/** @} */

/*
Expand Down Expand Up @@ -172,12 +181,12 @@ Used in node flags to indicate that a node is a sample node.
*/
#define TSK_NODE_IS_SAMPLE 1u

/**
/**
Null value used for cases such as absent id references.
*/
#define TSK_NULL ((tsk_id_t) -1)

/**
/**
Value used for missing data in genotype arrays.
*/
#define TSK_MISSING_DATA (-1)
Expand Down Expand Up @@ -206,7 +215,7 @@ whose representation differs from the NAN generated by computations such as divi

/* Place the common options at the top of the space; this way we can start
options for individual functions at the bottom without worrying about
clashing with the common options
clashing with the common options
*/

/** Turn on debugging output. Not supported by all functions. */
Expand All @@ -224,7 +233,7 @@ behaviour.
*/
#define TSK_NO_CHECK_INTEGRITY (1u << 29)

/**
/**
Instead of taking a copy of input objects, the function should take ownership
of them and manage their lifecycle. The caller specifying this flag should no
longer modify or free the object or objects passed. See individual functions
Expand Down Expand Up @@ -356,6 +365,12 @@ A time value was non-finite (NaN counts as finite)
A genomic position was non-finite
*/
#define TSK_ERR_GENOME_COORDS_NONFINITE -211
/**
One of the rows in the retained table refers to a row that has been
deleted.
*/
#define TSK_ERR_KEEP_ROWS_MAP_TO_DELETED -212

/** @} */

/**
Expand Down Expand Up @@ -543,6 +558,10 @@ The table collection contains more than 2**31 trees.
Metadata was attempted to be set on a table where it is disabled.
*/
#define TSK_ERR_METADATA_DISABLED -706
/**
There was an error with the table's indexes.
*/
#define TSK_ERR_TABLES_BAD_INDEXES -707
/** @} */

/**
Expand Down Expand Up @@ -595,13 +614,22 @@ A tree sequence cannot take ownership of a table collection where
TSK_NO_EDGE_METADATA.
*/
#define TSK_ERR_CANT_TAKE_OWNERSHIP_NO_EDGE_METADATA -809
/**
Operation is undefined for nonbinary trees
*/
#define TSK_ERR_UNDEFINED_NONBINARY -810
/**
Operation is undefined for trees with multiple roots.
*/
#define TSK_ERR_UNDEFINED_MULTIROOT -811

/** @} */

/**
@defgroup STATS_ERROR_GROUP Stats errors.
@{
*/
/**
/**
Zero windows were specified, at least one window must be specified.
*/
#define TSK_ERR_BAD_NUM_WINDOWS -900
Expand Down Expand Up @@ -653,17 +681,17 @@ were ``uncalibrated``.
@defgroup MAPPING_ERROR_GROUP Mutation mapping errors.
@{
*/
/**
/**
Only missing genotypes were specified, at least one non-missing is
required.
*/
#define TSK_ERR_GENOTYPES_ALL_MISSING -1000
/**
/**
A genotype value was greater than the maximum allowed (64) or less
than TSK_MISSING_DATA (-1).
*/
#define TSK_ERR_BAD_GENOTYPE -1001
/**
/**
A ancestral genotype value was greater than the maximum allowed (64) or less
than 0.
*/
Expand Down Expand Up @@ -760,7 +788,7 @@ specified table collection.
/**
The shared portions of the specified tree sequences are not equal.
Note that this may be the case if the table collections were not
fully sorted before union was called.
fully sorted before union was called.
*/
#define TSK_ERR_UNION_DIFF_HISTORIES -1401
/** @} */
Expand Down Expand Up @@ -812,6 +840,16 @@ An individual was its own parent.
An individual was its own ancestor in a cycle of references.
*/
#define TSK_ERR_INDIVIDUAL_PARENT_CYCLE -1702
/**
An individual had nodes from more than one population
(and only one was requested).
*/
#define TSK_ERR_INDIVIDUAL_POPULATION_MISMATCH -1703
/**
An individual had nodes from more than one time
(and only one was requested).
*/
#define TSK_ERR_INDIVIDUAL_TIME_MISMATCH -1704
/** @} */
// clang-format on

Expand Down
26 changes: 15 additions & 11 deletions treerec/tskit/genotypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ tsk_variant_decode(
tsk_id_t allele_index;
tsk_size_t j, num_missing;
int no_longer_missing;

tsk_mutation_t mutation;
bool impute_missing = !!(self->options & TSK_ISOLATED_NOT_MISSING);
bool by_traversal = self->alt_samples != NULL;
Expand All @@ -485,7 +484,7 @@ tsk_variant_decode(
goto out;
}

/* When we have a no specified samples we need sample lists to be active
/* When we have no specified samples we need sample lists to be active
* on the tree, as indicated by the presence of left_sample */
if (!by_traversal && self->tree.left_sample == NULL) {
ret = TSK_ERR_NO_SAMPLE_LISTS;
Expand Down Expand Up @@ -582,11 +581,11 @@ tsk_variant_restricted_copy(const tsk_variant_t *self, tsk_variant_t *other)
tsk_size_t total_len, offset, j;

/* Copy everything */
tsk_memcpy(other, self, sizeof(tsk_variant_t));
tsk_memcpy(other, self, sizeof(*other));
/* Tree sequence left as NULL and zero'd tree is a way of indicating this variant is
* fixed and cannot be further decoded. */
other->tree_sequence = NULL;
tsk_memset(&other->tree, sizeof(tsk_tree_t), 0);
tsk_memset(&other->tree, sizeof(other->tree), 0);
other->traversal_stack = NULL;
other->samples = NULL;
other->sample_index_map = NULL;
Expand All @@ -598,27 +597,32 @@ tsk_variant_restricted_copy(const tsk_variant_t *self, tsk_variant_t *other)
for (j = 0; j < self->num_alleles; j++) {
total_len += self->allele_lengths[j];
}
other->genotypes = tsk_malloc(other->num_samples * sizeof(int32_t));
other->user_alleles_mem = tsk_malloc(total_len * sizeof(char *));
other->samples = tsk_malloc(other->num_samples * sizeof(*other->samples));
other->genotypes = tsk_malloc(other->num_samples * sizeof(*other->genotypes));
other->user_alleles_mem = tsk_malloc(total_len * sizeof(*other->user_alleles_mem));
other->allele_lengths
= tsk_malloc(other->num_alleles * sizeof(*other->allele_lengths));
other->alleles = tsk_malloc(other->num_alleles * sizeof(*other->alleles));
if (other->genotypes == NULL || other->user_alleles_mem == NULL
|| other->allele_lengths == NULL || other->alleles == NULL) {
if (other->samples == NULL || other->genotypes == NULL
|| other->user_alleles_mem == NULL || other->allele_lengths == NULL
|| other->alleles == NULL) {
ret = TSK_ERR_NO_MEMORY;
goto out;
}

tsk_memcpy(other->genotypes, self->genotypes, other->num_samples * sizeof(int32_t));
tsk_memcpy(
other->samples, self->samples, other->num_samples * sizeof(*other->samples));
tsk_memcpy(other->genotypes, self->genotypes,
other->num_samples * sizeof(*other->genotypes));
tsk_memcpy(other->allele_lengths, self->allele_lengths,
other->num_alleles * sizeof(*other->allele_lengths));
offset = 0;
for (j = 0; j < other->num_alleles; j++) {
tsk_memcpy(other->user_alleles_mem + offset, self->alleles[j],
other->allele_lengths[j] * sizeof(char *));
other->allele_lengths[j] * sizeof(*other->user_alleles_mem));
other->alleles[j] = other->user_alleles_mem + offset;
offset += other->allele_lengths[j];
}

out:
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions treerec/tskit/haplotype_matching.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019-2022 Tskit Developers
* Copyright (c) 2019-2023 Tskit Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -250,7 +250,7 @@ tsk_ls_hmm_reset(tsk_ls_hmm_t *self)

/* This is safe because we've already zero'd out the memory. */
tsk_diff_iter_free(&self->diffs);
ret = tsk_diff_iter_init(&self->diffs, self->tree_sequence, false);
ret = tsk_diff_iter_init_from_ts(&self->diffs, self->tree_sequence, false);
if (ret != 0) {
goto out;
}
Expand Down
Loading

0 comments on commit 25199ac

Please sign in to comment.