Skip to content

Instantly share code, notes, and snippets.

@coela
Created August 31, 2017 05:55
Show Gist options
  • Save coela/a85cf348a985c508511a69da241ae15d to your computer and use it in GitHub Desktop.
Save coela/a85cf348a985c508511a69da241ae15d to your computer and use it in GitHub Desktop.
import re
class tRNAsynthetase(object):
def __init__(self, filepath="/Users/coela/projects/ATS_interaction/data/uniprot/aatrnasy.txt"):
fileHandle = open(filepath,'r')
match_tRNA = re.compile("(\S+)-tRNA synthetases \((EC \S+)\)")
count = 0
switch = False
self.info = dict()
self.aadict = {"Alanyl" : "Ala",
"Cysteinyl" : "Cys",
"Aspartyl" : "Asp",
"Glutamyl" : "Glu",
"Phenylalanyl" : "Phe",
"Glycyl" : "Gly",
"Histidyl" : "His",
"Isoleucyl" : "Ile",
"Lysyl" : "Lys",
"Leucyl" : "Leu",
"Methionyl" : "Met",
"Asparaginyl" : "Asn",
"Prolyl" : "Pro",
"Glutaminyl" : "Gln",
"Arginyl" : "Arg",
"Seryl" : "Ser",
"Threonyl" : "Thr",
"Valyl" : "Val",
"Tryptophanyl" : "Trp",
"Tyrosyl" : "Tyr"}
for line in fileHandle:
line = line.rstrip()
tRNA_data = match_tRNA.match(line)
if tRNA_data:
amino_type = tRNA_data.group(1)
ec_number = tRNA_data.group(2)
count = 0
switch = True
if switch:
count = count + 1
if line[0:5] == "Class":
tRNA_class = line[7:9]
if line[0:8] == "3D known":
known = line[10:13]
if count >= 5 and len(line) == 0:
count = 0
continue
if count >= 5:
matchlist = re.finditer(r"(\S+)\s+\((\S+)\)",line)
for match in matchlist:
self.info[match.group(1)] = {"aa" : self.aadict[amino_type], "ec" : ec_number, "class" : tRNA_class}
if __name__ == "__main__":
tRNAsynthetase = tRNAsynthetase()
print tRNAsynthetase.info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment