Calculate average parental genotype I am interested in creating an averaged value for genotype across two parents:

E.g. Input (three unrelated couples, 1, 2 and 3):

Individual    SNP1    SNP2    SNP3    SNP4 ...
Father_1      1       0       1       2    ...
Mother_1      0       0       2       1    ...
Father_2      1       0       1       1    ...
Mother_2      2       1       0       1    ...
Father_3      1       2       0       1    ...
Mother_3      1       .       0       2    ...


E.g. Output (the midparental genotypes for couple 1, 2 and 3):

Individual    SNP1    SNP2    SNP3    SNP4 ...
Midparent_1   0.5     0       1.5     1.5  ...
Midparent_2   1.5     0.5     0.5     1    ...
Midparent_3   1       .       0       1.5  ...


I can think of a way to do this using e.g. a PLINK .raw file and manipulating that in R, but am concerned that would become memory- and storage-heavy when assessing 100000s of SNPs and 1000s of pairs.

Does anyone know of an existing tool that can do this?

Thanks
Beside the correct question by @Kamil, this sounds like a job for datamash.

First let's get the number of columns in the file

$ head -n1 genotypes.txt| awk -v FS="\t" '{print NF}'


Now lets calculate the average per column with datamash

$ datamash -H mean 2-&lt;n&gt; &lt; genotypes.txt &gt; mean.txt


Replace &lt;n&gt; with the number of columns we received with command above.

For your example the output will look like this:

mean(SNP1)  mean(SNP2)  mean(SNP3)  mean(SNP4)
0,5 0   1,5 1,5


One can remove the mean with sed

$ sed -i -e 's/mean(//g' -e 's/)//g' mean.txt