text: user9868: I am working on a project using the following command within nano:
  from Bio import SeqIO
  import sys
  import re 
  
  
      fasta_file = (sys.argv[1])
      for myfile in SeqIO.parse(fasta_file, "fasta"):
        if len(myfile) > 250:
         gene_id = myfile.id
         mylist = re.match(r"H149xcV_\w+_\w+_\w+", gene_id)
         print (">"+mylist.group(0))   # edited from list to mylist
  
  and its providing with the following outout:
  >H149xcV_Fge342_r3_h2_d1
  >H149xcV_bTr423_r3_h2_d1
  >H149xcV_kN893_r3_h2_d1
  >H149xcV_DNp021_r3_h2_d1
  >H149xcV_JEP3324_r3_h2_d1
  >H149xcV_SRt424234_r3_h2_d1
  
  How can I change my command so that it provides me with the desired format and only the UNIQUE gene id's:
  >H149xcV_Fge342_r3_h2
  >H149xcV_bTr423_r3_h2
  >H149xcV_kN893_r3_h2
  >H149xcV_DNp021_r3_h2
  >H149xcV_JEP3324_r3_h2
  >H149xcV_SRt424234_r3_h2
  
  
  user3848: its easy replace match with sub but please stop using list as a variable ... mylist is fine.
  This might work
     mylist = re.sub(r'H149xcV_\w+_\w+_\w+', gene_id)
  
  otherwise
  myregex = re.compile('_\w+\s+.*') 
  fastaid = myregex.sub('', myfile)
  
  OR from @MaximilianPress
  myregex2 = re.compile('_\w+\n') # or myregex2 = re.compile('_\w+$')
  fastaid2 = myregex.sub('\n', myfile) # or fasaid2 = myregex.sub('', myfile)
  
  The above will work ... As with all my code I never proof it ..
  
original_text: 9868: <p>I am working on a project using the following command within <code>nano</code>:</p>
  <pre><code>from Bio import SeqIO
  import sys
  import re 
  
  
      fasta_file = (sys.argv[1])
      for myfile in SeqIO.parse(fasta_file, &quot;fasta&quot;):
        if len(myfile) &gt; 250:
         gene_id = myfile.id
         mylist = re.match(r&quot;H149xcV_\w+_\w+_\w+&quot;, gene_id)
         print (&quot;&gt;&quot;+mylist.group(0))   # edited from list to mylist
  </code></pre>
  <p>and its providing with the following outout:</p>
  <pre><code>&gt;H149xcV_Fge342_r3_h2_d1
  &gt;H149xcV_bTr423_r3_h2_d1
  &gt;H149xcV_kN893_r3_h2_d1
  &gt;H149xcV_DNp021_r3_h2_d1
  &gt;H149xcV_JEP3324_r3_h2_d1
  &gt;H149xcV_SRt424234_r3_h2_d1
  </code></pre>
  <p>How can I change my command so that it provides me with the desired format and only the <strong>UNIQUE</strong> gene id's:</p>
  <pre><code>&gt;H149xcV_Fge342_r3_h2
  &gt;H149xcV_bTr423_r3_h2
  &gt;H149xcV_kN893_r3_h2
  &gt;H149xcV_DNp021_r3_h2
  &gt;H149xcV_JEP3324_r3_h2
  &gt;H149xcV_SRt424234_r3_h2
  </code></pre>
   3848: <p>its easy replace <code>match</code> with <code>sub</code> but please stop using <code>list</code> as a variable ... mylist is fine.</p>
  <p>This might work</p>
  <pre><code>   mylist = re.sub(r'H149xcV_\w+_\w+_\w+', gene_id)
  </code></pre>
  <p>otherwise</p>
  <pre><code>myregex = re.compile('_\w+\s+.*') 
  fastaid = myregex.sub('', myfile)
  </code></pre>
  <p>OR from @MaximilianPress</p>
  <pre><code>myregex2 = re.compile('_\w+\n') # or myregex2 = re.compile('_\w+$')
  fastaid2 = myregex.sub('\n', myfile) # or fasaid2 = myregex.sub('', myfile)
  </code></pre>
  <p>The above will work ... As with all my code I never proof it ..</p>
  