From: Tara L Andrews Date: Tue, 10 Jan 2012 12:32:04 +0000 (+0100) Subject: allow distance program specification X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0f5d05c6adca96ece82661de0a262b038a00ba5f;p=scpubgit%2Fstemmatology.git allow distance program specification --- diff --git a/Makefile.PL b/Makefile.PL index 73cb7ad..a03074d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -8,6 +8,7 @@ all_from( 'lib/Text/Tradition.pm' ); requires( 'Algorithm::Diff' ); requires( 'Bio::Phylo::IO' ); requires( 'File::chdir' ); +requires( 'File::Which' ); requires( 'Graph' ); requires( 'Graph::Reader::Dot' ); requires( 'IPC::Run' ); diff --git a/lib/Text/Tradition/Stemma.pm b/lib/Text/Tradition/Stemma.pm index 70fd634..ba0d51f 100644 --- a/lib/Text/Tradition/Stemma.pm +++ b/lib/Text/Tradition/Stemma.pm @@ -30,6 +30,12 @@ has distance_trees => ( predicate => 'has_distance_trees', ); +has distance_program => ( + is => 'rw', + isa => 'Str', + default => '', + ); + sub BUILD { my( $self, $args ) = @_; # If we have been handed a dotfile, initialize it into a graph. @@ -181,15 +187,20 @@ sub witnesses { before 'distance_trees' => sub { my $self = shift; - my %args = @_; + my %args = ( + 'program' => 'phylip_pars', + @_ ); # TODO allow specification of method for calculating distance tree - if( $args{'recalc'} || !$self->has_distance_trees ) { + if( !$self->has_distance_trees + || $args{'program'} ne $self->distance_program ) { # We need to make a tree before we can return it. - my( $ok, $result ) = $self->run_phylip_pars(); + my $dsub = 'run_' . $args{'program'}; + my( $ok, $result ) = $self->$dsub(); if( $ok ) { # Save the resulting trees my $trees = _parse_newick( $result ); $self->_save_distance_trees( $trees ); + $self->distance_program( $args{'program'} ); } else { warn "Failed to calculate distance trees: $result"; } @@ -306,7 +317,7 @@ sub run_phylip_pars { # And then we run the program. my $program = File::Which::which( 'pars' ); unless( -x $program ) { - return( undef, "Phylip pars not found in path" ); + return( undef, "Phylip pars not found in path" ); } { diff --git a/t/stemma.t b/t/stemma.t index 7f3bc7d..67ded66 100644 --- a/t/stemma.t +++ b/t/stemma.t @@ -49,7 +49,7 @@ foreach my $i ( 0 .. $#wits ) { # Test that pars runs SKIP: { - skip "pars not installed", 3 unless File::Which::which('pars'); + skip "pars not in path", 3 unless File::Which::which('pars'); my( $status, $tree ) = $stemma->run_phylip_pars(); ok( $status, "pars ran successfully" ); print STDERR "Error was $tree\n" unless $status;