-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsfr.mgrast.to.ShotgunFunctionalizeR.pl
370 lines (326 loc) · 10.9 KB
/
sfr.mgrast.to.ShotgunFunctionalizeR.pl
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#!/usr/bin/env perl
###############################################################################
#
# scriptname
#
# Short description
#
# Copyright (C) 2012 Mads Albertsen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
#pragmas
use strict;
use warnings;
#core Perl modules
use Getopt::Long;
#locally-written modules
BEGIN {
select(STDERR);
$| = 1;
select(STDOUT);
$| = 1;
}
# get input params
my $global_options = checkParams();
my $dir;
$dir = &overrideDefault(".",'dir');
my $filename;
my %categories;
my $header;
my %catheader;
######################################################################
# CODE HERE
######################################################################
open(OUTcog, ">all.cog.txt") or die("Cannot create file: all.cog.txt\n");
opendir(DIR, $dir) or die "Cannot open dir: $dir!";
$header = "GeneFamily";
while ( $filename = readdir(DIR)){ #Read all cog files and concatetate them
if ($filename =~/.cog.tab/){
$header = $header."\t".$filename;
open(IN, $filename) or die("Cannot read file: $filename\n");
while (my $line = <IN>) {
chomp $line;
my @splitline = split(/\t/,$line);
$categories{$splitline[0]} = $splitline[0];
$catheader{$splitline[0]} = $splitline[2];
}
close IN;
}
}
closedir DIR;
opendir(DIR, $dir) or die "Cannot open dir: $dir!";
while ( $filename = readdir(DIR)){
if ($filename =~/.cog.tab/){
my %cog = ();
open(IN, $filename) or die("Cannot read file: $filename\n");
while (my $line = <IN>) {
chomp $line;
my @splitline = split(/\t/,$line);
$cog{$splitline[0]} = $splitline[1];
$catheader{$splitline[0]} = $splitline[2];
}
close IN;
foreach my $key (keys %categories){
if (exists($cog{$key})){
$categories{$key} = "$categories{$key}\t$cog{$key}";
}
else{
$categories{$key} = "$categories{$key}\t0";
}
}
}
}
print OUTcog "$header\n";
foreach my $key (keys %categories){
print OUTcog "$categories{$key}\t$catheader{$key}\n";
}
close OUTcog;
closedir DIR;
open(OUTec, ">all.ec.txt") or die("Cannot create file: all.ec.txt\n");
$header = "GeneFamily";
%categories = ();
opendir(DIR, $dir) or die "Cannot open dir: $dir!";
while ( $filename = readdir(DIR)){ #Read all ec files and concatetate them
if ($filename =~/.ec.tab/){
$header = $header."\t".$filename;
open(IN, $filename) or die("Cannot read file: $filename\n");
while (my $line = <IN>) {
chomp $line;
my @splitline = split(/\t/,$line);
$categories{$splitline[0]} = $splitline[0];
$catheader{$splitline[0]} = $splitline[2];
}
close IN;
}
}
closedir DIR;
opendir(DIR, $dir) or die "Cannot open dir: $dir!";
while ( $filename = readdir(DIR)){
if ($filename =~/.ec.tab/){
my %ec = ();
open(IN, $filename) or die("Cannot read file: $filename\n");
while (my $line = <IN>) {
chomp $line;
my @splitline = split(/\t/,$line);
$ec{$splitline[0]} = $splitline[1];
}
close IN;
foreach my $key (keys %categories){
if (exists($ec{$key})){
$categories{$key} = "$categories{$key}\t$ec{$key}";
}
else{
$categories{$key} = "$categories{$key}\t0";
}
}
}
}
print OUTec "$header\n";
foreach my $key (keys %categories){
print OUTec "$categories{$key}\t$catheader{$key}\n";
}
close OUTec;
closedir DIR;
open(OUTgo, ">all.go.txt") or die("Cannot create file: all.go.txt\n");
$header = "GeneFamily";
%categories = ();
opendir(DIR, $dir) or die "Cannot open dir: $dir!";
while ( $filename = readdir(DIR)){ #Read all GO files and concatetate them
if ($filename =~/.go.tab/){
$header = $header."\t".$filename;
open(IN, $filename) or die("Cannot read file: $filename\n");
while (my $line = <IN>) {
chomp $line;
my @splitline = split(/\t/,$line);
$categories{$splitline[0]} = $splitline[0];
$catheader{$splitline[0]} = $splitline[2];
}
close IN;
}
}
closedir DIR;
opendir(DIR, $dir) or die "Cannot open dir: $dir!";
while ( $filename = readdir(DIR)){
if ($filename =~/.go.tab/){
my %go = ();
open(IN, $filename) or die("Cannot read file: $filename\n");
while (my $line = <IN>) {
chomp $line;
my @splitline = split(/\t/,$line);
$go{$splitline[0]} = $splitline[1];
}
close IN;
foreach my $key (keys %categories){
if (exists($go{$key})){
$categories{$key} = "$categories{$key}\t$go{$key}";
}
else{
$categories{$key} = "$categories{$key}\t0";
}
}
}
}
print OUTgo "$header\n";
foreach my $key (keys %categories){
print OUTgo "$categories{$key}\t$catheader{$key}\n";
}
close OUTgo;
closedir DIR;
open(OUTko, ">all.ko.txt") or die("Cannot create file: all.ko.txt\n");
$header = "GeneFamily";
%categories = ();
opendir(DIR, $dir) or die "Cannot open dir: $dir!";
while ( $filename = readdir(DIR)){ #Read all KO files and concatetate them
if ($filename =~/.ko.tab/){
$header = $header."\t".$filename;
open(IN, $filename) or die("Cannot read file: $filename\n");
while (my $line = <IN>) {
chomp $line;
my @splitline = split(/\t/,$line);
$categories{$splitline[0]} = $splitline[0];
$catheader{$splitline[0]} = $splitline[2];
}
close IN;
}
}
closedir DIR;
opendir(DIR, $dir) or die "Cannot open dir: $dir!";
while ( $filename = readdir(DIR)){
if ($filename =~/.ko.tab/){
my %ko = ();
open(IN, $filename) or die("Cannot read file: $filename\n");
while (my $line = <IN>) {
chomp $line;
my @splitline = split(/\t/,$line);
$ko{$splitline[0]} = $splitline[1];
}
close IN;
foreach my $key (keys %categories){
if (exists($ko{$key})){
$categories{$key} = "$categories{$key}\t$ko{$key}";
}
else{
$categories{$key} = "$categories{$key}\t0";
}
}
}
}
print OUTko "$header\n";
foreach my $key (keys %categories){
print OUTko "$categories{$key}\t$catheader{$key}\n";
}
close OUTko;
closedir DIR;
open(OUTss, ">all.subsystems.txt") or die("Cannot create file: all.subsystems.txt\n");
$header = "GeneFamily";
%categories = ();
opendir(DIR, $dir) or die "Cannot open dir: $dir!";
while ( $filename = readdir(DIR)){ #Read all KO files and concatetate them
if ($filename =~/.subsystems.tab/){
$header = $header."\t".$filename;
open(IN, $filename) or die("Cannot read file: $filename\n");
while (my $line = <IN>) {
chomp $line;
my @splitline = split(/\t/,$line);
$categories{$splitline[0]} = $splitline[0];
$catheader{$splitline[0]} = $splitline[2];
}
close IN;
}
}
closedir DIR;
opendir(DIR, $dir) or die "Cannot open dir: $dir!";
while ( $filename = readdir(DIR)){
if ($filename =~/.subsystems.tab/){
my %ss = ();
open(IN, $filename) or die("Cannot read file: $filename\n");
while (my $line = <IN>) {
chomp $line;
my @splitline = split(/\t/,$line);
$ss{$splitline[0]} = $splitline[1];
}
close IN;
foreach my $key (keys %categories){
if (exists($ss{$key})){
$categories{$key} = "$categories{$key}\t$ss{$key}";
}
else{
$categories{$key} = "$categories{$key}\t0";
}
}
}
}
print OUTss "$header\n";
foreach my $key (keys %categories){
print OUTss "$categories{$key}\t$catheader{$key}\n";
}
close OUTss;
closedir DIR;
######################################################################
# TEMPLATE SUBS
######################################################################
sub checkParams {
#-----
# Do any and all options checking here...
#
my @standard_options = ( "help|h+", "dir|d:s");
my %options;
# Add any other command line options, and the code to handle them
#
GetOptions( \%options, @standard_options );
#if no arguments supplied print the usage and exit
#
#exec("pod2usage $0") if (0 == (keys (%options) ));
# If the -help option is set, print the usage and exit
#
exec("pod2usage $0") if $options{'help'};
# Compulsosy items
#if(!exists $options{'infile'} ) { print "**ERROR: $0 : \n"; exec("pod2usage $0"); }
return \%options;
}
sub overrideDefault
{
#-----
# Set and override default values for parameters
#
my ($default_value, $option_name) = @_;
if(exists $global_options->{$option_name})
{
return $global_options->{$option_name};
}
return $default_value;
}
__DATA__
=head1 NAME
vprobes.generateprobes.pl
=head1 COPYRIGHT
copyright (C) 2012 Mads Albertsen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 DESCRIPTION
=head1 SYNOPSIS
script.pl -i [-h]
[-help -h] Displays this basic usage information
[-dir -d] Location of files (default: .)
=cut