Answers.Body: <p>The 1st code snippet is not an error, it's a deprecation warning. You can remove that warning by dropping the <code>&quot;U&quot;</code> and just specifying <code>&quot;r&quot;</code> as the mode. (The <code>&quot;U&quot;</code> is for universal newlines, which is now the default behaviour since python 3, and should be specified by a separate <code>newline</code> arg anyway).</p>
  <p>The 2nd code snippet is a trivial error because you're missing a closing parantheses <code>)</code> on the final line.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-20T13:25:11.980Z
Answers.Text: Second code ... of course and ah yes!
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-20T13:02:37.253Z
Answers.LastActivityDate: 2020-10-20T13:02:37.253Z
Answers.UserDisplayName: Chris_Rands
Answers.Body: <p>If you're not married to Python, here's a one liner in <a href="https://github.com/lh3/bioawk" rel="nofollow noreferrer">bioawk</a>:</p>
  <pre><code>bioawk -c fastx '{ if($seq !~ /[Nn]/) {print &quot;&gt;&quot;$name; print $seq}}' old_file.fa &gt; new_file.fa
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-20T20:44:36.117Z
Answers.LastActivityDate: 2020-10-20T20:44:36.117Z
Answers.UserDisplayName: Bastian Schiffthaler
Answers.Body: <p>With Visual Studio Code you can delete them using a regular expression. Replace <code>^&gt;.*\n[^&gt;]*N[^&gt;]*</code> with an empty string
  You can also do that in a similar way using the sed Linux command. You can use regular expressions in Python too.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-20T09:55:58.873Z
