comparison dividePgSnpAlleles.pl @ 2:35c20b109be5

Retrying upload with "bare" tarball (i.e. one without a top containing directory).
author cathy
date Tue, 28 May 2013 17:54:02 -0400
parents
children
comparison
equal deleted inserted replaced
1:1d8b23a21735 2:35c20b109be5
1 #!/usr/bin/perl -w
2 use 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
7 my $ref;
8 my $in;
9 if (@ARGV && $ARGV[0] =~ /-ref=(\d+)/) {
10 $ref = $1 -1;
11 if ($ref == -1) { undef $ref; }
12 shift @ARGV;
13 }
14 if (@ARGV) {
15 $in = shift @ARGV;
16 }
17
18 open(FH, $in) or die "Couldn't open $in, $!\n";
19 while (<FH>) {
20 chomp;
21 my @f = split(/\t/);
22 if ($f[0] =~ /^\d+$/ && $f[1] =~ /chr/) { #has bin column shift list
23 shift @f; #remove bin
24 }
25 my @a = split(/\//, $f[3]);
26 my @fr = split(/,/, $f[5]);
27 my @sc = split(/,/, $f[6]);
28 if ($f[4] == 1) { #homozygous add N, 0, 0
29 if ($ref) { push(@a, $f[$ref]); }
30 else { push(@a, "N"); }
31 push(@fr, 0);
32 push(@sc, 0);
33 }
34 if ($f[4] > 2) { next; } #skip those with more than 2 alleles
35 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]";
36 if (scalar @f > 7) {
37 splice(@f, 0, 7); #remove first 7
38 print "\t", join("\t", @f), "\n";
39 }else { print "\n"; }
40 }
41 close FH;
42
43 exit;
44