Created
September 2, 2020 14:35
-
-
Save fransua/36dba6f8d1a6eabc5fbb492d3591ee5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
""" | |
import sys | |
from random import random, seed | |
table={"TTT": "F", "TTC": "F", "TTA": "L", "TTG": "L", | |
"TCT": "S", "TCC": "S", "TCA": "S", "TCG": "S", | |
"TAT": "Y", "TAC": "Y", "TGT": "C", "TGC": "C", | |
"TGG": "W", "CTT": "L", "CTC": "L", "CTA": "L", | |
"CTG": "L", "CCT": "P", "CCC": "P", "CCA": "P", | |
"CCG": "P", "CAT": "H", "CAC": "H", "CAA": "Q", | |
"CAG": "Q", "CGT": "R", "CGC": "R", "CGA": "R", | |
"CGG": "R", "ATT": "I", "ATC": "I", "ATA": "I", | |
"ATG": "M", "ACT": "T", "ACC": "T", "ACA": "T", | |
"ACG": "T", "AAT": "N", "AAC": "N", "AAA": "K", | |
"AAG": "K", "AGT": "S", "AGC": "S", "AGA": "R", | |
"AGG": "R", "GTT": "V", "GTC": "V", "GTA": "V", | |
"GTG": "V", "GCT": "A", "GCC": "A", "GCA": "A", | |
"GCG": "A", "GAT": "D", "GAC": "D", "GAA": "E", | |
"GAG": "E", "GGT": "G", "GGC": "G", "GGA": "G", | |
"GGG": "G"} | |
fnam, seed_num = sys.argv[1:] | |
seed(int(seed_num)) | |
reverse = {} | |
for aa in set(list(table.values())): | |
codons = [c for c, a in table.items() if a == aa] | |
lena = len(codons) | |
reverse[aa] = [codons[int(random() * lena)] if random() < 0.2 else codons[0] | |
for i in range(100)] | |
sequences = {} | |
for l in open(fnam): | |
if l.startswith('>'): | |
name = l[1:].strip() | |
sequences[name] = '' | |
else: | |
sequences[name] += l.strip() | |
line_len = 60 | |
for name, seq in sequences.items(): | |
print('>{}'.format(name)) | |
tr_seq = ''.join(reverse[a][int(random() * 100)] for a in seq) | |
print('\n'.join(tr_seq[i:i + line_len] for i in range(0, len(tr_seq), line_len))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment