Contact maps¶
metator.metacool writes the contact map of a run, grouped by cluster, as a
.metacool file, from the map that the run started from,
with its clustering rounds and the normalization of its network. See
The contact map of the clusters.
metator.metacool ¶
Contact map of a metaTOR run as a .metacool file.
A .metacool file is metacooler's HDF5 contact map: a cooler whose
chromosomes are the contigs, grouped by genome, readable by
cooler.Cooler. The map is the interface between the steps of a run:
network stores the contig columns and the weights of its normalization
(the raw contacts stay as they are; a normalized contact is the count times
both weights, as cooler stores balancing weights), partition the rounds
core and overlapping (see read_partition), and validation the map of the
clusters: one genome per final cluster, __unbinned__ for the others, the
summary in the genomes table and every round. pipeline stores what the
three steps store, in one map (see write_map), then what markers stores:
the marker genes of each contig, in its contigs table (see Markers).
Every map is written in one metacooler edit session, validated in full
once, then renamed onto the map of the output directory of the run (or over
the input map, with --inplace): the map is whole whatever stops the run
and does not grow from run to run. A run holds the map's lock from its
checks to its end (see metator.cli.hold_lock).
MetacoolError ¶
MapReplacedError ¶
Bases: MetacoolError
A map was replaced or written while it was read (see read_errors): what was read of it would mix two maps.
Network
dataclass
¶
The network of the contigs of a run, as a map stores it (see write_map).
Attributes:
| Name | Type | Description |
|---|---|---|
table |
DataFrame
|
The contig data of the contigs of the map, in its order (see metator.network.contig_table): its columns that the run measured (GC_content and Hit, and Shotgun_coverage and Restriction_site when it has them) go to the contigs table of the map. |
normalization |
str
|
The normalization of the network, stored as the weights
|
entry |
dict or None
|
What the map records of the run that stored the network, under the network key of its metator metadata: the version of metaTOR, the command line and the parameters of the run, and the columns of the map that it read (see metator.cli.network_entry). |
tmp_dir |
(str, optional)
|
Where the contig data is written for metacooler annotate (contig_data_network.txt): the temporary directory of the run. |
Source code in src/metator/metacool.py
Markers
dataclass
¶
The marker genes of the contigs of a map, as metator markers stores them (see write_map and metator.markers.contig_markers).
Attributes:
| Name | Type | Description |
|---|---|---|
table |
DataFrame
|
One row per contig of the map: its name (Name) and its markers in each set (MARKER_COLUMNS, see metator.markers.encode_markers), an empty text for none. |
entry |
dict
|
What the map records of the run, under the markers key of its metator metadata (see metator.cli.markers_entry). |
tmp_dir |
(str, optional)
|
Where the table is written for metacooler annotate (contig_markers.txt): the temporary directory of the run. |
Source code in src/metator/metacool.py
FinalClusters
dataclass
¶
The final clusters of a validation, as the map of the clusters stores them (see write_map).
Attributes:
| Name | Type | Description |
|---|---|---|
assignment |
dict
|
The final cluster of each binned contig, by name: the other contigs of the map go to metacooler's unbinned genome. |
summary |
str
|
The summary of the final clusters at full precision (cluster_summary_full.txt, in the temporary directory of the run; see metator.io.SUMMARY_FULL_FILE): one row per final cluster, named by its first column, whose other columns go to the genomes table, with the values of miComplete, where cluster_summary.txt rounds them. |
rounds |
tuple of pandas.DataFrame
|
The clustering rounds of the run, every cluster and its contigs (see metator.clusters.read_rounds), which replace those of the map. |
entry |
dict
|
The entry validation of the metator metadata of the map: what the run was, what it read of the map, and the columns of its summary, in order. |
Source code in src/metator/metacool.py
MgeGenomes
dataclass
¶
The genomes of a map once metator mge stores its round mge in it (see mge_reassignment and write_map).
Attributes:
| Name | Type | Description |
|---|---|---|
assignment |
dict
|
The genome of each contig of the map, by name: ND for none. |
table |
DataFrame
|
The values of each genome, indexed by its name: the genomes table that metacooler reassign stores (see _write_genomes_table). |
Source code in src/metator/metacool.py
open_map ¶
The metacooler.MetaCooler of a .metacool map, or of an entry of a .mmetacool collection: a map that cannot be read (a missing file, a file that is not a map, a collection without the entry...) is a MetacoolError naming it.
Source code in src/metator/metacool.py
read_errors ¶
Raise, as a MapReplacedError (a MetacoolError), metacooler's refusal of a read of the map metacool that spans a replacement of its file (MapChangedError): a run that updates a map in place replaces it with the map of its clusters, whose bins are in another order, and so are the bin ids of its pixels. metacooler reads a map one chunk of pixels at a time, and checks its file before and after each: a read that spanned the replacement would mix the bins of one map with the pixels of the other. The message ends with remedy: what the reader does about it.
Source code in src/metator/metacool.py
check_map_lengths ¶
Refuse a map that gives contigs another length than lengths (by contig
name; the contigs it lacks are not checked): it is not a map of the contigs
of of (the assembly, or a contig data file), where (where) they have
these lengths.
Source code in src/metator/metacool.py
map_file ¶
The file of a .metacool map: the map, or the .mmetacool collection of an entry given as file.mmetacool::entries/NAME.
is_map ¶
Whether path is a contact map rather than a pairs file: an HDF5 file, which a pairs file never is, or the URI of a map inside one (file::group). A path that is a file is a map only when it is an HDF5 file, whatever its name: a pairs file may have :: in its name.
A URI is one when its file part is an HDF5 file; so are a .mmetacool collection and a .cool file, which open_map then refuses with metacooler's reason.
Source code in src/metator/metacool.py
is_entry ¶
Whether metacool names an entry inside a file (a .mmetacool collection): file::group with a group other than the root of the file (file::/ is the file itself, as metacooler reads it).
Source code in src/metator/metacool.py
is_input_map ¶
Whether writing the map at outfile updates the map metacool in place: outfile, its own name not followed (see _named), names the file of the map, its symbolic links followed, as metacooler edits the file that a link points to. A symbolic link at outfile is a file of its own, which a write replaces, whatever it points to; and a map given as a symbolic link is updated in place through its target, not through outfile = the link.
Source code in src/metator/metacool.py
is_hard_link_of ¶
Whether outfile is the file of the map metacool under another name (a hard link: the same file, which is not the map's own name, nor a symbolic link). Written as a map of its own, it would replace that name only; metacooler refuses an output that is the same file as its input.
Source code in src/metator/metacool.py
non_ascii_names ¶
check_ascii_names ¶
Refuse contig or cluster names that are not ASCII.
Source code in src/metator/metacool.py
check_bin_names ¶
Refuse bin names that metacooler reads as no bin.
metacooler would put the contigs of such a bin in unbinned silently.
Source code in src/metator/metacool.py
make_map_directory ¶
Make the directory of the map at outfile, where metacooler locks and stages the map before it renames it there. A directory that cannot be made is a MetacoolError, which names outfile as named says (outfile itself by default).
Source code in src/metator/metacool.py
normalization_weight_name ¶
The weight column of the bins table of a map that stores a normalization of the network (see store_normalization).
store_normalization ¶
Store a normalization of the network in a .metacool map, as a weight column
of its bins table: metator_<normalization>.
Every bin of a contig takes its contig's weight, so the normalized contact of two contigs is their count times both weights, as cooler stores balancing weights. depends_on lets metacooler drop the column when an edit changes what it was computed from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the .metacool file, or URI of an entry of a .mmetacool
collection: |
required |
normalization
|
str
|
Mode of normalization (see metator.network.normalization_weights), but "None". |
required |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the normalization is unknown, the contigs table of the map lacks a column it reads, the map is replaced or written as it is read, or metacooler cannot store the column (a ValueError, OSError or KeyError, message kept). |
Source code in src/metator/metacool.py
network_columns ¶
The columns of the contig data of a network (table, see Network) that the map stores (CONTIG_COLUMNS, in that order): those that the run measured. The shotgun coverage and the restriction sites are text (-) where it has none.
Source code in src/metator/metacool.py
holds_partition ¶
Whether the map mc holds a partition of its network: the clustering round core or overlapping, which metator partition stores (see read_partition).
Source code in src/metator/metacool.py
partition_network ¶
The digest of the network that the partition of the map mc was made on (see metator.network.network_digest), which metator partition records with it, under the partition key of the metator metadata of the map (as NETWORK_DIGEST): None when the map records none.
Source code in src/metator/metacool.py
holds_hosts ¶
Whether the map mc holds the hosts of its MGE clusters that metator host found: the host entry of its metator metadata (see HOST_ENTRY).
host_entry ¶
The host entry of the metator metadata of the map mc (see HOST_ENTRY): what the run that found the hosts of its MGE clusters recorded, its command line and its parameters among them; None when the map holds no hosts.
Source code in src/metator/metacool.py
hosts_network ¶
The digest of the network that metator host read to find the hosts that the map mc holds (see holds_hosts), as its host entry records it: None when the map records none.
Source code in src/metator/metacool.py
holds_markers ¶
Whether the map mc holds the marker genes of its contigs that metator markers found: the markers entry of its metator metadata, or a column of MARKER_COLUMNS in its contigs table.
Source code in src/metator/metacool.py
markers_entry ¶
The markers entry of the metator metadata of the map mc (see MARKERS_ENTRY): what the run that found the marker genes of its contigs recorded, its marker sets among them (see metator.markers.map_sets); None when the map holds no markers.
Source code in src/metator/metacool.py
map_assignment ¶
The binning of the map mc (opened): the names of its contigs, in the order of its contigs table, and the name of the genome of each (UNBINNED_GENOME for none), as two arrays (see assignment_digest).
Source code in src/metator/metacool.py
assignment_digest ¶
The identity of a binning of the contigs of a map: the SHA-256 of the genome of each contig, by the names of the contigs, as metator.network.network_digest is the identity of a network. It is that of the assignment, not of a map: the same whatever the order of the contigs, another one once a contig is in another genome, or a genome is renamed. metator markers records the binning that it found the marker genes of the contigs in (see ASSIGNMENT_DIGEST), which markers_predate checks the binning of the map against.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contigs
|
sequence of str
|
The names of the contigs of the map. |
required |
genomes
|
sequence of str
|
The name of the genome of each, in the same order: UNBINNED_GENOME for none (see map_assignment). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The SHA-256, in hexadecimal, of the name of each contig and of its genome, the contigs by name, each field ended by a NUL, which no name holds. |
Source code in src/metator/metacool.py
markers_binning ¶
The digest of the binning that metator markers found the marker genes of the contigs of the map mc in (see assignment_digest), as its markers entry records it (ASSIGNMENT_DIGEST): None when the map records none (it holds no markers, or markers that an earlier metaTOR found).
Source code in src/metator/metacool.py
markers_predate ¶
Whether the marker genes of the contigs of the map mc predate its genomes, as metator report says: found by metator markers in another binning of its contigs than the one the map has (the digest that its markers entry records is not that of its genomes, see assignment_digest). Each contig has its own markers still, but summed over a genome whose contigs changed since, they give an estimate of miComplete's numbers, not those of the genome as metator markers would find its genes. None when the map cannot tell: it records no such digest (see markers_binning).
Source code in src/metator/metacool.py
store_rounds ¶
Store the clustering rounds of a run in the /clusters group of a map, in place of those it held: the overlapping, recursive and final clusters of metator.clusters, with their contigs, their parents and their columns (those of miComplete, and of the bin summary for the final clusters).
A text column holds an empty text where a round has no value (HDF5 stores no missing text), and the contigs of a cluster that the map lacks are left out, with a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the .metacool file, written in place. |
required |
rounds
|
tuple of pandas.DataFrame, or None
|
The clusters and their contigs (see metator.clusters.read_rounds). |
required |
names
|
list of str
|
The names of the rounds, in the order they were made: by default, those of the clusters, in their order. |
None
|
name
|
str
|
The map that path is staged for, which the warnings name (path by default). |
None
|
Source code in src/metator/metacool.py
map_rounds ¶
The clustering rounds of a map (mc, opened), as metator.clusters.Rounds gives them (see Rounds.tables), and as _store_clusters stored them: every cluster of every round, in the order of the rounds and of their clusters, with its parent and the columns its round stored, not those that metacooler computes; and every contig of a cluster, in the order of the map. An empty text of a text column, which _store_clusters stores for a missing value (HDF5 holds no missing text), is a missing value again (None): a genuinely empty text too.
Returns:
| Type | Description |
|---|---|
tuple of pandas.DataFrame
|
The clusters and their contigs (columns round, cluster, contig). |
Source code in src/metator/metacool.py
read_partition ¶
The partition that a map stores, as metator partition MAP stores it (see write_map and metator.clusters.partition_rounds): its clustering rounds core and overlapping, read back as metator.clusters.Partition. With network, the digest of the network stored in the map (see metator.network.stored_network), the partition must have been made on that network, as the map records it (see partition_network): metator network can store another network in the map, and leaves the partition there, which is then not that of the network.
Clusters are numbered as their names say (see metator.clusters.cluster_number) and contigs get their positions in the map, from 1. A core cluster's contigs come in ID order, an overlapping cluster's in the order of its core clusters, then of IDs: the order metator.partition.partition gives, which the map's sorted rounds lose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the .metacool file, or URI of an entry of a .mmetacool collection, for the messages. |
required |
mc
|
MetaCooler
|
The map, opened: by default, metacool is opened. |
None
|
network
|
str
|
The digest of the network stored in the map, which the partition must have been made on. |
None
|
Returns:
| Type | Description |
|---|---|
Partition
|
The core and the overlapping clusters of the map. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the map lacks the round core or overlapping (metator partition has not run on it), or, with network, does not record that its partition was made on that network, or a cluster of them is not named as metator partition names it, or holds a contig in no core cluster (an overlapping cluster), or the map cannot be read. |
Source code in src/metator/metacool.py
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 | |
write_map ¶
write_map(
metacool,
outfile,
*,
network=None,
partition=None,
rounds=None,
round_names=None,
clusters=None,
mge=None,
reassign=False,
hosts=None,
drop_hosts=False,
markers=None,
force=False,
planned=None,
mge_follows=False,
markers_follow=False,
)
Write the map of a run at outfile from its input map, metacool: what the run stores in it, everything else as it was. Each step of a run writes its map so, and pipeline writes what its three steps store, in one map, as the steps one by one write it (then its step markers stores the marker genes of the contigs in it, and, with --mges, its steps mge and host the round mge and the hosts, as markers, mge and host do).
Everything goes into one edit session (see _staged_edit), validated once and renamed once; on any failure outfile is left as it was. In order: the final clusters (a map written anew from the input map, contigs grouped by cluster then longest first), or the genomes that the round mge makes (see mge_reassignment: a map written anew from the input map too), the network (columns and weights, last in both tables), the partition's rounds and entry, then the round mge, or the hosts of the MGE clusters. A run that replaces the rounds warns of those the binning did not make, and drops them.
The hosts that metator host stored in the map (see HOST_ENTRY) describe its round mge, its genomes and its network as they were: a run that replaces the round mge (metator mge, but --random), the rounds (partition) or the genomes (validation, pipeline) drops them, and so does a network run with drop_hosts (another network than the one they were found on), each with a warning.
The marker genes that metator markers stored in the map (see MARKERS_ENTRY) are facts about its contigs, which every write but that of markers keeps: a run that regroups the contigs into other genomes than those that the genes were found in (validation, mge --reassign) says so once the map is written, as they predate its new genomes (see markers_predate), unless markers_follow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the input .metacool file, or URI of an entry of a .mmetacool
collection: |
required |
outfile
|
str
|
Path to the .metacool file to write. |
required |
network
|
Network
|
|
None
|
partition
|
dict
|
The entry partition of the metator metadata. |
None
|
rounds
|
tuple of pandas.DataFrame
|
Clustering rounds, which replace those of the map: the rounds core and overlapping of a partition (see metator.clusters.partition_rounds). |
None
|
round_names
|
list of str
|
The names of the rounds, in the order they were made (see store_rounds). |
None
|
clusters
|
FinalClusters
|
|
None
|
mge
|
tuple
|
The tables of the round mge or mge_random (see metator.clusters.mge_round) and its entry (its name, and what made it: see metator.cli.mge_entry). The round mge undoes the MGE genomes of the map (see mge_reassignment). |
None
|
reassign
|
bool
|
With the round mge (mge), whether its clusters are genomes of the map then (metator mge --reassign). |
False
|
hosts
|
tuple
|
The hosts of the MGE clusters of the map (a metator.host.Hosts) and the host entry of the run that found them (see metator.cli.host_entry), stored alone (see _store_hosts). |
None
|
drop_hosts
|
bool
|
Whether to drop the hosts that the map holds, which another network than the one stored now gave (a network run). |
False
|
markers
|
Markers
|
The marker genes of the contigs of the map (metator markers), stored alone (see _store_markers). Every other write keeps those that the map holds (see MARKERS_ENTRY). |
None
|
force
|
bool
|
Whether to replace an existing outfile: the input map itself, which a run updates in place, or another file. |
False
|
planned
|
MetaCooler
|
The input map as the run read it, opened when the run started: the map is refused if it changed since (another run replaced it, or a program wrote it), rather than written from another map than the one that the run worked on. |
None
|
mge_follows
|
bool
|
Whether the run stores the round mge and the hosts of its MGE clusters in the map once it is written (pipeline --mges, in its steps mge and host): the warnings of what the map no longer holds leave them out, which the run makes again. |
False
|
markers_follow
|
bool
|
Whether the run says later what becomes of the marker genes of the contigs that the map holds, which this write does not say then: it finds them again once the map is written (pipeline, in its step markers), or regroups the contigs again (pipeline --no-markers --mges, in its step mge, which says it). |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If clusters come with rounds or round_names: the rounds of a validation are those of its clusters; or with mge: the genomes of a validation are its final clusters; or hosts, or markers, with anything else to store. If reassign comes without the round mge. |
MetacoolError
|
If the outfile is no file's path (a URI), exists (without force), is the .mmetacool collection of the input map or a hard link of the input map, the input map is missing, cannot be read or changed since planned was opened, a contig of the clusters is not a contig of the input map, a cluster name is not ASCII or one that metacooler reads as no cluster (NA, nan, -1...), an MGE cluster is named after a genome that the map keeps (see mge_reassignment), or metacooler cannot write the map (a ValueError, OSError or KeyError, message kept). |
Source code in src/metator/metacool.py
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 | |
mge_genomes ¶
The MGE genomes of the map mc (opened), by name, in the order of its genomes table: those that its column mge says are (True), which metator mge --reassign made of the clusters of its round mge (see write_map).
Source code in src/metator/metacool.py
mge_reassignment ¶
The genomes of the map mc (opened) once metator mge stores the round mge of its run in it (rounds: its clusters and their contigs, see metator.clusters.mge_round), or None when the run leaves them as they are.
The MGE genomes that the map holds are undone first: those that its column mge says are (see mge_genomes), and those named after a cluster of its round mge (which metacooler reassign --round mge makes, say). Their contigs go back to their final cluster (the round final), or to none. With reassign (--reassign), each MGE cluster of the run is a genome then, named after it, with its values (GC, Hit, BinningScore): its contigs leave the genomes that held them, MAGs or none. The other genomes are kept, with their values, those of the validation, which describe them with the contigs that they lose, as the log says; a genome whose contigs all leave it is no genome any more, and its values go with it. The column mge of the genomes table says which genomes are MGE genomes (True): it is not there without reassign.
Returns:
| Type | Description |
|---|---|
MgeGenomes, or None
|
None without reassign, on a map that holds no MGE genome. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If a genome that the run keeps is named after an MGE cluster of the run: their contigs would make one genome. |
Source code in src/metator/metacool.py
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 | |
metator.inputs reads the inputs of metator network and metator
pipeline, and makes the map of the contigs that a run starts from out of its
pairs files or BAM files (see The inputs of a run).
metator.inputs ¶
The inputs of metator network and metator pipeline.
A run starts from the .metacool contact map of the contigs, or makes it from
the pairs files or the BAM files of its Hi-C libraries: one or several of
them, each argument a path, a comma-separated list or a glob pattern (see
expand), and what each file holds is read from its first bytes (see
file_kind). make_map then writes the map of the contigs, one bin per contig
of the assembly, all of them in no cluster yet, as metacooler create
pairs makes it from the pairs files: the BAM files give their pairs first
(see bam_pairs), into the temporary directory of the run.
A BAM file holds both mates of its reads (paired-end alignments, as bwa mem
-5SP writes them), or one mate of each (as bowtie2 aligns them, one mate at
a time, in two files per library). A pair is the primary alignments of the
two mates of a read, both aligned with a mapping quality of at least
--min-quality, neither flagged as a PCR or optical duplicate nor as failing
QC (see flagged), each at the 5' end of its alignment, as pairtools and
hicstuff's mapping mode 5spm record it (see five_prime).
Inputs
dataclass
¶
The inputs of a run, as resolve finds them.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
MAP, PAIRS or BAM. |
files |
list of str
|
The files, in the order of the arguments: the map alone, for MAP. |
libraries |
list of tuple of str
|
The files of each Hi-C library: a pairs file, a BAM file of both mates, or the BAM files of its two mates (R1, R2). |
layout |
str or None
|
For BAM files, BOTH_MATES or ONE_MATE. |
Source code in src/metator/inputs.py
describe ¶
What the inputs are, for the log: "a map", "a pairs file", "3 pairs files", "2 BAM files of both mates", "4 BAM files of one mate each".
Source code in src/metator/inputs.py
expand ¶
The files that an argument of a run names, in order.
A path that exists is that file, whatever its name holds (a comma, a glob
character). Otherwise the argument is a comma-separated list, each item a
path or a glob pattern (*, ?, [...]), which stands for the
files it matches, sorted by name, as hicstuff 4.0 reads its inputs. A
pattern that matches no file, and an empty item, are refused.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
argument
|
str
|
A path, comma-separated paths or glob patterns. |
required |
Returns:
| Type | Description |
|---|---|
list of str
|
The paths, which may not exist (see resolve). |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If a pattern matches no file, or the list holds an empty item. |
Examples:
Source code in src/metator/inputs.py
file_kind ¶
What a file of the inputs of a run holds, from its first bytes, whatever its name: MAP, PAIRS or BAM.
An HDF5 file is a map (open_map refuses one that is not a .metacool map, with metacooler's reason), and so is file::group, a map inside a file, which is no path. A BAM file (compressed with BGZF) and a SAM file (text that starts with its header) are alignments. Any other file is a pairs file, plain or compressed, which metacooler reads. Reads (FASTQ), an assembly (FASTA) and a CRAM file are refused.
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the file is not there, is a directory, or holds reads, an assembly or CRAM alignments. |
Source code in src/metator/inputs.py
resolve ¶
The inputs of a run (see Inputs) from its arguments: one .metacool map, or pairs files, or BAM files (or SAM files), each argument a path, a comma-separated list or a glob pattern (see expand), each file found to be what it is from its first bytes (see file_kind).
Each pairs file, and each BAM file of both mates, is a library. BAM files of one mate each come in two halves, as hicstuff takes them: two arguments are the R1 files and the R2 files; more arguments (as the shell expands unquoted patterns) are as many R1 arguments, then as many R2 arguments. The i-th R1 file and the i-th R2 file are the mates of one library.
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If an argument names no file, a file is given twice, a map is given with other inputs, kinds or layouts are mixed, or BAM files of one mate each do not come in two halves of as many files. |
Source code in src/metator/inputs.py
bam_layout ¶
BOTH_MATES or ONE_MATE: whether a BAM (or SAM) file holds the two mates of its reads (paired-end alignments), or one mate of each, from its first LAYOUT_PROBE primary alignments: a read flagged first or second of its pair is a mate, an unpaired read one mate aligned on its own.
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the file cannot be read, or holds no read. |
Source code in src/metator/inputs.py
check_references ¶
Refuse the pairs or the alignments of a file that is not of the assembly: sequences (references: (name, length) pairs) that the assembly gives another length (lengths: by contig name), or none of which is a contig of the assembly. The sequences that are not contigs of the assembly (a spike-in, a host genome) are left out, with a warning: so are the pairs with a read on them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The BAM or pairs file, for the messages. |
required |
references
|
list of tuple
|
Its sequences, as (name, length). |
required |
lengths
|
dict
|
The length of each contig of the assembly, by name. |
required |
what
|
str
|
What the sequences are, in the messages. |
'reference sequences'
|
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If a sequence has another length in the assembly, or none is a contig of the assembly. |
Source code in src/metator/inputs.py
five_prime ¶
The 1-based position of the 5' end of an alignment (a pysam.AlignedSegment): its first aligned base on the forward strand, its last on the reverse strand, soft-clipped bases left out, as pairtools and hicstuff's mapping mode 5spm record a mate.
It moves the mates on the reverse strand by the length of their alignment from the leftmost base, which metaTOR 1.x recorded: a contact stays between the same two contigs, which the network counts, and only the contacts within a contig at about 1 kb (the short and long contacts that metator mge reads) may change.
Source code in src/metator/inputs.py
flagged ¶
Why a read leaves its pair out for its flags: "duplicate", flagged as a PCR or optical duplicate (0x400, as Picard MarkDuplicates or samtools markdup flag it), or "QC", as failing quality checks (0x200); None for a read that counts.
Source code in src/metator/inputs.py
natural_key ¶
The sort key of a read name in the order of samtools sort -n: its
characters one by one, but its runs of digits found at the same place in
two names compared by value (strnum_cmp of samtools: r9 before r10), and
their leading zeros ignored (samtools 1.17 and later). Adapted from
hicstuff (BSD-3-Clause), which matches the mates of two BAM files so.
Returns:
| Type | Description |
|---|---|
tuple
|
The text between runs of digits, each ended with "0" when digits follow (samtools compares a digit and another character as characters, and every digit compares alike with a character that is no digit), and the value of each run of digits. |
Examples:
>>> sorted(["r10", "r9", "r1"], key=natural_key)
['r1', 'r9', 'r10']
>>> natural_key("r010") == natural_key("r10")
True
Source code in src/metator/inputs.py
bam_pairs ¶
Write the pairs file of a library of BAM files: the pairs of the reads whose two mates are aligned, each with a mapping quality of at least min_quality, on contigs of the assembly (their primary alignments; the secondary and supplementary ones are left out), each mate at the 5' end of its alignment (see five_prime). A read with a mate flagged as a PCR or optical duplicate, or as failing QC, is left out (see flagged), and the log counts them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
library
|
tuple of str
|
The BAM file of both mates, or the BAM files of the two mates. |
required |
out
|
str
|
The pairs file to write. |
required |
lengths
|
dict
|
The length of each contig of the assembly, by name, in its order. |
required |
layout
|
str
|
BOTH_MATES or ONE_MATE. |
required |
min_quality
|
int
|
The mapping quality that both mates of a pair must reach. |
30
|
tmp_dir
|
str
|
Where the files are grouped or sorted by read name, when they need it. |
'.'
|
threads
|
int
|
Threads decompressing the BAM files, and grouping or sorting them. |
1
|
Returns:
| Type | Description |
|---|---|
int
|
The number of pairs written. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If a file cannot be read, holds no read with both mates (BAM files of the mates of other libraries), or the mates cannot be matched. |
Source code in src/metator/inputs.py
pairs_chromsizes ¶
The sequences that the header of a pairs file lists (#chromsize lines), as (name, length) pairs: none for a file without them, or compressed with zstd or LZ4, whose header is not read here (metacooler reads the file).
Source code in src/metator/inputs.py
map_name ¶
The name of the map that a run makes from pairs or BAM files:
Source code in src/metator/inputs.py
assembly_name ¶
The name of an assembly: that of its FASTA file, without the extensions of a FASTA file and of its compression (assembly from assembly.fa.gz).
Source code in src/metator/inputs.py
make_map ¶
make_map(
inputs,
contig_data,
outfile,
assembly=None,
min_quality=30,
threads=1,
tmp_dir=".",
command=None,
)
Write the map of the contigs at outfile, from the pairs files or the BAM
files of a run (inputs, see resolve), as metacooler create pairs makes
it: one bin per contig of the assembly (contig_data, by name, in its
order: see metator.network.create_contig_data), every contig in
__unbinned__, the longest first, and the contacts of the pairs of
every library, summed, with the contact statistics that metacooler counts
on the reads (the QC block, which metator mge reads).
The BAM files give the pairs of each library (see bam_pairs), written in tmp_dir. The headers of the BAM files, and the #chromsize lines of the pairs files, are checked against the assembly first (see check_references).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
Inputs
|
Pairs files or BAM files. |
required |
contig_data
|
dict
|
The contigs of the assembly, by name, with their "length". |
required |
outfile
|
str
|
The map to write. An earlier one there is replaced once the new map is written. |
required |
assembly
|
str
|
The FASTA file of the assembly, whose name the map stores (see assembly_name). |
None
|
min_quality
|
int
|
The mapping quality that both mates of a pair of a BAM file must reach. |
30
|
threads
|
int
|
Threads reading the BAM files and binning the pairs. |
1
|
tmp_dir
|
str
|
Where the pairs of the BAM files are written. |
'.'
|
command
|
str
|
The command line, stored in the history of the map. |
None
|
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If an input is not of the assembly, cannot be read, or no pair of the inputs is on the contigs of the assembly. outfile is then left as it was: the map is written next to it, as a hidden file, and renamed onto it once it holds contacts. |
Source code in src/metator/inputs.py
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 | |
metator.dump writes the tables of a run from the map of its clusters, as
metator dump does (see dump).
metator.dump ¶
The tables of a run, written from the map of its clusters: metator dump.
A run keeps everything it finds in its map and writes its tables in its
temporary directory only. metator dump MAP -o DIR writes them from the
map, read only: contig_data_final.txt (in the map's order, without the
ID column, whose values were positions in the map the run read),
cluster_summary.txt (rows, columns and formats as the validation
recorded them), binning.txt, clusters.txt (with the number of
contigs and the length of each cluster, which the map computes),
cluster_members.txt and network.txt.
The map must be the map of the clusters as its run wrote it (see check_dumpable); every table is read through one opened map, and they are renamed into place all at once.
check_dumpable ¶
Refuse a map that holds no run to dump: no validation entry in its metator metadata, or no clustering round final.
The genomes of the map need not be the final clusters of its run: the tables follow the genomes (those that metator mge --reassign makes of its MGE clusters, or a curation by hand with metacooler reassign), each with the values that the genomes table gives it.
Returns:
| Type | Description |
|---|---|
dict
|
The validation entry of the metator metadata of the map. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the map lacks either. |
Source code in src/metator/dump.py
contig_data_final ¶
The contig data of the final clusters of a run (contig_data_final.txt), from its map: one row per contig of the map, in its order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
The map, for the messages. |
required |
mc
|
MetaCooler
|
The map, opened. |
required |
table
|
DataFrame
|
The contig data of the contigs of the map (see metator.network.map_contig_table). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table, without its ID column. |
Source code in src/metator/dump.py
final_clusters ¶
The final cluster of each contig of the map, in its order: the name of its genome, ND for metacooler's unbinned (a contig in no final cluster).
Source code in src/metator/dump.py
binning ¶
Each contig of a final cluster, and its cluster (binning.txt, the table that anvi'o imports), from the contig data of the final clusters (see contig_data_final), in its order.
Source code in src/metator/dump.py
summary_layout ¶
How the run wrote the summary of its final clusters (cluster_summary.txt), as the validation entry of its map records it (validation, see metator.cli.validation_entry): its rows, its columns and their formats, with which the values in the genomes table of the map write it again (see cluster_summary).
Returns:
| Type | Description |
|---|---|
SummaryLayout
|
The rows, the columns and the format of each column. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the entry lacks one of them, as that of a map that a development build of metaTOR 2.0 validated does, or does not record them as metator validation records them: each time, run metator validation on the map again. |
Source code in src/metator/dump.py
cluster_summary ¶
The summary of the genomes of the map of a run (cluster_summary.txt), from its genomes table, as the validation wrote the summary of its final clusters (layout, see summary_layout): a line per genome, the final clusters of the summary that are genomes of the map, in its order, then its other genomes, in the order of the genomes table (the MGE genomes that metator mge --reassign makes, or genomes of a curation by hand); its name then the value of each column in the genomes table, written with the format of the column (an empty field for a missing value: NaN, None or an empty text), after a header, an empty field then the columns. The columns are those of the summary, then, when the genomes table says which genomes are MGE genomes, those of MGE_SUMMARY_FORMATS that it holds, then those of HOST_SUMMARY_FORMATS that it holds: the hosts of the MGE clusters that metator host stored there.
Returns:
| Type | Description |
|---|---|
DataFrame
|
The fields of the summary, as text, indexed by the names of the genomes (an index without a name, which gives the header its empty field). |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the genomes table lacks a column of the summary, or holds a value that the format of its column does not write (an edit of the map changed them since the run). |
Source code in src/metator/dump.py
check_network ¶
Refuse a map whose network is not the one that its clusters were made from: metator partition records the digest of the network that it partitioned (see metator.metacool.partition_network), which that of the network stored in the map (stored, see metator.network.stored_network) must be. metator network, run on the map after the run that wrote its clusters (with another normalization, or on the contacts of another library), stores another network there and keeps the clusters: the network and the clusters of the tables would not go together.
Raises:
| Type | Description |
|---|---|
MetacoolError
|
With the remedies: metator network with the normalization of the run, which stores its network again on the contacts that it read, or metator partition and validation, which cluster the network stored now. |
Source code in src/metator/dump.py
network_table ¶
The network of the contigs of a map (network.txt): one row per edge, the names of its two contigs and its weight, without the contacts within a contig, in the order of the map: from the first contig of the map to the last, each with the contigs after it (see metator.network.map_network). The weight is the count of the contacts of the two contigs times the weight of each, for the normalization that metator network stored, or the count for None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
DataFrame
|
The contig data of the contigs of the map, in its order. |
required |
network
|
DataFrame
|
The network of the map, by the positions of its contigs (see metator.network.map_network). |
required |
Source code in src/metator/dump.py
existing_tables ¶
The tables of metator dump that outdir holds already (see TABLES), by name.
read_run ¶
The map of the clusters of a run, opened once, as metator dump and metator export read it, once refused what they refuse: a map without the clusters of a validation, or whose clusters were edited since (see check_dumpable), without the summary that metaTOR 2.0 records (see summary_layout), or whose network is not the one that its clusters were made from (see check_network). A read that spans a replacement of the map raises a MapReplacedError, whose message ends with remedy.
Returns:
| Type | Description |
|---|---|
tuple
|
The map, opened (a metacooler.MetaCooler); the layout of the summary of its final clusters (see summary_layout); and its network, read through it (see metator.network.stored_network): the contig data of its contigs, and the network weighed with the stored normalization (whose Hit column must be that of its contacts), which must be the one that the clusters were made from. |
Source code in src/metator/dump.py
dump ¶
Write the tables of the run that wrote the map metacool (see the module's docstring) in outdir, made if it is not there. The map is read only: every table comes from one state of the map, read through one opened map, which is refused if it was replaced or written while it was read.
The tables are written under temporary names, then renamed: an earlier dump's tables are replaced all at once, or not at all.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the .metacool file of the clusters of a run, or URI of an entry
of a .mmetacool collection: |
required |
outdir
|
str
|
The directory of the tables. |
required |
force
|
bool
|
Whether to replace the tables that outdir holds already. |
False
|
Returns:
| Type | Description |
|---|---|
list of str
|
The paths of the tables, in the order of TABLES. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If outdir holds one of the tables already (without force), or a directory in the place of one, the map cannot be read, holds no clusters of a validation or clusters edited since (see check_dumpable), no summary of them that metaTOR 2.0 records (see summary_layout), no network, partition or summary that metaTOR stored, or a network other than the one its clusters were made from (see check_network), or was replaced while it was read, or a table cannot be written. |
Source code in src/metator/dump.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |