annotate dividePgSnpAlleles.pl @ 3:158ae5769173 draft default tip

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