1

I have a perl script to automate many multiple alignments (I'm making the script first with only one file and one multiple alignment - big one though. I can then modify for multiple files) and I want to output the resulting file, but I am unsure on how to do with with AlignIO: so far I have:

use warnings;
use strict;
use Bio::AlignIO;
use Bio::SeqIO;
use Bio::Tools::Run::Alignment::Clustalw;

my $file = shift or die; # Get filename from command prompt.
my $factory = Bio::Tools::Run::Alignment::Clustalw->new(-matrix => 'BLOSUM');
my $ktuple = 3;
$factory->ktuple($ktuple);

my $inseq = Bio::SeqIO->new(
                    -file => "<$file",
                    -format => $format
                   );

my $seq;
my @seq_array;
while ($seq = $inseq->next_seq) {
    push(@seq_array, $seq);
}

# Now we do the actual alignment.
my $seq_array_ref = \@seq_array;
my $aln = $factory->align($seq_array_ref);

Once the alignment is done I have $aln which is the alignment I want to get out of the process as a fasta file - I tried something like:

my $out = Bio::AlignIO->new(-file => ">outputalignmentfile",
                         -format => 'fasta');
while( my $outaln = $aln->next_aln() ){
    $out->write_aln($outaln);
}

but it didn't work, presumably because the method next_aln() only applies to AlignIO things, which $aln is probably not. So I need to know what it is that is generated by the line my $aln = $factory->align($seq_array_ref); and how to get the aligned sequences output into a file. My next step is tree estimation or network analysis.

Thanks, Ben.

SJWard
  • 3,629
  • 5
  • 39
  • 54

1 Answers1

0

$out->write_aln($outaln); Was the only line needed to write the object returned by the clustalw line to output the object to that stream.

SJWard
  • 3,629
  • 5
  • 39
  • 54