Hi
I am trying to convert .qual and .fna file to fastq using the script provided here. http://seqanswers.com/forums/showthread.php?t=2775&highlight=fasta+qual+fastq
The code is as follows:

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;
use File::Basename;

my $inFasta = $ARGV[0];
my $baseName = basename($inFasta, qw/Reads.fna/);
my $inQual = $baseName . "/Users/myfolder/Reads.qual";
my $outFastq = $baseName . "Reads.fastq";

my %seqs;

$/ = ">";

open (FASTA, "<$inFasta");
my $junk = (<FASTA>);

while (my $frecord = <FASTA>) {
    chomp $frecord;
    my ($fdef, @seqLines) = split /\n/, $frecord;
    my $seq = join '', @seqLines;
    $seqs{$fdef} = $seq;
}

close FASTA;

open (QUAL, "<$inQual");
$junk = <QUAL>;
open (FASTQ, ">$outFastq");

while (my $qrecord = <QUAL>) {
    chomp $qrecord;
    my ($qdef, @qualLines) = split /\n/, $qrecord;
    my $qualString = join ' ', @qualLines;
    $qualString =~ s/\s+/ /g;
    my @quals = split / /, $qualString;
    print FASTQ "@","$qdef\n";
    print FASTQ "$seqs{$qdef}\n";
    print FASTQ "+\n";
    foreach my $qual (@quals) {
        print FASTQ chr($qual + 33);
    }
    print FASTQ "\n";
}

close QUAL;
close FASTQ;

I keep getting the error:

readline() on closed filehandle QUAL at fastaQual2fastq.pl line 30.
readline() on closed filehandle QUAL at fastaQual2fastq.pl line 33.

I am running it from command line as:

perl fastaQual2fastq.pl Reads.fna 

I get an output file but its 0 kb file which is clearly incorrect. Am I missing something?

Hi perllearner007,

Cool that you are doing great with Perl. However, I think it should be mentioned that when altering the input line record separator namely $/ in Perl since it influences ( or define ) what a line is. You will want to use it in a loop of it own defined as local, like so:

{
  local $/='>';
  .....
  ...
}

So that when your loop is done. The input line record separator is restored back to it default. Except you don't want that.

check perldoc -v $/ for more info.

Just saying. Nice one!

Member Avatar for Kwetal

You should check the return code of your open() statements.

commented: Right. +8
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.