1 | #!/usr/bin/perl |
---|
2 | use strict; |
---|
3 | use warnings; |
---|
4 | |
---|
5 | # ------------------------------ configure SAIs to keep |
---|
6 | |
---|
7 | # simply enter names of SAIs to remain in the list below. |
---|
8 | my @keep = |
---|
9 | ( |
---|
10 | '3_prime', |
---|
11 | '5_prime', |
---|
12 | 'gap_align', |
---|
13 | 'termini', |
---|
14 | 'termini_5_3', |
---|
15 | 'ECOLI', |
---|
16 | 'HELIX', |
---|
17 | 'HELIX_NR', |
---|
18 | 'E_coli_I_Accessibility', |
---|
19 | 'E_coli_II_Accessibility', |
---|
20 | 'E_coli_III_Accessibility', |
---|
21 | 'E_coli_IV_Accessibility', |
---|
22 | 'E_coli_V_Accessibility', |
---|
23 | 'Met_Sedu_I_Accessibility', |
---|
24 | 'Met_Sedu_II_Accessibility', |
---|
25 | 'Met_Sedu_III_Accessibility', |
---|
26 | 'MetSedu_IV_Accessibility', # 'MetSedu' here and 'Met_Sedu' above (bug in silva DB?) |
---|
27 | 'MetSedu_V_Accessibility', |
---|
28 | 'PirStr1_I_Accessibility', |
---|
29 | 'PirStr1_II_Accessibility', |
---|
30 | 'SaccCer_I_Accessibility', |
---|
31 | 'SaccCer_II_Accessibility', |
---|
32 | ); |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | # ------------------------------ configure SAIs to keep [end] |
---|
37 | |
---|
38 | BEGIN { |
---|
39 | if (not exists $ENV{'ARBHOME'}) { die "Environment variable \$ARBHOME has to be defined"; } |
---|
40 | my $arbhome = $ENV{'ARBHOME'}; |
---|
41 | push @INC, "$arbhome/lib"; |
---|
42 | push @INC, "$arbhome/PERL_SCRIPTS/lib"; |
---|
43 | 1; |
---|
44 | } |
---|
45 | |
---|
46 | use ARB; |
---|
47 | use tools; |
---|
48 | |
---|
49 | my $gb_main = ARB::open(":","r"); |
---|
50 | if (not $gb_main) { |
---|
51 | my $error = ARB::await_error(); |
---|
52 | die "$error"; |
---|
53 | } |
---|
54 | |
---|
55 | die "This script will delete most SAIs from your database.\nTo use, edit it, uncomment this line and save it locally.\nAlso edit list of kept SAIs to fit your needs."; |
---|
56 | |
---|
57 | # ------------------------------ read existing SAIs |
---|
58 | |
---|
59 | dieOnError(ARB::begin_transaction($gb_main), 'begin_transaction'); |
---|
60 | |
---|
61 | my $gb_SAIs = ARB::search($gb_main, '/extended_data', 'NONE'); |
---|
62 | die 'failed to find SAI-data' if not $gb_SAIs; |
---|
63 | |
---|
64 | my @SAIs = (); |
---|
65 | |
---|
66 | for (my $gb_SAI = ARB::entry($gb_SAIs, 'extended'); $gb_SAI; $gb_SAI = ARB::nextEntry($gb_SAI)) { |
---|
67 | my $gb_name = ARB::entry($gb_SAI, 'name'); |
---|
68 | die 'SAI lacks name' if not $gb_name; |
---|
69 | my $name = ARB::read_string($gb_name); |
---|
70 | expectError('read name of SAI') if not $name; |
---|
71 | push @SAIs, $name; |
---|
72 | } |
---|
73 | |
---|
74 | dieOnError(ARB::commit_transaction($gb_main), 'commit_transaction'); |
---|
75 | |
---|
76 | my $SAIs = scalar(@SAIs); |
---|
77 | BIO::message($gb_main, "Found $SAIs SAIs"); |
---|
78 | |
---|
79 | # ------------------------------ read existing SAIs [end] |
---|
80 | # ------------------------------ decide which SAIs to delete |
---|
81 | |
---|
82 | my %keep = map { $_ => 1; } @keep; |
---|
83 | my @delete = grep { not defined $keep{$_}; } @SAIs; |
---|
84 | |
---|
85 | my $keep = scalar(@keep); |
---|
86 | my $delete = scalar(@delete); |
---|
87 | BIO::message($gb_main, "Deleting $delete SAIs ($keep listed as protected)"); |
---|
88 | |
---|
89 | # ------------------------------ decide which SAIs to delete [end] |
---|
90 | |
---|
91 | BIO::remote_action($gb_main,'ARB_NT','sai_admin'); |
---|
92 | |
---|
93 | my $count = 0; |
---|
94 | foreach my $saidel (@delete) { |
---|
95 | ++$count; |
---|
96 | my $percent = int($count/$delete*100.0); |
---|
97 | print "Deleting field $count/$delete ($percent%, '$saidel')\n"; |
---|
98 | BIO::remote_awar($gb_main,'ARB_NT','tmp/focus/sai_name', $saidel); |
---|
99 | BIO::remote_action($gb_main,'ARB_NT','INFO_OF_SAI/DELETE'); |
---|
100 | } |
---|
101 | |
---|
102 | BIO::message($gb_main, "$delete unlisted SAIs have been deleted."); |
---|
103 | BIO::message($gb_main, "Check remaining SAIs before you overwrite your database."); |
---|
104 | |
---|
105 | # recording stopped @ Sun Dec 26 11:19:28 2021 |
---|
106 | ARB::close($gb_main); |
---|