-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathanvi-delete-misc-data
executable file
·83 lines (62 loc) · 4.01 KB
/
anvi-delete-misc-data
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
#!/usr/bin/env python
# -*- coding: utf-8
"""Remove stuff from misc data tables"""
import sys
from anvio.argparse import ArgumentParser
import anvio
import anvio.terminal as terminal
from anvio.errors import ConfigError, FilesNPathsError
from anvio.tables.miscdata import MiscDataTableFactory
__copyright__ = "Copyleft 2015-2024, The Anvi'o Project (http://anvio.org/)"
__credits__ = []
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__authors__ = ['meren', 'ekiefl']
__requires__ = ["pan-db", "profile-db", "misc-data-items", "misc-data-layers", "misc-data-layer-orders", "misc-data-nucleotides", "misc-data-amino-acids"]
__description__ = ("Remove stuff from 'additional data' or 'order' tables for either items or layers in either "
"pan or profile databases. OR, remove stuff from the 'additional data' tables for nucleotides "
"or amino acids in contigs databases")
__resources__ = [("Working with anvi'o additional data tables", "http://merenlab.org/2017/12/11/additional-data-tables/#views-items-layers-orders-some-anvio-terminology")]
run = terminal.Run()
def main(args):
d = args.__dict__
if not d['contigs_db'] and not d['pan_or_profile_db']:
raise ConfigError("Please provide either a contigs database (--contigs-db) or a profile/pan "
"database (--pan-or-profile-db)")
if d['contigs_db'] and d['pan_or_profile_db']:
raise ConfigError("You provided a contigs db (--contigs-db) and a profile/pan "
"db (--pan-or-profile-db). Please provide only one.")
table_for_additional_data = MiscDataTableFactory(args)
if args.list_available_keys:
table_for_additional_data.list_data_keys()
sys.exit(0)
keys_to_remove = [k for k in args.keys_to_remove.split(',')] if args.keys_to_remove else []
groups_to_remove = [k for k in args.groups_to_remove.split(',')] if args.groups_to_remove else []
table_for_additional_data.remove(data_keys_list=keys_to_remove, data_groups_list=groups_to_remove)
if __name__ == '__main__':
parser = ArgumentParser(description=__description__)
group1 = parser.add_argument_group('Database input', "Provide 1 of these")
group2 = parser.add_argument_group('Details', "Everything else.")
group1.add_argument(*anvio.A('pan-or-profile-db'), **anvio.K('pan-or-profile-db', {'required': False}))
group1.add_argument(*anvio.A('contigs-db'), **anvio.K('contigs-db', {'required': False}))
group2.add_argument(*anvio.A('target-data-table'), **anvio.K('target-data-table', {'required': True}))
group2.add_argument('--keys-to-remove', help="A comma-separated list of data keys to remove from the database. If you\
do not use this parameter, anvi'o will simply remove everything from the\
target data table immediately. Please note that you should not use this\
parameter together with `--groups-to-remove` in a single command.")
group2.add_argument('--groups-to-remove', help="A comma-separated list of data groups to remove from the database. If you\
do not use this parameter, anvi'o will simply remove everything from the\
target data table immediately. Please note that you should not use this\
parameter together with `--keys-to-remove` in a single command.")
group2.add_argument('--list-available-keys', action='store_true', help="Using this flag will list available data keys in\
the target data table and quit without doing anything else.")
group2.add_argument(*anvio.A('just-do-it'), **anvio.K('just-do-it'))
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)