Mobile genetic elements¶
metator.mge clusters the contigs of mobile genetic elements (MGEs), from their
contacts, and metator.host finds the MAGs that host each MGE cluster. See
Clustering mobile genetic elements.
metator.mge ¶
Cluster the contigs of a .metacool map that are mobile genetic elements.
The MGE contigs are clustered from their Hi-C contacts: those the map holds between two contigs, and those its QC block counts within each contig, between reads at least 1001 bp apart.
check_mge_map ¶
Refuse a map that mge cannot cluster the MGE contigs of, before any work.
The contacts within an MGE contig are its reads at least 1001 bp apart, which only the map's QC block, measured from the pairs, gives; its pixels do not (see check_mge_qc).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the .metacool file, or URI of an entry of a .mmetacool
collection: |
required |
mc
|
MetaCooler
|
The map, opened. |
required |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the map holds no contact statistics of its pairs, has them measured from its pixels or at another distance than 1001 bp, or lacks the columns of metator network: the reason, and how to make a map that mge reads. |
Source code in src/metator/mge.py
check_mge_qc ¶
Refuse a map without the contact statistics that mge counts the contacts within each MGE contig from: its QC block, measured from the pairs at 1001 bp, with the counts of each contig (see check_mge_map).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the .metacool file, or URI of an entry of a .mmetacool
collection: |
required |
mc
|
MetaCooler
|
The map, opened. |
required |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the map holds no contact statistics of its pairs, or has them measured from its pixels or at another distance than 1001 bp: the reason, and how to make a map that mge reads. |
Source code in src/metator/mge.py
check_contig_map ¶
Refuse, before any work, the map of the contigs of a run that clusters its MGE contigs once it has stored its network and its clusters there (metator pipeline --mges, in its step mge): a map that mge would refuse then for want of the contact statistics of its reads (see check_mge_qc), not of the columns of metator network, which the run stores first, and a map that holds none of the MGE contigs (see mge_contigs). The map of the clusters has the contigs of the map of the contigs, under the same names, and its contact statistics, which metacooler carries over as it groups the contigs by cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the .metacool file, or URI of an entry of a .mmetacool
collection: |
required |
mc
|
MetaCooler
|
The map, opened. |
required |
mges_list
|
list of str
|
Names of the MGE contigs (see metator.io.import_mges_contigs). |
required |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the map has no contact statistics that mge reads, or holds none of the MGE contigs. |
Source code in src/metator/mge.py
mge_contigs ¶
The MGE contigs of a map, the longest first (ties by name), with the values of each that mge reads.
Longest first, ties by name: resolve_matrix breaks ties and update_mge_data numbers single-contig clusters in that order, so the result depends on neither the map's order nor its clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the .metacool file, or URI of an entry of a .mmetacool
collection: |
required |
mc
|
MetaCooler
|
The map, opened (see check_mge_map). |
required |
mges_list
|
list of str
|
Names of the MGE contigs (see metator.io.import_mges_contigs). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per MGE contig of the map, the longest first, ties by name: Name, Size (its length), GC_content and Hit (as metator network stored them). |
ndarray
|
Their positions in the map, from 0, in that order. |
ndarray
|
The contacts within each, between reads more than 1 kb apart (its qc_intra_contig_long). |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If none of the MGE contigs is in the map: there is nothing to cluster. |
Source code in src/metator/mge.py
map_matrix ¶
The contacts of the MGE contigs of a map, as resolve_matrix reads them: the matrix of their raw contacts, in the order of positions.
Only the upper triangle is filled, which resolve_matrix reads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the .metacool file, or URI of an entry of a .mmetacool
collection: |
required |
n_contigs
|
int
|
Number of contigs of the map. |
required |
positions
|
ndarray
|
Positions in the map of the MGE contigs, from 0, in the order of the matrix (see mge_contigs). |
required |
intra
|
ndarray
|
Contacts within each, between reads more than 1 kb apart. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Raw matrix of contacts between the MGE contigs. |
Source code in src/metator/mge.py
generate_bin_summary ¶
The summary of the MGE clusters: one row per cluster, with its length, GC content, hits, clustering score and contigs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contigs_data
|
DataFrame
|
The MGE contigs (see mge_contigs): Name, Size, GC_content and Hit. |
required |
mge_bins
|
dict
|
Dictionary with the mge bin id as key and its contigs ("Contigs") and score ("Score") as value. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per cluster, in the order of mge_bins: BinName
( |
Source code in src/metator/mge.py
mge_binning ¶
mge_binning(
metacool: str,
mges_list: List[str],
threshold_bin: float = 0.8,
random: bool = False,
) -> Tuple[pd.DataFrame, dict]
Main function to cluster the MGE contigs of a map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the .metacool file, or URI of an entry of a .mmetacool
collection: |
required |
mges_list
|
list of str
|
Names of the MGE contigs. |
required |
threshold_bin
|
float
|
Threshold of score to bin contigs. |
0.8
|
random
|
bool
|
If enabled, make a random shuffling of the bins. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The summary of the MGE clusters (see generate_bin_summary). |
dict
|
The MGE clusters: their id as key, their contigs ("Contigs", the longest first, ties by name: see mge_contigs) and score ("Score") as value. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the map cannot be read, cannot be clustered (see check_mge_map), or holds none of the MGE contigs. |
Source code in src/metator/mge.py
write_mges_fasta ¶
Write the FASTA files of the MGE clusters in out_dir (made if missing), two
for each, named after the cluster (MetaTOR_MGE_<ID>), side by side (see
metator.outputs.write_fasta_files): <name>.fa, its contigs as records of
their own, and <name>.stitched.fa, one record, so that the tools that
check the quality of an MGE genome, which expect one sequence per genome,
read the cluster as one: its contigs joined by 200 N, in lines of 80 bases.
Both list the contigs in the order of the cluster (the longest first, ties
by name: see mge_binning). Files of those names are replaced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metacool
|
str
|
Path to the .metacool file, or URI of an entry of a .mmetacool collection: the map whose contigs the MGE clusters are. |
required |
assembly
|
str
|
Path to the assembly the map was made from: FASTA, plain or compressed with gzip. |
required |
mge_bins
|
dict
|
The MGE clusters (see mge_binning). |
required |
out_dir
|
str
|
The directory to write them in: fasta/mges of the output directory of the run (see metator.outputs.MGES_DIR). |
required |
temp_dir
|
str
|
Where a compressed assembly is copied, plain: the temporary directory of the run. |
None
|
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the files cannot be written: the assembly lacks a contig, gives one another length than the map, or is not FASTA (a ValueError, KeyError or OSError of metacooler, message kept). |
Source code in src/metator/mge.py
resolve_matrix ¶
Main function to bin mges contigs.
Contacts are divided by the geometric mean of the intra-contig contacts (reads at least 1001 bp apart); two contigs binned together are fused.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mat
|
array
|
Matrix of the raw contacts between the contigs. |
required |
threshold
|
float
|
Threshold of score to bin contigs. |
0.8
|
Returns:
| Type | Description |
|---|---|
list of list
|
Each binning, in the order made: the two rows of the matrix binned together, then their score. |
Source code in src/metator/mge.py
shuffle_mge_bins ¶
Function to shuffle id to imitate a random binning with the same bins distribution as the one created by Metator MGE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mges_data
|
DataFrame
|
Table with the contigs name as index and with information from metator partition or validation. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Input table with the mge bin id column randomly shuffled. |
dict
|
Dictionary with the mge bin id as key and the list of the contigs name as value from the shuffle contigs bins. |
Source code in src/metator/mge.py
update_mge_data ¶
Function to update the mge bins data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mges_data
|
DataFrame
|
Table wit the mge contig information. |
required |
bins
|
list of tuple
|
List of pairs of contigs with their score of association. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Table wit the mge contig information updated. |
dictionnary
|
Dictionary of the mge bins. |
Source code in src/metator/mge.py
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 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |
metator.host ¶
Find the MAGs that host the MGE clusters of a .metacool map: metator host.
The MGE clusters are those of the round mge of the map, which metator
mge stores, and the MAGs are the genomes of the map, whatever made them:
the final clusters of a metaTOR run, or the bins of another binner that
metacooler reassign made the genomes of the map. __unbinned__ is no
MAG, and neither is a genome named after an MGE cluster (an MGE cluster made
a genome of the map, by metator mge --reassign or metacooler reassign
--round mge). A contig of an MGE cluster counts for its MGE cluster only:
a MAG that holds it too (a validation clusters the MGE contigs with the
other contigs) is taken without it, or the contacts of the MGE cluster
within itself would count as contacts with that MAG.
The signal of an MGE cluster with a MAG is the sum of the weights of the
edges of the network between their contigs: the network that metator
network stored in the map, weighed with its normalization (see
metator.network.stored_network). A MAG hosts the MGE cluster when that
signal is at least min_share percent (10 by default) of the signal of the
MGE cluster with all the MAGs, and when the MGE cluster is in contact with at
least min_contigs of its contigs (5 by default). The contacts of the MGE
cluster with the contigs in no MAG and with the other MGE clusters do not
count in that share: an MGE cluster with few contacts with the MAGs, as a
phage that the library caught in its free particles, can be given a host
from a small part of its contacts. share_of_all, the share of all the
contacts of the MGE cluster with the other contigs, says how small.
metator host stores what it finds in the map (see
metator.metacool.write_map): the hosts of each MGE cluster in the round
mge (HOST_CLUSTER_COLUMNS), and the MGE clusters of each MAG in the
genomes table (HOST_GENOME_COLUMNS); and writes every MGE cluster and MAG in
contact in tables/mge_hosts.txt (see write_hosts), and the signal and share
of the hosts in plots/mge_hosts.pdf (see plot_hosts), in its output
directory.
Hosts
dataclass
¶
The hosts of the MGE clusters of a map (see find_hosts).
Attributes:
| Name | Type | Description |
|---|---|---|
pairs |
DataFrame
|
One row per MGE cluster and MAG in contact (PAIRS_COLUMNS), the MGE clusters in the order of the round mge, the MAGs of each by decreasing signal (ties in the order of the genomes table): the signal of the MGE cluster with the MAG (signal), the number of contigs of the MAG in contact with it (contigs), the signal as a percentage of that of the MGE cluster with all the MAGs (share) and of all its contacts with the other contigs (share_of_all), and whether the MAG hosts it (host). |
clusters |
DataFrame
|
One row per MGE cluster, in the order of the round mge: its name, its number of hosts (n_hosts), its hosts by decreasing share (hosts) and their shares, with two decimals (host_shares), each list separated by commas, missing for none. |
genomes |
DataFrame
|
One row per MAG, in the order of the genomes table: its name, the number of MGE clusters that it hosts (n_mges), and their names, in the order of the round mge, separated by commas (mges, an empty text for none). |
Source code in src/metator/host.py
map_bins ¶
The MAGs and the MGE clusters of a map, as find_hosts reads them (see the module's docstring).
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. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The MAG of each contig of the map, in its order: an empty text for a contig in no MAG (in unbinned, in an MGE genome, or in an MGE cluster). |
DataFrame
|
The MGE clusters and their contigs: one row per contig of an MGE cluster, its cluster (mge) and its position in the map, from 0 (position). |
list of str
|
The MGE clusters, in the order of the round mge. |
list of str
|
The MAGs, in the order of the genomes table. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the map holds no round mge, or no MAG. |
Source code in src/metator/host.py
contact_pairs ¶
The signal of each MGE cluster with each MAG it is in contact with (see the module's docstring), from the network of the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
DataFrame
|
The network of the map, by the positions of its contigs, from 1 (see metator.network.map_network): contig1, contig2 and weight. |
required |
mag
|
The MAGs and the MGE clusters of the map (see map_bins). |
required | |
members
|
The MAGs and the MGE clusters of the map (see map_bins). |
required | |
mges
|
The MAGs and the MGE clusters of the map (see map_bins). |
required | |
mags
|
The MAGs and the MGE clusters of the map (see map_bins). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per MGE cluster and MAG in contact: mge, mag, signal, contigs, share and share_of_all (see Hosts.pairs), the MGE clusters in the order of mges, the MAGs of each by decreasing signal, ties in the order of mags. |
Source code in src/metator/host.py
find_hosts ¶
The hosts of the MGE clusters of a map (see the module's docstring).
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: it gives the MAGs and the MGE clusters (see map_bins). |
required |
network
|
DataFrame
|
The network of the map, by the positions of its contigs, from 1 (see metator.network.stored_network). |
required |
min_share
|
float
|
The share of the signal of an MGE cluster with the MAGs, in percent, from which a MAG is a host. |
MIN_SHARE
|
min_contigs
|
int
|
The number of contigs of a MAG in contact with an MGE cluster from which the MAG is a host. |
MIN_CONTIGS
|
Returns:
| Type | Description |
|---|---|
Hosts
|
The MGE clusters and MAGs in contact, the hosts of each MGE cluster, and the MGE clusters of each MAG. |
Raises:
| Type | Description |
|---|---|
MetacoolError
|
If the map holds no round mge, or no MAG (see map_bins). |
Source code in src/metator/host.py
recorded_thresholds ¶
The thresholds with which the hosts of the MGE clusters of a map (mc, opened) were found, as (min_share, min_contigs): the --min-share and --min-contigs of metator host, or the --mge-min-share and --mge-min-contigs of pipeline --mges, as the host entry of the metator metadata of the map records the parameters of the run (see metator.metacool.host_entry); MIN_SHARE and MIN_CONTIGS for one that it does not record.
Source code in src/metator/host.py
write_hosts ¶
Write the MGE clusters and MAGs in contact (pairs, see Hosts.pairs) at path, tab-separated, with a header: PAIRS_COLUMNS, host True or False. The file is replaced if it exists (a symbolic link there, not its target).
Source code in src/metator/host.py
plot_hosts ¶
Plot the hosts of the MGE clusters (the rows of pairs that are hosts, see Hosts.pairs) at path: the distribution of their signal, on a log scale, and of their share. The axes say so when there is no host.