Answers.Text: so using command line by applying "" Sed ^>.*\n[^>]N[^>] MyfastaFile.fa  "" will remove them?
Answers.UserDisplayName: M.Bioinfo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-20T10:01:45.757Z
Answers.Text: I don't know the exact syntax for the sed command... I think it's something like  `sed 's/^>.*\n[^>]N[^>]//g' yourfile.fa > yourfilewithoutn.fa`
Answers.UserDisplayName: juanjo75es
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-20T10:04:33.137Z
Answers.Text: thank you, but this command produces a similar header number of the original file nothing change I assume
Answers.UserDisplayName: M.Bioinfo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-20T10:07:19.763Z
Answers.Text: That will work in VS Code... I did not try with sed but if you write it with the right syntax it will work too.
Answers.UserDisplayName: juanjo75es
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-20T13:19:18.850Z
Answers.Text: There was a  typo in the regex expression due to not marking it as code. It's `^>.*\n[^>]*N[^>]*`. The sed command also is wrong for that reason.
Answers.UserDisplayName: juanjo75es
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-20T09:48:17.173Z
Answers.LastActivityDate: 2020-10-20T13:17:07.133Z
Answers.LastEditDate: 2020-10-20T13:17:07.133Z
Answers.UserDisplayName: juanjo75es
Body: <p>I have Fasta file contain multiple sequences, some of those sequences contain N's or n's, I'm trying to discard all the sequences and related header that contain Ns or ns in the file.</p>
  <p>I have tried multiple python code but return an error.</p>
  <pre><code>import sys
  from Bio import SeqIO
  handle = open(sys.argv[1], &quot;rU&quot;)
  filtered = [record for record in SeqIO.parse(handle, &quot;fasta&quot;) if record.seq.count('N') == 0]
  output_handle = open(&quot;N_removed.fasta&quot;, &quot;w&quot;)
  SeqIO.write(filtered, output_handle, &quot;fasta&quot;)
  output_handle.close()
  handle.close()
  </code></pre>
  <p>Error:</p>
  <pre><code>NsScript.py:3: DeprecationWarning: 'U' mode is deprecated
    handle = open(sys.argv[1], &quot;rU&quot;)
  </code></pre>
  <p>and</p>
  <pre><code>import sys
  from Bio import SeqIO
  for record in SeqIO.parse(sys.argv[1], &quot;fasta&quot;):
      if record.seq.count('N') == 0:
          print(record.format(&quot;fasta&quot;)
  </code></pre>
  <p>Error:</p>
  <pre><code>/RemoveNs.py&quot;, line 6
      
                                          ^
  SyntaxError: unexpected EOF while parsing
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-18T18:34:06.187Z
Comments.Text: Need to see what the errors are really 'sys.argv' means the file is from the command line
Comments.UserDisplayName: M__
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-20T09:16:10.067Z
Comments.Text: @Michael I have added the error kindly have a look.
Comments.UserDisplayName: M.Bioinfo
Tags: <filtering>
Title: Discard sequences contain Ns
ThreadText: # Discard sequences contain Ns
  
  (Asked by: username_0 on 2020-10-18)
  
  I have Fasta file contain multiple sequences, some of those sequences contain N's or n's, I'm trying to discard all the sequences and related header that contain Ns or ns in the file.
  
  I have tried multiple python code but return an error.
  
  ```
  import sys
  from Bio import SeqIO
  handle = open(sys.argv[1], "rU")
  filtered = [record for record in SeqIO.parse(handle, "fasta") if record.seq.count('N') == 0]
  output_handle = open("N_removed.fasta", "w")
  SeqIO.write(filtered, output_handle, "fasta")
  output_handle.close()
  handle.close()
  
  ```
  
  Error:
  
  ```
  NsScript.py:3: DeprecationWarning: 'U' mode is deprecated
    handle = open(sys.argv[1], "rU")
  
  ```
  
  and
  
  ```
  import sys
  from Bio import SeqIO
  for record in SeqIO.parse(sys.argv[1], "fasta"):
      if record.seq.count('N') == 0:
          print(record.format("fasta")
  
  ```
  
  Error:
  
  ```
  /RemoveNs.py", line 6
      
                                          ^
  SyntaxError: unexpected EOF while parsing
  
  ```
  
  **Tags:** filtering
  
  > **Comments:**
  > **username_1**: Need to see what the errors are really 'sys.argv' means the file is from the command line  
  > **username_0**: @Michael I have added the error kindly have a look.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2020-10-20. Score: 2
  
  The 1st code snippet is not an error, it's a deprecation warning. You can remove that warning by dropping the `"U"` and just specifying `"r"` as the mode. (The `"U"` is for universal newlines, which is now the default behaviour since python 3, and should be specified by a separate `newline` arg anyway).
  
  The 2nd code snippet is a trivial error because you're missing a closing parantheses `)` on the final line.
  
  > **Comments:**
  > **username_1**: Second code ... of course and ah yes!  
  
  ---
  
  ### Answer by username_3 on 2020-10-20. Score: 2
  
  If you're not married to Python, here's a one liner in [bioawk](https://github.com/lh3/bioawk):
  
  ```
  bioawk -c fastx '{ if($seq !~ /[Nn]/) {print ">"$name; print $seq}}' old_file.fa > new_file.fa
  
  ```
  
  
  ---
  
  ### Answer by username_4 on 2020-10-20. Score: 1
  
  With Visual Studio Code you can delete them using a regular expression. Replace `^>.*\n[^>]*N[^>]*` with an empty string
  You can also do that in a similar way using the sed Linux command. You can use regular expressions in Python too.
  
  > **Comments:**
  > **username_0**: so using command line by applying "" Sed ^>.*\n[^>]N[^>] MyfastaFile.fa  "" will remove them?  
  > **username_4**: I don't know the exact syntax for the sed command... I think it's something like  `sed 's/^>.*\n[^>]N[^>]//g' yourfile.fa > yourfilewithoutn.fa`  
  > **username_0**: thank you, but this command produces a similar header number of the original file nothing change I assume  
  > **username_4**: That will work in VS Code... I did not try with sed but if you write it with the right syntax it will work too.  
  > **username_4**: There was a  typo in the regex expression due to not marking it as code. It's `^>.*\n[^>]*N[^>]*`. The sed command also is wrong for that reason.  
  
  ---
  
  