8 use Bio
::DB
::SeqFeature
::Store
;
10 my $DSN = 'dbi:mysql:test';
13 my $ADAPTOR = 'DBI::mysql';
23 'adaptor=s' => \
$ADAPTOR,
24 'verbose!' => \
$VERBOSE,
25 'dryrun|dry-run' => \
$TEST,
31 'password=s' => \
$PASS,
33 Usage: $0 [options] <feature1> <feature2> <feature3>
35 -d --dsn The database name ($DSN)
36 -a --adaptor The storage adaptor to use ($ADAPTOR)
37 -n --name Delete features based on name or wildcard pattern (default)
38 -t --type Delete features based on type
39 -i --id Delete features based on primary id
40 -v --verbose Turn on verbose progress reporting (default)
41 --noverbose Turn off verbose progress reporting
42 --dryrun Dry run; report features to be deleted without actually deleting them
43 -u --user User to connect to database as
44 -p --password Password to use to connect to database
45 -f --fast Deletes each item instantly not atomic for full dataset (mainly for deleting massive datasets linked to a type)
49 Delete from mysql database volvox features named f08 f09 f10
50 $0 -d volvox -n f08 f09 f10
52 Delete features whose names start with f
55 Delete all features of type remark, source example
56 $0 -d volvox -t remark:example
58 Delete all remark features, regardless of source
59 $0 -d volvox -t 'remark:*'
61 Delete the feature with ID 1234
64 Delete all features named f* from a berkeleydb database
65 $0 -a berkeleydb -d /usr/local/share/db/volvox -n 'f*'
67 Remember to protect wildcards against shell interpretation by putting
68 single quotes around them!
72 if ($NAME+$TYPE+$ID > 1) {
73 die "Please provide only one of the --name, --type or --id options.\nRun \"$0 --help\" for usage.\n";
77 die "Please provide a list of feature names, types or ids.\n Run \"$0 --help\" for usage.\n";
87 @options = ($USER,$PASS) if $USER || $PASS;
89 my $store = Bio
::DB
::SeqFeature
::Store
->new(
96 or die "Couldn't create connection to the database";
98 my @features = retrieve_features
($store,$mode,\
@ARGV);
100 if ($VERBOSE || $TEST) {
101 print scalar (@features)," feature(s) match.\n\n";
103 foreach (@features) {
104 printf "%-20s %-20s %-12s\n%-20s %-20s %-12s\n",
105 'Name','Type','Primary ID',
106 '----','----','----------'
108 printf "%-20s %-20s %-12d\n",$_->display_name,$_->type,$_->primary_id;
113 if (@features && !$TEST) {
116 foreach my $feat(@features) {
117 my @tmp_feat = ($feat);
118 my $deleted = $store->delete(@tmp_feat);
120 if ($VERBOSE && $deleted) {
121 print 'Feature ',$del," successfully deleted.\n";
122 } elsif (!$deleted) {
123 die "An error occurred. Some or all of the indicated features could not be deleted.";
128 my $deleted = $store->delete(@features);
129 if ($VERBOSE && $deleted) {
130 print scalar(@features)," features successfully deleted.\n";
131 } elsif (!$deleted) {
132 die "An error occurred. Some or all of the indicated features could not be deleted.";
139 sub retrieve_features
{
140 my($db,$mode,$list) = @_;
142 if ($mode eq 'name') {
143 @features = map {$db->get_features_by_alias($_)} @
$list;
145 elsif ($mode eq 'type') {
146 my $regexp = glob2regexp
(@
$list);
147 my @types = grep {/$regexp/} $db->types;
148 @features = $db->get_features_by_type(@types) if @types;
150 elsif ($mode eq 'id') {
151 @features = grep {defined $_} map {$db->get_feature_by_primary_id($_)} @
$list;
162 return '^(?:'.join('|',@globs).')$';