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
|
#!/usr/bin/env perl
use strict;
use warnings;
my $usage = "venn_pairwise_out.dat\n\n";
my $venn_txt = $ARGV[0] or die $usage;
main: {
my %combos;
my %sample_pair_to_combo_count;
open (my $fh, $venn_txt) or die $!;
while (<$fh>) {
chomp;
my ($feature, $sampleA, $sampleB, $combo) = split(/\t/);
my @combo_renamed;
foreach my $c (split(/,/, $combo)) {
$c =~ /^([^\.]+)/ or die "Error, cannot parse combo $c";
push (@combo_renamed, $1);
}
$combo = join(",", @combo_renamed);
my $sample_pair = join(",", $sampleA, $sampleB);
$sample_pair_to_combo_count{$sample_pair}->{$combo}++;
$combos{$combo}++;
}
close $fh;
my @combos = sort keys %combos;
print join("\t", "#sample", @combos) . "\n";
foreach my $sample_pair (sort keys %sample_pair_to_combo_count) {
print $sample_pair;
foreach my $combo (@combos) {
my $val = $sample_pair_to_combo_count{$sample_pair}->{$combo} || 0;
print "\t$val";
}
print "\n";
}
exit(0);
}
|