Debian Codegraph @

test/arrayind1.awk

raw
1 # this script renums pedigrees with metafounders
2 # so that they are added *before*regular animals
3 # mf are ascertained because they are not in the 1st column
4 # also ordered by generation assuming that all metafounders
5 # start at generation 1
6 #
7 #
8 function maxval (a,b) {
9 max=b
10 if (a>b){max=a}
11 return max
12 }
13 BEGIN{
14 pos[0]=0 # actual position in the original data file
15 changed=1
16 posout[0]=0 # position in the new file
17 last=0
18 cum[0]=0 #number of times it acts as parent
19 gen[0]=0
20 }
21 # read and store pedigree file
22 {
23 pos[$1]=NR
24 dam[$1]=$2
25 sire[$1]=$3
26 included[$1]=0
27 gen[$1]=9999
28 }
29 END{
30 #printf("%10s%10s\n",NR,"animals") > "/dev/stderr"
31 # find out who is a genetic group
32 for (x in sire){
33 if(! (sire[x] in pos)){
34 is_group[sire[x]]=1
35 #printf("%10s%10s\n","sire",sire[x]) > "/dev/stderr"
36 cum[sire[x],"sire"]++
37 }
38 }
39 for (x in dam){
40 if(! (dam[x] in pos)){
41 is_group[dam[x]]=1
42 #printf("%10s%10s\n","dam",dam[x]) > "/dev/stderr"
43 cum[dam[x],"dam"]++
44 }
45 }
46 # compute numbers, but don't write them out
47 #printf("%16s\n","info on mf") > "/dev/stderr"
48 for (x in is_group){
49 nmf++
50 posout[x]=posout[last]+1
51 printf("%16s%16s%16s%16s%16s%16s%16s\n", posout[x],0,0,x,0,0,0)
52 included[x]=1
53 gen[x]=0
54 last=x
55 cumgen[0]++
56 #printf("%10s%16s%10s%16s%10s%10s%10s\n","group",last," included as",posout[x]," as sire, as dam",cum[x,"sire"],cum[x,"dam"]) > "/dev/stderr"
57 }
58 # regular individuals
59 # printf("%16s\n","recoding animals") > "/dev/stderr"
60 iter=1
61 #--> comment next line and this element of the associative array becomes null
62 #printf("%s%16s\n","at the beginning it should be empty: ",posout["00000779770060"]) > "/dev/stderr"
63 #-->
64 while (changed){
65 changed=0
66 for (x in pos){
67 if(x!=0 && !included[x]){
68 # change to number of generation
69 # if(included[dam[x]] && included[sire[x]]){
70 if((gen[dam[x]]<iter) && (gen[sire[x]]<iter)){
71 # the new code is actually the order animals are printed
72 posout[x]=posout[last]+1
73 gen[x]=maxval(gen[dam[x]],gen[sire[x]])+1
74 printf("%16s%16s%16s%16s%16s%16s%16s\n", posout[x],posout[dam[x]],posout[sire[x]],x,dam[x],sire[x],gen[x])
75 included[x]=1
76 changed=1
77 last=x
78 nanim++
79 cumgen[gen[x]]++
80 }
81 # }
82 }
83 }
84 iter++
85 #-->
86 # printf("%s%16s\n","in the loop: ",posout["00000779770060"]) > "/dev/stderr"
87 # fflush("/dev/stderr")
88 #-->
89 #printf("%10s%10s%10s%10s%16s%16s\n","round",iter,"included",posout[last],"last ",last) > "/dev/stderr"
90 }
91 #printf("%10s%10s%10s%10s%10s%10s\n","metafounders:",nmf," animals",nanim," total",posout[last]) > "/dev/stderr"
92 #printf("%16s%16s\n","pseudogenerations:",gen[last]) > "/dev/stderr"
93 for (x in cumgen){
94 #printf("%10s%16s%10s%16s\n","pseudogeneration:",x," including: ",cumgen[x]) > "/dev/stderr"
95 }
96 #--> this is the guilty line
97 # printf("%s%16s\n","at the end: ",posout["00000779770060"]) > "/dev/stderr"
98 # fflush("/dev/stderr")
99 #-->
100 }