-
Notifications
You must be signed in to change notification settings - Fork 145
/
anvi-import-state
executable file
·59 lines (42 loc) · 1.74 KB
/
anvi-import-state
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
#!/usr/bin/env python
# -*- coding: utf-8
import sys
import anvio
import anvio.utils as utils
import anvio.terminal as terminal
import anvio.filesnpaths as filesnpaths
from anvio.errors import ConfigError, FilesNPathsError
from anvio.tables.states import TablesForStates
__copyright__ = "Copyleft 2015-2024, The Anvi'o Project (http://anvio.org/)"
__credits__ = []
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__authors__ = ['meren']
__requires__ = ['pan-db', 'profile-db', 'state-json']
__provides__ = ['state']
__description__ = "Import an anvi'o state into a profile database"
run = terminal.Run()
progress = terminal.Progress()
def main(args):
utils.is_pan_or_profile_db(args.pan_or_profile_db, genes_db_is_also_accepted=True)
filesnpaths.is_file_json_formatted(args.state)
utils.is_this_name_OK_for_database('--name parameter', args.name)
TablesForStates(args.pan_or_profile_db).store_state(args.name, open(args.state).read())
run.info('Done', 'State "%s" is added to the database' % args.name)
if __name__ == '__main__':
from anvio.argparse import ArgumentParser
parser = ArgumentParser(description=__description__)
parser.add_argument(*anvio.A('pan-or-profile-db'), **anvio.K('pan-or-profile-db'))
parser.add_argument('-s', '--state', metavar="STATE_FILE", default = None, required = True,
help = "JSON serializable anvi'o state file.")
parser.add_argument('-n', '--name', metavar = 'STATE_NAME', default = None, required = True,
help = 'State name.')
args = parser.get_args(parser)
try:
main(args)
except ConfigError as e:
print(e)
sys.exit(-1)
except FilesNPathsError as e:
print(e)
sys.exit(-2)