|
Packit |
575503 |
# this script renums pedigrees with metafounders
|
|
Packit |
575503 |
# so that they are added *before*regular animals
|
|
Packit |
575503 |
# mf are ascertained because they are not in the 1st column
|
|
Packit |
575503 |
# also ordered by generation assuming that all metafounders
|
|
Packit |
575503 |
# start at generation 1
|
|
Packit |
575503 |
#
|
|
Packit |
575503 |
#
|
|
Packit |
575503 |
function maxval (a,b) {
|
|
Packit |
575503 |
max=b
|
|
Packit |
575503 |
if (a>b){max=a}
|
|
Packit |
575503 |
return max
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
BEGIN{
|
|
Packit |
575503 |
pos[0]=0 # actual position in the original data file
|
|
Packit |
575503 |
changed=1
|
|
Packit |
575503 |
posout[0]=0 # position in the new file
|
|
Packit |
575503 |
last=0
|
|
Packit |
575503 |
cum[0]=0 #number of times it acts as parent
|
|
Packit |
575503 |
gen[0]=0
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
# read and store pedigree file
|
|
Packit |
575503 |
{
|
|
Packit |
575503 |
pos[$1]=NR
|
|
Packit |
575503 |
dam[$1]=$2
|
|
Packit |
575503 |
sire[$1]=$3
|
|
Packit |
575503 |
included[$1]=0
|
|
Packit |
575503 |
gen[$1]=9999
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
END{
|
|
Packit |
575503 |
#printf("%10s%10s\n",NR,"animals") > "/dev/stderr"
|
|
Packit |
575503 |
# find out who is a genetic group
|
|
Packit |
575503 |
for (x in sire){
|
|
Packit |
575503 |
if(! (sire[x] in pos)){
|
|
Packit |
575503 |
is_group[sire[x]]=1
|
|
Packit |
575503 |
#printf("%10s%10s\n","sire",sire[x]) > "/dev/stderr"
|
|
Packit |
575503 |
cum[sire[x],"sire"]++
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
for (x in dam){
|
|
Packit |
575503 |
if(! (dam[x] in pos)){
|
|
Packit |
575503 |
is_group[dam[x]]=1
|
|
Packit |
575503 |
#printf("%10s%10s\n","dam",dam[x]) > "/dev/stderr"
|
|
Packit |
575503 |
cum[dam[x],"dam"]++
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
# compute numbers, but don't write them out
|
|
Packit |
575503 |
#printf("%16s\n","info on mf") > "/dev/stderr"
|
|
Packit |
575503 |
for (x in is_group){
|
|
Packit |
575503 |
nmf++
|
|
Packit |
575503 |
posout[x]=posout[last]+1
|
|
Packit |
575503 |
printf("%16s%16s%16s%16s%16s%16s%16s\n", posout[x],0,0,x,0,0,0)
|
|
Packit |
575503 |
included[x]=1
|
|
Packit |
575503 |
gen[x]=0
|
|
Packit |
575503 |
last=x
|
|
Packit |
575503 |
cumgen[0]++
|
|
Packit |
575503 |
#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"
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
# regular individuals
|
|
Packit |
575503 |
# printf("%16s\n","recoding animals") > "/dev/stderr"
|
|
Packit |
575503 |
iter=1
|
|
Packit |
575503 |
#--> comment next line and this element of the associative array becomes null
|
|
Packit |
575503 |
#printf("%s%16s\n","at the beginning it should be empty: ",posout["00000779770060"]) > "/dev/stderr"
|
|
Packit |
575503 |
#-->
|
|
Packit |
575503 |
while (changed){
|
|
Packit |
575503 |
changed=0
|
|
Packit |
575503 |
for (x in pos){
|
|
Packit |
575503 |
if(x!=0 && !included[x]){
|
|
Packit |
575503 |
# change to number of generation
|
|
Packit |
575503 |
# if(included[dam[x]] && included[sire[x]]){
|
|
Packit |
575503 |
if((gen[dam[x]]
|
|
Packit |
575503 |
# the new code is actually the order animals are printed
|
|
Packit |
575503 |
posout[x]=posout[last]+1
|
|
Packit |
575503 |
gen[x]=maxval(gen[dam[x]],gen[sire[x]])+1
|
|
Packit |
575503 |
printf("%16s%16s%16s%16s%16s%16s%16s\n", posout[x],posout[dam[x]],posout[sire[x]],x,dam[x],sire[x],gen[x])
|
|
Packit |
575503 |
included[x]=1
|
|
Packit |
575503 |
changed=1
|
|
Packit |
575503 |
last=x
|
|
Packit |
575503 |
nanim++
|
|
Packit |
575503 |
cumgen[gen[x]]++
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
# }
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
iter++
|
|
Packit |
575503 |
#-->
|
|
Packit |
575503 |
# printf("%s%16s\n","in the loop: ",posout["00000779770060"]) > "/dev/stderr"
|
|
Packit |
575503 |
# fflush("/dev/stderr")
|
|
Packit |
575503 |
#-->
|
|
Packit |
575503 |
#printf("%10s%10s%10s%10s%16s%16s\n","round",iter,"included",posout[last],"last ",last) > "/dev/stderr"
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
#printf("%10s%10s%10s%10s%10s%10s\n","metafounders:",nmf," animals",nanim," total",posout[last]) > "/dev/stderr"
|
|
Packit |
575503 |
#printf("%16s%16s\n","pseudogenerations:",gen[last]) > "/dev/stderr"
|
|
Packit |
575503 |
for (x in cumgen){
|
|
Packit |
575503 |
#printf("%10s%16s%10s%16s\n","pseudogeneration:",x," including: ",cumgen[x]) > "/dev/stderr"
|
|
Packit |
575503 |
}
|
|
Packit |
575503 |
#--> this is the guilty line
|
|
Packit |
575503 |
# printf("%s%16s\n","at the end: ",posout["00000779770060"]) > "/dev/stderr"
|
|
Packit |
575503 |
# fflush("/dev/stderr")
|
|
Packit |
575503 |
#-->
|
|
Packit |
575503 |
}
|