Partition and validation¶
metator.partition partitions the network many times with the Louvain or
Leiden algorithm, and merges the contigs that always fall together into
clusters. metator.clusters holds the clustering rounds of a run, the
partition among them, as the map stores them. metator.validation measures
the clusters with miComplete, and partitions the contaminated ones again, and
metator.figures draws the plots of the final clusters.
metator.markers finds miComplete's marker genes on each contig of a map,
and gives from them miComplete's numbers of a genome of the map, and an
estimate of those of any other group of contigs (see
Marker genes of the contigs).
See Partition and validation.
metator.partition ¶
Partition the metaHiC network with the Louvain or Leiden algorithm.
The partition iterates Louvain or Leiden on the network of the contigs of a map (see metator.network.map_network), finds the core clusters (contigs always together), then merges core clusters whose Hamming distance is below the overlap threshold (so as not to split genomes). metator partition MAP stores the result (metator.clusters.Partition) in the map as clustering rounds; the validation reads it back (partition_table).
algo_partition ¶
algo_partition(
algorithm="louvain",
network=None,
iterations=10,
resolution_parameter=1.0,
progress=False,
)
Function to partition the network depednding on the used algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
str
|
Algorithm to use to partition network. |
'louvain'
|
network
|
DataFrame
|
The network: one row per edge, with the ids of its two contigs and its weight, normalized or not (columns contig1, contig2 and weight, see metator.network.map_network). |
None
|
iterations
|
int
|
Number of iterations of the algorithm of Leiden or Louvain. |
10
|
resolution_parameter
|
float
|
Resolution parameter for Leiden clustering. |
1.0
|
progress
|
bool
|
Whether the log follows the iterations (see iterate): that of the partition of the network, not those of the recursive partitions of the validation. |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionnary with the id of the contig as key and the list of the results of each iterations separated by a semicolon as values. |
Source code in src/metator/partition.py
defined_overlapping_bins ¶
This function extract the overlapped bins
Two core bins overlap when the fraction of iterations that put them together reaches the threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
overlap
|
float
|
hamming distance threshold use to consider that two bins are overlapping. |
required |
hamming_distance
|
csr_matrix
|
Matrix with all the previously computed hamming distance between two core bins. |
required |
core_bins_contigs
|
dict
|
Dictionnary which has as keys the core bins id and as value the id of the contigs of the core bin. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionnary with the id of the overlapping bins as keys and the list of id of their contigs as values. |
Source code in src/metator/partition.py
detect_core_bins ¶
Detect core bins from the output of the partition algorithm.
A core bin holds the contigs that every iteration puts in the same community.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_partition
|
dict
|
Dictionnary with the id of the contig as key and the list of the results of each iterations separated by a semicolon as values. |
required |
iterations
|
int
|
Number of iterations made previously with the partition algorithm. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionnary which has as keys the core bins id and as value the id of the contigs of the core bin. |
DataFrame
|
Table with the id of the core bin and their values for each iterations. |
Source code in src/metator/partition.py
get_distances_splitmat ¶
This function takes a segment of the full iterative clustering matrix and computes, for each index (i.e. contig), the hamming distance to each of the other indices.
The values are one minus the normalized Hamming distance: the fraction of the iterations in which both core bins fell in the same community.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bins
|
DataFrame
|
Slice of the table with the id of the core bin and their values for each iterations. |
required |
core_bins_iterations
|
DataFrame
|
Table with the id of the core bin and their values for each iterations. |
required |
Returns:
| Type | Description |
|---|---|
csr_matrix
|
matrix of the distance of the possible pairs from the slice of the table and the table itself. |
Source code in src/metator/partition.py
get_hamming_distance ¶
Generate matrix of Hamming distances between all pairs of core bins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core_bins_iterations
|
DataFrame
|
Table with the id of the core bin as index and their values for each iterations. |
required |
threads
|
int
|
Number of cores to parallelize computation. |
required |
Returns:
| Type | Description |
|---|---|
csr_matrix
|
Matrix with all the previously computed hamming distance between two core bins. |
Source code in src/metator/partition.py
leiden_iterations ¶
Partition the network with the igraph implementation of Leiden.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
DataFrame
|
The network (see network_graph). |
required |
iterations
|
int
|
Number of iterations of the algorithm of Leiden. |
required |
resolution_parameter
|
float
|
Resolution parameter for Leiden clustering. |
required |
progress
|
bool
|
Whether the log follows the iterations (see iterate). |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionnary with the id of the contig as key and the list of the results of each iterations separated by a semicolon as values. |
Source code in src/metator/partition.py
louvain_iterations ¶
Partition the network with the igraph implementation of Louvain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
DataFrame
|
The network (see network_graph). |
required |
iterations
|
int
|
Number of iterations of the algorithm of Louvain. |
required |
progress
|
bool
|
Whether the log follows the iterations (see iterate). |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionnary with the id of the contig as key and the list of the results of each iterations separated by a semicolon as values. |
Source code in src/metator/partition.py
iterate ¶
The memberships of the vertices of a network in iterations iterations of an algorithm (louvain or leiden), each one call of membership.
With progress, the log follows them, as they can take minutes on a large network: a line at each tenth of the iterations, when PROGRESS_INTERVAL seconds have passed since the previous line, and one once they are all done, with the time they took.
Source code in src/metator/partition.py
merge_iterations ¶
Merge the clusters of each iteration in one dictionnary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contigs
|
ndarray
|
Contig ids of the network vertices. |
required |
memberships
|
list of list
|
Cluster of each vertex, for each iteration. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionnary with the id of the contig as key and the list of the results of each iterations separated by a semicolon as values. |
Source code in src/metator/partition.py
partition ¶
partition(
algorithm,
network,
iterations,
overlapping_parameter,
resolution_parameter,
threads,
prefix,
)
Partition the network of the contigs of a map: its core clusters, then its overlapping clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
str
|
Algorithm to use to partition the network. |
required |
network
|
DataFrame
|
The network of the contigs of the map (see metator.network.map_network). |
required |
iterations
|
int
|
Number of iterations to use for the partition. |
required |
overlapping_parameter
|
int
|
Hamming distance threshold to use to merge bins (percentage). |
required |
resolution_parameter
|
float
|
Resolution parameter to use if Leiden algorithm is chosen. |
required |
threads
|
int
|
Number of threads to use. |
required |
prefix
|
str
|
Sample prefix to use, which names the overlapping clusters (see metator.clusters.overlapping_name). |
required |
Returns:
| Type | Description |
|---|---|
Partition
|
The core and the overlapping clusters, numbered from 1, each with the IDs of its contigs. |
Source code in src/metator/partition.py
network_graph ¶
The network as an igraph graph: its vertices are the contigs of its edges, in the order of their ids, and its edges are in the order of its rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
DataFrame
|
One row per edge: the ids of its two contigs (columns contig1 and contig2) and its weight, normalized or not (column weight), as metator.network.map_network gives them. |
required |
Returns:
| Type | Description |
|---|---|
Graph
|
Weighted undirected network. |
ndarray
|
Contig ids of the vertices. |
Source code in src/metator/partition.py
partition_table ¶
The contig data table of a partition: the contig data with the core and the overlapping cluster of each contig, as contig_data_partition.txt held it, and as the validation reads it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contig_data
|
DataFrame
|
The contig data, which is left as it is. |
required |
partition
|
Partition
|
The core and the overlapping clusters of the partition. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Table with all the information on the contigs included their appartenance to the bins. |
Source code in src/metator/partition.py
metator.clusters ¶
The clustering rounds of a run: the map's /clusters group, and their tables.
A run reaches its final clusters in rounds:
core: the contigs that every iteration of Louvain or Leiden put together, namedcore_<number>(:func:core_name), with no parent;overlapping: the core clusters merged, named<prefix>_<number>_00000(:func:overlapping_name), every one; the validation checks those that reach--size;recursive_<k>: the clusters that step k of the validation makes from a contaminated cluster, their parent;final: the final clusters, each the cluster of its name in the round it comes from;mge, ormge_randomwith--random: the MGE clusters ofmetator mge, after the others.
metator partition stores the first two (:func:partition_rounds), the
validation reads them back (:func:metator.metacool.read_partition) and
records every round (:class:Rounds), which the map of the clusters stores
(:func:metator.metacool.write_map) and clusters.txt and
cluster_members.txt hold.
Partition
dataclass
¶
The clusters of a partition of the network of a map (see
:func:metator.partition.partition): its core and its overlapping
clusters, by number (from 1), each the IDs of its contigs (their positions
in the map, from 1, as in the network: see
:func:metator.network.map_network), in the order that the partition lists
them, and the name of each overlapping cluster (see
:func:overlapping_name).
An overlapping cluster's contigs come in the order of its core clusters, by number, then of their IDs: the record order of the FASTA file miComplete checks.
Source code in src/metator/clusters.py
sizes ¶
The size in bp of each overlapping cluster, by number: the sum of the lengths of its contigs (lengths, by contig ID - 1).
Source code in src/metator/clusters.py
Rounds ¶
The clustering rounds of a run, in the order they are made.
A cluster's parent is looked up in the latest round that holds a cluster of that name, as a recursive cluster replaces the one it was split from.
Source code in src/metator/clusters.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
add ¶
Record the cluster name of round_name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
round_name
|
str
|
The round. |
required |
name
|
str
|
The name of the cluster. |
required |
contigs
|
iterable of str
|
The names of its contigs. |
required |
parent
|
str
|
The name of the cluster it was split from, in an earlier round. |
None
|
columns
|
dict
|
Its other columns (those of miComplete). |
None
|
Source code in src/metator/clusters.py
close_round ¶
Make the clusters of round_name the latest ones of their names, once the round is recorded: its clusters' parents are of earlier rounds.
Source code in src/metator/clusters.py
tables ¶
The two tables of the rounds: one row per cluster of every round, with its parent (missing for none) and its columns, and one row per contig of a cluster.
Returns:
| Type | Description |
|---|---|
tuple of pandas.DataFrame
|
The clusters and their contigs, with the columns of the tables that
:meth: |
Source code in src/metator/clusters.py
write ¶
Write the two tables of the rounds in outdir: one row per cluster of every round, and one row per contig of a cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outdir
|
str
|
The directory of the tables. |
required |
lengths
|
Series
|
The length of each contig, by name: each cluster then gets its number of contigs and their length (see with_sizes), as a run writes them, and as metator dump writes them from the map. |
None
|
Returns:
| Type | Description |
|---|---|
tuple of str
|
The paths of the two tables. |
Source code in src/metator/clusters.py
recursive_round ¶
core_name ¶
The name of the core cluster number (1, 2...) of a partition:
core_00001..., as the Core_cluster_ID of the contig data tables
numbers it (00001...).
overlapping_name ¶
The name of the overlapping cluster number (1, 2...) of a partition:
<prefix>_<number>_00000, its FASTA file's name and its name in
miComplete's results, as the validation names its recursive clusters
<prefix>_<number>_<recursive number> (prefix: metator, or
<--prefix>_metator).
Source code in src/metator/clusters.py
cluster_number ¶
The number of a cluster of the round core or overlapping from its
name (see :func:core_name and :func:overlapping_name): the number that
the Core_cluster_ID or the Overlapping_cluster_ID of the contig
data tables gives it, as an int. None for a name of another form: a cluster
that metaTOR's partition did not name.
Source code in src/metator/clusters.py
record_partition ¶
Record the rounds core and overlapping of a partition in rounds
(a :class:Rounds): every core cluster, named :func:core_name, then
every overlapping cluster, named as the partition names it, each with its
contigs and no parent, in the order of their numbers. names: the name of
each contig, by ID - 1. quality: the columns of miComplete of each
overlapping cluster that it checked, by name (none for the others).
Source code in src/metator/clusters.py
partition_rounds ¶
The rounds core and overlapping of a partition, as metator
partition MAP stores them in the map: every cluster, with its contigs (by
name: names, the name of each contig by ID - 1), and no column of
miComplete (see :func:record_partition).
Returns:
| Type | Description |
|---|---|
tuple of pandas.DataFrame
|
The clusters and their contigs (see :meth: |
Source code in src/metator/clusters.py
with_sizes ¶
The clusters table of the rounds with the number of contigs and the length of each cluster (SIZE_COLUMNS), after its parent: what metacooler computes from the contigs of a cluster of the map, a cluster without contigs having none (0 and 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clusters
|
DataFrame
|
The tables of the rounds (see Rounds.tables). |
required |
members
|
DataFrame
|
The tables of the rounds (see Rounds.tables). |
required |
lengths
|
Series
|
The length of each contig, by name. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A copy of clusters with the columns n_contigs and length. |
Source code in src/metator/clusters.py
write_round_tables ¶
Write the two tables of clustering rounds (see :meth:Rounds.tables): the
clusters to clusters_file, a missing value written NA, and their contigs to
members_file. :meth:Rounds.write writes those of a run so, and metator
dump those of a map (see :func:metator.dump.dump).
Source code in src/metator/clusters.py
read_rounds ¶
The two tables of the rounds that a run wrote in outdir, as
:meth:Rounds.write writes them, without the number of contigs and the
length of each cluster (SIZE_COLUMNS), which the map computes: the tables
that :meth:Rounds.tables gives, which the map stores.
Returns:
| Type | Description |
|---|---|
tuple of pandas.DataFrame, or None
|
The clusters and their contigs, or None when the run wrote neither. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If only one of the two tables is there. |
Source code in src/metator/clusters.py
mge_round ¶
The round mge (or mge_random: name): the MGE clusters of a run of
metator mge, from their summary (see metator.mge.generate_bin_summary),
in its order: each named as its FASTA files in fasta/mges
(MetaTOR_MGE_<ID>), with its contigs (the Contigs column) and no
parent. Its other columns are those of the summary (GC, Hit, BinningScore),
but those that the map computes from the contigs (see
:data:MGE_SUMMARY_KEYS): BinLength is the length of the cluster, and
ContigsNumber its number of contigs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary
|
DataFrame
|
The summary of the MGE clusters. |
required |
name
|
str
|
The name of the round: |
MGE
|
Returns:
| Type | Description |
|---|---|
tuple of pandas.DataFrame
|
The clusters and their contigs (see :meth: |
Source code in src/metator/clusters.py
metator.validation ¶
Validates bins with miComplete, and partitions contaminated ones again.
Only bins with a weighted completeness of at least 33% and a contamination, (weighted redundancy - 1) / weighted completeness, of at least 5% go through the recursive step. Its bins replace the original when the most complete of them keeps more than 0.4 + (c - 0.4) / 1.6 of a completeness c; otherwise the original is kept. The step repeats on the new bins, 9 times at most (RECURSIVE_STEPS), and the log says when it stops sooner.
miComplete checks the overlapping clusters of the map's partition that reach --size, then those of each recursive step, from FASTA files that metacooler writes in the run's temporary directory. The validation's tables go there too (-N keeps them); the map of the clusters stores what they hold, and metator dump writes them from it. The plots of the final clusters go to the output directory of the run (see metator.figures).
bin_quality ¶
The quality class of a bin, from miComplete's weighted completeness and weighted redundancy, its contamination being the redundancy minus 1:
- HQ: completion >= 90% and contamination <= 5%;
- MQ: completion >= 70% and contamination <= 10%;
- LQ: completion >= 50% and contamination <= 10%;
- Contaminated: completion >= 50% and contamination > 10%;
- Other: completion < 50%.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
completeness
|
float
|
Weighted completeness of the bin, from 0 to 1. |
required |
redundancy
|
float
|
Weighted redundancy of the bin, 1 for no duplicated marker. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The class of the bin: "HQ", "MQ", "LQ", "Contaminated" or "Other". |
Source code in src/metator/validation.py
correct_final_bin ¶
Function to set the final bin of each contig from the contigs of the FASTA
files of the final bins: the contigs written in <bin>.fa (written, the
contigs of each FASTA file of the run, by cluster name: see
write_overlapping_fasta and write_recursive_fasta) get the bin as
Final_cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contigs_data
|
DataFrame
|
Dataframe with the contigs informations. |
required |
written
|
dict
|
The names of the contigs of the FASTA file of each cluster that the run checked, by cluster name. |
required |
bin_summary
|
dict
|
Dictionnary with the informations of the final bins kept by MetaTOR. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Dataframe with the contigs informations. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a contig written in the FASTA file of a final bin is not in contigs_data. |
Source code in src/metator/validation.py
get_bin_coverage ¶
Function to compute the coverage of each bin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_summary
|
dict
|
Dictionnary with the informations of the final bins kept by MetaTOR. |
required |
contigs_data
|
DataFrame
|
Dataframe with the contigs informations. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionnary with the informations of the final bins kept by MetaTOR with the coverage. |
Source code in src/metator/validation.py
give_results_info ¶
Function to return the general information about the binning results: the number and total size of the bins of each quality class (see bin_quality), in the log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_summary
|
dict
|
Dictionnary with the summary results of the kept bins. |
required |
Source code in src/metator/validation.py
merge_micomplete ¶
Merge the bacterial and archaeal outputs of miComplete into one file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_bact105
|
str
|
Output of miComplete with its 105 bacterial markers. |
required |
out_arch131
|
str
|
Output of miComplete with its 131 archaeal markers. |
required |
outfile
|
str
|
Path of the merged output. |
required |
Source code in src/metator/validation.py
micomplete_compare_bins ¶
Compare the completness and contamination of the bins from the first step and from the recursive step. If the recursive step decrease the completion of one bin without decreasing its contamination, it will kept the bin before the recursive step.
A recursive split that would drop below 50% completion is not taken: complete bins are kept, even contaminated, for a curation by hand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recursive_micomplete_file
|
str
|
Path to the miComplete summary from the recursive step. |
required |
bin_summary
|
dict
|
Dictionnary containing iinformation about the bins. |
required |
parent_dict
|
dict
|
Dictionnary with recursive bin_id as key and parent bin as values. |
required |
step
|
int
|
Recursive step. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionnary with the informations of the final bins kept by MetaTOR. |
Source code in src/metator/validation.py
micomplete_quality ¶
Function to evaluate fasta bins using miComplete. Write the bins quality summury in the outfile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_dir
|
str
|
Path to the input fasta of the bins to evaluate. |
required |
outfile
|
str
|
Path to the file where the results of miComplete will be written. |
required |
threads
|
int
|
Numbers of threads to use for miComplete. |
required |
Source code in src/metator/validation.py
write_overlapping_fasta ¶
Write the FASTA file of each overlapping cluster of a partition that
reaches size bp (--size), for miComplete to check: <outdir>/<name>.fa, the
records of its contigs as they are in the assembly, in the order of the
partition (that of its core clusters, then of their contigs: see
metator.clusters.Partition), through metacooler.write_fasta.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
The map of the partition (a path, or an entry of a collection). |
required |
assembly
|
str
|
Path to the assembly that the map was made from. |
required |
partition
|
Partition
|
The core and the overlapping clusters. |
required |
contig_data
|
DataFrame
|
The contig data of the contigs of the map, in its order (see metator.network.contig_table): their names and sizes. |
required |
size
|
int
|
The size in bp that an overlapping cluster reaches to be checked. |
required |
outdir
|
str
|
The directory to write the files in, made if missing. |
required |
temp_dir
|
str
|
Where metacooler copies a compressed assembly, plain: the temporary directory of the run. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The names of the contigs of each cluster written, in the order of their records, by cluster name, the clusters by number. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the assembly lacks a contig of a cluster, or gives it another length than the map (the reason is logged as an error). |
Source code in src/metator/validation.py
plain_assembly ¶
The assembly as the run hands it to metacooler.write_fasta: the file itself, when it is plain, or its copy decompressed in directory (the temporary directory of the run), when it is compressed with gzip, made once for the run: write_fasta would copy it again for every FASTA file write (the overlapping clusters, each recursive step). The copy is named after the assembly, without its .gz: an error of write_fasta names it.
Source code in src/metator/validation.py
write_recursive_fasta ¶
Write the FASTA file of each cluster of a recursive step for miComplete to
check: <outdir>/<name>.fa, the records of its contigs (groups: their names,
by cluster name) as they are in the assembly, in their order, through
metacooler.write_fasta, as write_overlapping_fasta writes those of the
overlapping clusters.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the assembly lacks a contig of a cluster, or gives it another length than the map (the reason is logged as an error). |
Source code in src/metator/validation.py
recursive_clustering ¶
recursive_clustering(
iterations,
overlapping_parameter,
resolution_parameter,
algorithm,
bin_summary,
contigs_data,
network,
size,
threads,
prefix,
)
Function to run recursive iterations on contaminated bins in order to try to improve the quality of the bins using Louvain or Leiden algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterations
|
int
|
Number of iterations to use for recursive iterations of Louvain or Leiden. |
required |
overlapping_parameter
|
float
|
Hamming distance threshold to consider two bins as the same bin. |
required |
resolution_parameter
|
float
|
Resolution parameter of Leiden algorithm. |
required |
algorithm
|
str
|
Algorithm to use, either louvain or leiden. |
required |
bin_summary
|
dict
|
Dictionary containing information about the bins. |
required |
contigs_data
|
DataFrame
|
Table with all the data from the contigs. |
required |
network
|
DataFrame
|
The network of the contigs of the map: one row per edge, with the columns contig1, contig2 and weight (see metator.network.map_network). |
required |
size
|
int
|
Size threshold in base pairs of the bins. |
required |
threads
|
int
|
Number of threads to use. |
required |
prefix
|
str
|
Sample prefix to use. |
required |
Returns:
| Type | Description |
|---|---|
boolean
|
True if at least one new recursive bin has been generated. |
DataFrame
|
Updated dictionnary which has as keys the values of the iterations from the recursive partition separated by a semicolon and as values the list of the id of the contigs. |
dict
|
Dictionnary with recursive bin_id as key and parent bin as values. |
dict
|
The names of the contigs of each new recursive bin, in the order of the records of its FASTA file (see write_recursive_fasta), by bin name. |
Source code in src/metator/validation.py
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 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
contaminated_bins ¶
The bins that a recursive step partitions again (see recursive_clustering): those that the step before made (their recursive flag: the overlapping clusters at the first step), with a weighted completeness of at least 33% and a contamination, (weighted redundancy - 1) / weighted completeness, of at least 5%.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_summary
|
dict
|
Dictionary containing information about the bins. |
required |
Returns:
| Type | Description |
|---|---|
list of str
|
The names of the bins, in the order of bin_summary. |
Source code in src/metator/validation.py
bin_contig_ids ¶
Function to list the IDs of the contigs of a bin from the contigs data:
those of its overlapping bin and recursive bin, given by its name
(<prefix>_<overlapping bin ID>_<recursive bin ID>).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_id
|
str
|
Name of the bin. |
required |
contigs_data
|
DataFrame
|
Table with all the data from the contigs. |
required |
Returns:
| Type | Description |
|---|---|
list of int
|
IDs of the contigs of the bin. |
Source code in src/metator/validation.py
recursive_clustering_worker ¶
recursive_clustering_worker(
bin_id, network, algorithm, iterations, resolution_parameter, contigs_data
)
Worker to partition one bin if it's contaminated: its subnetwork, the edges of the network between two of its contigs, in their order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_id
|
str
|
Name of the bin. |
required |
network
|
DataFrame
|
Network of contigs from HiC librairies: one row per edge, with the columns contig1, contig2 and weight. |
required |
algorithm
|
str
|
Algorithm to use, either louvain or leiden. |
required |
iterations
|
int
|
Number of iterations to use for recursive iterations of Louvain or Leiden. |
required |
resolution_parameter
|
float
|
Resolution parameter of Leiden algorithm. |
required |
contigs_data
|
DataFrame
|
The contig data of the partition, with the recursive bins so far. |
required |
Source code in src/metator/validation.py
recursive_decontamination ¶
recursive_decontamination(
algorithm,
assembly,
contig_data_file,
final_fasta_dir,
input_fasta_dir,
iterations,
network,
outdir,
overlapping_parameter,
recursive_fasta_dir,
resolution_parameter,
size,
threads,
prefix,
partition,
*,
metacool,
written,
temp_dir=None,
plot_outdir=None,
)
Function to validate bins do the recursive decontamination using Louvain or Leiden algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
str
|
Algorithm to use to recursively partition the network. |
required |
assembly
|
str
|
Path to the assembly file used for the partition. |
required |
contig_data_file
|
str
|
Path to the contig data table of the partition (see metator.partition.partition_table), to update. |
required |
final_fasta_dir
|
str
|
Path to write the final fasta decontaminated bins. |
required |
input_fasta_dir
|
str
|
Path to the directory of the FASTA files of the overlapping clusters to check (see write_overlapping_fasta). |
required |
iterations
|
int
|
Number of iterations to use for the recursive partition. |
required |
network
|
DataFrame
|
The network of the contigs of the map, in the IDs of the contigs in contig_data_file: their positions in the map as the run read it (see metator.network.map_network), which the contig data of the partition numbers them by too (see metator.partition.partition_table). |
required |
outdir
|
str
|
Path to the directory where to write the tables of the validation: the temporary directory of the run (see the module's docstring). |
required |
overlapping_parameter
|
int
|
Hamming distance threshold in percentage to use to consider to bins as one in the recursive partition. |
required |
recursive_fasta_dir
|
str
|
Path to write the fasta decontaminated bins, one directory per
recursive step ( |
required |
resolution_parameter
|
float
|
Resolution parameter to use if Leiden algorithm is chosen. |
required |
size
|
int
|
Threshold size in base pair of the output bins. |
required |
threads
|
int
|
Number of threads to use. |
required |
prefix
|
str
|
Sample prefix to use. |
required |
partition
|
Partition
|
The core and the overlapping clusters of the partition, recorded as the first rounds of the run (see metator.clusters.record_partition): every cluster, those that miComplete checked with its columns. |
required |
metacool
|
str
|
The map of the run, which metacooler writes the FASTA files of the recursive clusters from the assembly with (see write_recursive_fasta). |
required |
written
|
dict
|
The names of the contigs of the FASTA file of each overlapping cluster in input_fasta_dir, by cluster name (see write_overlapping_fasta). |
required |
temp_dir
|
str
|
Where metacooler copies a compressed assembly, plain: the temporary directory of the run. |
None
|
plot_outdir
|
str
|
The output directory of the run, where the plots of the final clusters
are drawn, in |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The contig data of the validation, with the final cluster of each contig (Final_cluster, ND for none), as contig_data_final.txt holds it. |
SummaryLayout
|
How the summary of the final clusters (cluster_summary.txt) is written: its rows, its columns and their format. |
Source code in src/metator/validation.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 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 | |
name_recursive_clusters ¶
Record the bins of the recursive partition of a contaminated bin that are larger than size: their IDs in the contig data, their parent, and their contigs, for their FASTA files (see write_recursive_fasta).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_id
|
str
|
Name of the parental bin. |
required |
contigs_data
|
DataFrame
|
Table with all the data from the contigs, updated in place: the Recursive_cluster_ID, Recursive_cluster_contigs and Recursive_cluster_size of the contigs of each new bin. |
required |
recursive_bins
|
dict
|
Dictionnary which has as keys the values of the recursive iterations from Louvain or Leiden separated by a semicolon and as values the list of the id of the contigs. |
required |
size
|
int
|
Size threshold of a bin. |
required |
parent_dict
|
dict
|
Dictionnary with recursive bin_id as key and parent bin as values, updated in place. |
required |
prefix
|
str
|
Sample prefix to use. |
required |
groups
|
dict
|
The names of the contigs of each new bin, in the order of the
partition, by bin name ( |
required |
Returns:
| Type | Description |
|---|---|
boolean
|
True if one bin is larger than size. |
Source code in src/metator/validation.py
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | |
metator.markers ¶
The marker genes of the contigs of a .metacool map, as miComplete finds those of a bin: metator markers.
miComplete gives a bin four numbers from the single-copy marker genes found
in it: its completeness, redundancy, weighted completeness and weighted
redundancy. Each comes from the marker genes of the bin, and each marker
gene lies on one contig: stored per contig, the markers of a genome give its
four numbers again, with no gene to find (see marker_quality), exactly those
that miComplete gives it as the markers were found (trained in single genome
mode on its contigs, in the order of the map, see below). Those of any other
group of contigs (two genomes merged, a contig moved from one to another,
contigs of no genome recruited) give an estimate of the numbers of a bin of
them, from the genes found in the genomes of the map, which miComplete's own
run on the group can differ from: it trains pyrodigal on the group itself,
and counts the E-values of the hits over its proteins. Of 28 curated groups
of the mock community MM133 (halves of MAGs, merges of two MAGs, MAGs with
contigs of no genome), 23 came out exact; the merge of the MAGs of two
organisms (GC 66.5% and 39.0%) has a redundancy of 1.6667 from the stored
markers (175 copies of the 105 markers of Bact105), 1.1827 from miComplete,
which, trained on the two together, finds 123 copies of 104 of them. This is
what metator markers stores in a map (see metator.metacool.write_map), so
that a viewer recomputes the numbers of a bin as a curation edits it: those
of a genome of the map, and an estimate of those of a bin the curation
made.
The genes and their markers are found as metaTOR's miComplete finds them in a bin (see metator._micomplete): pyrodigal in its single genome mode, trained on all the contigs of the bin together, in their order, then run on each contig; then pyhmmer's hmmsearch of the marker HMMs of a set (Bact105: 105 bacterial markers, Arch131: 131 archaeal ones) in the proteins of the genes, with miComplete's E-value threshold (--evalue, 4e-10), its E-values counted over the proteins of the bin (Z, the number of proteins). miComplete reads the hits from the table that hmmsearch writes (--tblout), and drops a hit whose bias is too high for its score (--bias, 0.3) or whose best domain is much less significant than the whole protein (--domain-cutoff, 1e-5): read here from the same table, written by pyhmmer as metaTOR's miComplete writes it, so that the hits are those of miComplete, its rounding of the table's numbers included (see read_hits).
On a map, each genome of the map (not __unbinned__) is a bin: its contigs
are trained on in the order of the map, the order in which metaTOR writes
the FASTA file of a genome (metacooler fasta, fasta/mags/). Summed
over the contigs of such a genome, the markers give the four numbers that
miComplete gives that FASTA file. miComplete finds no gene in a bin of less
than 20 kb, which prodigal cannot train on: the contigs of a genome that
small, and those of no genome, have their genes found in metagenome mode
(pyrodigal's pre-trained models, contig by contig), and their markers
searched with Z the median number of proteins of the genomes trained in
single mode: every genome of the map of 20 kb or more, whatever it is, an
MGE genome of metator mge --reassign too, whose fewer proteins lower it.
The genomes, and groups of the other contigs, are searched side by side in
threads: pyrodigal and pyhmmer release the GIL, and each search runs on one
CPU, as miComplete runs hmmsearch in each of its processes.
The markers of a contig, in a set, are written as a text (see
encode_markers): its markers sorted by name, comma-separated, each with the
number of its proteins that miComplete keeps when above one
(Ribosomal_L22,SecY*2); *0 for a marker that miComplete sees on the
contig (a hit in the table of hmmsearch) but whose every hit it drops, which
still counts in its weighted completeness, as miComplete counts the markers
it sees there, and in none of its other numbers. Both columns hold text, an
empty one for a contig without a marker. The markers entry of the map
records the marker sets that they were found with, their markers and their
weights, which turn them into numbers again (see map_sets and
stored_quality): those of the miComplete that found them, which the one
installed later, whose sets find new markers (see marker_set), may weigh
otherwise.
MarkerSet
dataclass
¶
A marker set of miComplete (see marker_set).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Its name: Bact105 or Arch131. |
hmms |
str
|
The path to its HMMs (share/ |
markers |
tuple of str
|
The names of its markers, in the order of its HMMs. |
weights |
tuple of float
|
The weight of each marker, in the same order, as miComplete reads them
(share/ |
Source code in src/metator/markers.py
entry ¶
The set as the markers entry of the metadata of a map records it: its markers in the order of its HMMs, and their weights.
Proteins
dataclass
¶
The proteins of the genes of a group of contigs (see find_proteins).
Attributes:
| Name | Type | Description |
|---|---|---|
fasta |
str
|
The proteins, as pyrodigal writes them, and prodigal (-a): one record
per gene, |
contigs |
list of str
|
The contig of each protein, in the order of the records. |
Source code in src/metator/markers.py
GroupMarkers
dataclass
¶
The markers of the contigs of a group (see group_markers).
Attributes:
| Name | Type | Description |
|---|---|---|
proteins |
int, or None
|
The number of proteins of the group; None when it is too short to train on (in single genome mode). |
markers |
dict
|
By marker set, the markers of each contig that has some (see count_markers). |
Source code in src/metator/markers.py
ContigMarkers
dataclass
¶
The markers of the contigs of a map (see contig_markers).
Attributes:
| Name | Type | Description |
|---|---|---|
table |
DataFrame
|
One row per contig of the map, in its order: its name (Name) and its markers in each set (markers_Bact105, markers_Arch131; see encode_markers), an empty text for none. |
trained |
dict
|
The genomes whose genes were found in single genome mode, trained on their contigs: the number of proteins of each, by name, in the order of the genomes table. |
small |
list of str
|
The genomes too short to train on, whose contigs are in metagenome mode, in the order of the genomes table. |
meta |
int
|
The number of contigs in metagenome mode: those of the small genomes and of no genome (unbinned). |
z |
float, or None
|
The number of proteins over which the E-values of the contigs in metagenome mode are counted (see metagenome_z); None without such contigs. |
assignment |
str, or None
|
The binning that the genes were found in: the digest of the genome of each contig of the map as the run read it (see metator.metacool.assignment_digest), which the markers entry of the map records. |
Source code in src/metator/markers.py
Quality ¶
Bases: NamedTuple
The four numbers that miComplete gives a bin, as it writes them (see marker_quality).
Source code in src/metator/markers.py
marker_column ¶
The column of the contigs table of a map that holds the markers of each
contig in the marker set name (see encode_markers): markers_
marker_set
cached
¶
The marker set name of miComplete (Bact105 or Arch131), from the files
that miComplete installs: its markers named as miComplete names them (the
NAME lines of the HMMs), and their weights (the lines name
Source code in src/metator/markers.py
find_proteins ¶
The proteins of the genes of a group of contigs, as metaTOR's miComplete finds those of a bin (see metator._micomplete.create_proteome): pyrodigal in its single genome mode, trained on all the contigs together, joined in their order as prodigal joins them, then run on each contig; or, with meta, in its metagenome mode, contig by contig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contigs
|
list of (str, bytes)
|
The name and the sequence of each contig, in order. |
required |
meta
|
bool
|
Whether to find the genes in metagenome mode. |
False
|
Returns:
| Type | Description |
|---|---|
Proteins, or None
|
None in single genome mode when the contigs, joined, are too short to train on (MIN_TRAINING): miComplete finds no gene in such a bin. |
Source code in src/metator/markers.py
search_table ¶
The hits of the HMMs of a marker set (a MarkerSet) in proteins (a
Proteins), as metaTOR's miComplete runs hmmsearch on a bin (see
metator._micomplete.hmm_search): hmmsearch -E <evalue> --tblout, the
table written by pyhmmer as hmmsearch writes it (its target E-values per
protein of the search, Z: by default, the number of proteins searched).
Returns:
| Type | Description |
|---|---|
str
|
The table (--tblout), its header once: empty without a protein. |
Source code in src/metator/markers.py
read_hits ¶
The hits of a table of hmmsearch (--tblout) as miComplete reads them (micomplete.completeness.calcCompleteness.get_completeness): the target protein, the marker (the query) and whether miComplete keeps the hit, from the numbers as the table writes them (two significant digits for an E-value, one decimal for a score): it drops a hit whose score times bias is no more than its bias, or whose best domain has an E-value more than domain_cutoff above that of the whole protein (suspicion_check). Every hit of the table counts in the markers miComplete sees, kept or dropped.
Returns:
| Type | Description |
|---|---|
list of (str, str, bool)
|
The protein, the marker and whether the hit is kept, in the order of the table. |
Source code in src/metator/markers.py
count_markers ¶
The markers of each contig of a group (see find_proteins), from the hits of a marker set in their proteins (see read_hits): by contig, the number of its proteins that miComplete keeps for each marker that it sees on the contig, 0 for a marker whose every hit there it drops. A protein counts for each marker that it is kept for.
Returns:
| Type | Description |
|---|---|
dict
|
By contig (those with a marker only): a dict of the count of each marker. |
Source code in src/metator/markers.py
group_markers ¶
group_markers(
contigs,
sets=MARKER_SETS,
meta=False,
z=None,
evalue=EVALUE,
bias=BIAS,
domain_cutoff=DOMAIN_CUTOFF,
proteins=None,
)
The markers of each contig of a group of contigs, found as metaTOR's miComplete finds those of a bin of these contigs, in their order (see find_proteins, search_table and read_hits): in single genome mode, or in metagenome mode with meta; the E-values counted over z proteins (by default, the proteins of the group: those of the bin).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contigs
|
list of (str, bytes)
|
The name and the sequence of each contig, in order. |
required |
sets
|
sequence of str
|
The marker sets (see MARKER_SETS). |
MARKER_SETS
|
meta
|
bool
|
Whether to find the genes in metagenome mode. |
False
|
z
|
float
|
The number of proteins that the E-values are counted over. |
None
|
evalue
|
float
|
miComplete's thresholds (--evalue, --bias, --domain-cutoff). |
EVALUE
|
bias
|
float
|
miComplete's thresholds (--evalue, --bias, --domain-cutoff). |
EVALUE
|
domain_cutoff
|
float
|
miComplete's thresholds (--evalue, --bias, --domain-cutoff). |
EVALUE
|
proteins
|
Proteins
|
The proteins of the group, when found already. |
None
|
Returns:
| Type | Description |
|---|---|
GroupMarkers
|
Its proteins and the markers of its contigs; without markers, and proteins None, for a group too short to train on (in single genome mode). |
Source code in src/metator/markers.py
metagenome_z ¶
The number of proteins that the E-values of the contigs in metagenome mode are counted over: the median number of proteins of the genomes trained in single mode (trained, by genome), every genome of the map that pyrodigal trains on, whatever it is, an MGE genome of metator mge --reassign too, whose fewer proteins lower it; without a trained genome, proteins, the number of proteins of the contigs in metagenome mode, searched as one bin.
Source code in src/metator/markers.py
read_contigs ¶
The sequences of the contigs of a map (mc, opened) from its assembly, as metaTOR's miComplete reads those of a bin (Biopython: a record's name is the first word of its header, and its sequence its bases as they are, in upper or lower case).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
The map, for the messages. |
required |
mc
|
MetaCooler
|
The map, opened. |
required |
assembly
|
str
|
The assembly that the map was made from: a FASTA file, plain or compressed with gzip. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The sequence of each contig of the map, as bytes, by name. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the assembly names a contig by several records, or the map is not a map of the contigs of the assembly: a contig that the assembly lacks, or of another length there. |
Source code in src/metator/markers.py
contig_markers ¶
contig_markers(
metacool,
mc,
sequences,
threads=1,
evalue=EVALUE,
bias=BIAS,
domain_cutoff=DOMAIN_CUTOFF,
)
The markers of every contig of a map, in each marker set of miComplete (see the module's docstring): each genome of the map (not unbinned) as a bin of its contigs, in the order of the map, trained on in single genome mode, its E-values counted over its proteins; the contigs of the genomes too short to train on, and of no genome, in metagenome mode, their E-values counted over the median number of proteins of the genomes trained in single mode, MGE genomes included (see metagenome_z).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
The map, for the messages. |
required |
mc
|
MetaCooler
|
The map, opened: its genomes and contigs. |
required |
sequences
|
dict
|
The sequence of each contig of the map, by name (see read_contigs). |
required |
threads
|
int
|
The number of genomes, or groups of contigs, searched side by side. |
1
|
evalue
|
float
|
miComplete's thresholds (--evalue, --bias, --domain-cutoff). |
EVALUE
|
bias
|
float
|
miComplete's thresholds (--evalue, --bias, --domain-cutoff). |
EVALUE
|
domain_cutoff
|
float
|
miComplete's thresholds (--evalue, --bias, --domain-cutoff). |
EVALUE
|
Returns:
| Type | Description |
|---|---|
ContigMarkers
|
The markers of the contigs, and how their genes were found. |
Source code in src/metator/markers.py
encode_markers ¶
The markers of a contig (counts: the number of proteins of each, see
count_markers) as the contigs table of a map stores them: sorted by name
(in the order of their bytes, ASCII), comma-separated, each followed by
* and its count when that is not 1 (Ribosomal_L22,SecY*2; *0
for a marker that miComplete sees but drops); an empty text for none.
Source code in src/metator/markers.py
decode_markers ¶
The markers of a contig from their text (see encode_markers): the count of each, by name. An empty text is none, and so is a missing value (None or NaN), which a contigs table edited by another tool may hold: metaTOR stores both columns as text (see metator.metacool._store_markers).
Source code in src/metator/markers.py
sum_markers ¶
The markers of a group of contigs: those of its contigs (counts, an iterable of dicts, see decode_markers), summed by marker. A marker that miComplete sees on a contig but drops (0) stays, as seen, at 0.
Source code in src/metator/markers.py
marker_quality ¶
The completeness, redundancy, weighted completeness and weighted redundancy that miComplete gives a bin whose markers are counts, in a marker set, as miComplete computes and rounds them (micomplete.micomplete._compile_results and micomplete.completeness.calcCompleteness.attribute_weights).
With P the markers present (a count of one or more) and N the markers of the set: completeness = P / N, and redundancy = the sum of the counts of the present markers / P, each rounded to 4 decimals (by Python's round, as miComplete: an exact tie to the even digit, 1.03125 to 1.0312). The weighted completeness WC is the sum of the weights of the markers that miComplete sees (present, or seen and dropped: a count of 0), rounded to 4 decimals, 0.0001 if that is 0; the weighted redundancy is (the sum of the weights of the markers of more than one copy, each once, + WC) / WC, WC not rounded, the quotient rounded to 4 decimals. A bin without a present marker has 0 for all four.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
counts
|
dict
|
The count of each marker of the bin, by name (see sum_markers): the markers that miComplete sees in it only. |
required |
markers
|
sequence of str
|
The markers of the set (see MarkerSet.markers). |
required |
weights
|
sequence of float
|
The weight of each marker of the set, in the order of markers. |
required |
Returns:
| Type | Description |
|---|---|
Quality
|
The four numbers. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If counts names a marker that is not in the set. |
Source code in src/metator/markers.py
kept_quality ¶
The marker set that metaTOR keeps for a bin, and its numbers, from the numbers of each set (qualities, by set name; see marker_quality), as metator.validation.merge_micomplete keeps miComplete's results: Bact105, unless Arch131 has the higher weighted completeness.
Returns:
| Type | Description |
|---|---|
tuple
|
The set's name for metaTOR (Bacteria or Archaea, see KINGDOMS), and its Quality. |
Source code in src/metator/markers.py
quality_of ¶
The numbers that miComplete gives a group of contigs, from their markers as a map stores them (texts: by marker set, the markers of each contig, see encode_markers), with the marker sets that they were found with (sets: by set, its markers and their weights), as metaTOR keeps them (see kept_quality). For the markers that a map stores, the sets are those that its markers entry records (see map_sets and stored_quality): those of the miComplete that found them, which the one installed now may weigh otherwise; for markers found now (see group_markers), those of the installed miComplete (see entry_sets).
Returns:
| Type | Description |
|---|---|
tuple
|
Bacteria or Archaea, and the Quality of that set. |
Source code in src/metator/markers.py
entry_sets ¶
The marker sets of the miComplete installed now, which metator markers finds new markers with, as the markers entry of the metadata of a map records them (see metator.cli.markers_entry): by set, its column in the contigs table, its markers in the order of its HMMs and their weights.
Source code in src/metator/markers.py
map_sets ¶
The marker sets that the marker genes of the contigs of a map were found with, as its markers entry records them (see entry_sets and metator.metacool.markers_entry): by set, in the order of MARKER_SETS, its column in the contigs table (column), its markers (markers) and their weights (weights). The numbers of a group of contigs of the map come from them (see quality_of and stored_quality), not from the files of the miComplete installed now, which finds new markers (see marker_set): its weights, or its markers, may be other than those of the miComplete that found the markers of the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mc
|
MetaCooler
|
The map, opened. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
By set name: its column, its markers and their weights. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the map records no such sets: it holds no markers that metator markers found, or its entry lacks a set, its column, or a weight (a number) for each of its markers (by name). |
Source code in src/metator/markers.py
stored_quality ¶
The numbers that miComplete gives a group of contigs of a map (mc, opened; contigs: their names, each counted once), from the markers that the map stores, in the columns of its contigs table that its markers entry names, with the marker sets that it records (see map_sets), as metaTOR keeps them (see quality_of): those of a genome of the map as metator markers found its genes, and an estimate of those of any other group (see the module's docstring).
Returns:
| Type | Description |
|---|---|
tuple
|
Bacteria or Archaea, and the Quality of that set. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the map records no marker sets (see map_sets), lacks the column of one, or a contig of the group. |
Source code in src/metator/markers.py
metator.figures ¶
The plots of the final clusters of a validation.
validation and pipeline draw them in plots/, in their output
directory, as PDF files, once the clusters are final (see plot_figures), where
host draws its own (see metator.host.plot_hosts):
bins_distribution.pdf: the completeness and the contamination of each cluster, the clusters by decreasing completeness (see figures_bins_distribution);bins_size_distribution.pdf: the share of the contigs of the run in each quality class of the clusters (see metator.validation.bin_quality), and in no cluster (see figures_bins_size_distribution).
They are drawn with matplotlib's Figure, without pyplot: no window, whatever the backend of matplotlib.
figures_bins_distribution ¶
Plot the completeness and the contamination of each final cluster: a dot each, in percent, the clusters by decreasing completeness (their rank on the x axis), with dashed lines at the thresholds of the quality classes and at 100%.
The contamination is the weighted redundancy minus 1 (see metator.validation.bin_quality), drawn from 0 to 105%: a cluster in which miComplete finds no marker gene, of a redundancy of 0, at 0, and a contamination of more than 105% at 105%.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_summary
|
DataFrame
|
The final clusters, one per row, with miComplete's Weighted completeness and Weighted redundancy, as fractions. |
required |
out_file
|
str
|
Path of the PNG file to write. |
required |
Source code in src/metator/figures.py
figures_bins_size_distribution ¶
Plot a pie chart of the size of the contigs in each quality class of the final clusters (see metator.validation.bin_quality: HQ, MQ and LQ MAGs, contaminated clusters and other clusters), and in no final cluster.
The legend counts the clusters of each class and their size, in Mb; below the pie, the total size of the contigs, the share of the MAGs (HQ, MQ and LQ) in it, and the size threshold of the clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_summary
|
DataFrame
|
The final clusters, one per row, with their Length and miComplete's Weighted completeness and Weighted redundancy. |
required |
total_size
|
int
|
The size of the contigs of the run, in bp: those of its map, the whole assembly for a map of all its contigs. |
required |
threshold
|
int
|
The size threshold of the clusters (--size), in bp. |
required |
out_file
|
str
|
Path of the PNG file to write. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A copy of bin_summary, with the quality class of each cluster in a MAG_quality column. |
Source code in src/metator/figures.py
plot_paths ¶
The plots that a run draws in its output directory, out_dir, in the order of PLOTS: plots/bins_distribution.pdf and plots/bins_size_distribution.pdf.
plot_figures ¶
Draw the plots of the final clusters of a validation in plots/ of its output directory, out_dir, made if missing (see plot_paths): bins_distribution.pdf (see figures_bins_distribution) and bins_size_distribution.pdf (see figures_bins_size_distribution). They replace files of their names; the other files of plots/ are left as they are.
They are figures: one that cannot be drawn is a warning, with the type, message and traceback of the error, and the other one is drawn; a run goes on to write the map of its clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_dir
|
str
|
The output directory of the run. |
required |
contigs_data
|
DataFrame
|
The contig data of the validation: the Size of each contig of the run, those of its map. |
required |
bin_summary
|
dict
|
The final clusters, by name, with their Length and miComplete's Weighted completeness and Weighted redundancy. |
required |
threshold
|
int
|
The size threshold of the clusters (--size), in bp. |
required |