#!/usr/bin/perl -w # The program split_fastq_paired_reads.pl splits a fastq files with paired reads into two files containing first and second reads of each pair, respectively. # Copyright (C) 2012 Minou Nowrousian # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details (http://www.gnu.org/licenses/). use strict; use warnings; unless (@ARGV == 1) { die("program usage: split_fastq_paired_reads.pl paired_read_file.fastq\n"); } unless (-e $ARGV[0]) { die("Can't open file $ARGV[0]: $!"); } print "Splitting fastq file $ARGV[0] into two fastq files.\nAssuming read order pair1_read1, pair1_read2, pair2_read1, pair2_read2 etc.\n"; open INPUTFILE, "< $ARGV[0]" or die "Kann Datei nicht oeffnen: $!"; my $outfile1 = $ARGV[0] . "_read1.fastq"; my $outfile2 = $ARGV[0] . "_read2.fastq"; open OUTFILE1, ">> $outfile1" or die "Kann Datei $outfile1 nicht oeffnen: $!"; open OUTFILE2, ">> $outfile2" or die "Kann Datei $outfile2 nicht oeffnen: $!"; while () { my $line1_1 = $_; if ($line1_1 !~ /^@/) { print "first line of read does not start with @ at read $line1_1\n"; } my $line1_2 = ; my $line1_3 = ; my $line1_4 = ; my $line2_1 = ; if ($line2_1 !~ /^@/) { print "first line of read does not start with @ at read $line2_1\n"; } my $line2_2 = ; my $line2_3 = ; my $line2_4 = ; print OUTFILE1 $line1_1, $line1_2, $line1_3, $line1_4; print OUTFILE2 $line2_1, $line2_2, $line2_3, $line2_4; } close INPUTFILE; close OUTFILE1; close OUTFILE2;