<commit_before>#!/usr/bin/python
# encoding: utf-8
"""
basics.py
Basic objects for bioinformatics.

Created by <NAME> 2013
"""

# todo: To update code which uses these objects formally in pdb.py:
#   replace aa1 with residue_type_3to1_map
#   replace relaxed_amino_acid_codes (a list) with relaxed_residue_types_1 (a set)
#   replace amino_acid_codes (a list) with residue_types_1 (a set)
#   replace non_canonical_aa1 with non_canonical_amino_acids
#   replace residues with allowed_PDB_residues_types
#   replace nucleotides_dna_to_shorthand with dna_nucleotides_2to1_map
#   replace nucleotides_dna and nucleotides_rna with dna_nucleotides and rna_nucleotides respectively
#   The Residue class is now located here and renamed to PDBResidue (since we assert that the chain is 1 character long).
#   The Mutation class is now located here. ChainMutation was called something else.

import types

from Bio.SubsMat.MatrixInfo import blosum62 as _blosum62, pam250 as _pam250# The amino acid codes BXZ in these blosum62 and pam250 matrices appear to be amino acid ambiguity codes
import tools.colortext as colortext

###
# Residue maps and sets.
###

residue_type_3to1_map = {
    "ALA": "A",
    "CYS": "C",
    "ASP": "D",
    "GLU": "E",
    "PHE": "F",
    "GLY": "G",
    "HIS": "H",
    "ILE": "I",
    "LYS": "K",
    "LEU": "L",
    "MET": "M",
    "ASN": "N",
    "PRO": "P",
    "GLN": "Q",
    "ARG": "R",
    "SER": "S",
    "THR": "T",
    "VAL": "V",
    "TRP": "W",
    "TYR": "Y",
    "UNK": 'X',
}

residue_types_3 = set(residue_type_3to1_map.keys())
residue_types_1 = set(residue_type_3to1_map.values()) # formally a list called amino_acid_codes
relaxed_residue_types_1 = residue_types_1.union(set(['X']))

protonated_residue_type_3to1_map = {
    'ARN': 'R', # neutral arginine
    'ASH': 'D', # protonated aspartic acid
    'GLH': 'E', # protonated glutamic acid
    'LYN': 'K', # neutral lysine
    'HIE': 'H', # epsilon-protonated histidine
    'HIP': 'H', # epsilon- and delta-protonated histidine
    'HIS': 'H', # delta-protonated histidine
    'CYM': 'C', # deprotonated or bonded to metal atom
    'CYT': 'C', # deprotonated negative cysteine
    'CYX': 'C', # involved in disulphide bridge and other bonds / neutral cysteine
}
protonated_residues_types_3 = set(protonated_residue_type_3to1_map.keys())
protonated_residues_types_1 = set(protonated_residue_type_3to1_map.values())

non_canonical_amino_acids = {
    'ABA' : 'A', # Alpha-aminobutyric acid
    'CCS' : 'C', # Carboxymethylated cysteine
    'CME' : 'C', # S,S-(2-Hydroxyethyl)Thiocysteine (DB04530)
    'CSD' : 'C', # 3-sulfinoalanine
    'CSO' : 'C', # s-hydroxycysteine
    'CSS' : 'C', # S-Mercaptocysteine (DB02761)
    'CSU' : 'C', # ? some type of cysteine or a typo
    'CSW' : 'C', # Cysteine-S-dioxide
    'CSX' : 'C', # Modified cysteine residue
    'SCH' : 'C', # S-Methyl-Thio-Cysteine
    'SMC' : 'C', # S-methylcysteine
    'PCA' : 'E', # Pyroglutamic acid
    'GLZ' : 'G', # Amino-acetaldehyde
    'HIC' : 'H', # 4-Methyl-Histidine
    'M3L' : 'K', # N-Trimethyllysine
    'MLY' : 'K', # dimethyl lysine
    'FME' : 'M', # N-Formylmethionine
    'MSE' : 'M', # selenomethionine
    'MEN' : 'N', # N-methyl asparagine
    'SEP' : 'S', # Phosphoserine
    'SVA' : 'S', # Serine vanadate
    'TPO' : 'T', # phosphothreonine
    'TRN' : 'W', # Nz2-Tryptophan
    'NEH' : 'X', # Ethanamine
    'MPT' : 'X', # Beta-Mercaptopropionic acid
    'NH2' : 'X', # Amino group
    'PTR' : 'Y', # phospotyrosine
    'BHD' : 'D', # (3S)-3-HYDROXY-L-ASPARTIC ACID
    #
    'ASX' : 'N', # ??? N in UniProt entry P0A786 for 2ATC, chain A
    'GLX' : 'Q', # ??? Q in UniProt entry P01075 for 4CPA, chain I
    'CRT' : 'CRT', # Specially defined by Noah
    'CRG' : 'CRG'  # Specially defined by Noah
}

