text: user1629: I am trying to make a phylogenetic tree from sequences obtained with blast. I have files that contains hundreds of fasta protein sequences which are all named like >NP_567483.1 transcriptional regulator [Pseudomonas aeruginosa PAO1]. But if I use these files to do multiple alignments or phylogenetic trees using either ClustalX or MEGA7, every sequence are named after the first ID in the sequence names (for this example it would be NP_567483.1), and what I want is to have the name of the strain instead (here Pseudomonas aeruginosa PAO1) which is part of the sequence description. 
  So I don't know whether the softwares I'm using understand that the information between the [ ] is the species and that I just didn't find where to set this as the name or if I have to write some kind of a script to change my fasta files before. I'm really new to this and don't know much about it. Thanks for your help in advance. Julian
  
  user1392: You can replace fasta header of each sequence with the string that is inside the brackets using awk:
  awk -F '[][]' '{if ($0~/>/) {print ">"$2} else {print $0}}' input.fasta > output.fasta
  
  For lines starting with > (fasta header), it replaces the line with the string inside the brackets and for other lines (which contain the sequence), it prints the line without making any changes.
  
  user1642: With sed, first test it:
  echo '>NP_567483.1 transcriptional regulator [Pseudomonas aeruginosa PAO1]' | sed "s/>.*\[\(.*\)\]/>\1/"
  
  Then modify your fasta:
  sed -i.bak "s/>.*\[\(.*\)\]/>\1/" file.fasta
  
  
  user824: There might be a "cleaner" way to do this, but what I would do is first remove all of the spaces from the fasta sequence names and replace them with underscores using something like sed.
  sed 's/ /_/g'
  
  Run your BLAST after you remove the spaces and you will get the whole ID string in the result instead of only that first part (e.g. NP_567483.1). From here you can parse out the species name, or whatever other ID you would like.
  Hope this is helpful! :)
  
original_text: 1629: <p>I am trying to make a phylogenetic tree from sequences obtained with blast. I have files that contains hundreds of fasta protein sequences which are all named like <code>&gt;NP_567483.1 transcriptional regulator [Pseudomonas aeruginosa PAO1]</code>. But if I use these files to do multiple alignments or phylogenetic trees using either ClustalX or MEGA7, every sequence are named after the first ID in the sequence names (for this example it would be <code>NP_567483.1</code>), and what I want is to have the name of the strain instead (here <code>Pseudomonas aeruginosa PAO1</code>) which is part of the sequence description. </p>
  
  <p>So I don't know whether the softwares I'm using understand that the information between the [ ] is the species and that I just didn't find where to set this as the name or if I have to write some kind of a script to change my fasta files before. I'm really new to this and don't know much about it. Thanks for your help in advance. Julian</p>
   1392: <p>You can replace fasta header of each sequence with the string that is inside the brackets using awk:</p>
  
  <pre><code>awk -F '[][]' '{if ($0~/&gt;/) {print "&gt;"$2} else {print $0}}' input.fasta &gt; output.fasta
  </code></pre>
  
  <p>For lines starting with <code>&gt;</code> (fasta header), it replaces the line with the string inside the brackets and for other lines (which contain the sequence), it prints the line without making any changes.</p>
   1642: <p>With <code>sed</code>, first test it:</p>
  
  <pre><code>echo '&gt;NP_567483.1 transcriptional regulator [Pseudomonas aeruginosa PAO1]' | sed "s/&gt;.*\[\(.*\)\]/&gt;\1/"
  </code></pre>
  
  <p>Then modify your fasta:</p>
  
  <pre><code>sed -i.bak "s/&gt;.*\[\(.*\)\]/&gt;\1/" file.fasta
  </code></pre>
   824: <p>There might be a "cleaner" way to do this, but what I would do is first remove all of the spaces from the fasta sequence names and replace them with underscores using something like sed.</p>
  
  <pre><code>sed 's/ /_/g'
  </code></pre>
  
  <p>Run your BLAST after you remove the spaces and you will get the whole ID string in the result instead of only that first part (e.g. <code>NP_567483.1</code>). From here you can parse out the species name, or whatever other ID you would like.</p>
  
  <p>Hope this is helpful! :)</p>
  