-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbwa_split_indiv
executable file
·66 lines (57 loc) · 1.35 KB
/
bwa_split_indiv
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
64
65
66
#!/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.
#
#Revised: Nick Hazekamp
#Date: 12/02/2013
#
#Purpose: Split a FASTQ file into smaller files determined by the number of sequences input
use strict;
use Symbol;
if ($#ARGV != 1) {
print "Usage: perl bwa_split_indiv <barcode->individual file> <fastq file>\n";
exit 1;
}
my $prog_file = shift;
my $file = shift;
my %progs = ();
my $output;
my $numargs = $#ARGV + 1;
open(PROG, $prog_file);
while (my $line = <PROG>) {
my @line_array = split(' ',$line);
my $file = $line_array[1];
my $name = gensym;
open( $name, ">$file.fq");
$progs{ $line_array[0] } = $name;
$output = $file;
}
close(PROG);
#Open input file
open(INPUT, $file);
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 =~ /^[@]/){
my @matches = ($line =~ /(index_[^_]+_[^_]+)/);
$output = $progs{ $matches[0] };
if ($output){
print $output $line;
print $output "\n";
}
}
#place all other lines in FASTQ file under same sequence
else {
if ($output){
print $output $line;
print $output "\n";
}
}
}
close(INPUT);
while ( my ($key, $value) = each(%progs) ) {
close($value);
}