title: Concatenate fasta files in loop
body: <p>I have multiple fasta files with multiple individuals with sequences of the same lenght. What I want to do is to create a concatenation of the sequence of species along the fasta files.</p>
  
  <p>In the loop: If one species is found in the next file, I concatenate its sequence, if not, I concatenate gaps ('-'), with the same lenght as the rest of sequences. (See the files are aligned)</p>
  
  <pre><code>species_list = []
  files = [file for file in glob.glob('~/*.fa')]
  for aln in files:
      with open (aln, 'rU') as multispecies:
          sequences = SeqIO.parse(multispecies, 'fasta')
          for species in sequences:
              species_list.append(species.id)
  
  species_list=list(set(species_list))
  #print(species_list)
  
  concat = {}
  for aln in files:
      #print(aln)
      dict = {}
      with open (aln, 'rU') as multispecies:
          sequences = SeqIO.parse(multispecies, 'fasta')
          names = []
          for fasta in sequences:
              names.append(fasta.id)
              dict[fasta.id] = fasta.seq
          count_species = 0
          for i in species_list:
              if i in names:
                  count_species = count_species + 1
                  print('&gt;' + i + '\n' + dict[i])
                  gap = int(len(dict[i]))
                  concat[i] += dict[i]    #I cannot find a way to concatenate here
              else:
                  print('&gt;' + i + '\n' + '-'*gap)
                  concat[i] += '-'*gap #I cannot find a way to concatenate here
  </code></pre>