Skip to content

Instantly share code, notes, and snippets.

@kwcooper
Created December 15, 2022 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwcooper/2174cb4aea0299c824ed0cbd19015907 to your computer and use it in GitHub Desktop.
Save kwcooper/2174cb4aea0299c824ed0cbd19015907 to your computer and use it in GitHub Desktop.
Simple function to mutate a string of amino acids given their indicies
def mutate_amino(protein_str, mutations, offset=1):
''' mutations: {int>mutation_idx:str>AminoID}'''
mut_protein_str = list(protein_str)
for mut_idx in mutations.keys():
mut_protein_str[mut_idx-offset] = mutations[mut_idx] # Arg 71 His | R > H
mut_protein_str = ''.join(mut_protein_str)
return mut_protein_str
protein_str = "MISPFLVLAIGTCLTNSLVPEKEKDPKYWRDQAQETLKYALELQKLNTNVAKNVIMFLGDGMGVSTVTAARILKGQLHHNPGEETRLEMDKFPFVALSKTYNTNAQVPDSAGTATAYLCGVKANEGTVGVSAATERSRCNTTQGNEVTSILRWAKDAGKSVGIVTTTRVNHATPSAAYAHSADRDWYSDNEMPPEALSQGCKDIAYQLMHNIRDIDVIMGGGRKYMYPKNKTDVEYESDEKARGTRLDGLDLVDTWKSFKPRYKHSHFIWNRTELLTLDPHNVDYLLGLFEPGDMQYELNRNNVTDPSLSEMVVVAIQILRKNPKGFFLLVEGGRIDHGHHEGKAKQALHEAVEMDRAIGQAGSLTSSEDTLTVVTADHSHVFTFGGYTPRGNSIFGLAPMLSDTDKKPFTAILYGNGPGYKVVGGERENVSMVDYAHNNYQAQSAVPLRHETHGGEDVAVFSKGPMAHLLHGVHEQNYVPHVMAYAACIGANLGHCAPASSAGSLAAGPLLLALALYPLSVLF"
mutations = {71:'H', 263:'H', 522:'A'}
mut_str = mutate_amino(protein_str, mutations)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment