Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def dump_tables(self):
"""
A copy of the tables defining this tree sequence.
:return: A :class:`.TableCollection` containing all tables underlying
the tree sequence.
:rtype: TableCollection
"""
t = tables.TableCollection(sequence_length=self.sequence_length)
self._ll_tree_sequence.dump_tables(t.ll_tables)
return t
def dump_tables(self):
"""
A copy of the tables defining this tree sequence.
:return: A :class:`.TableCollection` containing all tables underlying
the tree sequence.
:rtype: TableCollection
"""
t = tables.TableCollection(sequence_length=self.sequence_length)
self._ll_tree_sequence.dump_tables(t.ll_tables)
return t
:param bool strict: If True, require strict tab delimiting (default). If
False, a relaxed whitespace splitting algorithm is used.
:param string encoding: Encoding used for text representation.
:param bool base64_metadata: If True, metadata is encoded using Base64
encoding; otherwise, as plain text.
:return: The tree sequence object containing the information
stored in the specified file paths.
:rtype: :class:`tskit.TreeSequence`
"""
# We need to parse the edges so we can figure out the sequence length, and
# TableCollection.sequence_length is immutable so we need to create a temporary
# edge table.
edge_table = parse_edges(edges, strict=strict)
if sequence_length == 0 and len(edge_table) > 0:
sequence_length = edge_table.right.max()
tc = tables.TableCollection(sequence_length)
tc.edges.set_columns(
left=edge_table.left, right=edge_table.right, parent=edge_table.parent,
child=edge_table.child)
parse_nodes(
nodes, strict=strict, encoding=encoding, base64_metadata=base64_metadata,
table=tc.nodes)
# We need to add populations any referenced in the node table.
if len(tc.nodes) > 0:
max_population = tc.nodes.population.max()
if max_population != NULL:
for _ in range(max_population + 1):
tc.populations.add_row()
if sites is not None:
parse_sites(
sites, strict=strict, encoding=encoding, base64_metadata=base64_metadata,
table=tc.sites)
return TableCollection, tuple(), state
# Pickle support for the various tables. We are forced to use copyreg.pickle
# here to support Python 2. For Python 3, we can just use the __setstate__.
# It would be cleaner to attach the pickle_*_table functions to the classes
# themselves, but this causes issues with Mocking on readthedocs. Sigh.
copyreg.pickle(IndividualTable, _pickle_individual_table)
copyreg.pickle(NodeTable, _pickle_node_table)
copyreg.pickle(EdgeTable, _edge_table_pickle)
copyreg.pickle(MigrationTable, _migration_table_pickle)
copyreg.pickle(SiteTable, _site_table_pickle)
copyreg.pickle(MutationTable, _mutation_table_pickle)
copyreg.pickle(PopulationTable, _population_table_pickle)
copyreg.pickle(ProvenanceTable, _provenance_table_pickle)
copyreg.pickle(TableCollection, _table_collection_pickle)
#############################################
# Table functions.
#############################################
def sort_tables(
nodes, edges, migrations=None, sites=None, mutations=None,
provenances=None, individuals=None, populations=None, edge_start=0):
"""
**This function is deprecated. Please use TableCollection.sort() instead**
Sorts the given tables **in place**, ensuring that all tree
sequence ordering requirements are met. See
the :ref:`sec_valid_tree_sequence_requirements` section for details on these
def _table_collection_pickle(tables):
state = {
"sequence_length": tables.sequence_length,
"individuals": tables.individuals,
"populations": tables.populations,
"nodes": tables.nodes,
"edges": tables.edges,
"migrations": tables.migrations,
"sites": tables.sites,
"mutations": tables.mutations,
"provenances": tables.provenances,
}
return TableCollection, tuple(), state
kwargs["mutations"] = _tskit.MutationTable()
if provenances is not None:
kwargs["provenances"] = provenances.ll_table
else:
kwargs["provenances"] = _tskit.ProvenanceTable()
if individuals is not None:
kwargs["individuals"] = individuals.ll_table
else:
kwargs["individuals"] = _tskit.IndividualTable()
if populations is not None:
kwargs["populations"] = populations.ll_table
else:
kwargs["populations"] = _tskit.PopulationTable()
ll_tables = _tskit.TableCollection(**kwargs)
return TreeSequence.load_tables(tables.TableCollection(ll_tables=ll_tables))
:param bool strict: If True, require strict tab delimiting (default). If
False, a relaxed whitespace splitting algorithm is used.
:param string encoding: Encoding used for text representation.
:param bool base64_metadata: If True, metadata is encoded using Base64
encoding; otherwise, as plain text.
:return: The tree sequence object containing the information
stored in the specified file paths.
:rtype: :class:`tskit.TreeSequence`
"""
# We need to parse the edges so we can figure out the sequence length, and
# TableCollection.sequence_length is immutable so we need to create a temporary
# edge table.
edge_table = parse_edges(edges, strict=strict)
if sequence_length == 0 and len(edge_table) > 0:
sequence_length = edge_table.right.max()
tc = tables.TableCollection(sequence_length)
tc.edges.set_columns(
left=edge_table.left, right=edge_table.right, parent=edge_table.parent,
child=edge_table.child)
parse_nodes(
nodes, strict=strict, encoding=encoding, base64_metadata=base64_metadata,
table=tc.nodes)
# We need to add populations any referenced in the node table.
if len(tc.nodes) > 0:
max_population = tc.nodes.population.max()
if max_population != NULL:
for _ in range(max_population + 1):
tc.populations.add_row()
if sites is not None:
parse_sites(
sites, strict=strict, encoding=encoding, base64_metadata=base64_metadata,
table=tc.sites)