The updated one -- following Alan's advice.
#!/usr/bin/python3
import os.path
mapping={}
DICTIONARYFILE="dictionary.pdb"
TOBETRANSLATEDFILEEXT=".out"
OUTPUTFILEEXT=".txt"
def generate_dict(dictionarysourcefile):
for line in open(dictionarysourcefile,"r"):
parts=line.strip().split()
mapping[parts[2]]=parts[0]
def translate_process(dictionary,tobetranslatedfile):
results=[]
unique={}
for line in open(tobetranslatedfile,"r"):
tobetranslatedparts=line.strip().split()
results.append(dictionary[tobetranslatedparts[2]])
for residue in results:
unique[residue]=unique.get(residue,0)+1
for residue, numbers in unique.items():
print(residue,numbers)
with open(base+OUTPUTFILEEXT,"w") as f:
f.write(str(unique))
if __name__=="__main__":
generate_dict(DICTIONARYFILE)
for infilename in os.listdir("."):
base, ext = os.path.splitext(infilename)
if ext == TOBETRANSLATEDFILEEXT:
translate_process(mapping, infilename)
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor