Skip to content

Instantly share code, notes, and snippets.

@hyphaltip
Created October 5, 2009 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hyphaltip/202528 to your computer and use it in GitHub Desktop.
Save hyphaltip/202528 to your computer and use it in GitHub Desktop.
# 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment