title: Comparing two FASTA files to get the position of the difference using dictionary
body: <p>I have two files <code>f1.fasta</code> and <code>f2.fasta</code>. I want to compare sequence in <code>f1</code> and <code>f2</code>, but also get the position where the nucleotides are different so I can replace them.</p>
  
  <p>Example of <code>f1</code> FASTA: </p>
  
  <pre><code>&gt;VFG0127
  
  ATGCCTGGAAATATA...
  
  &gt;VFG0007
  
  TTAGGCATATTTCAT...
  </code></pre>
  
  <p>Example of <code>f2</code> FASTA:</p>
  
  <pre><code>&gt;VFG0127
  
  ATGCCTGGXXXTATA...
  
  &gt;VFG0007
  
  TTAJGCATATSTCAT...
  </code></pre>
  
  <p>I would like to get for example: VFG0127|position 7, X should be A ...</p>
  
  <p>I tried this code but I'm not getting anywhere </p>
  
  <pre><code>dict_1 = {}
  dict_2 = {}
  
  with open(f1, 'r') as f1, open (f2, 'r') as f2:
      for line in f1:
          if line.startswith('&gt;'):
              id_acc1 = line.strip()
              seq_1 = f1.next().strip()
              dict_1[id_acc1]=seq_1
              #print dict_1
      for line in f2: 
          if line.startswith('&gt;'):
              id_acc2 = line.strip()
              seq_2 = f2.next().strip()
              dict_2[id_acc2]=seq_2
              #print dict_2
  
      diffkeys = [k for k in dict_1.values()[index] if dict_1[k] != dict_2[k]]
      for k in diffkeys:
          print k, ':', dict_1[k], '-&gt;', dict_2[k]
  </code></pre>
  
  <p>I spent hours on this matter and I can't make it work.
  Please I am still a beginner, a simple code would be much appreciated.</p>