-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfix_multiple_lines_in_tables.pl
48 lines (41 loc) · 1.12 KB
/
fix_multiple_lines_in_tables.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
#!/usr/bin/perl
use strict;
use warnings;
# This script fixes multiple instances of a genomic position in
# the variant table. I want one line per position with all of the
# transcript IDs and effects included.
my $file = shift;
open (my $fh, '<', $file) or die "Can't open $file:$!\n";
my %positions;
while (<$fh>) {
chomp $_;
if ($_ =~ "^Position") {
next;
}
my @cols = split('\t', $_);
my $pos = $cols[0];
# You have to actually split these and add them to the hash
# If not, you will lose data
my @all_ids = split(';', $cols[1]);
foreach (@all_ids) {
if ($_ ne '.') {
push (@{$positions{$pos}{'ids'}}, $_);
}
}
my @all_effects = split(';', $cols[2]);
foreach (@all_effects) {
if ($_ ne '.') {
push (@{$positions{$pos}{'effects'}}, $_);
}
}
}
foreach my $key (sort keys %positions) {
my %ids = map {$_ => 1} @{$positions{$key}{'ids'}};
my @ids = keys %ids;
my %effects = map {$_ => 1} @{$positions{$key}{'effects'}};
my @effects = keys %effects;
my $ids = join(';', @ids);
my $effects = join(';', @effects);
print "$key\t$ids\t$effects\n";
}
close $fh;