-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcombine_diff.pl
More file actions
executable file
·86 lines (83 loc) · 1.94 KB
/
combine_diff.pl
File metadata and controls
executable file
·86 lines (83 loc) · 1.94 KB
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
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
sub usage {
print <<"END_USAGE";
Usage: perl $0
Needed:
--input input file,sep with ","
--output output file
--suffix example:txt or vcf or ...
Optional:
--col default ALL!!! Start col=0,sep with "/," exp 1/2/3,3/4,6/7,1
--head if file has header exp 0,1,0,1
--fill default 0
END_USAGE
exit;
}
my ($input,$output,$suffix,$head,$fill,$col);
GetOptions (
'input=s'=>\$input,
'output=s'=>\$output,
'suffix=s'=>\$suffix,
'col=s'=>\$col,
'fill=s'=>\$fill,
'head=s'=>\$head,
) or usage();
usage() if (!$input or !$output or !$suffix);
my @file=split(/,/,$input);
if (defined $col){
my @col=split(/,/,$col);
die "sample counts!= col counts\n" if ($#col!=$#file);
}
if (defined $head){
my @headcount=split(/,/,$head);
die "sample counts!= head counts\n "if ($#headcount!=$#file);
}
$fill=0 if (!$fill);
my %hash;
my @sample;
for my $num(0..$#file){
open my $file_in,"$file[$num]";
$file[$num]=~s/\.$suffix$// if ($suffix);
if (defined $head){
my @headcount=split(/,/,$head);
<$file_in> if ($headcount[$num]==1);
}
while (<$file_in>){
chomp;
my @F=split;
my $value;
if (defined $col){
my @col=split(/,/,$col);
my @col_sample=split(/\//,$col[$num]);
if ($#col_sample==0){
$value=$F[$col_sample[0]];
}
elsif($#col_sample>=0){
$value=$F[$col_sample[0]];
$value=join "\t",$value,$F[$col_sample[$_]] for (1..$#col_sample);
}
}
else{
$value=join "\t",@F[1..$#F];
}
$hash{$F[0]}{$file[$num]}=$value;
}
close $file_in;
push @sample,$file[$num];
}
open my $output_file,">$output";
print $output_file "Event";
print $output_file "\t$_" for @sample;
print $output_file "\n";
for my $keys (keys %hash){
print $output_file "$keys";
for my $sample (@sample){
print $output_file "\t$hash{$keys}{$sample}" if (exists $hash{$keys}{$sample});
print $output_file "\t$fill" if (!exists $hash{$keys}{$sample});
}
print $output_file "\n";
}
close $output_file;