Permalink
Browse files

memory adapter does not expect fasta database to be closed after init…

…ial load, so leave it open
  • Loading branch information...
1 parent 7dd1aca commit 5f0e6da7ee2633700e854f9009780ab7c96c565d @lstein lstein committed Jul 31, 2014
Showing with 17 additions and 9 deletions.
  1. +0 −1 Bio/DB/Fasta.pm
  2. +8 −2 Bio/DB/IndexedBase.pm
  3. +5 −3 Bio/DB/SeqFeature/Store/Loader.pm
  4. +4 −3 Bio/DB/SeqFeature/Store/memory.pm
View
@@ -187,7 +187,6 @@ sub _calculate_offsets {
@ids = $self->_makeid($line);
($offset, $headerlen, $linelen, $seq_lines) = ($pos, length $line, 0, 0);
($l3_len, $l2_len, $l_len, $blank_lines) = (0, 0, 0, 0);
-
} else {
# Catch bad header lines, bug 3172
$self->throw("FASTA header doesn't match '>(\\S+)': $line");
View
@@ -353,6 +353,7 @@ sub new {
require Cwd;
$dirname = Cwd::getcwd();
} else {
+ $self->{index_name} ||= $self->_default_index_name($path);
if (-d $path) {
# because Win32 glob() is broken with respect to long file names
# that contain whitespace.
@@ -442,7 +443,7 @@ sub index_dir {
my ($self, $dir, $force_reindex) = @_;
my @files = glob( File::Spec->catfile($dir, $self->{glob}) );
return if scalar @files == 0;
- $self->{index_name} ||= File::Spec->catfile($dir, 'directory.index');
+ $self->{index_name} ||= $self->_default_index_name($dir);
my $offsets = $self->_index_files(\@files, $force_reindex);
return $offsets;
}
@@ -480,11 +481,16 @@ sub get_all_primary_ids {
sub index_file {
my ($self, $file, $force_reindex) = @_;
- $self->{index_name} ||= "$file.index";
+ $self->{index_name} ||= $self->_default_index_name($file);
my $offsets = $self->_index_files([$file], $force_reindex);
return $offsets;
}
+sub _default_index_name {
+ my ($self,$path) = @_;
+ return File::Spec->catfile($path,'directory.index') if -d $path;
+ return "$path.index";
+}
=head2 index_files
@@ -113,7 +113,7 @@ default.
sub new {
my $self = shift;
my ($store,$seqfeature_class,$tmpdir,$verbose,$fast,
- $seq_chunk_size,$coordinate_mapper,$index_subfeatures,$summary_stats) =
+ $seq_chunk_size,$coordinate_mapper,$index_subfeatures,$summary_stats,$no_close_fasta) =
rearrange(['STORE',
['SF_CLASS','SEQFEATURE_CLASS'],
['TMP','TMPDIR'],
@@ -122,7 +122,8 @@ sub new {
'CHUNK_SIZE',
'MAP_COORDS',
'INDEX_SUBFEATURES',
- 'SUMMARY_STATS'
+ 'SUMMARY_STATS',
+ 'NO_CLOSE_FASTA',
],@_);
@@ -185,6 +186,7 @@ END
coordinate_mapper => $coordinate_mapper,
index_subfeatures => $index_subfeatures,
summary_stats => $summary_stats,
+ no_close_fasta => $no_close_fasta,
},ref($self) || $self;
}
@@ -727,7 +729,7 @@ sub DESTROY {
) {
$store->private_fasta_file->close;
- if ($store->{fasta_db}) {
+ if ($store->{fasta_db} && !$self->{no_close_fasta}) {
while (my ($file, $fh) = each %{ $store->{fasta_db}->{fhcache} }) {
$fh->close;
}
@@ -148,8 +148,9 @@ sub post_init {
return unless $file_or_dir;
my $loader = Bio::DB::SeqFeature::Store::GFF3Loader->new(-store => $self,
- -sf_class => $self->seqfeature_class)
- or $self->throw("Couldn't create GFF3Loader");
+ -sf_class => $self->seqfeature_class,
+ -no_close_fasta => 1
+ ) or $self->throw("Couldn't create GFF3Loader");
my @argv;
if (-d $file_or_dir) {
@argv = (
@@ -694,7 +695,7 @@ sub _insert_sequence {
sub _fetch_sequence {
my ($self, $seqid, $start, $end) = @_;
my $db = $self->{fasta_db} or return;
- $db->seq($seqid,$start,$end);
+ return $db->seq($seqid,$start,$end);
}
sub private_fasta_file {

0 comments on commit 5f0e6da

Please sign in to comment.