Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import sys
- filename = sys.argv[1]
- totfile = open(filename).read()
- contains_aminoacid = False
- header = ''
- type_file = ''
- for header in totfile:
- if header.startswith('>'):
- print(header,'/n')
- for line in totfile:
- if not line.startswith('>'):
- pass
- stripped = line.strip()
- for characters in stripped:
- if characters not in ['A','T','C','G','U']
- contains_aminoacid = True
- if contains_aminoacid == True:
- type_file = "aminoacid"
- print(type_file)
- break
- start_num = input("On what character would you like to start the translation?\n")
- start_num = int(start_num)
- count = 1
- templist = []
- if contains_aminoacid == False:
- for char in stripped:
- count += 1
- templist.append(char)
- if count == start_num:
- tempstring = ''.join(templist)
- string_ready = stripped.replace(tempstring, '')
- elif count > start_num:
- break
- tripletlist = []
- templist = []
- if contains_aminoacid == False:
- for char in string_ready:
- templist.append(char)
- if len(templist) == 3:
- triplet = "".join(templist)
- tripletlist.append(triplet)
- templist = []
- else:
- continue
- aminoacid_codons = {"GCT":"A", "GCC":"A", "GCA":"A", "GCG":"A", "CGT":"R",
- "CGC":"R", "CGA":"R", "CGG":"R", "AGA":"R", "AGG":"R",
- "AAT":"N", "AAC":"N", "GAT":"D", "GAC":"D", "TGT":"C",
- "TGC":"C", "CAA":"Q", "CAG":"Q", "GAA":"E", "GAG":"E",
- "GGT":"G", "GGC":"G", "GGA":"G", "GGG":"G", "CAT":"H",
- "CAC":"H", "ATT":"I", "ATC":"I", "ATA":"I", "TTA":"L",
- "TTG":"L", "CTT":"L", "CTC":"L", "CTA":"L", "CTG":"L",
- "AAA":"K", "AAG":"K", "ATG":"M", "TTT":"F", "TTC":"F",
- "CCT":"P", "CCC":"P", "CCA":"P", "CCG":"P", "TCT":"S",
- "TCC":"S", "TCA":"S", "TCG":"S", "ATG":"S", "AGC":"S",
- "ACT":"T", "ACC":"T", "ACA":"T", "ACG":"T", "TGG":"W",
- "TAT":"Y", "TAC":"Y", "GTT":"V", "GTC":"V", "GTA":"V",
- "GTG":"V"}
- protein_file = open("proteinseq.fasta", 'r+')
- for item in tripletlist:
- if item in aminoacid_codons:
- protein_file.write(aminoacid_codons[item])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement