Supply TEMPLATE and SUFFIX for temporary query sequence files.
[bioperl-run.git] / scripts / run_neighbor.PLS
blobc0b4b5b1c1f18566f26a0553c843480525edb2da
1 #!/usr/bin/perl -w
2 use strict;
4 =head1 NAME
6 run_neighbor - run Phylip's 'neighbor' program through Bioperl
8 =head1 SYNOPSIS
10 run_neighbor [-i inputfile] [-o outfilename]
12 =head1 DESCRIPTION
14 Provide an matrix file to run neighbor on. File should be named of
15 the forma file.matrix or file.protdist (the ending doesn't matter, but
16 the program expects a file in the form of (\S+)\.(\S+).
18 This will run the application 'neighbor' to build a
19 Neighbor-Joining tree from a protein distance matrix.
21 =head1 AUTHOR
23 Jason Stajich, jason-AT-open-bio-DOT-org
25 =cut
27 use Bio::TreeIO;
28 use Bio::Tools::Run::Phylo::Phylip::Neighbor;
29 use Getopt::Long;
31 my @params = ('type'=>'NJ', 'quiet' => 1);
33 my $matrixfile;
34 my $out;
35 GetOptions(
36 'i|input:s' => \$matrixfile,
37 'o|out:s' => \$out,
38 'h|help' => sub { exec('perldoc',$0); exit(0) }
40 ($matrixfile) ||= shift @ARGV;
42 my ($stem,$ext) = ($matrixfile =~ /(\S+)\.(\S+)$/) ;
43 $stem ||= $matrixfile;
45 my $outfh;
46 if( $out ) {
47 open($outfh, ">$out") || die($!);
48 } else {
49 open($outfh, ">$stem.tree") || die($!);
52 my $tree_factory = Bio::Tools::Run::Phylo::Phylip::Neighbor->new(@params);
53 my (@trees) = $tree_factory->create_tree($matrixfile);
55 my $outtree = new Bio::TreeIO(-fh => $outfh);
56 foreach my $tree ( @trees ){
57 $outtree->write_tree($tree);