imported>Baik BuKyung |
imported>Baik BuKyung |
Line 1: |
Line 1: |
− | <div>import random</div>
| |
| | | |
− | <div> </div>
| |
− |
| |
− | <div>def random_sequence():<br />
| |
− | SL = open('sequence_list.txt','w')<br />
| |
− | number = int(input('How many genes do you want?: '))<br />
| |
− | for n in range(number):<br />
| |
− | gene_name = input('input gene name: ')<br />
| |
− | SL.write('>' + gene_name + '\n')<br />
| |
− | print('input the length of ',gene_name,': ',end='')<br />
| |
− | length = int(input())<br />
| |
− | sequence = str()<br />
| |
− | for i in range(length):<br />
| |
− | sequence += random_base()<br />
| |
− | SL.write(sequence + '\n')<br />
| |
− | SL.close()<br />
| |
− | return</div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div><br />
| |
− | def random_base():<br />
| |
− | i = random.randrange(1,5)<br />
| |
− | if i == 1:<br />
| |
− | return 'A'<br />
| |
− | elif i == 2:<br />
| |
− | return 'T'<br />
| |
− | elif i == 3:<br />
| |
− | return 'G'<br />
| |
− | elif i == 4:<br />
| |
− | return 'C'</div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div>def reverse():<br />
| |
− | SL = open('sequence_list.txt','r')<br />
| |
− | RL = open('reverse_list.txt','w')<br />
| |
− | read = SL.readlines()<br />
| |
− | rev_name = list()<br />
| |
− | rev = list()</div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div> for i in range(0,len(read)):<br />
| |
− | if i % 2 == 0:<br />
| |
− | rev_name.append(read[i])<br />
| |
− | else:<br />
| |
− | rev.append(read[i])</div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div> for k in range(0,len(rev)):<br />
| |
− | rev_seq = str()<br />
| |
− | for i in range(0,len(rev[k])):<br />
| |
− | if rev[k][i] == 'A':<br />
| |
− | rev_seq = 'T' + rev_seq<br />
| |
− | elif rev[k][i] == 'T':<br />
| |
− | rev_seq = 'A' + rev_seq<br />
| |
− | elif rev[k][i] == 'G':<br />
| |
− | rev_seq = 'C' + rev_seq<br />
| |
− | elif rev[k][i] == 'C':<br />
| |
− | rev_seq = 'G' + rev_seq<br />
| |
− | RL.write(rev_name[k][:-1]+'_rev\n')<br />
| |
− | RL.write(rev_seq + '\n')<br />
| |
− | SL.close()<br />
| |
− | RL.close()<br />
| |
− | return<br />
| |
− | <br />
| |
− | <br />
| |
− | def ORF_seq(name,seq):<br />
| |
− | file_name = name[1:-1]<br />
| |
− | ORF_file = open((file_name)+'_ORF.txt','w')<br />
| |
− | ini_cod = list()<br />
| |
− | ter_cod = list()<br />
| |
− | <br />
| |
− | for i in range(0,len(seq)-2):<br />
| |
− | if seq[i:i+3] == 'ATG':<br />
| |
− | ini_cod.append(i)</div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div> for i in range(0,len(seq)-2):<br />
| |
− | if seq[i:i+3] == 'TGA':<br />
| |
− | ter_cod.append(i)<br />
| |
− | elif seq[i:i+3] == 'TAA': <br />
| |
− | ter_cod.append(i)<br />
| |
− | elif seq[i:i+3] == 'TAG':<br />
| |
− | ter_cod.append(i)<br />
| |
− | p=0<br />
| |
− | for i in range(0,len(ini_cod)):<br />
| |
− | for j in range(0,len(ter_cod)):<br />
| |
− | if ter_cod[j] > ini_cod[i] and (ter_cod[j] - ini_cod[i]) % 3 == 0:<br />
| |
− | p+=1<br />
| |
− | ORF_file.write(">ORF_"+str(p)+"\n")<br />
| |
− | ORF_file.write(seq[ini_cod[i]:(ter_cod[j]+3)]+'\n')<br />
| |
− | break</div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div> ORF_file.close<br />
| |
− | return</div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div>def ORF():<br />
| |
− | file_name = input('input file name to find ORF in directory: ')<br />
| |
− | fseq = open(file_name,'r')<br />
| |
− | gene_list = fseq.readlines()<br />
| |
− | name_list = list()<br />
| |
− | seq_list = list()<br />
| |
− | <br />
| |
− | for i in range(0,len(gene_list)):<br />
| |
− | if i % 2 == 0:<br />
| |
− | name_list.append(gene_list[i])<br />
| |
− | else:<br />
| |
− | seq_list.append(gene_list[i])</div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div> for i in range(0,len(seq_list)):<br />
| |
− | ORF_seq(name_list[i],seq_list[i])<br />
| |
− | <br />
| |
− | fseq.close()</div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div> return<br />
| |
− | <br />
| |
− | def TRANS():<br />
| |
− | file_name = input('input ORF file name to translate in directory: ')<br />
| |
− | fseq = open(file_name,'r')<br />
| |
− | trans_file = open((file_name[:-4] + '_trans.txt'),'w')<br />
| |
− | seq = fseq.readlines()<br />
| |
− | <br />
| |
− | codon_table = {"TTT":"F", "TTC":"F", "TTA":"L", "TTG":"L",<br />
| |
− | "TCT":"S", "TCC":"s", "TCA":"S", "TCG":"S",<br />
| |
− | "TAT":"Y", "TAC":"Y", "TAA":"STOP", "TAG":"STOP",<br />
| |
− | "TGT":"C", "TGC":"C", "TGA":"STOP", "TGG":"W",<br />
| |
− | "CTT":"L", "CTC":"L", "CTA":"L", "CTG":"L",<br />
| |
− | "CCT":"P", "CCC":"P", "CCA":"P", "CCG":"P",<br />
| |
− | "CAT":"H", "CAC":"H", "CAA":"Q", "CAG":"Q",<br />
| |
− | "CGT":"R", "CGC":"R", "CGA":"R", "CGG":"R",<br />
| |
− | "ATT":"I", "ATC":"I", "ATA":"I", "ATG":"M",<br />
| |
− | "ACT":"T", "ACC":"T", "ACA":"T", "ACG":"T",<br />
| |
− | "AAT":"N", "AAC":"N", "AAA":"K", "AAG":"K",<br />
| |
− | "AGT":"S", "AGC":"S", "AGA":"R", "AGG":"R",<br />
| |
− | "GTT":"V", "GTC":"V", "GTA":"V", "GTG":"V",<br />
| |
− | "GCT":"A", "GCC":"A", "GCA":"A", "GCG":"A",<br />
| |
− | "GAT":"D", "GAC":"D", "GAA":"E", "GAG":"E",<br />
| |
− | "GGT":"G", "GGC":"G", "GGA":"G", "GGG":"G",}</div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div> for i in range(0,len(seq)):<br />
| |
− | seq_line = str()<br />
| |
− | if((i%2)==1):<br />
| |
− | for j in range(0,len(seq[i])-1,3):<br />
| |
− | seq_line += (codon_table[seq[i][j:j+3]])<br />
| |
− | else:<br />
| |
− | seq_line=">ORF_"+str(int(i/2+1))<br />
| |
− | trans_file.write(seq_line+'\n')<br />
| |
− | fseq.close()<br />
| |
− | trans_file.close()<br />
| |
− | return<br />
| |
− | </div>
| |
− |
| |
− | <div> </div>
| |
− |
| |
− | <div> </div>
| |