Aligning protein sequences using Perl
2
0
Entering edit mode
9.7 years ago
Andrea ▴ 60

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 • 3.9k views
ADD COMMENT
1
Entering edit mode
9.7 years ago
SES 8.6k

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.

ADD COMMENT
1
Entering edit mode

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

ADD REPLY
0
Entering edit mode

'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.

ADD REPLY
0
Entering edit mode

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.
ADD REPLY
0
Entering edit mode

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).

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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??

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode
9.7 years ago

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

ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2400 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6