-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecute_codopt.py
104 lines (91 loc) · 4.27 KB
/
execute_codopt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import re
from functions import get_codon_usage,visualize_codon_usage,optimize_codon_usage
print('\n')
print('Hi, I will optimize the codon usage of your gene.')
print('\n')
print('First, I need some input. Do NOT type any file extensions unless I ask you to. Also, no typos, please.')
print('\n')
gene = input('Enter name of gene to be optimized: ')
gene_OPT = gene + '_opt'
sequence = re.sub(r"[\n\t\s]*", "", input('Copy and paste the DNA sequence of your gene (only CDS): ').upper())
organism_ORIGIN = input('Enter name of original host organism: ')
CDS_source_nofile_ORIGIN = input("Enter name of its genbank file ('xxx'.gb) or csv file from Kazusa ('xxx'.csv): ")
CDS_type_ORIGIN = input("file extension: 'gb' or 'csv?'")
CDS_source_ORIGIN = CDS_source_nofile_ORIGIN + '.' + CDS_type_ORIGIN
save_table_ORIGIN = CDS_source_nofile_ORIGIN + '_codon_usage'
CDSdict_txt_ORIGIN = 'CDS_dict_' + save_table_ORIGIN + '.txt'
save_table_txt_ORIGIN = save_table_ORIGIN + '.txt'
save_table_csv_ORIGIN = save_table_ORIGIN + '.csv'
savefig_ORIGIN = 'codon_usage_' + gene + '_vs_' + organism_ORIGIN + '.pdf'
organism_DEST = input('Enter name of destination organism: ')
CDS_source_nofile_DEST = input("Enter name of its genbank file ('xxx'.gb) or csv file from Kazusa ('xxx'.csv): ")
CDS_type_DEST = input("file extension: 'gb' or 'csv?'")
CDS_source_DEST = CDS_source_nofile_DEST + '.' + CDS_type_DEST
save_table_DEST = CDS_source_nofile_DEST + '_codon_usage'
CDSdict_txt_DEST = 'CDS_dict_' + save_table_DEST + '.txt'
save_table_txt_DEST = save_table_DEST + '.txt'
save_table_csv_DEST = save_table_DEST + '.csv'
savefig_DEST = 'codon_usage_' + gene + '_vs_' + organism_DEST + '.pdf'
save_optimized_seq = gene_OPT + '_for_' + organism_DEST + '.txt'
savefig_OPT = 'codon_usage_' + gene_OPT + '_vs_' + organism_DEST + '.pdf'
print('I create codon usage tables for both organisms.')
get_codon_usage(CDS_source_nofile_ORIGIN,
CDS_type_ORIGIN,
CDS_source_ORIGIN,
CDSdict_txt_ORIGIN,
save_table_ORIGIN,
save_table_txt_ORIGIN,
save_table_csv_ORIGIN)
get_codon_usage(CDS_source_nofile_DEST,
CDS_type_DEST,
CDS_source_DEST,
CDSdict_txt_DEST,
save_table_DEST,
save_table_txt_DEST,
save_table_csv_DEST)
print("I create bar charts for you.")
visualize_codon_usage(organism_ORIGIN,
CDS_type_ORIGIN,
save_table_ORIGIN,
save_table_txt_ORIGIN,
gene,
sequence,
savefig_ORIGIN)
visualize_codon_usage(organism_DEST,
CDS_type_DEST,
save_table_DEST,
save_table_txt_DEST,
gene,
sequence,
savefig_DEST)
print('Now, you can take a look at the figures that I made for you.')
print("Do you still want to optimize " + gene + " for the usage of " + organism_DEST + "?")
optimization = input("Type 'Y' or 'N': ")
if optimization == 'Y' or optimization == 'y':
print("OK, a '.txt' file containing the optimized sequence will be stored in your folder.")
optimize_codon_usage(save_table_ORIGIN,
save_table_txt_ORIGIN,
save_table_DEST,
save_table_txt_DEST,
gene,
sequence,
organism_ORIGIN,
organism_DEST,
save_optimized_seq
)
with open(save_optimized_seq, 'r') as opt_seq:
sequence_OPT = opt_seq.read().replace('\n', '')
opt_seq.close
print('Codon usage optimized.')
print('\n')
print("Lastly, let's generate bar charts of the codon optimized gene.")
visualize_codon_usage(organism_DEST,
CDS_type_DEST,
save_table_DEST,
save_table_txt_DEST,
gene_OPT,
sequence_OPT,
savefig_OPT)
print('Bye.')
if optimization == 'N' or optimization == 'n':
print('Ok, bye.')