Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. #Excersice 8
  2. try:
  3.     sprot = input('Please insert a filename')
  4.     infile = open(sprot, 'r')
  5. except IOError as error:
  6.     print("We have a problem opening the file, due to:", str(error))
  7.     sys.exit(1)
  8. dna = ''
  9. startCodon = 0
  10. stopCodon = 0
  11.  
  12. for line in infile:
  13.     if line[0] != '>':
  14.         dna += str(line[:-1])
  15. for base in range(len(dna)):
  16.     if (dna[base:base+3] == 'ATG' and base > stopCodon):
  17.         startCodon = base
  18.         iterations = (len(dna) - startCodon) / 3
  19.         for i in range(iterations):
  20.             index = i * 3 + startCodon
  21.             if (dna[index:index+3] == 'TAA' or dna[index*3:index*3+3] == 'TAG' or dna[index*3:index*3+3] == 'TGA'):
  22.                 stopCodon = index
  23.                 print('The start codon is:', startCodon + 1, 'and the coresponding stopcodon is:', stopCodon + 1)    #print +1 since python counts from 0 and not 1.
  24.                 break
  25. infile.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement