And boom goes the dynamite!! Thanks this worked perfectly!
How To Remove The Identifier And Quality From A Fastq File
I have a fastq file and need to remove the identifier, quality, and white space. So far my script looks something like this:
#!/usr/bin/perl -w
use strict;
my $inputFileName = shift;
my $outputFileName = shift;
open INPUTFILE, "<$inputFileName" or die "poop";
open OUTPUT, ">$outputFileName" or die "poop";
my @bases = ('A', 'G', 'T', 'C');
my $line;
while ($line = <INPUTFILE>) {
chomp $line;
if ($line =~ /^\s*$/)
elsif ($line =~ /^\s*@/)
elsif ($line =~ /^+/)
else {print OUTPUT $line, "\n";
}
}
However I keep getting an empty output file. I'm very new to perl, so be gently.
Thanks!!
• 5,606 views
•
link
4 answers
#!/usr/bin/env perl
use strict;
use warnings;
my $lines = 4;
my $delimiter = "\t";
my $input = shift @ARGV;
open(INPUT,"$input");
while (<INPUT>) {
if($. % $lines == 2){ # the % character is the modulo operator Pierre was talking about
print
}
}
close(INPUT);
Put that in a file called extract_reads_from_fastq.pl and do the trick with:
perl extract_reads_from_fastq.pl input.fastq
• 0 views
•
link
• 0 views
•
link
You could also do something like this:
#!/usr/bin/perl
use strict;
use warnings;
my $file = shift;
open my $F, $file;
LINE: while ($_=<$F>) {
my @line = split /\t/;
chomp @line;
next if /^@/; # gets rid of line 1 of fastq
next if /^\+/; # gets rid of line 3
next if /^!/; # gets rid of line 4 if it begins with a ! -- check your files format
my $printme = 0;
++$printme;
print join(qq/\t/, @line) if $printme;
}
print STDERR "Done.\n";
Of course there's probably a nice one-liner too for this...
• 0 views
•
link
I used to eval fastq files with those reg-ex, but Illumina 1.8+ (Phred+33) brokes that.
• 0 views
•
link
Perl one liner:
perl -ne 'print if (++$n % 4 == 2)' < file.fq > output
• 0 views
•
link
Log in to answer this question.
Your problem is the fastq format doesn't contains spaces, to get only the sequence, it's better to count lines like the solutions proposed below. Also you have no instructions after your
if,elsif, you should usenext.