1 | #!/usr/bin/perl |
---|
2 | use strict; |
---|
3 | use warnings; |
---|
4 | |
---|
5 | # ------------------------------ configure speciesSelections to keep |
---|
6 | |
---|
7 | # simply enter names of speciesSelections to remain in the list below. |
---|
8 | my @keep = |
---|
9 | ( |
---|
10 | 'name_of_species_selection', |
---|
11 | ); |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | # ------------------------------ configure speciesSelections to keep [end] |
---|
16 | |
---|
17 | BEGIN { |
---|
18 | if (not exists $ENV{'ARBHOME'}) { die "Environment variable \$ARBHOME has to be defined"; } |
---|
19 | my $arbhome = $ENV{'ARBHOME'}; |
---|
20 | push @INC, "$arbhome/lib"; |
---|
21 | push @INC, "$arbhome/PERL_SCRIPTS/lib"; |
---|
22 | 1; |
---|
23 | } |
---|
24 | |
---|
25 | use ARB; |
---|
26 | use tools; |
---|
27 | |
---|
28 | my $gb_main = ARB::open(":","r"); |
---|
29 | if (not $gb_main) { |
---|
30 | my $error = ARB::await_error(); |
---|
31 | die "$error"; |
---|
32 | } |
---|
33 | |
---|
34 | die "This script will delete most speciesSelections from your database.\nTo use, edit it, uncomment this line and save it locally.\nAlso edit list of kept speciesSelections to fit your needs."; |
---|
35 | |
---|
36 | # ------------------------------ read existing speciesSelections |
---|
37 | |
---|
38 | dieOnError(ARB::begin_transaction($gb_main), 'begin_transaction'); |
---|
39 | |
---|
40 | my $gb_configs = ARB::search($gb_main, '/configuration_data', 'NONE'); |
---|
41 | die 'failed to find speciesSelection-data' if not $gb_configs; |
---|
42 | |
---|
43 | my @speciesSelections = (); |
---|
44 | |
---|
45 | for (my $gb_sel = ARB::entry($gb_configs, 'configuration'); $gb_sel; $gb_sel = ARB::nextEntry($gb_sel)) { |
---|
46 | my $gb_name = ARB::entry($gb_sel, 'name'); |
---|
47 | die 'speciesSelection lacks name' if not $gb_name; |
---|
48 | my $name = ARB::read_string($gb_name); |
---|
49 | expectError('read name of speciesSelection') if not $name; |
---|
50 | push @speciesSelections, $name; |
---|
51 | } |
---|
52 | |
---|
53 | dieOnError(ARB::commit_transaction($gb_main), 'commit_transaction'); |
---|
54 | |
---|
55 | my $speciesSelections = scalar(@speciesSelections); |
---|
56 | BIO::message($gb_main, "Found $speciesSelections speciesSelections"); |
---|
57 | |
---|
58 | # ------------------------------ read existing speciesSelections [end] |
---|
59 | # ------------------------------ decide which speciesSelections to delete |
---|
60 | |
---|
61 | my %keep = map { $_ => 1; } @keep; |
---|
62 | my @delete = grep { not defined $keep{$_}; } @speciesSelections; |
---|
63 | |
---|
64 | my $keep = scalar(@keep); |
---|
65 | my $delete = scalar(@delete); |
---|
66 | BIO::message($gb_main, "Deleting $delete speciesSelections ($keep listed as protected)"); |
---|
67 | |
---|
68 | # ------------------------------ decide which speciesSelections to delete [end] |
---|
69 | |
---|
70 | BIO::remote_action($gb_main,'ARB_NT','ARB_NT/selection_admin2'); |
---|
71 | |
---|
72 | my $count = 0; |
---|
73 | foreach my $seldel (@delete) { |
---|
74 | ++$count; |
---|
75 | my $percent = int($count/$delete*100.0); |
---|
76 | print "Deleting speciesSelection $count/$delete ($percent%, '$seldel')\n"; |
---|
77 | BIO::remote_awar($gb_main,'ARB_NT','focus/configuration', $seldel); |
---|
78 | BIO::remote_action($gb_main,'ARB_NT','SPECIES_SELECTIONS_0/DELETE'); |
---|
79 | } |
---|
80 | |
---|
81 | BIO::message($gb_main, "$delete unlisted speciesSelections have been deleted."); |
---|
82 | BIO::message($gb_main, "Check remaining speciesSelections before you overwrite your database."); |
---|
83 | |
---|
84 | # recording stopped @ Sun Dec 26 11:19:28 2021 |
---|
85 | ARB::close($gb_main); |
---|