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
48 use Digest
::MD5
qw(md5_hex);
49 my ($output,$append,$min_len,
50 $no_duplicate_check,$desc_count,
51 $delimiter, $expect_prefixes,$help);
55 'o|output:s' => \
$output,
56 'a|append:s' => \
$append,
57 'n:s' => \
$desc_count,
60 'p' => \
$expect_prefixes,
61 'i' => \
$no_duplicate_check,
65 die("must supply a positive integer for -d") if ( defined $desc_count &&
66 ( $desc_count !~ /^\d+$/ ||
68 die("must supply a positive integer for -l") if ( defined $min_len &&
69 ( $min_len !~ /^\d+$/ ||
73 if( $help || ! @ARGV ) {
79 my ($file, $id) = (undef,'');
80 if( $expect_prefixes ) {
81 ($file,$id) = (shift @ARGV, shift @ARGV);
83 die("Must provide 'name id' pairing of dbfile and id");
88 push @files, [ $file,$id];
94 $out = new Bio
::SeqIO
(-file
=> ">>$append");
96 $out = new Bio
::SeqIO
(-file
=> ">$output");
98 $out = new Bio
::SeqIO
(); # use STDOUT
104 foreach my $pair ( @files ) {
105 my ($file,$id) = @
$pair;
106 my $in = new Bio
::SeqIO
(-file
=> $file);
107 while( my $seq = $in->next_seq ) {
108 next if defined $min_len && $seq->length < $min_len;
110 $seq->display_id("$id:".$seq->display_id);
112 my $s = lc($seq->seq());
113 my $md5sum = md5_hex
($s);
114 if( $no_duplicate_check ) {
115 $md5sum = $counter++;
118 if( defined $unique{$md5sum} ) {
119 $seqcount{$md5sum}++;
120 next if defined $desc_count && $seqcount{$md5sum++} > $desc_count;
121 my $desc = $unique{$md5sum}->description;
122 my $id2 = sprintf("%s %s:%s %s",$delimiter,
123 $id,$seq->display_id,$seq->description);
124 $unique{$md5sum}->desc($desc . $id2);
126 $unique{$md5sum} = $seq;
131 foreach my $seq ( values %unique ) {
132 $out->write_seq($seq);