Error '"use" not allowed' when running a bioperl script
2
0
Entering edit mode
9.7 years ago
jeccy.J ▴ 60

Hello all I would like to blast multiple sequence individually one after another and output I need in excel sheet, I tried like this:

use Bio::Tools::Run::StandAloneBlastPlus;
Bio.SearchIO.BlastIO.blast_xml
use Excel::Writer::XLSX;
use strict;
use Bio::SearchIO;
for file in *.fasta
do
    echo $file
      out=`echo $file | sed 's/_.fasta_/_.excel_/'`
my $factory = Bio::Tools::Run::StandAloneBlastPlus->new(
    -db_data => 'Autotransporters.fasta',  # Specifies the file to use for database
    -create => 1               # Creates a new temporary database
);
my $result = $factory->blastn(
    -query => '$file',                # Specifies the query file     
    -outfile => '$out' );  # Specifies the output location
$factory->cleanup;                        # Deletes the temporary database files

Error :

"use" not allowed in expression at multifasta_blast.pl line 3, at end of line
syntax error at multifasta_blast.pl line 3, near "blast_xml
use Excel::Writer::XLSX"
BEGIN not safe after errors--compilation aborted at multifasta_blast.pl line 4.

Can anyone help me out to solve the error?

Blast perl • 3.7k views
ADD COMMENT
2
Entering edit mode
9.7 years ago
SES 8.6k

The problem is that this is not Perl code, it has some Perl statements but they are mixed in with some Bash and Python (I think) syntax. Unfortunately, no interpreter is going to know what to do with this code. If you are trying to execute this with the Perl interpreter, start by removing the second line, and re-work your for loop so it will work with Perl (explained here). Also, you don't need to use sed from within Perl, just use the substitution operator.

Those very minor changes will make this code compile, and I would personally just output your blast as a blasttable (tab-delimited) and then import it to Excel, if you must. You will save yourself a lot of time if you work with the tab-delimited blast because you can easily manipulate it at the command-line or in Excel. For that reason, it is not advisable to spend a lot of time trying to create the spreadsheet, unless it is for an assignment or practice, then the experience may be helpful.

.

ADD COMMENT
0
Entering edit mode

I wonder why OP is looking to import BLAST results into Excel though. Wouldn't R be a much MUCH better alternative? I'd personally prefer a simple plain text TSV myself.

ADD REPLY
0
Entering edit mode

I'm not sure what the goal is, but I don't think reading blast in R is any better than Excel because both will use lots of memory and cause problems with large files (unless using scan() or something similar in R, but that will still be slower than unix tools).

ADD REPLY
0
Entering edit mode

I agree. Like I said, I'd personally use shell builtins.

ADD REPLY
0
Entering edit mode

My goal is : i have multiple genome in one folder , now i want blast one after another with specific query sequence.

Could you please help me out.

ADD REPLY
0
Entering edit mode
9.7 years ago
Ram 43k

Hi,

Elucidating your request,

OP's premise: OP has multiple database sequence sets in a folder and would like to BLAST a query against each database sequence set and output to a format that can be imported to Excel.

OP's problem: Mixed usage of Perl and BASH syntaxes

Solution: Convert to BASH loop, like so:

mkdir tmp_dbs out_dir
for file in *.fasta
do
  makeblastdb -in ${file} -dbtype nucl -out ./tmp_dbs/${file}_db
  blastn -db ./tmp_dbs/${file}_db -query AutoTransporters.fasta -out ./out_dir/${file}_results.tsv -outfmt 6
done
rm -rf ./tmp_dbs #Delete DBs
ADD COMMENT

Login before adding your answer.

Traffic: 1983 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