script showing error
OK so I want to extract a set of protein sequences based on their 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?
• 2,451 views
•
link
0 answers
No answers yet.
Log in to answer this question.
This question is Perl related. Please post it to Perl Monks also.
Please do not suggest/encourage cross-posting.
Alright! I am sorry about that.I encouraged this because I think that the question is related to programming with perl.
OK, but OP should then ask PerlMonks, not multiple forums.
Yes, you are right!
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?
Are lines 7 and 8 really part of your script?
yes they are, i didn’t mention that a new to perl programming so am sure there would be mistakes
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.
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!