Question: (Closed) script showing error
0
gravatar for mwanerhi  erfgtr
3.8 years ago by
United States
mwanerhi erfgtr30 wrote:

ok so i want to extract a set of protein sequences based on thier ids in one file and the sequences in the other file.

i modified a perl script but it is showing errors

01 #!/usr/bin/perl
02 
03 if ($#ARGV != 1) {
04  print "usage:  extracting sequences.pl IDFILE fasta_library > outputfile\n";
05  exit;
06 }
07 $home/samuel/Desktop/Darwin/Research/Masters/Analysis/BASYS/L111/L111ids.txt =$ARGV [0];
08 $home/samuel/Desktop/Darwin/Research/Masters/Analysis/BASYS/L111/L111.faa =$ARGV [1];
09 
10 use strict;
11 use Bio::DB::Fasta;
12 
13 my $database;
14 my $fasta_library = $ARGV[1];   #path to fastalibrary in the second argument
15 my %records;
16 
17 open IDFILE, "<$ARGV[0]" or die $!; #first argument is the path of the file containing all the IDs you need to extract
18 open OUTPUT, <STDOUT>;
19 
20 # creates the database of the library, based on the file
21 $database = Bio::DB::Fasta->new("$fasta_library") or die "Failed to creat Fasta DP object on fasta library\n";
22 
23 # now, it parses the file with the fasta headers you want to get
24 while (<IDFILE>) {
25
26  my ($id) = (/^>*(\S+)/);  # capture the id string (without the initial ">")
27  my $header = $database->header($id);
28  #print "$header\n";
29  print ">$header\n", $database->seq( $id ), "\n";
30  print OUTPUT ">$header\n", $database->seq( $id ), "\n";
31 }
32 
33 #remove the index file that is useless for user
34 unlink "$fasta_library.index";
35 
36 #close the filehandles
37 close IDFILE;
38 close OUTPUT;
39 exit;

here is the error it is showing

:~/Desktop/Darwin/Research/Masters/Analysis/BASYS/L111$ perl extractingsequences.pl
Can't modify concatenation (.) or string in scalar assignment at extractingsequences.pl line 22, near "];"
BEGIN not safe after errors--compilation aborted at extractingsequences.pl line 25.

what am i doing wrong?

 

perl • 1.5k views
ADD COMMENTlink modified 3.8 years ago by RamRS21k • written 3.8 years ago by mwanerhi erfgtr30
1

This question is Perl related. Please post it to Perl Monks also.

ADD REPLYlink written 3.8 years ago by Deepak Tanwar3.9k
1

Please do not suggest/encourage cross-posting.

ADD REPLYlink written 3.8 years ago by RamRS21k
1

Alright! I am sorry about that.I encouraged this because I think that the question is related to programming with perl.

ADD REPLYlink written 3.8 years ago by Deepak Tanwar3.9k
1

OK, but OP should then ask PerlMonks, not multiple forums.

ADD REPLYlink written 3.8 years ago by RamRS21k
1

Yes, you are right!

ADD REPLYlink written 3.8 years ago by Deepak Tanwar3.9k

Why do you use a space while indexing @ARGV? $ARGV[0] is the right way, not $ARGV [0]

Scratch that, lines 07 and 08 make no sense. Are you creating variable names that look like file absolute path for any reason? Are those even valid variable names?

ADD REPLYlink modified 3.8 years ago • written 3.8 years ago by RamRS21k

Are lines 7 and 8 really part of your script?

ADD REPLYlink written 3.8 years ago by h.mon24k

yes they are, i didn’t mention that a new to perl programming so am sure there would be mistakes

ADD REPLYlink written 3.8 years ago by mwanerhi erfgtr30

A quick suggestion, use just letters, numbers and underscore as variable names in Perl. I am almost sure they are the only characters allowed, if other characters are allowed, they are discouraged. One of your errors is slashes on variable names on lines 7 and 8.

ADD REPLYlink modified 3.8 years ago • written 3.8 years ago by h.mon24k

Hello samuelkiwa!

We believe that this post does not fit the main topic of this site.

This is a Perl question. Please ask PerlMonks or StackOverflow

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

ADD REPLYlink written 3.8 years ago by RamRS21k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 907 users visited in the last hour