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

Last change on this file was 19352, checked in by westram, 2 years ago
  • added script to delete unlisted species selections.
  • Property svn:executable set to *
File size: 2.7 KB
Line 
1#!/usr/bin/perl
2use strict;
3use warnings;
4
5# ------------------------------ configure speciesSelections to keep
6
7# simply enter names of speciesSelections to remain in the list below.
8my @keep =
9  (
10   'name_of_species_selection',
11  );
12
13
14
15# ------------------------------ configure speciesSelections to keep [end]
16
17BEGIN {
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
25use ARB;
26use tools;
27
28my $gb_main = ARB::open(":","r");
29if (not $gb_main) {
30  my $error = ARB::await_error();
31  die "$error";
32}
33
34die "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
38dieOnError(ARB::begin_transaction($gb_main), 'begin_transaction');
39
40my $gb_configs = ARB::search($gb_main, '/configuration_data', 'NONE');
41die 'failed to find speciesSelection-data' if not $gb_configs;
42
43my @speciesSelections = ();
44
45for (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
53dieOnError(ARB::commit_transaction($gb_main), 'commit_transaction');
54
55my $speciesSelections = scalar(@speciesSelections);
56BIO::message($gb_main, "Found $speciesSelections speciesSelections");
57
58# ------------------------------ read existing speciesSelections [end]
59# ------------------------------ decide which speciesSelections to delete
60
61my %keep = map { $_ => 1; } @keep;
62my @delete = grep { not defined $keep{$_}; } @speciesSelections;
63
64my $keep = scalar(@keep);
65my $delete = scalar(@delete);
66BIO::message($gb_main, "Deleting $delete speciesSelections ($keep listed as protected)");
67
68# ------------------------------ decide which speciesSelections to delete [end]
69
70BIO::remote_action($gb_main,'ARB_NT','ARB_NT/selection_admin2');
71
72my $count = 0;
73foreach 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
81BIO::message($gb_main, "$delete unlisted speciesSelections have been deleted.");
82BIO::message($gb_main, "Check remaining speciesSelections before you overwrite your database.");
83
84# recording stopped @ Sun Dec 26 11:19:28 2021
85ARB::close($gb_main);
Note: See TracBrowser for help on using the repository browser.