Aa codes: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Bio.Data.SCOPData.protein_letters_3to1) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 3: | Line 3: | ||
= The Code = | = The Code = | ||
== Simple == | == Simple == | ||
<source lang="python"> | <source lang="python" enclose="pre"> | ||
# one_letter["SER"] will now return "S" | # one_letter["SER"] will now return "S" | ||
one_letter ={'VAL':'V', 'ILE':'I', 'LEU':'L', 'GLU':'E', 'GLN':'Q', \ | one_letter ={'VAL':'V', 'ILE':'I', 'LEU':'L', 'GLU':'E', 'GLN':'Q', \ | ||
Line 12: | Line 12: | ||
# three_letter["S"] will now return "SER" | # three_letter["S"] will now return "SER" | ||
three_letter = dict([[v,k] for k,v in one_letter.items()]) | three_letter = dict([[v,k] for k,v in one_letter.items()]) | ||
three_letter ={'V':'VAL', 'I':'ILE', 'L':'LEU', 'E':'GLU', 'Q':'GLN', \ | |||
'D':'ASP', 'N':'ASN', 'H':'HIS', 'W':'TRP', 'F':'PHE', 'Y':'TYR', \ | |||
'R':'ARG', 'K':'LYS', 'S':'SER', 'T':'THR', 'M':'MET', 'A':'ALA', \ | |||
'G':'GLY', 'P':'PRO', 'C':'CYS'} | |||
</source> | </source> | ||
Line 20: | Line 25: | ||
# kind of hash by just adding a matching list, and zipping. | # kind of hash by just adding a matching list, and zipping. | ||
aa1 = list("ACDEFGHIKLMNPQRSTVWY") | aa1 = list("ACDEFGHIKLMNPQRSTVWY") | ||
aa3 = "ALA CYS ASP GLU PHE GLY HIS ILE LYS MET ASN PRO GLN ARG SER THR VAL TRP TYR".split() | aa3 = "ALA CYS ASP GLU PHE GLY HIS ILE LYS LEU MET ASN PRO GLN ARG SER THR VAL TRP TYR".split() | ||
aa123 = dict(zip(aa1,aa3)) | aa123 = dict(zip(aa1,aa3)) | ||
aa321 = dict(zip(aa3,aa1)) | aa321 = dict(zip(aa3,aa1)) | ||
Line 29: | Line 34: | ||
== Using BioPython == | == Using BioPython == | ||
If you have BioPython you can use the following | If you have BioPython you can use the following, which includes also many three-letter codes of modified amino acids: | ||
<source lang="python"> | <source lang="python"> | ||
from Bio.PDB import to_one_letter_code as one_letter | from Bio.PDB import to_one_letter_code as one_letter | ||
</source> | |||
<source lang="python"> | |||
from Bio.Data.SCOPData import protein_letters_3to1 as one_letter | |||
</source> | |||
== Using PyMOL == | |||
<source lang="python"> | |||
from pymol.exporting import _resn_to_aa as one_letter | from pymol.exporting import _resn_to_aa as one_letter | ||
</source> | </source> | ||
Latest revision as of 12:48, 6 September 2017
Just a quick little script to allow you to convert from 1-to-3 letter codes and 3-to-1 letter codes in PyMOL. Copy the code below and drop it into your .pymolrc file. Then, each time you load PyMOL, "one_letter" and "three_letter" will be defined.
The Code
Simple
# one_letter["SER"] will now return "S"
one_letter ={'VAL':'V', 'ILE':'I', 'LEU':'L', 'GLU':'E', 'GLN':'Q', \
'ASP':'D', 'ASN':'N', 'HIS':'H', 'TRP':'W', 'PHE':'F', 'TYR':'Y', \
'ARG':'R', 'LYS':'K', 'SER':'S', 'THR':'T', 'MET':'M', 'ALA':'A', \
'GLY':'G', 'PRO':'P', 'CYS':'C'}
# three_letter["S"] will now return "SER"
three_letter = dict([[v,k] for k,v in one_letter.items()])
three_letter ={'V':'VAL', 'I':'ILE', 'L':'LEU', 'E':'GLU', 'Q':'GLN', \
'D':'ASP', 'N':'ASN', 'H':'HIS', 'W':'TRP', 'F':'PHE', 'Y':'TYR', \
'R':'ARG', 'K':'LYS', 'S':'SER', 'T':'THR', 'M':'MET', 'A':'ALA', \
'G':'GLY', 'P':'PRO', 'C':'CYS'}
Simple and Clever
Here's another way to accomplish this
# The real convenience in there is that you can easily construct any
# kind of hash by just adding a matching list, and zipping.
aa1 = list("ACDEFGHIKLMNPQRSTVWY")
aa3 = "ALA CYS ASP GLU PHE GLY HIS ILE LYS LEU MET ASN PRO GLN ARG SER THR VAL TRP TYR".split()
aa123 = dict(zip(aa1,aa3))
aa321 = dict(zip(aa3,aa1))
# Then to extract a sequence, I tend to go for a construction like:
sequence = [ aa321[i.resn] for i in cmd.get_model(selection + " and n. ca").atom ]
Using BioPython
If you have BioPython you can use the following, which includes also many three-letter codes of modified amino acids:
from Bio.PDB import to_one_letter_code as one_letter
from Bio.Data.SCOPData import protein_letters_3to1 as one_letter
Using PyMOL
from pymol.exporting import _resn_to_aa as one_letter
Example Usage
# we used to have to do the following to get the amino acid name
from pymol import stored
stored.aa = ""
cmd.iterate("myselection", "stored.aa=resn")
# now we can just call
three_letter[string.split(cmd.get_fastastr("myselection"),'\n')[1]]