-
Notifications
You must be signed in to change notification settings - Fork 18
/
fastq_reduce
executable file
·63 lines (53 loc) · 1.3 KB
/
fastq_reduce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl
#
#Copyright (C) 2013- The University of Notre Dame
#This software is distributed under the GNU General Public License.
#See the file COPYING for details.
#
#Programmer: Brian Kachmarck
#Date: 7/28/2009
#
#Revised: Nick Hazekamp
#Date: 12/02/2013
#
#Purpose: Split a FASTQ file into smaller files determined by the number of sequences input
use strict;
my $numargs = $#ARGV + 1;
my $file = $ARGV[0];
my $num_reads= $ARGV[1];
my $num_outputs = 0;
my $line_count=0;
#Open input file
open(INPUT, $file);
my $read_count = 0;
open (OUTPUT,">$file.$num_outputs");
$num_outputs++;
while (my $line = <INPUT>) {
chomp $line;
#FASTQ files begin sequence with '@' character
#If line begins with '@' then it is a new sequence and has 3 lines in between
if ($line =~ /^[@]/ and $line_count % 4 ==0){
#Check if the new sequence should be placed in a new file, otherwise place it in same file
if ($read_count == $num_reads){
close(OUTPUT);
open(OUTPUT, ">$file.$num_outputs");
print OUTPUT $line;
print OUTPUT "\n";
$num_outputs++;
$read_count = 1;
}
else{
print OUTPUT $line;
print OUTPUT "\n";
$read_count++;
}
}
#place all other lines in FASTQ file under same sequence
else {
print OUTPUT $line;
print OUTPUT "\n";
}
$line_count++;
}
print $num_outputs;
close(INPUT);