-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat5.pl
175 lines (122 loc) · 3.01 KB
/
format5.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
use warnings;
use Data::Dumper qw(Dumper);
#use Spreadsheet::WriteExcel;
open(FL,"$ARGV[0]") or die "$!";
$count=1;
while($l=<FL>) {
chomp($l);
@tmp=split(/\t/,$l);
$filetab=$tmp[0];
$coord=$tmp[1];
$index=$tmp[2];
$ref=$tmp[3];
$type=$tmp[4];
$mut=$tmp[5];
$snp = join ">",$ref,$mut;
# $subst=$tmp[11];
@st=split(/\(/,$tmp[11]);
$subst=$st[0];
#need white space after freq
$freq=join("",$tmp[9]," ");
$gene_name=$tmp[13];
$gene=$tmp[12];
# IR is the antibiotic
$IR=$tmp[17];
$c=1;
if ($gene_name ne "GeneName") {
@temp=split('_',$filetab);
$ID=$temp[0];
# GeneName exists
if ($gene_name ne " ") {
# Subst exists -> use Subst
if ($subst ne " ") {
if ($freq < 75) {
#remove white space from subst
chop($subst);
$subst = join(":",$subst,$freq);
}
push( @{ $rows{$ID}{$gene_name} }, $subst);
$found{$gene_name}++;
$a=++$c{$ID};
push (@IR,$IR);
$IR{$IR}+=1;
++$count;
# Subst does NOT exist -> use coordinate
}elsif($subst eq " ") {
# $gene_name="UNK";
# print "$index $mut\n";
if ($index > 0) {
push @string, $mut;
}else{
$ncoord=join("-",$coord, $mut);
}
# print "@string\n";
$size= scalar @string;
# print "$size\n";
# size > 0 means that there is a peptide insertion
if ($size > 0) {
$ncoord=join("", @string);
}else{
$ncoord=join("-",$coord, $mut);
}
if ($freq<75) {
$ncoord=join("",$ncoord,$freq);
}
# @string=();
# $ncoord=join("-",$coord, $mut);
push( @{ $rows{$ID}{$gene_name} }, $ncoord);
$found{$gene_name}++;
$c++;
@string=();
}
# GeneName does NOT exist
}elsif($gene_name eq " ") {
# Gene exists -> use Gene
if ($gene ne " ") {
$gene_name=$gene;
# Subst exists
if ($subst ne " ") {
if ($freq < 75) {
#remove white space from subst
chop($subst);
$subst = join(":",$subst,$freq);
}
push( @{ $rows{$ID}{$gene_name} }, $subst);
$found{$gene_name}++;
# Subst does NOT exist
}elsif($subst eq " ") {
$ncoord=join("-",$coord, $mut);
if ($freq<75) {
$ncoord=join("",$ncoord,$freq);
}
push( @{ $rows{$ID}{$gene_name} }, $ncoord);
$found{$gene_name}++;
}
# Gene does NOT exist -> use coordinate
}elsif($gene eq " ") {
$gene_name = "UNK";
$ncoord=join("-",$coord, $mut);
if ($freq<75) {
$ncoord=join("",$ncoord,$freq);
}
push( @{ $rows{$ID}{$gene_name} }, $ncoord);
$found{$gene_name}++;
}
}
}
}
@setNames = sort keys %found;
print join ("\t", 'Name', @setNames), "\n";
foreach $rowName (sort keys %rows) {
foreach $l (@setNames) {
if (defined $rows{$rowName}{$l}) {
# $val=join("+", @{$rows{$rowName}{$l}});
$val=join("", @{$rows{$rowName}{$l}});
push @data, $val;
}else {
push @data, "";
}
}
print join("\t", $rowName, @data), "\n";
@data=();
}