-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmake_rgi_clusters.pl
executable file
·145 lines (93 loc) · 3.37 KB
/
make_rgi_clusters.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
#!/usr/bin/env perl
#Copyright (C) 2016-2021 The J. Craig Venter Institute (JCVI). All rights reserved
#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/>
=pod
=head1 NAME
make_rgi_clusters.pl
=head1 SYNOPSIS
make_rgi_clusters.pl [options] -d directory -t type -o outputFlatFile
Options:
-i --input Location of dataSummary.txt file that is read. Required.
-o --output Output file. Default is aro_centroid.list.txt.
-t --type Output type of the file. "Best" (all) or "all".
=head1 DESCRIPTION
make_rgi_clusters.pl generates the PanACEA readable term map file from a RGI generated
dataSummary.txt. Can make either a map film showing only the best hit (the default) or
all hits.
=head1 AUTHOR
Thomas Clarke ([email protected])
2017 J. Craig Venter Institute
=cut
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
# Usage perl make_rgi_clusters.pl dataSummary.txt output_centroid_list.txt
# output is
# centroid_id AMR ARO1,ARO2,etc
my $rgi_file;
my $output_file = "aro_centroid.list.txt";
my $type = "best";
my $help;
GetOptions(
"input|i:s" => \$rgi_file,
"type|t:s" => \$type,
"output|o:s" => \$output_file,
"help|h|?" => \$help,
) || die "Error getting options!\n";
pod2usage( { -verbose => 2, -exitval => 0 } ) if ( $help );
#Probably should set up a verbose tag to level the printing
if ( !$rgi_file ) {
warn "Please enter in a directory from which to create the ARO map file\n";
pod2usage( { -verbose => 2, -exitval => 0 } );
}
if ( !-e $rgi_file ) {
warn "$rgi_file does not exist. Please check...\n";
pod2usage( { -verbose => 2, -exitval => 0 } )
}
$type = lc($type);
if ( $type ne "best" && $type ne "all" ) {
warn "Cannot recognize output type. Reverting to default (best)...\n\n";
$type = "best";
}
my $list;
open( my $ifh, "<", $rgi_file ) or die("Cannot open rgi_file: $!\n");
open( my $ofh, ">", $output_file ) or die("Cannot open output file: $!\n");
while ( <$ifh> ) {
next if /ORF_ID/;
chomp;
my @arr = split "\t", $_;
if ( $arr[0] =~ /centroid_(\d+)/ ) {
my $id = "centroid_$1";
my $best = $arr[8];
my @names = split ", ", $arr[11];
my @aro = split ", ", $arr[10];
if ( $type eq "best" && $best ) {
for ( my $i = 0 ; $i < scalar(@aro) ; $i++ ) {
if ( $names[$i] && $names[$i] eq $best ) {
$aro[$i] =~ s/(\s)//g;
$list->{$id}->{ $aro[$i] }++;
}
}
} else {
while ( $arr[10] =~ /([^,]+)/g ) {
my $aro = $1;
$aro =~ s/(\s)//g;
$list->{$id}->{$aro}++;
}
}
}
}
foreach my $id ( keys(%$list) ) {
my $out = join( ',', keys( %{ $list->{ $id } } ) );
print $ofh "$id\t$out\n";
}