#!/usr/bin/perl -w # # illumina_split_read.pl # A script to split a fastq file reads into two parts # # Martin.Trick@bbsrc.ac.uk, 21/1/2010 # Option to include a read number on command line if the required number of reads for the first part differs from the default of 40 # Script output two files,the program will exit if these files exist. # the first file ends with .1 contains the first part of the reads, each read identifier ending with _1 # the second file ending with .2 contains the last part of the reads, each read identifier ending with _2 unless (@ARGV >= 1) { print "Usage: illumina_split_read.pl [split at base N (default 40)]\n"; exit; } open (FQ, "<$ARGV[0]") or die "Couldn't open input fastq file ($!)\n"; my $out_1 = "$ARGV[0]" . ".1"; my $out_2 = "$ARGV[0]" . ".2"; if (-e $out_1 || -e $out_2) { print "Output files will be clobbered\n"; exit; } open (OUT_1, ">>$out_1") or die "Couldn't open FH ($!)"; open (OUT_2, ">>$out_2") or die "Couldn't open FH ($!)"; my $split = $ARGV[1] || 40; my $read_string; my $quality_string; my $read_name; my $reads = 0; my @record = (); READ: while () { if ($.%4 == 1) { ($read_name = $_ ) =~ s/^\;//; chomp $read_name; } if ($.%4 == 2) { $read_string = $_; } next if ($.%4 == 3); if ($.%4 == 0) { $reads++; $quality_string = $_; print OUT_1 "$read_name" . "_1\n" . substr($read_string,0,$split) . "\n\+\n"; print OUT_1 substr($quality_string,0,$split) . "\n"; print OUT_2 "$read_name" . "_2\n" . substr($read_string,$split) . "+\n"; print OUT_2 substr($quality_string,$split); } } print "Processed $reads reads\n"; close FQ; close OUT_1; close OUT_2;