/usr/bin/bp_seqfeature_delete is in bioperl 1.6.924-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | #!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
use strict;
use warnings;
use Getopt::Long;
use File::Spec;
use Bio::DB::SeqFeature::Store;
my $DSN = 'dbi:mysql:test';
my $USER = '';
my $PASS = '';
my $ADAPTOR = 'DBI::mysql';
my $NAME = 0;
my $TYPE = 0;
my $ID = 0;
my $VERBOSE = 1;
my $TEST = 0;
my $FAST = 0;
GetOptions(
'dsn|d=s' => \$DSN,
'adaptor=s' => \$ADAPTOR,
'verbose!' => \$VERBOSE,
'dryrun|dry-run' => \$TEST,
'name|n' => \$NAME,
'type|t' => \$TYPE,
'id' => \$ID,
'fast|f' => \$FAST,
'user=s' => \$USER,
'password=s' => \$PASS,
) || die <<END;
Usage: $0 [options] <feature1> <feature2> <feature3>
Options:
-d --dsn The database name ($DSN)
-a --adaptor The storage adaptor to use ($ADAPTOR)
-n --name Delete features based on name or wildcard pattern (default)
-t --type Delete features based on type
-i --id Delete features based on primary id
-v --verbose Turn on verbose progress reporting (default)
--noverbose Turn off verbose progress reporting
--dryrun Dry run; report features to be deleted without actually deleting them
-u --user User to connect to database as
-p --password Password to use to connect to database
-f --fast Deletes each item instantly not atomic for full dataset (mainly for deleting massive datasets linked to a type)
Examples:
Delete from mysql database volvox features named f08 f09 f10
$0 -d volvox -n f08 f09 f10
Delete features whose names start with f
$0 -d volvox -n 'f*'
Delete all features of type remark, source example
$0 -d volvox -t remark:example
Delete all remark features, regardless of source
$0 -d volvox -t 'remark:*'
Delete the feature with ID 1234
$0 -d volvox -i 1234
Delete all features named f* from a berkeleydb database
$0 -a berkeleydb -d /usr/local/share/db/volvox -n 'f*'
Remember to protect wildcards against shell interpretation by putting
single quotes around them!
END
;
if ($NAME+$TYPE+$ID > 1) {
die "Please provide only one of the --name, --type or --id options.\nRun \"$0 --help\" for usage.\n";
}
unless (@ARGV) {
die "Please provide a list of feature names, types or ids.\n Run \"$0 --help\" for usage.\n";
}
my $mode = $ID ? 'id'
:$TYPE ? 'type'
:$NAME ? 'name'
:'name';
my @options;
@options = ($USER,$PASS) if $USER || $PASS;
my $store = Bio::DB::SeqFeature::Store->new(
-dsn => $DSN,
-adaptor => $ADAPTOR,
-user => $USER,
-pass => $PASS,
-write => 1,
)
or die "Couldn't create connection to the database";
my @features = retrieve_features($store,$mode,\@ARGV);
if ($VERBOSE || $TEST) {
print scalar (@features)," feature(s) match.\n\n";
my $heading;
foreach (@features) {
printf "%-20s %-20s %-12s\n%-20s %-20s %-12s\n",
'Name','Type','Primary ID',
'----','----','----------'
unless $heading++;
printf "%-20s %-20s %-12d\n",$_->display_name,$_->type,$_->primary_id;
}
print "\n";
}
if (@features && !$TEST) {
if($FAST) {
my $del = 0;
foreach my $feat(@features) {
my @tmp_feat = ($feat);
my $deleted = $store->delete(@tmp_feat);
$del++ if($deleted);
if ($VERBOSE && $deleted) {
print 'Feature ',$del," successfully deleted.\n";
} elsif (!$deleted) {
die "An error occurred. Some or all of the indicated features could not be deleted.";
}
}
}
else {
my $deleted = $store->delete(@features);
if ($VERBOSE && $deleted) {
print scalar(@features)," features successfully deleted.\n";
} elsif (!$deleted) {
die "An error occurred. Some or all of the indicated features could not be deleted.";
}
}
}
exit 0;
sub retrieve_features {
my($db,$mode,$list) = @_;
my @features;
if ($mode eq 'name') {
@features = map {$db->get_features_by_alias($_)} @$list;
}
elsif ($mode eq 'type') {
my $regexp = glob2regexp(@$list);
my @types = grep {/$regexp/} $db->types;
@features = $db->get_features_by_type(@types) if @types;
}
elsif ($mode eq 'id') {
@features = grep {defined $_} map {$db->get_feature_by_primary_id($_)} @$list;
}
return @features;
}
sub glob2regexp {
my @globs = map {
$_ = quotemeta($_);
s/\\\*/.*/g;
s/\?/./g;
$_ } @_;
return '^(?:'.join('|',@globs).')$';
}
|