forked from Axolotl233/Simple_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Phase.merge.go.background.pl
81 lines (76 loc) · 1.5 KB
/
Phase.merge.go.background.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
#! perl
use warnings;
use strict;
use Getopt::Long;
(my @type1,my@type2,my $out);
GetOptions(
'type1=s' => \@type1,
'type2=s' => \@type2,
'out' => \$out
);
$out //= "merge.go.out";
my $c = 0;
for my $s (\@type1,\@type2){
$c += scalar @{$s}
}
if($c == 0){
print STDERR "perl $0 --type1 xxxx --type1 xxx --type2 xxx --type2 xxx\n";
exit;
}
my %h;
%h = (%h , &type1(\@type1));
%h = (%h, &type2(\@type2));
%h = (%h, filter(\%h));
open O,'>',$out;
for my $k(sort{$a cmp $b} keys %h){
print O "$k\t";
print O join "\t",@{$h{$k}};
print O "\n";
}
close O;
sub type1{
my $ref_a = shift @_;
my %t;
my @f = @{$ref_a};
for my $e (@f){
open IN ,'<',$e;
while(<IN>){
next if /^#/;
next if /^$/;
chomp;
my @l = split/\s+/;
push @{$t{$l[0]}} ,$l[1];
}
close IN;
}
return %t;
}
sub type2{
my $ref_a = shift @_;
my %t;
my @f = @{$ref_a};
for my $e (@f){
open IN ,'<',$e or die "$!";
while(<IN>){
next if /^#/;
next if /^$/;
chomp;
my @l = split/\s+/;
my $n = shift @l;
push @{$t{$n}} ,@l;
}
close IN;
}
return %t;
}
sub filter{
my $ref_h = shift @_;
my %b = %{$ref_h};
for my $k(keys %b){
my @a = @{$b{$k}};
my %t;
$t{$_} = 1 for @a;
@{$b{$k}} = (sort{$a cmp $b} keys %t);
}
return %b;
}