Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# concat multiple nexus formatted files into one nexus format file
# assuming sequence IDs are the same across all files
# and data is all aligned and all seqs are present in all files
use Bio::AlignIO;
use Bio::SimpleAlign;
use strict;
my %seqs;
for my $file ( @ARGV ) {
my $in = Bio::AlignIO->new(-format=> 'nexus', -file => $file);
if ( my $aln = $in->next_aln ) {
for my $seq ( $aln->each_seq ) {
$seqs{$seq->display_id} .= $seq->seq;
my $newaln = Bio::SimpleAlign->new;
for my $id ( keys %seqs ) {
$newaln->add_seq(Bio::LocatableSeq->new(-id=> $id,-seq=>$seqs{$id}));
my $out = Bio::AlignIO->new(-format => 'nexus');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment