I received the following error, but I don't understand how to fix it. Help?

"readline() on closed filehandle IN at transcribe.pl line 21."

#!/usr/bin/perl
#transcribe.pl
#convert DNA to RNA (T to U)
use strict;
use warnings;

#TASK: Read DNA sequences from ‘DNAseq’ input file – 
#there is one sequence per line
#For each sequence find the reverse complement and 
#print it to ‘DNAseqRC’ output file


#open input and output files
open(IN,"~/Documents/fastafiles/Genomes/LuContig091010.fa");
open(OUT,">~/Documents/fastafiles/LuContig091010RNAcomp.fa");

#read the input file line-by-line
#for each line find the complimentary RNA
#print it in the output file
my $rcRNA;
while(<IN>){
    chomp;
    $rcRNA = revcompRNA($_);
    print OUT "$rcRNA\n";
}

#close input and output files
close(IN);
close(OUT);

exit();

#definition of the function for reverse complement
sub revcompRNA{
    my($DNAin) = @_;
    my($RNAout) = reverse($DNAin);
    $RNAout =~ tr/ACGT/UGCA/;
    return $RNAout;
}

Add

or die $!

to the end of line 14. This will show what error, if any, is being encountered on the open.

Okay, I edited and am no longer receiving "error messages", but I'm not getting data. I think it doesn't like the OUT file. Any ideas?

In the terminal I see this...

....
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347629.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347630.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347631.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347632.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347633.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347634.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347635.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347636.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347637.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347638.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347639.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347640.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347641.
Filehandle OUT opened only for input at transcribe.pl line 24, <IN> line 1347642.
...
etc.

Here is the code as it is currently:

#!/usr/bin/perl
#transcribe.pl
#convert DNA to RNA (T to U)
use strict;
use warnings;

#TASK: Read DNA sequences from ‘DNAseq’ input file – 
#there is one sequence per line
#For each sequence find the reverse complement and 
#print it to ‘DNAseqRC’ output file


#open input and output files
open(IN,"LuContig091010.fa")or die $!;
open(OUT,"LuContig091010RNAcomp.fa")or die $!;

#read the input file line-by-line
#for each line find the complimentary RNA
#print it in the output file
my $rcRNA;
while(<IN>){
    chomp;
    $rcRNA = revcompRNA($_);
    print OUT "$rcRNA\n";
}

#close input and output files
close(IN);
close(OUT);

exit();

#definition of the function for reverse complement
sub revcompRNA{
    my($DNAin) = @_;
    my($RNAout) = reverse($DNAin);
    $RNAout =~ tr/ACGT/UGCA/;
    return $RNAout;
}

The following statement fails to specify the file open mode. The default mode of read only is assumed. open(OUT,"LuContig091010RNAcomp.fa")or die $!;#No redirection character so file is opened in read mode I prefer the 3-argument version of the open, like this: open( OUT, ">", "LuContig091010RNAcomp.fa" ) || die "Can't create output file $!"; See http://perldoc.perl.org/perlopentut.html#Simple-Opens

Edited 6 Years Ago by d5e5: n/a

thanks for that link. Although I know of perldoc.perl.org, I'm not always sure what I'm looking for....I'm such a novice, but I really want to learn this. Thanks for your help d5e5.

This question has already been answered. Start a new discussion instead.