text: user2686: I have this code to filter some IDs from a fasta file:
  for line in file_open:
      line=line.rstrip()
      if '16S' in line:
          header=line
          header=header[0] + header[1:]
          seq=file_open.readline()
          seq=seq.strip()
          print(header + '\n'  + seq)
  
  however, this code doesn't get me all content of each ID sequence. I get this result:
  >ID1
  AGTTTTGCCGAATTCCTTTAGGATTTTGTGAGGAACATTGTGTTAAATGTATTTATAGTTCTACTAATTC
  
  When I should get this:
  >ID1
  AGTTTTGCCGAATTCCTTTAGGATTTTGTGAGGAACATTGTGTTAAATGTATTTATAGTTCTACTAATTC
  TGCGAAGGTAGCATAATCATTAGCCTTTTGATTTGAGGCTGGAATGAATGGTTTGACGAGAGATGGTCTG
  GGGCCGTGGTATACTGACCATGCGAAGGTAGCATAATCATTAGCCTCTTGATTTGAGGCTGGAATGAATG
  GGGCCGTGGTATAC
  
  Thanks
  
  user104: You're assuming 2-line FASTA format, but the sequence can (and typically does) span multiple lines. You can use Biopython to build a simple parser:
  from Bio import SeqIO
  
  for record in SeqIO.parse("file_name.fa", "fasta"):
      if "16S" in record.description:
          print(record.format("fasta"))
  
  
original_text: 2686: <p>I have this code to filter some IDs from a fasta file:</p>
  
  <pre><code>for line in file_open:
      line=line.rstrip()
      if '16S' in line:
          header=line
          header=header[0] + header[1:]
          seq=file_open.readline()
          seq=seq.strip()
          print(header + '\n'  + seq)
  </code></pre>
  
  <p>however, this code doesn't get me all content of each ID sequence. I get this result:</p>
  
  <pre><code>&gt;ID1
  AGTTTTGCCGAATTCCTTTAGGATTTTGTGAGGAACATTGTGTTAAATGTATTTATAGTTCTACTAATTC
  </code></pre>
  
  <p>When I should get this:</p>
  
  <pre><code>&gt;ID1
  AGTTTTGCCGAATTCCTTTAGGATTTTGTGAGGAACATTGTGTTAAATGTATTTATAGTTCTACTAATTC
  TGCGAAGGTAGCATAATCATTAGCCTTTTGATTTGAGGCTGGAATGAATGGTTTGACGAGAGATGGTCTG
  GGGCCGTGGTATACTGACCATGCGAAGGTAGCATAATCATTAGCCTCTTGATTTGAGGCTGGAATGAATG
  GGGCCGTGGTATAC
  </code></pre>
  
  <p>Thanks</p>
   104: <p>You're assuming 2-line FASTA format, but the sequence can (and typically does) span multiple lines. You can use <a href="https://biopython.org/" rel="noreferrer">Biopython</a> to build a simple parser:</p>
  
  <pre><code>from Bio import SeqIO
  
  for record in SeqIO.parse("file_name.fa", "fasta"):
      if "16S" in record.description:
          print(record.format("fasta"))
  </code></pre>
  