source: branches/properties/lib/macros/keep_listed_SAIs.amc

Last change on this file was 19351, checked in by westram, 2 years ago
  • added script to delete unlisted SAIs.
  • Property svn:executable set to *
File size: 3.0 KB
Line 
1#!/usr/bin/perl
2use strict;
3use warnings;
4
5# ------------------------------ configure SAIs to keep
6
7# simply enter names of SAIs to remain in the list below.
8my @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
38BEGIN {
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
46use ARB;
47use tools;
48
49my $gb_main = ARB::open(":","r");
50if (not $gb_main) {
51  my $error = ARB::await_error();
52  die "$error";
53}
54
55die "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
59dieOnError(ARB::begin_transaction($gb_main), 'begin_transaction');
60
61my $gb_SAIs = ARB::search($gb_main, '/extended_data', 'NONE');
62die 'failed to find SAI-data' if not $gb_SAIs;
63
64my @SAIs = ();
65
66for (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
74dieOnError(ARB::commit_transaction($gb_main), 'commit_transaction');
75
76my $SAIs = scalar(@SAIs);
77BIO::message($gb_main, "Found $SAIs SAIs");
78
79# ------------------------------ read existing SAIs [end]
80# ------------------------------ decide which SAIs to delete
81
82my %keep = map { $_ => 1; } @keep;
83my @delete = grep { not defined $keep{$_}; } @SAIs;
84
85my $keep = scalar(@keep);
86my $delete = scalar(@delete);
87BIO::message($gb_main, "Deleting $delete SAIs ($keep listed as protected)");
88
89# ------------------------------ decide which SAIs to delete [end]
90
91BIO::remote_action($gb_main,'ARB_NT','sai_admin');
92
93my $count = 0;
94foreach 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
102BIO::message($gb_main, "$delete unlisted SAIs have been deleted.");
103BIO::message($gb_main, "Check remaining SAIs before you overwrite your database.");
104
105# recording stopped @ Sun Dec 26 11:19:28 2021
106ARB::close($gb_main);
Note: See TracBrowser for help on using the repository browser.