io¶
Reading and writing sequences and substitution model data.
sequences
¶
Module for reading and writing sequence files.
Read and write fasta files and multiple sequence alignments in various formats.
labeled_sequences(sequences: dict | list[tuple]) -> list[tuple[str, str]]
¶
Converts dictionaries to lists and keys into strings.
If the keys are TreeNode instances, then their label is taken. Also works if sequences
already is a list (of tuples).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequences
|
dict | list[tuple]
|
A dictionary mapping keys to sequences, or a list of (key, sequence) tuples. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, str]]
|
A list of (label, sequence) tuples, where labels are strings. |
Source code in asymmetree/io/sequences.py
write_fasta(file_path: Path | str, sequences: dict | list[tuple]) -> None
¶
Write sequences to a fasta file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path | str
|
The path to the output fasta file. |
required |
sequences
|
dict | list[tuple]
|
A dictionary mapping keys to sequences, or a list of (key, sequence) tuples. If
the keys are |
required |
Source code in asymmetree/io/sequences.py
write_alignment(file_path: Path | str, alignment: dict | list[tuple], alignment_format: str = 'phylip') -> None
¶
Write a multiple sequence alignment to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path | str
|
The path to the output alignment file. |
required |
alignment
|
dict | list[tuple]
|
A dictionary mapping keys to sequences, or a list of (key, sequence) tuples. If
the keys are |
required |
alignment_format
|
str
|
The format of the alignment file. Options are "phylip", "clustal", and "pretty". |
'phylip'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the specified alignment format is not available. |
Source code in asymmetree/io/sequences.py
substitution_model
¶
Module for reading and writing substitution models.
parse_paml(file_path: Path | str, model_type: str = 'a') -> tuple[list[list[float]], list[float]]
¶
Parse a PAML substitution model file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path | str
|
The path to the PAML file containing the substitution model. |
required |
model_type
|
str
|
The type of the substitution model, either "a" for amino acid or "n" for nucleotide. |
'a'
|
Returns:
| Type | Description |
|---|---|
tuple[list[list[float]], list[float]]
|
A tuple containing the exchangeability matrix and the equilibrium frequencies. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the model type is not supported. |
ValueError
|
If the number of equilibrium frequencies is not correct. |