modified: Makefile
[GalaxyCodeBases.git] / perl / etc / WoodyMiaoLin / PbeBefore2015 / collect_genetic_information.pl
blob83ca81d3524529bc1b84969f2648dad497292342
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 open I0, "<", "../a.information/Haplotype_Region.txt";
6 my %hap_reg;
7 while (<I0>) {
8 chomp;
9 my @c = split /\t/;
10 next if !$c[0];
11 $hap_reg{$c[0]} = $c[1];
13 close I0;
15 open I1, "<", "../a.information/Sample_MT_X_Y.txt";
16 my %sample_gt; # Sample, MT, X, Y, ATP8, Autosome.
17 my %sample_re; # Sample, MT, X, Y, ATP8, Autosome.
18 while (<I1>) {
19 chomp;
20 my @c = split /\t/;
21 my $d = shift @c;
22 $sample_gt{$d} = [@c];
23 $sample_re{$d} = [$hap_reg{$c[0]}, $hap_reg{$c[1]}, $hap_reg{$c[2]}];
25 close I1;
27 open I2, "<", "/share/users/miaolin/5.Leopard_cat/3.PBE_paper_2015/g.ATP8_haplotype_tree/b.modified_alignment/f.modified_alignment/ATP8_haplotype_location_sampleID.txt";
28 while (<I2>) {
29 chomp;
30 next if !/^Pbe/;
31 my @c = split /\t/;
32 my @d = split / /, $c[2];
33 foreach (@d) {
34 push @{$sample_gt{$_}}, $c[0];
35 push @{$sample_re{$_}}, $hap_reg{$c[0]};
38 close I2;
39 foreach (keys %sample_gt) {
40 if (@{$sample_gt{$_}} == 3) {
41 push @{$sample_gt{$_}}, 0;
42 } elsif (@{$sample_gt{$_}} == 4) {
43 next;
44 } else {
45 warn @{$sample_gt{$_}};
49 foreach (keys %sample_re) {
50 if (@{$sample_re{$_}} == 3) {
51 push @{$sample_re{$_}}, 0;
52 } elsif (@{$sample_re{$_}} == 4) {
53 next;
54 } else {
55 warn @{$sample_re{$_}};
59 open I3, "<", "../a.information/Sample_AutoRegion.txt";
60 while (<I3>) {
61 chomp;
62 my @c = split /\t/;
63 push @{$sample_gt{$c[0]}}, $c[1];
64 push @{$sample_re{$c[0]}}, $c[2];
66 close I3;
67 foreach (keys %sample_gt) {
68 if (@{$sample_gt{$_}} == 4) {
69 push @{$sample_gt{$_}}, 0;
70 } elsif (@{$sample_gt{$_}} == 5) {
71 next;
72 } else {
73 warn @{$sample_gt{$_}};
77 foreach (keys %sample_re) {
78 if (@{$sample_re{$_}} == 4) {
79 push @{$sample_re{$_}}, 0;
80 } elsif (@{$sample_re{$_}} == 5) {
81 next;
82 } else {
83 warn @{$sample_re{$_}};
87 foreach (sort keys %sample_gt) {
88 foreach (@{$sample_gt{$_}}) {
89 $_ = "n/a" unless $_;
91 my %region;
92 foreach (@{$sample_re{$_}}) {
93 $_ = "n/a" unless $_;
94 $region{$_} = 1;
96 delete $region{"n/a"};
97 if ((keys %region) == 1) {
98 push @{$sample_re{$_}}, (keys %region);
99 } elsif ((keys %region) == 2) {
100 if ($region{Northern}) {
101 if ($region{Iriomote}) {
102 push @{$sample_re{$_}}, "Iriomote";
103 } elsif ($region{"China/Indochina"}) {
104 push @{$sample_re{$_}}, "China/Indochina";
105 } elsif ($region{Taiwan}) {
106 push @{$sample_re{$_}}, "Taiwan";
107 } elsif ($region{Amur}) {
108 push @{$sample_re{$_}}, "Amur";
109 } elsif ($region{Sunda}) {
110 push @{$sample_re{$_}}, "Hybrid";
111 } elsif ($region{Philippines}) {
112 push @{$sample_re{$_}}, "Hybrid";
113 } elsif ($region{Southern}) {
114 push @{$sample_re{$_}}, "Hybrid";
115 } else {
116 push @{$sample_re{$_}}, "CHECK!";
118 } elsif ($region{Southern}) {
119 if ($region{Iriomote}) {
120 push @{$sample_re{$_}}, "Hybrid";
121 } elsif ($region{"China/Indochina"}) {
122 push @{$sample_re{$_}}, "Hybrid";
123 } elsif ($region{Taiwan}) {
124 push @{$sample_re{$_}}, "Hybrid";
125 } elsif ($region{Amur}) {
126 push @{$sample_re{$_}}, "Hybrid";
127 } elsif ($region{Sunda}) {
128 push @{$sample_re{$_}}, "Sunda";
129 } elsif ($region{Philippines}) {
130 push @{$sample_re{$_}}, "Philippines";
131 } else {
132 push @{$sample_re{$_}}, "CHECK!";
135 } else {
136 if ($region{Northern} and $region{Southern}) {
137 push @{$sample_re{$_}}, "Hybrid";
138 } else {
139 push @{$sample_re{$_}}, "CHECK!";
144 open O, ">", "sample_genotype_region.txt";
145 print O "#SampleID\tgtMT\tgtX\tgtY\tgtATP8\tqAutosome(K=2)\tregionMT\tregionX\tregionY\tregionATP8\tregionAutosome\tGeneticRegion\n";
146 foreach (sort keys %sample_gt) {
147 print O $_, "\t";
148 print O join("\t", @{$sample_gt{$_}}), "\t";
149 print O join("\t", @{$sample_re{$_}}), "\n";
151 close O;