###
# DNA
# I am unsure whether this is all correct. The code I inherited seems to leave out DI and DU for DNA and T and I for RNA which seems wrong.
###

dna_nucleotides = set(['DA', 'DC', 'DG', 'DT', 'DU', 'DI']) # deoxyribonucleic acids
rna_nucleotides = set(['A', 'C', 'G', 'U', 'I']) # ribonucleic acids

dna_nucleotides_3to1_map = {
    # Used to map Rosetta features database mappings to single letter sequences
    'ADE' : 'A', 'CYT' : 'C', 'GUA' : 'G', 'THY' : 'T', #'DU' : 'U', 'DI' : 'I',
}

dna_nucleotides_2to1_map = {
    # Used to map PDB SEQRES DNA sequences to single letter sequences
    'DA' : 'A', 'DC' : 'C', 'DG' : 'G', 'DT' : 'T', 'DU' : 'U', 'DI' : 'I',
}

non_canonical_dna = {
    '5IU' : 'U', # 5-Iodo-2'-Deoxyuridine-5'-Monophosphate
}
<commit_msg>Real amino acids<commit_after>#!/usr/bin/python
# encoding: utf-8
"""
basics.py
Basic objects for bioinformatics.

Created by <NAME> 2013
"""

# todo: To update code which uses these objects formally in pdb.py:
#   replace aa1 with residue_type_3to1_map
#   replace relaxed_amino_acid_codes (a list) with relaxed_residue_types_1 (a set)
#   replace amino_acid_codes (a list) with residue_types_1 (a set)
#   replace non_canonical_aa1 with non_canonical_amino_acids
#   replace residues with allowed_PDB_residues_types
#   replace nucleotides_dna_to_shorthand with dna_nucleotides_2to1_map
#   replace nucleotides_dna and nucleotides_rna with dna_nucleotides and rna_nucleotides respectively
#   The Residue class is now located here and renamed to PDBResidue (since we assert that the chain is 1 character long).
#   The Mutation class is now located here. ChainMutation was called something else.

import types

from Bio.SubsMat.MatrixInfo import blosum62 as _blosum62, pam250 as _pam250# The amino acid codes BXZ in these blosum62 and pam250 matrices appear to be amino acid ambiguity codes
import tools.colortext as colortext

###
# Residue maps and sets.
###

residue_type_3to1_map = {
    "ALA": "A",
    "CYS": "C",
    "ASP": "D",
    "GLU": "E",
    "PHE": "F",
    "GLY": "G",
    "HIS": "H",
    "ILE": "I",
    "LYS": "K",
    "LEU": "L",
    "MET": "M",
    "ASN": "N",
    "PRO": "P",
    "GLN": "Q",
    "ARG": "R",
    "SER": "S",
    "THR": "T",
    "VAL": "V",
    "TRP": "W",
    "TYR": "Y",
    "UNK": 'X',
}

residue_types_3 = set(residue_type_3to1_map.keys())
residue_types_1 = set(residue_type_3to1_map.values()) # formally a list called amino_acid_codes
relaxed_residue_types_1 = residue_types_1.union(set(['X']))

