#! /usr/bin/python 2 import re 3 import sys 4 import traceback 5 from codon import Codon 6 7 #counters for the current line and index 8 line = -1 9 #lists for storing index positions 10 pos_start = [] 11 pos_stop = [] 12 neg_start = [] 13 neg_stop = [] 14 15 codon_list = [ 16 Codon('ATG'), 17 Codon('GTG'), 18 Codon('TAG'), 19 Codon('TAA'), 20 Codon('TGA'), 21 ] 22 # Codon('TAC'), 23 # Codon('CAC'), 24 # Codon('ATC'), 25 # Codon('ATT'), 26 # Codon('ACT') 27 #] 28 29 def addToList(this_codon): 30 """Sort out the codons and add the matching index to the respective list""" 31 if this_codon == 'ATG' or this_codon == 'GTG': 32 pos_start.append(index) 33 #print "Codon: %s, %s, %d" % (co.codon_str, co.currFrame.tostring(),index) 34 elif this_codon == 'TAG' or this_codon == 'TAA' or \ 35 this_codon == 'TGA': 36 pos_stop.append(index) 37 #print "Codon: %s, %s, %d" % (co.codon_str, co.currFrame.tostring(),index) 38 elif this_codon == 'TAC' or this_codon == 'CAC': 39 neg_start.append(index) 40 else: 41 neg_stop.append(index) 44 dna_file = open('./NC_007577.fna') 45 try: 46 try: 47 dna_file.readline() 48 first_codon = dna_file.read(3) 49 for co in codon_list: 50 #print "This codon is: %s" % co.codon_str 51 co.setFrame(first_codon) 52 if co.match_found(): 53 addToList(co.codon_str) 54 next_nuc = dna_file.read(1) 55 index = 3 56 while (next_nuc != '') and index < 5000: #while not end of file 57 if (next_nuc != '\n'): #skip line ends, don't count them 58 index += 1 59 for co in codon_list: 60 co.read_nucleotide(next_nuc) 61 if co.match_found(): 62 addToList(co.codon_str) 63 #print "%s found at %d" % (co, index) 64 next_nuc = dna_file.read(1) 65 except Exception, e: 66 traceback.print_exc(file=sys.stderr) 67 print "Unexpected error: %s" % e[0] 68 finally: 69 dna_file.close() 70 71 print "*********Preprocessing Complete**********" 72