This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Aligning protein sequences using Perl

Hi everyone

I'm trying to align a fasta file (sequence.fasta) using MUSCLE through Perl,

and I get this very annoying message:

Can't call method "align" on an undefined value at C:\perlscripts\new1.pl line 8

Any clue what might be the problem?

#!/ usr/bin/ perl
use Bio::Tools::Run::Alignment::Muscle
# Build a muscle alignment factory
my $factory =Bio::Tools::Run::Alignment::Muscle -> new( @params );
# Pass the factory a list of sequences to be aligned .
my $inputfilename = 'sequence.fasta ';
# $aln is a SimpleAlign object .
my $aln = $factory -> align ( $inputfilename );
# Perform a profile alignment on a MSA to include more seqs
my $alnfilename = 'sequence.fasta ';
my $seqsfilename = 'outfile ';
$aln = $factory -> profile ( $alnfilename , $seqsfilename );
use strict ;
perl sequence bioperl align muscle

2 answers

You haven't defined @params before you use it to create the $factory object, which results in you calling a method (align) on an undefined object. The synopsis sections of some BioPerl modules do not provide working examples, so copying the code may not do much (except generate warnings or errors).

Another approach would be to run muscle with system() and use Bio::SearchIO to parse the resulting alignment, which I assume is what you want to do.

'use strict' would have picked up the undefined @params.

'use strict' is in the script (at the end). It is an unconventional placement, but it doesn't matter where you put it because pragma imports happen at compile-time.

use strict only takes effect for code positioned after it. Consider:

#!/usr/bin/perl

$c = $a + $b;
use strict;
$d = $a + $b;

This gives:

Global symbol "$d" requires explicit package name at ./test.pl line 5.
Execution of ./test.pl aborted due to compilation errors.

You are right about the order, I stand corrected. If you specify a version above 5.12, that will have the same effect and enable modern features. There are other problems with this code as well (use of reserved variables).

ok!and how should i define @params? i m really new to all this stuff ..

@params should contain whatever parameters you want to pass to MUSCLE as key=value pairs.

ok i m really confused. I read the HOWTO from bioperl.wiki but i have no result.Can u suggest me any book that should help me??

The BioPerl documentation is lacking in some areas. In your case, you should actually look at the MUSCLE documentation since this is what you want BioPerl to run. As SES wrote above, you could try running MUSCLE directly and parse the output with BioPerl. This might be better documented.

You should 'use strict' and 'use warnings'. It would have caught the missing ; at the end of the second line: use Bio::Tools::Run::Alignment::Muscle

That is correct, and the code that is posted would not even compile so I'm guessing this is a typo in the question.

Log in to answer this question.