protonated_residue_type_3to1_map = {
    'ARN': 'R', # neutral arginine
    'ASH': 'D', # protonated aspartic acid
    'GLH': 'E', # protonated glutamic acid
    'LYN': 'K', # neutral lysine
    'HIE': 'H', # epsilon-protonated histidine
    'HIP': 'H', # epsilon- and delta-protonated histidine
    'HIS': 'H', # delta-protonated histidine
    'CYM': 'C', # deprotonated or bonded to metal atom
    'CYT': 'C', # deprotonated negative cysteine
    'CYX': 'C', # involved in disulphide bridge and other bonds / neutral cysteine
}
protonated_residues_types_3 = set(protonated_residue_type_3to1_map.keys())
protonated_residues_types_1 = set(protonated_residue_type_3to1_map.values())

non_canonical_amino_acids = {
    'ABA' : 'A', # Alpha-aminobutyric acid
    'CCS' : 'C', # Carboxymethylated cysteine
    'CME' : 'C', # S,S-(2-Hydroxyethyl)Thiocysteine (DB04530)
    'CSD' : 'C', # 3-sulfinoalanine
    'CSO' : 'C', # s-hydroxycysteine
    'CSS' : 'C', # S-Mercaptocysteine (DB02761)
    'CSU' : 'C', # ? some type of cysteine or a typo
    'CSW' : 'C', # Cysteine-S-dioxide
    'CSX' : 'C', # Modified cysteine residue
    'SCH' : 'C', # S-Methyl-Thio-Cysteine
    'SMC' : 'C', # S-methylcysteine
    'PCA' : 'E', # Pyroglutamic acid
    'GLZ' : 'G', # Amino-acetaldehyde
    'HIC' : 'H', # 4-Methyl-Histidine
    'M3L' : 'K', # N-Trimethyllysine
    'MLY' : 'K', # dimethyl lysine
    'FME' : 'M', # N-Formylmethionine
    'MSE' : 'M', # selenomethionine
    'MEN' : 'N', # N-methyl asparagine
    'SEP' : 'S', # Phosphoserine
    'SVA' : 'S', # Serine vanadate
    'TPO' : 'T', # phosphothreonine
    'TRN' : 'W', # Nz2-Tryptophan
    'NEH' : 'X', # Ethanamine
    'MPT' : 'X', # Beta-Mercaptopropionic acid
    'NH2' : 'X', # Amino group
    'PTR' : 'Y', # phospotyrosine
    'BHD' : 'D', # (3S)-3-HYDROXY-L-ASPARTIC ACID
    #
    'ASX' : 'N', # ??? N in UniProt entry P0A786 for 2ATC, chain A
    'GLX' : 'Q', # ??? Q in UniProt entry P01075 for 4CPA, chain I
    'CRT' : 'T', # Specially defined by Noah
    'CRG' : 'YG'  # Specially defined by Noah
}

###
# DNA
# I am unsure whether this is all correct. The code I inherited seems to leave out DI and DU for DNA and T and I for RNA which seems wrong.
###

dna_nucleotides = set(['DA', 'DC', 'DG', 'DT', 'DU', 'DI']) # deoxyribonucleic acids
rna_nucleotides = set(['A', 'C', 'G', 'U', 'I']) # ribonucleic acids

dna_nucleotides_3to1_map = {
    # Used to map Rosetta features database mappings to single letter sequences
    'ADE' : 'A', 'CYT' : 'C', 'GUA' : 'G', 'THY' : 'T', #'DU' : 'U', 'DI' : 'I',
}

dna_nucleotides_2to1_map = {
    # Used to map PDB SEQRES DNA sequences to single letter sequences
    'DA' : 'A', 'DC' : 'C', 'DG' : 'G', 'DT' : 'T', 'DU' : 'U', 'DI' : 'I',
}

non_canonical_dna = {
    '5IU' : 'U', # 5-Iodo-2'-Deoxyuridine-5'-Monophosphate
}

{'fraction_non_alphanumeric': 0.15822923515231208, 'fraction_numerical': 0.018408941485864562, 'mean_word_length': 3.5841285786037167, 'pattern_counts': {'":': 42, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '598450', 'n_tokens_mistral': 3976, 'n_tokens_neox': 3562, 'n_words': 976}