Mercurial > repos > tiagoantao > barcode_stacks
annotate barcode_sort.pl @ 0:5dc02b8a2a57 draft default tip
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
author | tiagoantao |
---|---|
date | Fri, 08 Apr 2016 11:38:00 -0400 |
parents | |
children |
rev | line source |
---|---|
0
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
1 #!/usr/bin/perl -w |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
2 use strict; use warnings; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
3 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
4 my $cut_site = $ARGV[7]; #let the user specify the cut site keyword (e.g. "TGCA" for the SbfI 6 bp cutter) |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
5 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
6 my $b = $ARGV[6]; #let the user specify barcode length |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
7 my $n = 2; # set number of nucleotides to expect before the barcode (bestRAD libraries run at U. Oregon have 2bp here) |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
8 my $c = $b + $n; # set position for start of enzyme cutsite, which occurs after the initial nucleotides plus the barcode |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
9 my $e = 6; # set length of remaining enzyme cutsite sequence (e.g. 6 for SbfI) -- for other than SbfI, need to change the actual sequence below!!! |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
10 my $e = length($cut_site); #calculate the length of the cut site |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
11 # note this is the length of what's left after enzyme digestion, NOT the full length of the enzyme recognition site |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
12 # the program expects all correct forward reads to follow the pattern: $n initial nucleotides, then $b nucleotides of barcode, then $e nucleotides of the cutsite |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
13 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
14 my $is_resilient; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
15 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
16 open (IN, $ARGV[0]); # read file with barcodes |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
17 my %counts = (); # make a hash of barcodes that will be searched |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
18 while(<IN>) { # counts of each barcode can be tracked with this hash, with a few more lines of code below |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
19 chomp($_); |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
20 $counts{$_} = 0; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
21 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
22 close IN; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
23 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
24 open (IN1, $ARGV[1]); # read fastq file of raw forward reads |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
25 open (IN2, $ARGV[2]); # read fastq file of raw reverse reads -- these must have pairs in identical order |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
26 open (OUT1, ">$ARGV[3]"); # create fastq outfile for flipped forward reads (cutsite end) |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
27 open (OUT2, ">$ARGV[4]"); # create fastq outfile for flipped reverse reads (randomly sheared end) |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
28 my $forward; my $reverse; my $barcode; # establish string variables for all parts of fastq files |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
29 my $name1; my $name2; my $third1; my $third2; my $qual1; my $qual2; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
30 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
31 $is_resilient = $ARGV[5]; # true if is resilient to errors - Brian's additions |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
32 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
33 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
34 sub strDiffMaxDelta { |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
35 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
36 my ( $s1, $s2, $maxDelta ) = @_; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
37 my $diffCount = () = ( $s1 ^ $s2 ) =~ /[^\x00]/g; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
38 return $diffCount <= $maxDelta; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
39 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
40 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
41 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
42 if ($is_resilient eq "true") { |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
43 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
44 my $max_errors = $ARGV[8]; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
45 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
46 while($name1 = <IN1>) { # start reading through the paired fastq input files |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
47 $name2 = <IN2>; # read all parts of a single read pair (4 lines in each of the 2 fastq files) |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
48 $forward = <IN1>; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
49 $reverse = <IN2>; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
50 $third1 = <IN1>; $third2 = <IN2>; $qual1 = <IN1>; $qual2 = <IN2>; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
51 my $which = 0; my $for; my $rev; # establish variables used below |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
52 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
53 if(strDiffMaxDelta(substr($forward, $c, $e), $cut_site, $max_errors)) { # check for SbfI cutsite in the correct place in forward read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
54 if(strDiffMaxDelta(substr($reverse, $c, $e), $cut_site, $max_errors)) { # check for SbfI cutsite in the correct place in reverse read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
55 $for = substr($forward, $n, $b); # this is where a barcode should be if it's in the forward read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
56 $rev = substr($reverse, $n, $b); # this is where a barcode should be if it's in the reverse read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
57 if(exists $counts{$for} && (exists $counts{$rev}) == 0) { # if a correct barcode and cutsite are in forward but not reverse read... |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
58 $which = 1; $barcode = $for; $counts{$for}++; # which = 1 means the pair is correctly oriented |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
59 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
60 elsif((exists $counts{$for}) == 0 && exists $counts{$rev}) { # if a correct barcode and cutsite are only in the reverse read... |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
61 $which = 2; $barcode = $rev; $counts{$rev}++; # which = 2 means the pair needs to be flipped |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
62 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
63 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
64 else { # the cutsite is only found in the forward read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
65 #$barcode = substr($forward, $n, $b); |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
66 #if(exists $counts{$barcode}) {$which = 1; $counts{$barcode}++; } # if a correct barcode is in the forward read, the pair is correctly oriented |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
67 $which = 1; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
68 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
69 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
70 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
71 elsif(strDiffMaxDelta(substr($reverse, $c, $e), $cut_site, $max_errors)){ # cutsite not in forward read but is in reverse read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
72 #$barcode = substr($reverse, $n, $b); |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
73 #if(exists $counts{$barcode}) {$which = 2; $counts{$barcode}++; } # pair needs to be flipped |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
74 $which = 2; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
75 } # if a cutsite and correct barcode has not been found in either read, which = 0 at this point |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
76 if($which == 1) { # if the pair is correctly oriented, print out fastq format for the pair |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
77 my $temp1 = substr($forward, $n); # trim initial nucleotides off read and quality scores... |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
78 my $temp2 = substr($qual1, $n); # so that output keeps barcode and cutsite but not other nucleotides... |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
79 print OUT1 "$name1$temp1$third1$temp2"; # and is ready to go into process_radtags |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
80 print OUT2 "$name2$reverse$third2$qual2"; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
81 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
82 elsif($which == 2) { # if the pair needs to be flipped, print out fastq format for the flipped pair |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
83 my $temp1 = substr($reverse, $n); |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
84 my $temp2 = substr($qual2, $n); |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
85 print OUT1 "$name2$temp1$third2$temp2"; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
86 print OUT2 "$name1$forward$third1$qual1"; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
87 } # if which == 0, nothing is printed out for the pair |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
88 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
89 close IN1; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
90 close IN2; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
91 close OUT1; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
92 close OUT2; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
93 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
94 foreach my $key (sort keys %counts) { |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
95 print "$key" . "\t" . "$counts{$key}\n"; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
96 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
97 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
98 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
99 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
100 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
101 else{ #Paul's code |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
102 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
103 while($name1 = <IN1>) { # start reading through the paired fastq input files |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
104 $name2 = <IN2>; # read all parts of a single read pair (4 lines in each of the 2 fastq files) |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
105 $forward = <IN1>; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
106 $reverse = <IN2>; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
107 $third1 = <IN1>; $third2 = <IN2>; $qual1 = <IN1>; $qual2 = <IN2>; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
108 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
109 my $which = 0; my $for; my $rev; # establish variables used below |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
110 if(substr($forward, $c, $e) eq "TGCAGG") { # check for SbfI cutsite in the correct place in forward read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
111 if(substr($reverse, $c, $e) eq "TGCAGG") { # check for SbfI cutsite in the correct place in reverse read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
112 $for = substr($forward, $n, $b); # this is where a barcode should be if it's in the forward read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
113 $rev = substr($reverse, $n, $b); # this is where a barcode should be if it's in the reverse read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
114 if(exists $counts{$for} && (exists $counts{$rev}) == 0) { # if a correct barcode and cutsite are in forward but not reverse read... |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
115 $which = 1; $barcode = $for; $counts{$for}++; # which = 1 means the pair is correctly oriented |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
116 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
117 elsif((exists $counts{$for}) == 0 && exists $counts{$rev}) { # if a correct barcode and cutsite are only in the reverse read... |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
118 $which = 2; $barcode = $rev; $counts{$rev}++; # which = 2 means the pair needs to be flipped |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
119 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
120 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
121 else { # the cutsite is only found in the forward read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
122 $barcode = substr($forward, $n, $b); |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
123 if(exists $counts{$barcode}) {$which = 1; $counts{$barcode}++; } # if a correct barcode is in the forward read, the pair is correctly oriented |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
124 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
125 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
126 elsif(substr($reverse, $c, $e) eq "TGCAGG") { # cutsite not in forward read but is in reverse read |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
127 $barcode = substr($reverse, $n, $b); |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
128 if(exists $counts{$barcode}) {$which = 2; $counts{$barcode}++; } # pair needs to be flipped |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
129 } # if a cutsite and correct barcode has not been found in either read, which = 0 at this point |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
130 if($which == 1) { # if the pair is correctly oriented, print out fastq format for the pair |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
131 my $temp1 = substr($forward, $n); # trim initial nucleotides off read and quality scores... |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
132 my $temp2 = substr($qual1, $n); # so that output keeps barcode and cutsite but not other nucleotides... |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
133 print OUT1 "$name1$temp1$third1$temp2"; # and is ready to go into process_radtags |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
134 print OUT2 "$name2$reverse$third2$qual2"; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
135 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
136 elsif($which == 2) { # if the pair needs to be flipped, print out fastq format for the flipped pair |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
137 my $temp1 = substr($reverse, $n); |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
138 my $temp2 = substr($qual2, $n); |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
139 print OUT1 "$name2$temp1$third2$temp2"; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
140 print OUT2 "$name1$forward$third1$qual1"; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
141 } # if which == 0, nothing is printed out for the pair |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
142 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
143 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
144 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
145 close IN1; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
146 close IN2; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
147 close OUT1; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
148 close OUT2; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
149 |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
150 foreach my $key (sort keys %counts) { |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
151 print "$key" . "\t" . "$counts{$key}\n"; |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
152 } |
5dc02b8a2a57
planemo upload commit 70654da77972b29181d3b388035836b6fa84d59d-dirty
tiagoantao
parents:
diff
changeset
|
153 } |