http://qs321.pair.com?node_id=488509

rvosa has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I need to parse text files of several formats. Based on the contents of the text files, one or more trees, matrices, and/or taxon objects are created. I wonder if you can advice me, from a user perspective, what would be a convenient interface. Right now, what you'd do is:
use Bio::Phylo::Parsers; my $parser = new Bio::Phylo::Parsers; # the newick format contains one or more trees. my $trees = $parser->parse( -format => 'newick', -file => $newickfile +); # the 'taxlist' format is simply a list of names, from # which a taxa object is created my $taxa = $parser->parse( -format => 'taxlist', -file => $taxonfile ) +; # the nexus format is a mixed format, that can contain # trees, taxa, matrices, etc. my $arrayref = $parser->parse( -format => 'nexus', -file => $nexusfile + );
The Bio::Phylo::Parsers package functions as a facade, that require's the appropriate parser submodule based on the format switch.

The problem lies primarily in the nexus format, which can contain a bunch of different things. Right now, without recourse to the nexus text file, it is impossible to say what is returned by the parser (it simply returns an array ref with all objects it parsed from the file). This seems too ad hoc. All other parsers return Bio::Phylo::* objects.

An option I've been considering is to make it such that not all text in the file is parsed, but only those things (if present) that the user wants:
my $trees = $parser->parse(-format => 'nexus', -I_want => 'trees', -fi +le => $nexusfile);
So, based on the "-I_want => " switch, the parser only ever returns what the user wants (if present).

Would that be a convenient way to go about things? What would you do?

Thanks!