-
Notifications
You must be signed in to change notification settings - Fork 19
/
tech_guess
executable file
·172 lines (155 loc) · 4.5 KB
/
tech_guess
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
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
use List::Util qw(first max min sum);
my $verbose = 0;
my $help = 0;
my $complete = 0;
my $output = '';
my $header = '';
my $seq_num = 0;
my $avg_len = 0;
my $std_len = 0;
my $max_len = 0;
my $options = GetOptions ("verbose!" => \$verbose,
"output:s" => \$output,
"fasta=s" => \$header,
"seq_num=i" => \$seq_num,
"avg_len=f" => \$avg_len,
"dev_len=f" => \$std_len,
"max_len=i" => \$max_len,
"complete!" => \$complete,
"help!" => \$help
);
my $usage = "Usage: tech_guess.pl -f <fasta header> -s <seq number> -a <avg length> -d <stdev length> -m <max length> [-o <outfile> -c <boolean: full output>]\n";
if ($help) {
print STDOUT $usage;
exit(0);
}
unless ($header && $seq_num && $avg_len && $max_len) {
print STDERR "[error] ".$usage;
exit(1);
}
# (tech_guess, num_reads_guess, avg_length_guess, avg_length_stdev_guess, max_length_guess)
my $guess = { 'illumina' => [0,0,0,0,0],
'454' => [0,0,0,0,0],
'sanger' => [0,0,0,0,0],
'assembled' => [0,0,0,0,0],
'other' => [0,0,0,0,0]
};
########## consider the header (2x weighted)
my $tech_guess = technologyguess($header);
unless ($tech_guess eq 'other') {
$guess->{$tech_guess}[0] = 2;
}
########## consider the number of sequences
if ($seq_num >= 1000000) {
$guess->{illumina}[1] = 1;
}
########## consider the avg_length
if (($avg_len > 20) && ($avg_len < 200)) {
$guess->{illumina}[2] = 1;
}
if (($avg_len > 100) && ($avg_len < 500)) {
$guess->{454}[2] = 1;
}
if (($avg_len > 500) && ($avg_len < 1200)) {
$guess->{sanger}[2] = 1;
}
if ($avg_len > 1200) {
$guess->{assembled}[2] = 1;
}
########## consider the avg_length_stdev
if ($std_len == 0) {
$guess->{illumina}[3] = 1;
}
########### consider max_length
if (($max_len > 20) && ($max_len < 200)) {
$guess->{illumina}[4] = 1;
}
if (($max_len > 100) && ($max_len < 600)) {
$guess->{454}[4] = 1;
}
if (($max_len > 500) && ($max_len < 1200)) {
$guess->{sanger}[4] = 1;
}
if ($max_len > 1200) {
$guess->{assembled}[4] = 1;
}
my %total = map { $_, sum @{$guess->{$_}} } keys %$guess;
my $max = max values %total;
my @best_guess = grep { $total{$_} == $max } keys %total;
my $result = ((@best_guess == 1) ? $best_guess[0] : 'other') . "\n";
if ($complete) {
map { $result .= "$_\t".join("\t", @{$guess->{$_}})."\n" } sort keys %$guess;
}
if ($output) {
open(OUT, ">$output") || die "Unable to open file: $output\n";
print OUT $result;
close OUT;
}
else {
print STDOUT $result;
}
sub technologyguess {
my ($head) = @_;
my $tech = "other";
$head =~ s/>SRR\d{6}\.?\d* //;
if ($head =~ />SCUMS_READ_/)
{$tech = "454";}
elsif ($head =~ /JCVI_READ_\d{6,13}/)
{$tech = "sanger";}
elsif ($head =~ /JCVI_READ_\d{3,5}/)
{$tech = "sanger";}
elsif ($head =~ />NCBI_READ_\d{10,13}/)
{$tech = "sanger";}
elsif ($head =~ />([A-Z][\dA-Z]{6}\d\d[A-Z][\dA-Z]{4})[_\W$ ]/)
{$tech = "454";}
elsif ($head =~ />([A-Z][\dA-Z]{6}\d\d[A-Z][\dA-Z]{4})\W?length=/)
{$tech = "454";}
elsif ($head =~ /uaccno=([A-Z][\dA-Z]{6}\d\d[A-Z][\dA-Z]{4})/)
{$tech = "454";}
elsif ($head =~ />(.*)_([A-Z][\dA-Z]{6}\d\d[A-Z][\dA-Z]{4})[_\W$ ]/)
{$tech = "454";}
elsif ($head =~ /[=>_| -]([A-Z][\dA-Z]{6}\d\d[A-Z][\dA-Z]{4})[_\W$ ]/)
{$tech = "454";}
elsif ($head =~ /\|([A-Z][\dA-Z]{6}\d\d[A-Z][\dA-Z]{4})$/)
{$tech = "454";}
elsif ($head =~ />[A-Z]{7}.CL1Contig/)
{$tech = "sanger";}
elsif ($head =~ /CL1Contig/)
{$tech = "sanger";}
elsif ($head =~ />NCBI_...._READ_\d{6,14}/)
{$tech = "sanger";}
elsif ($head =~ />SOLEXA/)
{$tech = "illumina";}
elsif ($head =~ />\w\w[\w\d-]*:\d{1,2}:\d{1,3}:\d{1,6}:\d{1,6}\#?/)
{$tech = "illumina";}
elsif ($head =~ /\w\w[\w\d_-]*:\d{1,2}:\d{1,3}:\d{1,6}:\d{1,6}\#./)
{$tech = "illumina";}
elsif ($head =~ /\w[\w\d_-]*:\d{1,6}:\w[\w\d_-]*:\d{1,2}:\d{1,6}:\d{1,6}:\d{1,6}/)
{$tech = "illumina";}
elsif ($head =~ />NODE_\d*_length_/)
{$tech = "assembled";}
elsif ($head =~ /NODE_\d*_length_/)
{$tech = "assembled";}
elsif ($head =~ /_Contig/)
{$tech = "assembled";}
elsif ($head =~ /contig\d{3,5}/)
{$tech = "assembled";}
elsif ($head =~ />Contig/)
{$tech = "assembled";}
elsif ($head =~ />contig/)
{$tech = "assembled";}
elsif ($head =~ />scaffold/)
{$tech = "assembled";}
elsif ($head =~ />([A-Z][\dA-Z]{6}\d\d[A-Z][\dA-Z]{4})/)
{$tech = "454";}
elsif ($head =~ />([\d]{1,6} length \d{2,6} cvg_\d)/)
{$tech = "assembled";}
elsif ($head =~ />\d{6}_\d{4}_\d{4} length=/)
{$tech = "454";}
return $tech;
}