with open ("dna_sequence.txt", "r") as myfile:
    data=myfile.read()
geneticCode=""
for i in data:
    if(i!=" " and i!='\n'):
        geneticCode+=i
fout=open("Outrohit.txt","w")
dictionary={'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','TGC':'C', 'TGT':'C','TGG':'W'}
tempState=0
count=0
smallProtein=geneticCode
largeProtein=""
protein=""
i=-1
while i<(len(geneticCode)-3):
    i=i+1
    tempState=i
    temp=geneticCode[i:i+3]
    if(temp=='ATG'):
        for j in range(tempState,len(geneticCode)-3,3):
            temp1=geneticCode[j:j+3]
            if(temp1=="TAA" or temp1=="TAG" or temp1=="TGA"):
                count=count+1
                tempState=j+3
                if(len(protein)>=3):
                    fout.write(protein+"_")
                if(len(protein)>len(largeProtein)):
                    largeProtein=protein
                if(len(protein)<len(smallProtein) and len(protein)>=3):
                    smallProtein=protein
                protein=""                    
                break
            else:
                protein=protein+dictionary[temp1]    
    else:
        i=tempState
fout.write("\n\n")
fout.write("No.of proteins that can be generated by the given DNA Sequence is: "+str(count))
fout.write("\nLargest length of Protein generated is: "+largeProtein+" of length "+str(len(largeProtein)))
fout.write("\nSmallest length of Protein generated is: "+smallProtein+" of length "+str(len(smallProtein)))
count=0
for i in largeProtein:
    if(i=='R' or i=='D'or i=='E' or i=='H' or i=='K' or i=='S' or i=='T' or i=='N' or i=='C' or i=='Y' or i=='Q'):
        count=count+1
fout.write("\n"+str(count/len(largeProtein)*100)+" % of the protein is polar for the largest Protein.")
count=0
for i in smallProtein:
    if(i=='R' or i=='D'or i=='E' or i=='H' or i=='K' or i=='S' or i=='T' or i=='N' or i=='C' or i=='Y' or i=='Q'):
        count=count+1
fout.write("\n"+str(count/len(smallProtein)*100)+" % of the protein is polar for the smallest Protein.")
fout.write(str(len(geneticCode)))
fout.close()
