-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdedupTranscriptome.pl
More file actions
executable file
·177 lines (161 loc) · 3.34 KB
/
dedupTranscriptome.pl
File metadata and controls
executable file
·177 lines (161 loc) · 3.34 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/perl
my $usage="
Removes duplicated reads prior to transcriptome assembly.
Input must be fastq files, trimmed, quality-filtered and
sorted into left, right and unpaired reads.
Identifies duplicates based on identity of bases 5-30
on both left and right ends (if paired reads are supplied)
or in unpaired reads.
If all three types are given, unpaired are processed last
and are gettivn discarded if they find a match either
among left or right reads
Usage:
dedupTranscriptome.pl left=[filename] right=[filename] unp=[filename]
output: same file names with .dedup extention
Mikhail Matz, August-November 2014
matz\@utexas.edu
";
my $left="";
my $right="";
my $unp="";
my $rlcount=0;
if ("@ARGV"=~/left=(\S+)/) {
$left=$1;
$rlcount++;
open LL,$left or die "cannot open $left\n";
my $outleft=$left.".dedup";
open LLO,">$outleft";
}
if ("@ARGV"=~/right=(\S+)/) {
$right=$1;
$rlcount++;
open RR,$right or die "cannot open $right\n";
my $outright=$right.".dedup";
open RRO,">$outright";
}
if ("@ARGV"=~/unp=(\S+)/) {
$unp=$1;
open UU,$unp or die "cannot open $unp\n";
my $outunp=$unp.".dedup";
open UUO,">$outunp";
}
if ($rlcount >0 ){
if ($rlcount<2){ die "$usage
--------------------------
specify either both left and right reads
plus unpaired, or unpaired only\n";}
}
elsif (!$unp) {die "$usage
--------------------------
specify either both left and right reads
plus unpaired, or unpaired only\n";}
my %seenleft={};
my %seenright={};
my %seenunp={};
my $name="";
my $seql="";
my $seqr="";
my $ql="";
my $qr="";
my $ii=1;
my $lrcount=0;
my $lrall==0;
if ($left && $right) {
while (<LL>) {
chop;
my $llin=$_;
$rlin=<RR>;
chop($rlin);
if ($ii==1 ) {
$lrall++;
if (!$qr || !$ql) {
$name=$llin;
$ii=2;
next;
}
if (!$seenleft{substr($seql,4,25)} or !$seenright{substr($seqr,4,25)}) {
$seenleft{substr($seql,4,25)}=1;
$seenright{substr($seqr,4,25)}=1;
$lrcount++;
print {LLO} "$name\n$seql\n+\n$ql\n";
print {RRO} "$name\n$seqr\n+\n$qr\n";
}
$name=$llin;
$seql="";
$seqr="";
$ql="";
$qr="";
$ii=2;
}
elsif ($ii==2) {
$seql=$llin;
$seqr=$rlin;
$ii=3;
}
elsif ($ii==3){
$ii=4;
}
else {
$qr=$rlin;
$ql=$llin;
$ii=1;
}
}
if (!$seenleft{substr($seql,4,25)} or !$seenright{substr($seqr,4,25)}) {
$seenleft{substr($seql,4,25)}=1;
$seenright{substr($seqr,4,25)}=1;
$lrcount++;
print {LLO} "$name\n$seql\n+\n$ql\n";
print {RRO} "$name\n$seqr\n+\n$qr\n";
}
}
print "PAIRED: kept $lrcount out of $lrall\n";
close LL;
close RR;
close LLO;
close RRO;
my $sequ="";
my $qu="";
my $ii=1;
my $ucount=0;
my $uall==0;
if ($unp) {
while (<UU>) {
chop;
my $ulin=$_;
if ($ii==1 ) {
$uall++;
if (!$qu) {
$name=$ulin;
$ii=2;
next;
}
if (!$seenleft{substr($sequ,4,25)} && !$seenright{substr($sequ,4,25)} && !$seenu{substr($sequ,4,25)}) {
$seenu{substr($sequ,4,25)}=1;
$ucount++;
print {UUO} "$name\n$sequ\n+\n$qu\n";
}
$name=$ulin;
$sequ="";
$qu="";
$ii=2;
}
elsif ($ii==2) {
$sequ=$ulin;
$ii=3;
}
elsif ($ii==3){
$ii=4;
}
else {
$qu=$ulin;
$ii=1;
}
}
if (!$seenleft{substr($sequ,4,25)} && !$seenright{substr($sequ,4,25)} && !$seenu{substr($sequ,4,25)}) {
$seenu{substr($sequ,4,25)}=1;
$ucount++;
print {UUO} "$name\n$sequ\n+\n$qu\n";
}
}
print "UNPAIRED: kept $ucount out of $uall\n";