#!/usr/bin/python # -*- coding: utf-8 -*- # -------------------------------------------------- # File Name: txt2dna.py # Purpose: # Creation Date: 09-03-2017 # Last Modified: Mon, Mar 13, 2017 5:37:02 AM # Author(s): Mike Stout # Copyright 2017 The Author(s) All Rights Reserved # Credits: # -------------------------------------------------- import sys import string def read(a): with open(a) as f: #s= f.readlines() s=f.read() f.close() return s f1 = sys.argv[1] a = read(f1) asDNA = 0 if asDNA : bases = "ATGC" codons = [ ''.join([c1,c2,c3,c4]) for c1 in bases for c2 in bases for c3 in bases for c4 in bases] else: #bases = "KHERDQNPSLAGWTFV" bases = "ARNDBCEQZGHILKMFPSTWYV" codons = [ ''.join([c1,c2]) for c1 in bases for c2 in bases] geneticCode = dict(zip( xrange(256), codons )) def char2triplet(c): return geneticCode[ord(c)] def encode(s): return ''.join(map(char2triplet, s) ) a_ = encode(a)[:6000] print a_