-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
50 lines (46 loc) · 1.39 KB
/
convert.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
#import requests
import json
from io import StringIO
from Bio import Seq
from Bio import SeqIO
from Bio import SeqFeature
import sys
import uuid
import sys
from genbank_import import *
from genbank_export import *
def _decode_list(data):
rv = []
for item in data:
if isinstance(item, unicode):
item = item.encode('ascii', 'ignore')
elif isinstance(item, list):
item = _decode_list(item)
elif isinstance(item, dict):
item = _decode_dict(item)
rv.append(item)
return rv
def _decode_dict(data):
rv = {}
for key, value in data.iteritems():
if isinstance(key, unicode):
key = key.encode('ascii', 'ignore')
if isinstance(value, unicode):
value = value.encode('ascii', 'ignore')
elif isinstance(value, list):
value = _decode_list(value)
elif isinstance(value, dict):
value = _decode_dict(value)
rv[key] = value
return rv
to_genbank = sys.argv[1] == "to_genbank"
if to_genbank:
genbank_file = sys.argv[3]
project_file = sys.argv[2]
project = json.load(open(project_file,"r"), object_hook=_decode_dict)
export_project(genbank_file, project['project'], project['blocks'])
else:
genbank_file = sys.argv[2]
project_file = sys.argv[3]
project = genbank_to_project(genbank_file)
json.dump(project, open(project_file,'w'))