Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:bioperl/bioperl-live
  • Loading branch information
fangly committed Jun 9, 2012
2 parents 910afe6 + fc04d25 commit 714dac6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
54 changes: 53 additions & 1 deletion Bio/Align/Utilities.pm
Expand Up @@ -101,7 +101,7 @@ require Exporter;
use base qw(Exporter);

@EXPORT = qw();
@EXPORT_OK = qw(aa_to_dna_aln bootstrap_replicates cat);
@EXPORT_OK = qw(aa_to_dna_aln bootstrap_replicates cat bootstrap_replicates_codons);
%EXPORT_TAGS = (all =>[@EXPORT, @EXPORT_OK]);
BEGIN {
use constant CODONSIZE => 3;
Expand Down Expand Up @@ -226,6 +226,58 @@ sub bootstrap_replicates {
return \@alns;
}

=head2 bootstrap_replicates_codons
Title : bootstrap_replicates_codons
Usage : my $alns = &bootstrap_replicates_codons($aln,100);
Function: Generate a pseudo-replicate of the data by randomly
sampling, with replacement, the columns from a codon alignment for
the non-parametric bootstrap. The alignment is assumed to start on
the first position of a codon.
Returns : Arrayref of L<Bio::SimpleAlign> objects
Args : L<Bio::SimpleAlign> object
Number of replicates to generate
=cut

sub bootstrap_replicates_codons {
my ($aln,$count) = @_;
$count ||= 1;
my $alen = $aln->length;
my $ncodon = int($alen/3);
my (@seqs,@nm);
$aln->set_displayname_flat(1);
for my $s ( $aln->each_seq ) {
push @seqs, $s->seq();
push @nm, $s->id;
}
my (@alns,$i);
while( $count-- > 0 ) {
my @newseqs;
for($i =0; $i < $ncodon; $i++ ) {
my $index = int(rand($ncodon));
my $seqpos = $index * 3;
my $c = 0;
for ( @seqs ) {
$newseqs[$c++] .= substr($_,$seqpos,3);
}
}
my $newaln = Bio::SimpleAlign->new();
my $i = 0;
for my $s ( @newseqs ) {
(my $tmp = $s) =~ s{[$Bio::LocatableSeq::GAP_SYMBOLS]+}{}g;
$newaln->add_seq( Bio::LocatableSeq->new
(-start => 1,
-end => length($tmp),
-display_id => $nm[$i++],
-seq => $s));
}
push @alns, $newaln;
}
return \@alns;
}


=head2 cat
Title : cat
Expand Down
18 changes: 9 additions & 9 deletions scripts/index/bp_fetch.pl
Expand Up @@ -4,7 +4,7 @@ =head1 NAME
bp_fetch.pl - fetches sequences from bioperl indexed databases
=head1 SYNOPSIS
=head1 SYNOPSIS
bp_fetch.pl swiss:ROA1_HUMAN
Expand Down Expand Up @@ -45,26 +45,26 @@ =head1 OPTIONS
-fmt <format> - Output format
Fasta (default), EMBL, Raw, swiss or GCG
-acc - string is an accession number, not an
id.
id.
options only for expert use
-dir <dir> - directory to find the index files
(overrides BIOPERL_INDEX environment varaible)
-type <type> - type of DBM file to open
-type <type> - type of DBM file to open
(overrides BIOPERL_INDEX_TYPE environment variable)
=head1 ENVIRONMENT
bp_index and bp_fetch coordinate where the databases lie using the
environment variable BIOPERL_INDEX. This can be overridden using the
-dir option. The index type (SDBM or DB_File or another index file)
is controlled by the BIOPERL_INDEX_TYPE variable. This defaults to
SDBM_File
is controlled by the BIOPERL_INDEX_TYPE variable. This defaults to
SDBM_File
=head1 USING IT YOURSELF
bp_fetch is a wrapper around the bioperl modules which support
bp_fetch is a wrapper around the bioperl modules which support
the Bio::DB::BioSeqI abstract interface. These include:
Author Code
Expand Down Expand Up @@ -94,7 +94,7 @@ =head1 EXTENDING IT
=head1 FEEDBACK
=head2 Mailing Lists
=head2 Mailing Lists
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
Expand Down Expand Up @@ -176,7 +176,7 @@ BEGIN
my $type = $ENV{'BIOPERL_INDEX_TYPE'};
my $fmt = 'Fasta';
my $useacc = 0;
my $ret = GetOptions('f|dir=s' => \$dir,
my $ret = GetOptions('d|dir=s' => \$dir,
'f|fmt=s' => \$fmt ,
't|type=s' => \$type ,
'acc!' => \$useacc);
Expand Down Expand Up @@ -218,7 +218,7 @@ BEGIN
$meta = 'local';
}

# parse to db:id
# parse to db:id

/^(\S+)\:(\S+)$/ || do { warn "$_ is not parsed as db:name\n"; next; };
($db,$id) = split/:/,$_,2;
Expand Down

0 comments on commit 714dac6

Please sign in to comment.