[Bioperl-l] preparing nexus files for Mr. Bayes

Jason Stajich jason at bioperl.org
Wed Jun 11 11:13:20 EDT 2008


Giovanni -

Bits and pieces already exist, there is little to handle the text  
blocks that exist in NEXUS files because BioPerl has has been focused  
on the alignment data not the analysis.  Arlin Stolzfus has started a  
Bio::NEXUS project that is supposed to fully parse all NEXUS data in  
and out but I don't know what the status is right now.

If you look at the Bio::AlignIO::nexus documentation you need to turn  
off symbols and endblock when writing for MrBayes NEXUS.

my $out = Bio::AlignIO->new(-format => 'nexus',
			    -show_symbols => 0,
			    -show_endblock => 0);


# after you have written out the alignment
$out->write_aln;
# you can then print out whatever execution blocks you want with  
standard print statements.
print $out->_fh "begin mrbayes;\n"; ...


As for the other things, the Bio::SimpleAlign module lets you swap  
the match character (see map_char and gap_char methods).

For joining alignments and setting up partitions, you can join  
multiple alignments by making a new Bio::SimpleAlign and adding  
concatenated sequences together.

my %matrix;
  for my $aln ( @alns ) {
   for my $seq ( $aln->each_seq ) {
             my $id = $seq->id;
             $matrix{$id} .= $seq->seq;
   }
  }
  my $bigaln = Bio::SimpleAlign->new;
  while( my ($id,$seq) = each %matrix ) {
      $bigaln->add_seq(Bio::LocatableSeq->new(-id  => $id,
                                                 -seq => $seq));
  }


In general there is not a single solution to a lot of these tasks  
(although there should be one that concatenates a set of  alignments)  
so there are not ready-to-use functions.  I have my custom code I use  
to join datasets and establish partitions but much is specific to how  
I organize the data on my system so I don't know how informative it  
would be.

I'm not sure python code would be much good here... =) if you jump  
ship you should talk to Frank Kauff who has written some python code  
to manipulate alignments for biopython.

-jason

On Jun 11, 2008, at 2:46 AM, Giovanni Marco Dall'Olio wrote:

> Hi,
> I was wondering whether there is any bioperl module I can use to
> handle nexus files for Mr.Bayes.
>
> mr. Bayes is a program for bayesian estimation of phylogeny, which
> uses an alignment file in a customized nexus format as input.
> I would need a module to prepare these files, doing tasks like:
> - joining more than an alignment in a single file/line
> - substitute matching chars with '.'
> - customizing parameters displayed in the headers of the output  
> nexus file
> - manage mrbayes' extensions, like adding information about  
> partitions and taxas
> - adding batch instructions for the mr bayes interpreter
> - and similar stuff.
>
> I have tried Bio::AlignIO but I see it doesn't handle all of this,
> what I am looing for is bit more specific.
> Moreover, I found a bug in the way mrbayes recognizes the output from
> Bio::AlignIO (https://sourceforge.net/tracker/index.php? 
> func=detail&aid=1990655&group_id=129302&atid=714418).
>
> Is there any existing module already available?
> If there is not, I am going to have to write such scripts anyway.
> I would like to contribute them to bioperl, even if I am not a very
> good perl programmer, I prefer python.
>
> -- 
> -----------------------------------------------------------
>
> My Blog on Bioinformatics (italian): http://bioinfoblog.it
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l



More information about the Bioperl-l mailing list