FASTA Tools#

Convenience utils for working with (generalized) FASTA files.

atomworks.io.tools.fasta.infer_chain_type_from_one_letter(seq: str | list[str]) ChainType[source]#

Infer chain type from one-letter sequence notation.

Supports all common sequence input formats:

  • Simple one-letter: "ACDEFG"

  • Parenthesized notation: "(DA)(DT)(DG)" (PDB format for DNA/RNA disambiguation)

  • Mixed with non-canonical amino acids: "ACDE(SEP)FG"

Parameters:

seq – Sequence as string or list (supports all notation types).

Returns:

Inferred chain type (POLYPEPTIDE_L, DNA, or RNA).

Raises:

ValueError – If chain type cannot be inferred from the sequence.

See also

infer_chain_type_from_three_letter() - For CCD code arrays from parsed structures.

atomworks.io.tools.fasta.one_letter_to_ccd_code(seq: list[str], chain_type: ChainType, ccd_mirror_path: PathLike = None, check_ccd_codes: bool = True) list[str][source]#

Convert a sequence of one-letter codes or parenthesized full CCD IDs to full CCD IDs.

This function takes a list of either one-letter amino acid codes or parenthesized CCD IDs and converts them to their corresponding full CCD (Chemical Component Dictionary) IDs. It handles both standard amino acids and non-standard chemical components.

Parameters:
  • seq (list[str]) – A list of one-letter codes or parenthesized CCD IDs.

  • chain_type (ChainType) – The type of chain (e.g., POLYPEPTIDE_L, DNA, RNA) to determine the correct conversion for one-letter codes.

  • check_ccd_codes (bool) – If True, check if the CCD IDs are available in the CCD mirror.

Returns:

A list of full CCD IDs corresponding to the input sequence.

Return type:

  • list[str]

Raises:

- ValueError – If a non-standard chemical component ID is not found in the processed CCD.

Example

>>> seq = ["A", "C", "(SEP)", "G", "H"]
>>> chain_type = ChainType.POLYPEPTIDE_L
>>> one_letter_to_ccd_code(seq, chain_type)
['ALA', 'CYS', 'SEP', 'GLY', 'HIS']
atomworks.io.tools.fasta.split_generalized_fasta_sequence(sequence: str) list[str][source]#

Splits a sequence at each letter, keeping groups with parentheses intact.

Parameters:

sequence (-) – The input sequence to be split.

Returns:

A list of individual letters and/or groups with parentheses.

Return type:

  • List[str]

Example

>>> split_generalized_fasta_sequence("ABC(DEF)GH(IJ)K")
['A', 'B', 'C', '(DEF)', 'G', 'H', '(IJ)', 'K']