text: user1749: I have a big file containing 27 columns and nearly 6 million rows. The following is a little example of my file
  head data
  0.65   0.722222   1.0      0.75     0
  0.35   0.277778   0.0      0.25     0
  0      0.666667   0.75     0.5      0.5625
  0      0.333333   0.25     0.5      0.4375 
  
  Rows are SNPs and columns are individuals. and I have "2 rows per each SNP" (one for reference allele and the other for alternative allele). In the example above I showed data for 2 SNPs (rows 1 and 2 correspond to SNP1 and rows 3 and 4 correspond to SNP2). I want to check if for each SNP, both ref and alt allele frequencies are 0, replace them with 9. this is my desired output:
  head desired
  0.65   0.722222   1.0      0.75     9
  0.35   0.277778   0.0      0.25     9
  9      0.666667   0.75     0.5      0.5625
  9      0.333333   0.25     0.5      0.4375 
  
  
  user292: A possible approach in plain python:
  #!/usr/bin/env python3
  
  import sys
  
  def both_zero(freq1, freq2):
      return freq1 == "0" and freq2 == "0"
  
  with open(sys.argv[1], "r") as snp_file:
      for line1 in snp_file:
          # Consume one extra line to get the frequencies
          # for the alternative allele
          line2 = snp_file.readline()
          # "zip" the frequencies in pairs
          freq_pairs = zip(line1.strip().split(), line2.strip().split())
          recoded_pairs = [
              ("9", "9") if both_zero(freq1, freq2) else (freq1, freq2)
              for (freq1, freq2) in freq_pairs]
          # "unzip" the recoded frequencies into separate objects
          # (see https://stackoverflow.com/a/19343/1878788)
          (recoded1, recoded2) = zip(*recoded_pairs)
          print(*recoded1, sep="\t")
          print(*recoded2, sep="\t")
  
  Calling it with your example snp frequencies file as command-line argument:
  $ ./recode_absent.py snps.txt
  0.65    0.722222        1.0     0.75    9
  0.35    0.277778        0.0     0.25    9
  9       0.666667        0.75    0.5     0.5625
  9       0.333333        0.25    0.5     0.4375
  
  
original_text: 1749: <p>I have a big file containing 27 columns and nearly 6 million rows. The following is a little example of my file</p>
  
  <pre><code>head data
  0.65   0.722222   1.0      0.75     0
  0.35   0.277778   0.0      0.25     0
  0      0.666667   0.75     0.5      0.5625
  0      0.333333   0.25     0.5      0.4375 
  </code></pre>
  
  <p>Rows are SNPs and columns are individuals. and I have "2 rows per each SNP" (one for reference allele and the other for alternative allele). In the example above I showed data for 2 SNPs (rows 1 and 2 correspond to SNP1 and rows 3 and 4 correspond to SNP2). I want to check if for each SNP, both ref and alt allele frequencies are 0, replace them with 9. this is my desired output:</p>
  
  <pre><code>head desired
  0.65   0.722222   1.0      0.75     9
  0.35   0.277778   0.0      0.25     9
  9      0.666667   0.75     0.5      0.5625
  9      0.333333   0.25     0.5      0.4375 
  </code></pre>
   292: <p>A possible approach in plain python:</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import sys
  
  def both_zero(freq1, freq2):
      return freq1 == "0" and freq2 == "0"
  
  with open(sys.argv[1], "r") as snp_file:
      for line1 in snp_file:
          # Consume one extra line to get the frequencies
          # for the alternative allele
          line2 = snp_file.readline()
          # "zip" the frequencies in pairs
          freq_pairs = zip(line1.strip().split(), line2.strip().split())
          recoded_pairs = [
              ("9", "9") if both_zero(freq1, freq2) else (freq1, freq2)
              for (freq1, freq2) in freq_pairs]
          # "unzip" the recoded frequencies into separate objects
          # (see https://stackoverflow.com/a/19343/1878788)
          (recoded1, recoded2) = zip(*recoded_pairs)
          print(*recoded1, sep="\t")
          print(*recoded2, sep="\t")
  </code></pre>
  
  <p>Calling it with your example snp frequencies file as command-line argument:</p>
  
  <pre><code>$ ./recode_absent.py snps.txt
  0.65    0.722222        1.0     0.75    9
  0.35    0.277778        0.0     0.25    9
  9       0.666667        0.75    0.5     0.5625
  9       0.333333        0.25    0.5     0.4375
  </code></pre>
  