text: user4092: 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
  
  user3848: These are unusual parents because they all appear haploid. Anyway, if I was doing this I would calculate the allele frequency per progeny such as makefreq in adegenet in R-cran (just my personal thoughts). 
  Problem The issue is that you are using a continuous distribution 1,2,3 etc... for catagorical data and will result in confusing homozygotes with heterozygotes. 
  For example
  
  If you have allele 3 (father) and allele 1 (mother) the "progeny" wil
  be "allele" 2
  If you have allele 2 (father) and allele 2 (mother) the "progeny"
  will be "allele" 2
  
  However, one is homozygous and the other is heterozygous and the allelic background for each is quite differnt. 
  The alternative is to use letters rather than numbers. You can always use "OneHotKeyEncoder" to convert back from AA, aa etc... to numerical catagories for analysis later (its a standard feature in Python).
  If you used letters rather and then converted to numbers every "progeny" would have its own numerical catagory (but you would lose homozygous vs. heterozygous classification). It is standard practice to switch from letters to numbers and the "encoder" will ensure no mistakes are made. The other way around this is to designate the variable as a string, rather than as an integer... this might be more to your liking, but you are stuck in base 10.
  With regards the throughput, 100000s 1000 individuals, a 100 million SNPs is doable via R, the operations are simple.
  Just to clarify: it would be easy to script to a solution (even from base code), but I'm not sure about how to interpret the output. All I'm suggesting is you have another think about the goal of this analysis. 
  
  user1310: 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-<n> < genotypes.txt > mean.txt
  
  Replace <n> 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
  
  
original_text: 4092: <p>I am interested in creating an averaged value for genotype across two parents:</p>
  
  <p>E.g. Input (three unrelated couples, 1, 2 and 3):</p>
  
  <pre><code>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    ...
  </code></pre>
  
  <p>E.g. Output (the midparental genotypes for couple 1, 2 and 3):</p>
  
  <pre><code>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  ...
  </code></pre>
  
  <p>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.</p>
  
  <p>Does anyone know of an existing tool that can do this?</p>
  
  <p>Thanks</p>
   3848: <p>These are unusual parents because they all appear haploid. Anyway, if I was doing this I would calculate the allele frequency per progeny such as makefreq in adegenet in R-cran (just my personal thoughts). </p>
  
  <p><strong>Problem</strong> The issue is that you are using a continuous distribution 1,2,3 etc... for catagorical data and will result in confusing homozygotes with heterozygotes. </p>
  
  <p><strong><em>For example</em></strong></p>
  
  <ul>
  <li>If you have allele 3 (father) and allele 1 (mother) the "progeny" wil
  be "allele" 2</li>
  <li>If you have allele 2 (father) and allele 2 (mother) the "progeny"
  will be "allele" 2</li>
  </ul>
  
  <p>However, one is homozygous and the other is heterozygous and the allelic background for each is quite differnt. </p>
  
  <p>The alternative is to use letters rather than numbers. You can always use "OneHotKeyEncoder" to convert back from AA, aa etc... to numerical catagories for analysis later (its a standard feature in Python).</p>
  
  <p>If you used letters rather and then converted to numbers every "progeny" would have its own numerical catagory (but you would lose homozygous vs. heterozygous classification). It is standard practice to switch from letters to numbers and the "encoder" will ensure no mistakes are made. The other way around this is to designate the variable as a string, rather than as an integer... this might be more to your liking, but you are stuck in base 10.</p>
  
  <p>With regards the throughput, 100000s 1000 individuals, a 100 million SNPs is doable via R, the operations are simple.</p>
  
  <p>Just to clarify: it would be easy to script to a solution (even from base code), but I'm not sure about how to interpret the output. All I'm suggesting is you have another think about the goal of this analysis. </p>
   1310: <p>Beside the correct question by @Kamil, this sounds like a job for <a href="https://www.gnu.org/software/datamash/" rel="nofollow noreferrer">datamash</a>.</p>
  
  <p>First let's get the number of columns in the file</p>
  
  <pre><code>$ head -n1 genotypes.txt| awk -v FS="\t" '{print NF}'
  </code></pre>
  
  <p>Now lets calculate the average per column with <code>datamash</code></p>
  
  <pre><code>$ datamash -H mean 2-&lt;n&gt; &lt; genotypes.txt &gt; mean.txt
  </code></pre>
  
  <p>Replace <code>&lt;n&gt;</code> with the number of columns we received with command above.</p>
  
  <p>For your example the output will look like this:</p>
  
  <pre><code>mean(SNP1)  mean(SNP2)  mean(SNP3)  mean(SNP4)
  0,5 0   1,5 1,5
  </code></pre>
  
  <p>One can remove the <code>mean</code> with <code>sed</code></p>
  
  <pre><code>$ sed -i -e 's/mean(//g' -e 's/)//g' mean.txt
  </code></pre>
  