Answers.Body: <p><code>aligner.score(ref_seq_1.seq , seq1.seq)</code> doesn't produce an alignment. It just gives you the score of the alignment as float value.</p>
  <p>Instead you need to run:</p>
  <p><code>alignments = aligner.align(ref_seq_1.seq , seq1.seq)</code></p>
  <p>Now <code>alignments</code> is an <code>Bio.Align.PairwiseAlignments</code> you can iterate over <code>alignments</code> or get the score with <code>alignments.score</code> which gives you the same as aligner.score(ref_seq_1.seq , seq1.seq)`</p>
  <p>If you need more information, you could check the <a href="https://biopython.org/docs/1.75/api/Bio.Align.html?highlight=pairwisealigner#Bio.Align.PairwiseAligner" rel="nofollow noreferrer">documentation</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-01T10:33:24.763Z
Answers.Text: Thank you so much. 
  That helped a lot.
  Do you know anything to solve this- My final objective is to find out how many matches, mismatches and gaps are present in the final alignment using biopython.
Answers.UserDisplayName: Neeleshwar Pandey
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-01T12:58:32.217Z
Answers.Text: For your final objective check http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec100
Answers.UserDisplayName: Mr_Z
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-01T09:58:20.127Z
Answers.LastActivityDate: 2020-11-01T09:58:20.127Z
Answers.UserDisplayName: Mr_Z
Body: <pre><code>from Bio import SeqIO
  from Bio import Align
  
  ref_seq_1 = SeqIO.read('C:/Users/King_Arthur/Desktop/ref_seq/segment 1/ref_seq_8.fasta','fasta')
  
  seq1 = SeqIO.read('C:/Users/King_Arthur/Desktop/file/segment 1/Myfile_1 (1).fasta','fasta')
  
  aligner = Align.PairwiseAligner()
  aligner.mode = 'global'
  aligner.match_score = 1
  aligner.mismatch_score = -2
  aligner.gap_score = -2
  
  alignments = aligner.score(ref_seq_1.seq , seq1.seq)
  
  print(alignments)
  for alignment in sorted(alignments):
      print(alignment)
  </code></pre>
  <p>So this is my code and as you can see in the last section i am trying to iterate over my alignment but I am getting this error</p>
  <pre><code>TypeError: 'float' object is not iterable
  </code></pre>
  <p>I have tried various things like using <code>str()</code> but it gives some strange values and I also tried to read the source code by using the <code>inspect</code> module but I can't figure out the problem.</p>
  <p>Any help would be really appreciated.</p>
  <p>My final objective is to find out how many matches, mismatches and gaps are present in the final alignment using biopython.</p>
  <p>if there is any other better way to do it in python please feel free to suggest.</p>
  
Tags: <phylogenetics><python>
Title: Need help with Pairwise Alignment module in iterating over the alignment
ThreadText: # Need help with Pairwise Alignment module in iterating over the alignment
  
  (Asked by: username_0 on 2020-11-01)
  
  ```
  from Bio import SeqIO
  from Bio import Align
  
  ref_seq_1 = SeqIO.read('C:/Users/King_Arthur/Desktop/ref_seq/segment 1/ref_seq_8.fasta','fasta')
  
  seq1 = SeqIO.read('C:/Users/King_Arthur/Desktop/file/segment 1/Myfile_1 (1).fasta','fasta')
  
  aligner = Align.PairwiseAligner()
  aligner.mode = 'global'
  aligner.match_score = 1
  aligner.mismatch_score = -2
  aligner.gap_score = -2
  
  alignments = aligner.score(ref_seq_1.seq , seq1.seq)
  
  print(alignments)
  for alignment in sorted(alignments):
      print(alignment)
  
  ```
  
  So this is my code and as you can see in the last section i am trying to iterate over my alignment but I am getting this error
  
  ```
  TypeError: 'float' object is not iterable
  
  ```
  
  I have tried various things like using `str()` but it gives some strange values and I also tried to read the source code by using the `inspect` module but I can't figure out the problem.
  
  Any help would be really appreciated.
  
  My final objective is to find out how many matches, mismatches and gaps are present in the final alignment using biopython.
  
  if there is any other better way to do it in python please feel free to suggest.
  
  **Tags:** phylogenetics, python
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-11-01. Score: 2 | Accepted answer
  
  `aligner.score(ref_seq_1.seq , seq1.seq)` doesn't produce an alignment. It just gives you the score of the alignment as float value.
  
  Instead you need to run:
  
  `alignments = aligner.align(ref_seq_1.seq , seq1.seq)`
  
  Now `alignments` is an `Bio.Align.PairwiseAlignments` you can iterate over `alignments` or get the score with `alignments.score` which gives you the same as aligner.score(ref\_seq\_1.seq , seq1.seq)`
  
  If you need more information, you could check the [documentation](https://biopython.org/docs/1.75/api/Bio.Align.html?highlight=pairwisealigner#Bio.Align.PairwiseAligner).
  
  > **Comments:**
  > **username_0**: Thank you so much.  That helped a lot. Do you know anything to solve this- My final objective is to find out how many matches, mismatches and gaps are present in the final alignment using biopython.  
  > **username_1**: For your final objective check http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec100  
  
  ---
  
  