tskit 1.0.4__cp315-cp315-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
_tskit.cp315-win32.pyd ADDED
Binary file
tskit/__init__.py ADDED
@@ -0,0 +1,99 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2018-2025 Tskit Developers
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+ import _tskit
23
+
24
+ #: Special reserved value representing a null ID.
25
+ NULL = _tskit.NULL
26
+
27
+ #: Special value representing missing data in a genotype array
28
+ MISSING_DATA = _tskit.MISSING_DATA
29
+
30
+ #: Node flag value indicating that it is a sample.
31
+ NODE_IS_SAMPLE = _tskit.NODE_IS_SAMPLE
32
+
33
+ #: Constant representing the forward direction of travel (i.e.,
34
+ #: increasing genomic coordinate values).
35
+ FORWARD = _tskit.FORWARD
36
+
37
+ #: Constant representing the reverse direction of travel (i.e.,
38
+ #: decreasing genomic coordinate values).
39
+ REVERSE = _tskit.REVERSE
40
+
41
+ #: The allele mapping where the strings "0" and "1" map to genotype
42
+ #: values 0 and 1.
43
+ ALLELES_01 = ("0", "1")
44
+
45
+ #: The allele mapping where the four nucleotides A, C, G and T map to
46
+ #: the genotype integers 0, 1, 2, and 3, respectively.
47
+ ALLELES_ACGT = ("A", "C", "G", "T")
48
+
49
+ #: Special NAN value used to indicate unknown mutation times. Since this is a
50
+ #: NAN value, you cannot use `==` to test for it. Use :func:`is_unknown_time` instead.
51
+ UNKNOWN_TIME = _tskit.UNKNOWN_TIME
52
+
53
+ #: Default value of ts.time_units
54
+ TIME_UNITS_UNKNOWN = _tskit.TIME_UNITS_UNKNOWN
55
+
56
+ #: ts.time_units value when dimension is uncalibrated
57
+ TIME_UNITS_UNCALIBRATED = _tskit.TIME_UNITS_UNCALIBRATED
58
+
59
+ #: Options for printing to strings and HTML, modify with tskit.set_print_options.
60
+ _print_options = {"max_lines": 40}
61
+
62
+ TABLE_NAMES = [
63
+ "individuals",
64
+ "nodes",
65
+ "edges",
66
+ "migrations",
67
+ "sites",
68
+ "mutations",
69
+ "populations",
70
+ "provenances",
71
+ ]
72
+
73
+ #: Threshhold for warning about multiple top-level metadata use.
74
+ #: A warning will be thrown if top-level metadata is larger than "size" bytes and is
75
+ #: accessed more that "threshhold" times. To disable, set threshhold to a large number,
76
+ #: for instance: ``tskit.METADATA_ACCESS_WARNING_COUNT = 2**32``.
77
+ METADATA_ACCESS_WARNING_COUNT = 20
78
+ #: The minimum size of top-level metadata before a multiple access warning is produced.
79
+ METADATA_ACCESS_WARNING_SIZE = 200_000
80
+
81
+ from tskit.provenance import __version__ # NOQA
82
+ from tskit.provenance import validate_provenance # NOQA
83
+ from tskit.trees import * # NOQA
84
+ from tskit.genotypes import Variant # NOQA
85
+ from tskit.tables import * # NOQA
86
+ from tskit.stats import * # NOQA
87
+ from tskit.combinatorics import ( # NOQA
88
+ all_trees,
89
+ all_tree_shapes,
90
+ all_tree_labellings,
91
+ TopologyCounter,
92
+ Rank,
93
+ )
94
+ from tskit.drawing import SVGString # NOQA
95
+ from tskit.exceptions import * # NOQA
96
+ from tskit.util import * # NOQA
97
+ from tskit.metadata import * # NOQA
98
+ from tskit.text_formats import * # NOQA
99
+ from tskit.intervals import RateMap # NOQA
tskit/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from . import cli
2
+
3
+ if __name__ == "__main__":
4
+ cli.tskit_main()
tskit/_version.py ADDED
@@ -0,0 +1,4 @@
1
+ # Definitive location for the version number.
2
+ # During development, should be x.y.z.devN
3
+ # For beta should be x.y.zbN
4
+ tskit_version = "1.0.4"
tskit/cli.py ADDED
@@ -0,0 +1,281 @@
1
+ #
2
+ # MIT License
3
+ #
4
+ # Copyright (c) 2018-2026 Tskit Developers
5
+ # Copyright (c) 2015-2018 University of Oxford
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ """
25
+ Command line utilities for tskit.
26
+ """
27
+
28
+ import argparse
29
+ import json
30
+ import os
31
+ import signal
32
+ import sys
33
+
34
+ import tskit
35
+
36
+
37
+ def set_sigpipe_handler():
38
+ if os.name == "posix":
39
+ # Set signal handler for SIGPIPE to quietly kill the program.
40
+ signal.signal(signal.SIGPIPE, signal.SIG_DFL)
41
+
42
+
43
+ def sys_exit(message):
44
+ sys.exit(message)
45
+
46
+
47
+ def load_tree_sequence(path):
48
+ if path is None:
49
+ path = sys.stdin
50
+ try:
51
+ return tskit.load(path)
52
+ except (OSError, EOFError, tskit.FileFormatError) as e:
53
+ sys_exit(f"Load error: {e}")
54
+
55
+
56
+ def run_info(args):
57
+ print(load_tree_sequence(args.tree_sequence))
58
+
59
+
60
+ def run_trees(args):
61
+ ts = load_tree_sequence(args.tree_sequence)
62
+ for tree in ts.trees():
63
+ print(f"tree {tree.index}:")
64
+ print(f" num_sites: {tree.num_sites}")
65
+ print(
66
+ " interval: ({0:.{2}f}, {1:.{2}f})".format(
67
+ tree.interval.left, tree.interval.right, args.precision
68
+ )
69
+ )
70
+ if args.draw:
71
+ print(tree.draw(format="unicode"))
72
+
73
+
74
+ def run_individuals(args):
75
+ tree_sequence = load_tree_sequence(args.tree_sequence)
76
+ tree_sequence.dump_text(individuals=sys.stdout, precision=args.precision)
77
+
78
+
79
+ def run_nodes(args):
80
+ tree_sequence = load_tree_sequence(args.tree_sequence)
81
+ tree_sequence.dump_text(nodes=sys.stdout, precision=args.precision)
82
+
83
+
84
+ def run_edges(args):
85
+ tree_sequence = load_tree_sequence(args.tree_sequence)
86
+ tree_sequence.dump_text(edges=sys.stdout, precision=args.precision)
87
+
88
+
89
+ def run_sites(args):
90
+ tree_sequence = load_tree_sequence(args.tree_sequence)
91
+ tree_sequence.dump_text(sites=sys.stdout, precision=args.precision)
92
+
93
+
94
+ def run_mutations(args):
95
+ tree_sequence = load_tree_sequence(args.tree_sequence)
96
+ tree_sequence.dump_text(mutations=sys.stdout, precision=args.precision)
97
+
98
+
99
+ def run_populations(args):
100
+ tree_sequence = load_tree_sequence(args.tree_sequence)
101
+ tree_sequence.dump_text(populations=sys.stdout)
102
+
103
+
104
+ def run_migrations(args):
105
+ tree_sequence = load_tree_sequence(args.tree_sequence)
106
+ tree_sequence.dump_text(migrations=sys.stdout, precision=args.precision)
107
+
108
+
109
+ def run_provenances(args):
110
+ tree_sequence = load_tree_sequence(args.tree_sequence)
111
+ if args.human:
112
+ for provenance in tree_sequence.provenances():
113
+ d = json.loads(provenance.record)
114
+ print(
115
+ "id={}, timestamp={}, record={}".format(
116
+ provenance.id, provenance.timestamp, json.dumps(d, indent=4)
117
+ )
118
+ )
119
+ else:
120
+ tree_sequence.dump_text(provenances=sys.stdout)
121
+
122
+
123
+ def run_fasta(args):
124
+ tree_sequence = load_tree_sequence(args.tree_sequence)
125
+ tree_sequence.write_fasta(sys.stdout, wrap_width=args.wrap)
126
+
127
+
128
+ def run_vcf(args):
129
+ tree_sequence = load_tree_sequence(args.tree_sequence)
130
+ tree_sequence.write_vcf(
131
+ sys.stdout,
132
+ ploidy=args.ploidy,
133
+ contig_id=args.contig_id,
134
+ allow_position_zero=args.allow_position_zero,
135
+ )
136
+
137
+
138
+ def add_tree_sequence_argument(parser):
139
+ parser.add_argument(
140
+ "tree_sequence",
141
+ help="The tskit tree sequence file. If not provided, read from stdin.",
142
+ default=None,
143
+ nargs="?",
144
+ )
145
+
146
+
147
+ def add_precision_argument(parser):
148
+ parser.add_argument(
149
+ "--precision",
150
+ "-p",
151
+ type=int,
152
+ default=6,
153
+ help="The number of decimal places to print in records",
154
+ )
155
+
156
+
157
+ def get_tskit_parser():
158
+ top_parser = argparse.ArgumentParser(
159
+ prog="python3 -m tskit", description="Command line interface for tskit."
160
+ )
161
+ top_parser.add_argument(
162
+ "-V", "--version", action="version", version=f"%(prog)s {tskit.__version__}"
163
+ )
164
+ subparsers = top_parser.add_subparsers(dest="subcommand")
165
+ subparsers.required = True
166
+
167
+ parser = subparsers.add_parser(
168
+ "info", help="Print summary information about a tree sequence."
169
+ )
170
+ add_tree_sequence_argument(parser)
171
+ parser.set_defaults(runner=run_info)
172
+
173
+ parser = subparsers.add_parser("trees", help="Print information about trees.")
174
+ add_tree_sequence_argument(parser)
175
+ add_precision_argument(parser)
176
+ parser.add_argument(
177
+ "--draw", "-d", action="store_true", default=False, help="Draw the trees"
178
+ )
179
+ parser.set_defaults(runner=run_trees)
180
+
181
+ # suppress fasta visibility until we have a reference sequence
182
+ # See https://github.com/tskit-dev/tskit/issues/1888
183
+ # parser = subparsers.add_parser(
184
+ # "fasta",
185
+ # help="Convert the tree sequence haplotypes to fasta format")
186
+ # add_tree_sequence_argument(parser)
187
+ # parser.add_argument(
188
+ # "--wrap", "-w", type=int, default=60,
189
+ # help=("line-wrapping width for printed sequences"))
190
+ # parser.set_defaults(runner=run_fasta)
191
+ parser = subparsers.add_parser(
192
+ "vcf", help="Convert the tree sequence genotypes to VCF format."
193
+ )
194
+ add_tree_sequence_argument(parser)
195
+ parser.add_argument(
196
+ "--ploidy",
197
+ "-P",
198
+ type=int,
199
+ default=None,
200
+ help=(
201
+ "If the tree sequence does not contain information about "
202
+ "individuals, create them by combining adjacent samples nodes "
203
+ "into individuals of the specified ploidy. It is an error "
204
+ "to provide this argument if the tree sequence does contain "
205
+ "individuals"
206
+ ),
207
+ )
208
+ parser.add_argument(
209
+ "--contig-id", "-c", type=str, default="1", help="Specify the contig id"
210
+ )
211
+ parser.add_argument(
212
+ "--allow-position-zero",
213
+ "-0",
214
+ action="store_true",
215
+ default=False,
216
+ help="Allow position 0 sites",
217
+ )
218
+ parser.set_defaults(runner=run_vcf)
219
+
220
+ parser = subparsers.add_parser(
221
+ "individuals", help="Output individuals in tabular format."
222
+ )
223
+ add_tree_sequence_argument(parser)
224
+ add_precision_argument(parser)
225
+ parser.set_defaults(runner=run_individuals)
226
+
227
+ parser = subparsers.add_parser("nodes", help="Output nodes in tabular format.")
228
+ add_tree_sequence_argument(parser)
229
+ add_precision_argument(parser)
230
+ parser.set_defaults(runner=run_nodes)
231
+
232
+ parser = subparsers.add_parser("edges", help="Output edges in tabular format.")
233
+ add_tree_sequence_argument(parser)
234
+ add_precision_argument(parser)
235
+ parser.set_defaults(runner=run_edges)
236
+
237
+ parser = subparsers.add_parser("sites", help="Output sites in tabular format.")
238
+ add_tree_sequence_argument(parser)
239
+ add_precision_argument(parser)
240
+ parser.set_defaults(runner=run_sites)
241
+
242
+ parser = subparsers.add_parser(
243
+ "mutations", help="Output mutations in tabular format."
244
+ )
245
+ add_tree_sequence_argument(parser)
246
+ add_precision_argument(parser)
247
+ parser.set_defaults(runner=run_mutations)
248
+
249
+ parser = subparsers.add_parser(
250
+ "populations", help="Output population information in tabular format."
251
+ )
252
+ add_tree_sequence_argument(parser)
253
+ parser.set_defaults(runner=run_populations)
254
+
255
+ parser = subparsers.add_parser(
256
+ "migrations", help="Output migration information in tabular format."
257
+ )
258
+ add_tree_sequence_argument(parser)
259
+ add_precision_argument(parser)
260
+ parser.set_defaults(runner=run_migrations)
261
+
262
+ parser = subparsers.add_parser(
263
+ "provenances", help="Output provenance information in tabular format."
264
+ )
265
+ add_tree_sequence_argument(parser)
266
+ parser.add_argument(
267
+ "-H",
268
+ "--human",
269
+ action="store_true",
270
+ help="Print out the provenances in a human readable format",
271
+ )
272
+ parser.set_defaults(runner=run_provenances)
273
+
274
+ return top_parser
275
+
276
+
277
+ def tskit_main(arg_list=None):
278
+ set_sigpipe_handler()
279
+ parser = get_tskit_parser()
280
+ args = parser.parse_args(arg_list)
281
+ args.runner(args)