Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Shell calling input FASTA file

by JoUthoff (Initiate)
on Oct 16, 2014 at 01:05 UTC ( [id://1103991]=perlquestion: print w/replies, xml ) Need Help??

JoUthoff has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a perl program to find the longest open reading frames in a mRNA.fa sequence. I can easily do this by calling the file from the script using:

open FILE, "mRNA.fa" or die $!; # Opens mRNA, assoicates FILE

However, my instructor wants the file to be called using command line prompt

perl <programName.pl> <input file>

Now I have tried using the command ARGV to pull the filename from the bash:

my $file = $ARGV[0]; open (my $mRNAfile, "<", $file) or die $!; my @mRNAdata = ( ); # initalizes the variables of array @mRNAdata = <$mRNAfile>;

When I run this, I receive compilation errors for each of the 100 sequences saying:

"Number found where operator expected at - line 1, near "Sequence 1" ( +Do you need to predeclare Sequence?).

Any advice would be greatly appreciated! Thank you!

Replies are listed 'Best First'.
Re: Shell calling input FASTA file
by AnomalousMonk (Archbishop) on Oct 16, 2014 at 03:44 UTC

    Just sneaking suspicion and wild surmise here, can't test this, but your command line is something like
        perl programName.pl mRNA.fa
    and not
        perl <programName.pl> <mRNA.fa>
    isn't it? (The  < > angle brackets are just metasyntactic delimiters. (Update: Well, as used by your instructor, they're just metasyntactic delimiters. On a command line, of course, they're re-direction operators — a very significant difference!))

Re: Shell calling input FASTA file
by biohisham (Priest) on Oct 16, 2014 at 14:01 UTC

    How does a fasta header in your input file look like? I tried to reproduce the behavior you are alluding to by using your code and a couple of fasta sequences, but your code seems to be working just fine.

    A side notice on your first code (open FILE, "mRNA.fa" or die $!;). That open statement lacks telling it what mode you want to open mRNA.fa into. It is a good practice to decide if you want to open your file for input, output or appending. The second open statement from the newer code is a better way of opening a file since you have instructed open on the type of mode you want to open your file in.


    A 4 year old monk

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1103991]
Approved by kevbot
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 04:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found