Created
April 29, 2018 14:09
-
-
Save lorenapr92/97c2e11e4469363e76e922113ea258db to your computer and use it in GitHub Desktop.
This file contains 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
#This code will convert sequences into amino acids by using the gencode table below. | |
#Jennifer Owen | |
#Stephanie Perez | |
#Lisa DiMusto | |
import sys | |
import re | |
infile = 'practice1.fa' | |
class dnatranslate: | |
def __init__(self,infile,sequence=None,people=None): | |
self.infile = infile | |
self.sequence = '' | |
self.protein='' | |
self.start = '' | |
self.sequence_start = '' | |
def openfile(self): | |
with open ('practice1.fa','r') as file: | |
for line in file.readlines(): | |
aa=re.sub('-','',line) | |
#print (aa) | |
if line.startswith('>'): | |
self.protein = line.rstrip('\n')+ '\n' | |
#print(self.protein) | |
else: | |
self.sequence += line | |
def translate_dna(self): | |
gencode = { | |
'ATA':'I', 'ATC':'I', 'ATT':'I', 'ATG':'M', | |
'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACT':'T', | |
'AAC':'N', 'AAT':'N', 'AAA':'K', 'AAG':'K', | |
'AGC':'S', 'AGT':'S', 'AGA':'R', 'AGG':'R', | |
'CTA':'L', 'CTC':'L', 'CTG':'L', 'CTT':'L', | |
'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCT':'P', | |
'CAC':'H', 'CAT':'H', 'CAA':'Q', 'CAG':'Q', | |
'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGT':'R', | |
'GTA':'V', 'GTC':'V', 'GTG':'V', 'GTT':'V', | |
'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCT':'A', | |
'GAC':'D', 'GAT':'D', 'GAA':'E', 'GAG':'E', | |
'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGT':'G', | |
'TCA':'S', 'TCC':'S', 'TCG':'S', 'TCT':'S', | |
'TTC':'F', 'TTT':'F', 'TTA':'L', 'TTG':'L', | |
'TAC':'Y', 'TAT':'Y', 'TAA':'_', 'TAG':'_', | |
'TGC':'C', 'TGT':'C', 'TGA':'_', 'TGG':'W'} | |
self.start = self.sequence.find('ATG') | |
self.sequence_start = self.sequence[int(self.start):] | |
#self.stop = self.sequence_start.find('TAA') | |
#self.cds = str(self.sequence_start[:int(self.stop)+3]) | |
for n in range(0,len(self.sequence_start),3): | |
if self.sequence_start[n:n+3] in gencode: | |
self.protein += gencode[self.sequence_start[n:n+3]] | |
return self.protein | |
#print(self.protein) | |
def outfile(self): # need to work on this part | |
out = open('practice.out.fa','w') | |
out.write(self.protein) | |
out.close | |
transl = dnatranslate(infile) | |
transl.openfile() | |
transl.translate_dna() | |
transl.outfile() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment