3
# Author Jason Stajich <jason-at-bioperl-dot-org>
5
# Make a non-redundant database based on sequence (not on ID!)
6
# This script is still in progress but is intended to mimic what
7
# Warren Gish's nrdb does
9
# It requires that Digest::MD5 is installed (for now)
13
bp_nrdb.PLS - a script to emulate Warren Gish's nrdb, make a unique sequence database from a set of input databases
19
bp_nrdb.PLS [options] file1 file2 file3
22
bp_nrdb.PLS -p [options] file1 id1 file2 id2 file3 id3
26
This script will create a unique database of sequences
27
(quasi-nonredundant). The options are:
29
-o filename - the filename the db is written (STDOUT by default)
30
-a filename - the filename to append the db to
31
-l# - minimum required sequence length
32
-i - do not check for duplicates
33
-n# - max number of descriptions to report per seq
34
-d# - delimiter to use between consecutive descriptions
35
-p - use database id prefixes from command line
39
Jason Stajich, jason-at-bioperl-dot-org
47
use Digest::MD5 qw(md5_hex);
48
my ($output,$append,$min_len,
49
$no_duplicate_check,$desc_count,
50
$delimiter, $expect_prefixes,$help);
54
'o|output:s' => \$output,
55
'a|append:s' => \$append,
56
'n:s' => \$desc_count,
59
'p' => \$expect_prefixes,
60
'i' => \$no_duplicate_check,
64
die("must supply a positive integer for -d") if ( defined $desc_count &&
65
( $desc_count !~ /^\d+$/ ||
67
die("must supply a positive integer for -l") if ( defined $min_len &&
68
( $min_len !~ /^\d+$/ ||
72
if( $help || ! @ARGV ) {
78
my ($file, $id) = (undef,'');
79
if( $expect_prefixes ) {
80
($file,$id) = (shift @ARGV, shift @ARGV);
82
die("Must provide 'name id' pairing of dbfile and id");
87
push @files, [ $file,$id];
93
$out = new Bio::SeqIO(-file => ">>$append");
95
$out = new Bio::SeqIO(-file => ">$output");
97
$out = new Bio::SeqIO(); # use STDOUT
103
foreach my $pair ( @files ) {
104
my ($file,$id) = @$pair;
105
my $in = new Bio::SeqIO(-file => $file);
106
while( my $seq = $in->next_seq ) {
107
next if defined $min_len && $seq->length < $min_len;
109
$seq->display_id("$id:".$seq->display_id);
111
my $s = lc($seq->seq());
112
my $md5sum = md5_hex($s);
113
if( $no_duplicate_check ) {
114
$md5sum = $counter++;
117
if( defined $unique{$md5sum} ) {
118
$seqcount{$md5sum}++;
119
next if defined $desc_count && $seqcount{$md5sum++} > $desc_count;
120
my $desc = $unique{$md5sum}->description;
121
my $id2 = sprintf("%s %s:%s %s",$delimiter,
122
$id,$seq->display_id,$seq->description);
123
$unique{$md5sum}->desc($desc . $id2);
125
$unique{$md5sum} = $seq;
130
foreach my $seq ( values %unique ) {
131
$out->write_seq($seq);