annotate snp_analysis_conversion/dividePgSnpAlleles.pl @ 0:3871157bc013

Initial upload to toolshed.g2 via UI.
author cathy
date Tue, 28 May 2013 17:01:14 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
1 #!/usr/bin/perl -w
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
2 use strict;
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
3
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
4 #divide the alleles and their information into separate columns for pgSnp-like
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
5 #files. Keep any additional columns beyond the pgSnp ones.
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
6 #reads from stdin, writes to stdout
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
7 my $ref;
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
8 my $in;
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
9 if (@ARGV && $ARGV[0] =~ /-ref=(\d+)/) {
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
10 $ref = $1 -1;
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
11 if ($ref == -1) { undef $ref; }
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
12 shift @ARGV;
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
13 }
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
14 if (@ARGV) {
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
15 $in = shift @ARGV;
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
16 }
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
17
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
18 open(FH, $in) or die "Couldn't open $in, $!\n";
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
19 while (<FH>) {
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
20 chomp;
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
21 my @f = split(/\t/);
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
22 if ($f[0] =~ /^\d+$/ && $f[1] =~ /chr/) { #has bin column shift list
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
23 shift @f; #remove bin
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
24 }
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
25 my @a = split(/\//, $f[3]);
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
26 my @fr = split(/,/, $f[5]);
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
27 my @sc = split(/,/, $f[6]);
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
28 if ($f[4] == 1) { #homozygous add N, 0, 0
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
29 if ($ref) { push(@a, $f[$ref]); }
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
30 else { push(@a, "N"); }
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
31 push(@fr, 0);
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
32 push(@sc, 0);
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
33 }
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
34 if ($f[4] > 2) { next; } #skip those with more than 2 alleles
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
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]";
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
36 if (scalar @f > 7) {
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
37 splice(@f, 0, 7); #remove first 7
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
38 print "\t", join("\t", @f), "\n";
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
39 }else { print "\n"; }
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
40 }
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
41 close FH;
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
42
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
43 exit;
3871157bc013 Initial upload to toolshed.g2 via UI.
cathy
parents:
diff changeset
44