public
Last active

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 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');
$out->write_aln($newaln);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.