Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

all "nexml.pm": Fixed subroutines calling "Bio::Phylo::IO->parse".

They were all using a '-file' argument, so Phylo created a new
filehandle every time even though an open filehandle for the file
was already available in $self. This meant that there were 2 open
filehandles for the same file, that the Phylo fh could not be
closed, and that temporary files could not be deleted after script
end. Changed it to use the '-handle' argument when possible.
  • Loading branch information...
commit f3e87784bcf00573966bb2c3a5d0194568af41fc 1 parent a84f4ab
@fjossandon fjossandon authored
View
43 Bio/AlignIO/nexml.pm
@@ -131,23 +131,40 @@ sub doc {
}
sub _parse {
- my ($self) = @_;
+ my ($self) = @_;
$self->{'_parsed'} = 1;
$self->{'_alnsiter'} = 0;
my $fac = Bio::Nexml::Factory->new();
-
- $self->doc(parse(
- '-file' => $self->{'_file'},
- '-format' => 'nexml',
- '-as_project' => '1'
- ));
-
- $self->{'_alns'} = $fac->create_bperl_aln($self);
- if(@{ $self->{'_alns'} } == 0)
- {
- self->debug("no seqs in $self->{_file}");
- }
+
+ # Only pass filename if filehandle is not available,
+ # or "Bio::Phylo" will create a new filehandle that ends
+ # out of scope and can't be closed directly, leaving 2 open
+ # filehandles for the same file (so file can't be deleted)
+ my $file_arg;
+ my $file_value;
+ if ( exists $self->{'_filehandle'}
+ and defined $self->{'_filehandle'}
+ ) {
+ $file_arg = '-handle';
+ $file_value = $self->{'_filehandle'};
+ }
+ else {
+ $file_arg = '-file';
+ $file_value = $self->{'_file'};
+ }
+
+ $self->doc(parse(
+ $file_arg => $file_value,
+ '-format' => 'nexml',
+ '-as_project' => '1'
+ )
+ );
+ $self->{'_alns'} = $fac->create_bperl_aln($self);
+
+ if(@{ $self->{'_alns'} } == 0) {
+ self->debug("no seqs in $self->{_file}");
+ }
}
=head2 write_aln
View
51 Bio/NexmlIO.pm
@@ -135,22 +135,40 @@ my $nexml_fac = Bio::Nexml::Factory->new();
=cut
sub new {
- my($class,@args) = @_;
- my $self = $class->SUPER::new(@args);
-
- my %params = @args;
- my $file_string = $params{'-file'};
-
- #create unique ID by creating a scalar and using the memory address
- my $ID = bless \(my $dummy), "UniqueID";
- ($self->{'_ID'}) = sprintf("%s",\$ID) =~ /(0x[0-9a-fA-F]+)/;
-
- unless ($file_string =~ m/^\>/) {
- $self->{'_doc'} = Bio::Phylo::IO->parse('-file' => $params{'-file'}, '-format' => 'nexml', '-as_project' => '1');
- }
-
-
- return $self;
+ my($class,@args) = @_;
+ my $self = $class->SUPER::new(@args);
+
+ my %params = @args;
+ my $file_string = $params{'-file'};
+
+ #create unique ID by creating a scalar and using the memory address
+ my $ID = bless \(my $dummy), "UniqueID";
+ ($self->{'_ID'}) = sprintf("%s",\$ID) =~ /(0x[0-9a-fA-F]+)/;
+
+ unless ($file_string =~ m/^\>/) {
+ # Only pass filename if filehandle is not available,
+ # or "Bio::Phylo" will create a new filehandle that ends
+ # out of scope and can't be closed directly, leaving 2 open
+ # filehandles for the same file (so file can't be deleted)
+ my $file_arg;
+ my $file_value;
+ if ( exists $self->{'_filehandle'}
+ and defined $self->{'_filehandle'}
+ ) {
+ $file_arg = '-handle';
+ $file_value = $self->{'_filehandle'};
+ }
+ else {
+ $file_arg = '-file';
+ $file_value = $self->{'_file'};
+ }
+
+ $self->{'_doc'} = Bio::Phylo::IO->parse($file_arg => $file_value,,
+ '-format' => 'nexml',
+ '-as_project' => '1');
+ }
+
+ return $self;
}
=head2 doc
@@ -535,4 +553,3 @@ sub extract_trees {
}
1;
-
View
58 Bio/SeqIO/nexml.pm
@@ -145,31 +145,41 @@ sub doc {
}
sub _parse {
- my ($self) = @_;
- my $fac = Bio::Nexml::Factory->new();
-
- $self->{'_parsed'} = 1;
+ my ($self) = @_;
+
+ $self->{'_parsed'} = 1;
$self->{'_seqiter'} = 0;
-
- $self->doc(Bio::Phylo::IO->parse(
- '-file' => $self->{'_file'},
- '-format' => 'nexml',
- '-as_project' => '1'
- ));
-
-
-
- $self->{'_seqs'} = $fac->create_bperl_seq($self);
-
-
- unless(@{ $self->{'_seqs'} } == 0)
- {
-# self->debug("no seqs in $self->{_file}");
- }
- }
-
-
-
+ my $fac = Bio::Nexml::Factory->new();
+
+ # Only pass filename if filehandle is not available,
+ # or "Bio::Phylo" will create a new filehandle that ends
+ # out of scope and can't be closed directly, leaving 2 open
+ # filehandles for the same file (so file can't be deleted)
+ my $file_arg;
+ my $file_value;
+ if ( exists $self->{'_filehandle'}
+ and defined $self->{'_filehandle'}
+ ) {
+ $file_arg = '-handle';
+ $file_value = $self->{'_filehandle'};
+ }
+ else {
+ $file_arg = '-file';
+ $file_value = $self->{'_file'};
+ }
+
+ $self->doc(Bio::Phylo::IO->parse(
+ $file_arg => $file_value,
+ '-format' => 'nexml',
+ '-as_project' => '1'
+ )
+ );
+ $self->{'_seqs'} = $fac->create_bperl_seq($self);
+
+ unless(@{ $self->{'_seqs'} } == 0) {
+# self->debug("no seqs in $self->{_file}");
+ }
+}
=head2 write_seq
View
30 Bio/TreeIO/nexml.pm
@@ -149,14 +149,30 @@ sub _parse {
$self->{'_treeiter'} = 0;
my $fac = Bio::Nexml::Factory->new();
-
+ # Only pass filename if filehandle is not available,
+ # or "Bio::Phylo" will create a new filehandle that ends
+ # out of scope and can't be closed directly, leaving 2 open
+ # filehandles for the same file (so file can't be deleted)
+ my $file_arg;
+ my $file_value;
+ if ( exists $self->{'_filehandle'}
+ and defined $self->{'_filehandle'}
+ ) {
+ $file_arg = '-handle';
+ $file_value = $self->{'_filehandle'};
+ }
+ else {
+ $file_arg = '-file';
+ $file_value = $self->{'_file'};
+ }
+
$self->doc(parse(
- '-file' => $self->{'_file'},
- '-format' => 'nexml',
- '-as_project' => '1'
- ));
-
- $self->{'_trees'} = $fac->create_bperl_tree($self);
+ $file_arg => $file_value,
+ '-format' => 'nexml',
+ '-as_project' => '1'
+ )
+ );
+ $self->{'_trees'} = $fac->create_bperl_tree($self);
}
=head2 write_tree
View
3  t/AlignIO/nexml.t
@@ -73,5 +73,4 @@ SKIP: {
is ( ($feat->get_tag_values('taxon'))[0], $expected_taxa{$seq_num}, "$seq_num taxon ok" )
}
}
-
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.