upstream-extended/devteam/tools/divide_pg_snp/dividePgSnpAlleles.pl
1#!/usr/bin/perl -w
2use strict;
3
4#divide the alleles and their information into separate columns for pgSnp-like
5#files. Keep any additional columns beyond the pgSnp ones.
6#reads from stdin, writes to stdout
7my $ref;
8my $in;
9if (@ARGV && $ARGV[0] =~ /-ref=(\d+)/) {
10 $ref = $1 -1;
11 if ($ref == -1) { undef $ref; }
12 shift @ARGV;
13}
14if (@ARGV) {
15 $in = shift @ARGV;
16}
17
18open(FH, $in) or die "Couldn't open $in, $!\n";
19while (<FH>) {
20 chomp;
21 my @f = split(/\t/);
22 my @a = split(/\//, $f[3]);
23 my @fr = split(/,/, $f[5]);
24 my @sc = split(/,/, $f[6]);
25 if ($f[4] == 1) { #homozygous add N, 0, 0
26 if ($ref) { push(@a, $f[$ref]); }
27 else { push(@a, "N"); }
28 push(@fr, 0);
29 push(@sc, 0);
30 }
31 if ($f[4] > 2) { next; } #skip those with more than 2 alleles
32 print "$f[0]\t$f[1]\t$f[2]\t$a[0]\t$fr[0]\t$sc[0]\t$a[1]\t$fr[1]\t$sc[1]";
33 if (scalar @f > 7) {
34 splice(@f, 0, 7); #remove first 7
35 print "\t", join("\t", @f), "\n";
36 }else { print "\n"; }
37}
38close FH;
39
40exit;
41