revcomp_fastq

#!/usr/bin/perl -w
# Copyright 2013 Scott Hunicke-Smith
#
#
#given a fastq file, reverse complement the sequence and reverse the quality (quality in ASCII characters)
use strict; 
my ($rfile, $line, $dna, $revcomp);
$rfile=$ARGV[0];
open RFILE, "<$rfile";
while (defined(my $line = <RFILE>)) {
  chomp($line);
  my $dna = <RFILE>; #read to be revcomplemented
  chomp($dna);
  if ( substr($dna,0,15) eq "CCTATCCCCTGTGTG") {
     print "$line\n"; #read id
     print STDERR "$line\n"; #read id
     my $revcomp = reverse($dna);
     $revcomp =~ tr/ACGTNacgtn/TGCANtgcan/;
     print substr($revcomp,42), "\n"; 
     print STDERR substr($revcomp,30,11), "\n"; 
     $line = <RFILE>; #quality id
     chomp($line);
     print "$line\n";
     print STDERR "$line\n";
     my $qual = <RFILE>;
     chomp ($qual);
     my $revqual = reverse($qual);
     print substr($revqual,42),"\n";
     print STDERR substr($revqual,30,11), "\n"; 
  } else {
     if ( substr($dna,0,15) eq "CCATCTCATCCCTGC" ) {
        print "$line\n"; #read id
        print STDERR "$line\n"; #read id
        print substr($dna,42), "\n"; 
        print STDERR substr($dna,30,11), "\n"; 
        $line = <RFILE>; #quality id
        chomp($line);
        print "$line\n";
        print STDERR "$line\n";
        my $qual = <RFILE>;
        chomp ($qual);
        print substr($qual,42),"\n";
        print STDERR substr($qual,30,11), "\n"; 
     }
  }
}