1#!/usr/bin/perl -w 2use strict; 3use Bio::NEXUS; 4use Data::Dumper; 5use Getopt::Std; 6 7# nexdump is a simple tool for developers working on the NEXPL API. I found 8# myself frequently wanting to verify the structure or content of NEXUS objects, 9# and was annoyed that I always had to write the same few lines of code over 10# and over. - TH 050913 (Happy Birthday to me) 11 12 13my %flags; 14getopts('d:b:h', \%flags) or die &usage; 15die &usage if $flags{h}; 16 17$Data::Dumper::Maxdepth = $flags{d} if $flags{d}; 18 19my @blocktypes = split /[\s,]+/, $flags{b} if $flags{b}; 20 21my @nexusfiles = @ARGV; 22 23die &usage unless @nexusfiles; 24 25for my $file (@nexusfiles) { 26 unless (-e $file) {warn "File: <$file> is not a valid filepath\n"; next}; 27 my $nexus = new Bio::NEXUS($file); 28 if ($flags{b}) { 29 for my $blocktype (@blocktypes) { 30 my $blocks = $nexus->get_blocks($blocktype); 31 if (@$blocks) { 32 print Dumper $blocks; 33 } else {warn "No <$blocktype> blocks found\n";} 34 } 35 } else { 36 print Dumper $nexus; 37 } 38} 39 40 41sub usage { 42 43 print STDERR << "EOF"; 44 45 Usage: nexdump.pl [-h] [-d depth] [-b 'blocks'] file1.nex [file2.nex ...] 46 47 -d depth : sets \$Data::Dumper::Maxdepth 48 -b 'blocks' : specifies which blocks are to be dumped 49 -h : displays this usage information 50 51EOF 52 exit; 53} 54