Bio-BioStudio
view release on metacpan or search on metacpan
lib/Bio/BioStudio/BLAST.pm view on Meta::CPAN
{
remove_tree($blastdir);
return _make_species_database($species, $repo);
}
#Recover existing BLAST database
my $factory = Bio::Tools::Run::StandAloneBlastPlus->new(
-db_dir => $blastdir,
-db_name => _BLAST_name($species),
);
return $factory;
}
=head2 _BLAST_name
=cut
sub _BLAST_name
{
my ($species) = @_;
return 'BLAST_' . $species;
}
=head2 _path_to_BLAST_database
=cut
sub _path_to_BLAST_database
{
my ($species, $repo) = @_;
$repo = _endslash($repo) || _repobase();
return $repo . $species . q{/} . '_blast/';
}
=head2 _path_to_BLAST_index
=cut
sub _path_to_BLAST_index
{
my ($species, $repo) = @_;
my $blbase = _path_to_BLAST_database($species, $repo);
return $blbase . '_chrindex.txt';
}
=head2 _fetch_BLAST_index
=cut
sub _fetch_BLAST_index
{
my ($species, $repo) = @_;
my $indexpath = _path_to_BLAST_index($species, $repo);
my %index = ();
if (-e $indexpath)
{
open (my $BLASTINDEX, '<', $indexpath)
|| croak "BS_ERROR: Can't open BLAST index $indexpath : $OS_ERROR";
my $indexref = do {local $/ = <$BLASTINDEX>};
close $BLASTINDEX;
my @indexkeys = split m{\s}, $indexref;
%index = map {$_ => 1} @indexkeys;
}
return \%index;
}
=head2 _make_BLAST_index
=cut
sub _make_BLAST_index
{
my ($species, $repo, $chrlist) = @_;
my $indexpath = _path_to_BLAST_index($species, $repo);
my @list = @{$chrlist};
my $str = join qq{\t}, @list;
open (my $BLASTINDEX, '>', $indexpath)
|| croak "BS_ERROR: Can't write BLAST index $indexpath : $OS_ERROR";
print $BLASTINDEX $str;
close $BLASTINDEX;
return;
}
=head2 _verify_BLAST_index
=cut
sub _verify_BLAST_index
{
my ($species, $repo) = @_;
my %index = %{_fetch_BLAST_index($species, $repo)};
my @chrs = @{_gather_latest($species, $repo)};
my %latest = map {$_ => 1} @chrs;
my $flags = 0;
foreach my $chr (keys %latest)
{
$flags++ if (! exists $index{$chr});
}
foreach my $chr (keys %index)
{
$flags++ if (! exists $latest{$chr});
}
return $flags ? 0 : 1;
}
=head2 _make_species_database
=cut
sub _make_species_database
{
my ($species, $repo) = @_;
my @latest = @{_gather_latest($species, $repo)};
my @blastdata = ();
foreach my $chrname (@latest)
{
my $chr = Bio::BioStudio::Chromosome->new(-name => $chrname);
my $seqobj = $chr->seqobj;
my $seqlen = $seqobj->length();
push @blastdata, $chr->seqobj;
( run in 0.839 second using v1.01-cache-2.11-cpan-39bf76dae61 )