Answers.Body: <p>First of all, you aren't actually setting the <code>$outfile</code> variable. Your loop has this basic format:</p>
  <pre><code>for var in *; do newVar=&quot;something&quot; command $newVar; done
  </code></pre>
  <p>For example:</p>
  <pre><code><span class="math-container">$ for var in 1 2 3 4; do newVar="new:$</span>var&quot; echo &quot;<span class="math-container">$var: $</span>newVar&quot;; done
  1: 
  2: 
  3: 
  4: 
  </code></pre>
  <p>As you can see, <code>newVar</code> is never actually being set. That's because setting a variable is its own operation. So you need to do that, end it with a control character like <code>;</code>, or <code>&amp;</code>, or a newline, and <em>then</em> run your <code>cutadapt</code>:</p>
  <pre><code><span class="math-container">$ for var in 1 2 3 4; do newVar="new:$</span>var&quot;; echo &quot;<span class="math-container">$var: $</span>newVar&quot;; done
  1: new:1
  2: new:2
  3: new:3
  4: new:4
   
  </code></pre>
  <p>Or, with your data:</p>
  <pre><code>for infile in /data/HTS_seq/*_read1.fastq; do 
      outfile=&quot;<span class="math-container">$infile"_trim.fastq 
      cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC \ 
        -e 0.1 -O 3 -m 30 --max-n 2 -o "$</span>outfile&quot; &quot;$infile&quot;
  done
  
  
  for infile in /data/HTS_seq/*_read2.fastq; do 
      outfile=&quot;<span class="math-container">$infile"_trim.fastq
      cutadapt -a AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTA \ 
        -e 0.1 -O 3 -m 30 --max-n 2 -o $</span>outfile $infile
  done
  </code></pre>
  <p>But that would give a weird file name, like <code>foo_S1_L001_read1.fastq_trim.fastq</code>. You probably want names like <code>foo_S1_L001_read1_trim.fastq</code> instead, so you would want:</p>
  <pre><code>for infile in /data/HTS_seq/*_read1.fastq; do 
      outfile=&quot;<span class="math-container">${infile%.fastq}"_trim.fastq
      cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC \ 
        -e 0.1 -O 3 -m 30 --max-n 2 -o "$</span>outfile&quot; &quot;$infile&quot;
  done
  
  
  for infile in /data/HTS_seq/*_read2.fastq; do 
      outfile=&quot;<span class="math-container">${infile%.fastq}"_trim.fastq
      cutadapt -a AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTA \ 
        -e 0.1 -O 3 -m 30 --max-n 2 -o $</span>outfile $infile
  done
  </code></pre>
  <hr />
  <p>Now, the specific error you show makes me think that isn't the command you ran. Could you perhaps have run this one instead by mistake (note the <code>/</code> instead of <code>\</code> before the <code>_trim.fastq</code>)?</p>
  <pre><code>for infile in /data/HTS_seq/*_read1.fastq; do
   outfile=<span class="math-container">$infile/_trim.fastq cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC \ 
  -e 0.1 -O 3 -m 30 --max-n 2 -o $</span>outfile $infile
  done
  </code></pre>
  <p>Your error message is:</p>
  <pre><code>  IOError: [Errno 20] Not a directory: '/data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq/_trim.fastq'
  </code></pre>
  <p>Which means that <code>cutadapt</code> tried to open <code>/data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq/</code> as a directory and then look for a file named <code>_trim.fastq</code> inside it. The only way I can think that this would happen is if you ran the command I gave above and not the one you show in your question.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-01T09:53:43.803Z
Answers.Text: It works! Thank you Terdon
Answers.UserDisplayName: Adrián P.L.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-30T15:37:23.673Z
Answers.LastActivityDate: 2020-06-30T15:48:14.667Z
Answers.LastEditDate: 2020-06-30T15:48:14.667Z
Answers.UserDisplayName: terdon
Answers.Body: <p>There is a bug here</p>
  <pre><code>/data/HTS_seq/*_read1.fastq 
  </code></pre>
  <p>This will go to your root directory <code>/</code> and there is definiately no folder called <code>data</code> in the root. To prove it type <code>ls /</code> and that is where the command is pointing, then compare this to <code>ls ./</code>.</p>
  <p>To solve it go to the directory <code>HTS_seq</code> and type <code>pwd</code> then copy and paste the directory structure. I suspect <code>./data/HTS_seq</code> will solve it</p>
  <pre><code> for infile in ./data/HTS_seq; ...
  </code></pre>
  <p>This will look for the folder <code>data</code> in your current working directory rather than the root directory.</p>
  <hr />
  <p>Okay you've been assigned /data as root ... no biggie.</p>
  <pre><code>PV589_03664AAB_AGGACT_read1.fastq/_trim.fastq
  </code></pre>
  <p>Why is <code>/</code> in the file name? What happens if you <code>ls /data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq/_trim.fastq</code>?
  and <code>ls /data/HTS_seq/</code> Finally could you please <code>ls /data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq\/_trim.fastq</code>?</p>
  <p>The <code>\/</code> is important. What I think has happened is a <code>/</code> is in the file name and that will cause problems because it will think that <code>_trim.fastq</code> is a directory when its part of a file name, and would explain the error.</p>
  <p>Then do the same thing using <code>head</code> instead of <code>ls</code> see what happens.</p>
  <p>If the last <code>ls</code> and <code>head</code> works then rename the files by typing <code>rename</code> in the command line. If <code>rename</code> works it will be easy to remove <code>/</code> from all your files using the power of the <code>rename</code> function (its a Perl function BTW).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-30T13:03:19.137Z
Answers.Text: Hi Michael, thanks you for your answer. I typed pwd in HTS_seq folder and I got this direction: /data/HTS_seq                                                                                                 Anyways I typed the code with the . :                                                                                                              for infile in ./data/HTS_seq/*_read1.fastq; do outfile=$infile\_trim.fastq cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC -e 0.1 -O 3 -m 30 --max-n 2 -o $outfile $infile; done and I got the same error. Which is my mistake? Thanks you
Answers.UserDisplayName: Adrián P.L.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-30T14:19:19.883Z
Answers.Text: Hi @AdriánP.L. please try the above, I should have read the error more carefully first time around
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-30T15:16:34.063Z
Answers.Text: You can never have a `/` in a file name. The `/` alone with `\0` are the _only_ two characters that can never be in file names.
Answers.UserDisplayName: terdon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-30T12:18:56.133Z
Answers.LastActivityDate: 2020-06-30T14:16:39.270Z
Answers.LastEditDate: 2020-06-30T14:16:39.270Z
Answers.UserDisplayName: M__
Body: <p>I am removing illumina adapters of the NGS data with a loop. My NGS data is storage in /data/HTS_seq/.
  I used this function:</p>
  <pre><code> for infile in /data/HTS_seq/*_read1.fastq; do outfile=<span class="math-container">$infile\_trim.fastq cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC -e 0.1 -O 3 -m 30 --max-n 2 -o $</span>outfile $infile; done
  
   for infile in /data/HTS_seq/*_read2.fastq; do outfile=<span class="math-container">$infile\_trim.fastq cutadapt -a AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTA -e 0.1 -O 3 -m 30 --max-n 2 -o $</span>outfile $infile; done
  </code></pre>
  <p>and It gives to me this error:</p>
  <pre><code>  IOError: [Errno 20] Not a directory: '/data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq/_trim.fastq'
    Traceback (most recent call last):
    File &quot;/usr/local/bin/cutadapt&quot;, line 10, in &lt;module&gt;
  cutadapt.main()
    File &quot;/usr/local/lib/python2.7/dist-packages/cutadapt/scripts/cutadapt.py&quot;, line 652, in main
  options.discard_untrimmed)
    File &quot;/usr/local/lib/python2.7/dist-packages/cutadapt/scripts/cutadapt.py&quot;, line 327, in trimmed_and_untrimmed_files
  trimmed = untrimmed = xopen(output_path, 'w')
    File &quot;/usr/local/lib/python2.7/dist-packages/cutadapt/xopen.py&quot;, line 178, in xopen
  return open(filename, mode)
        IOError: [Errno 20] Not a directory: '/data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq/_trim.fastq'
  </code></pre>
  <p>Which is my error?
  Thank you in advance.</p>
  
Tags: <ngs><cutadapt><loop>
Title: Error after trimming illumina adapters
ThreadText: # Error after trimming illumina adapters
  
  (Asked by: username_0 on 2020-06-30)
  
  I am removing illumina adapters of the NGS data with a loop. My NGS data is storage in /data/HTS\_seq/.
  I used this function:
  
  ```
   for infile in /data/HTS_seq/*_read1.fastq; do outfile=$infile\_trim.fastq cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC -e 0.1 -O 3 -m 30 --max-n 2 -o $outfile $infile; done
  
   for infile in /data/HTS_seq/*_read2.fastq; do outfile=$infile\_trim.fastq cutadapt -a AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTA -e 0.1 -O 3 -m 30 --max-n 2 -o $outfile $infile; done
  
  ```
  
  and It gives to me this error:
  
  ```
    IOError: [Errno 20] Not a directory: '/data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq/_trim.fastq'
    Traceback (most recent call last):
    File "/usr/local/bin/cutadapt", line 10, in <module>
  cutadapt.main()
    File "/usr/local/lib/python2.7/dist-packages/cutadapt/scripts/cutadapt.py", line 652, in main
  options.discard_untrimmed)
    File "/usr/local/lib/python2.7/dist-packages/cutadapt/scripts/cutadapt.py", line 327, in trimmed_and_untrimmed_files
  trimmed = untrimmed = xopen(output_path, 'w')
    File "/usr/local/lib/python2.7/dist-packages/cutadapt/xopen.py", line 178, in xopen
  return open(filename, mode)
        IOError: [Errno 20] Not a directory: '/data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq/_trim.fastq'
  
  ```
  
  Which is my error?
  Thank you in advance.
  
  **Tags:** ngs, cutadapt, loop
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-06-30. Score: 1 | Accepted answer
  
  First of all, you aren't actually setting the `$outfile` variable. Your loop has this basic format:
  
  ```
  for var in *; do newVar="something" command $newVar; done
  
  ```
  
  For example:
  
  ```
  $ for var in 1 2 3 4; do newVar="new:$var" echo "$var: $newVar"; done
  1: 
  2: 
  3: 
  4: 
  
  ```
  
  As you can see, `newVar` is never actually being set. That's because setting a variable is its own operation. So you need to do that, end it with a control character like `;`, or `&`, or a newline, and *then* run your `cutadapt`:
  
  ```
  $ for var in 1 2 3 4; do newVar="new:$var"; echo "$var: $newVar"; done
  1: new:1
  2: new:2
  3: new:3
  4: new:4
   
  
  ```
  
  Or, with your data:
  
  ```
  for infile in /data/HTS_seq/*_read1.fastq; do 
      outfile="$infile"_trim.fastq 
      cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC \ 
        -e 0.1 -O 3 -m 30 --max-n 2 -o "$outfile" "$infile"
  done
  
  for infile in /data/HTS_seq/*_read2.fastq; do 
      outfile="$infile"_trim.fastq
      cutadapt -a AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTA \ 
        -e 0.1 -O 3 -m 30 --max-n 2 -o $outfile $infile
  done
  
  ```
  
  But that would give a weird file name, like `foo_S1_L001_read1.fastq_trim.fastq`. You probably want names like `foo_S1_L001_read1_trim.fastq` instead, so you would want:
  
  ```
  for infile in /data/HTS_seq/*_read1.fastq; do 
      outfile="${infile%.fastq}"_trim.fastq
      cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC \ 
        -e 0.1 -O 3 -m 30 --max-n 2 -o "$outfile" "$infile"
  done
  
  for infile in /data/HTS_seq/*_read2.fastq; do 
      outfile="${infile%.fastq}"_trim.fastq
      cutadapt -a AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTA \ 
        -e 0.1 -O 3 -m 30 --max-n 2 -o $outfile $infile
  done
  
  ```
  
  ---
  
  Now, the specific error you show makes me think that isn't the command you ran. Could you perhaps have run this one instead by mistake (note the `/` instead of `\` before the `_trim.fastq`)?
  
  ```
  for infile in /data/HTS_seq/*_read1.fastq; do
   outfile=$infile/_trim.fastq cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC \ 
  -e 0.1 -O 3 -m 30 --max-n 2 -o $outfile $infile
  done
  
  ```
  
  Your error message is:
  
  ```
    IOError: [Errno 20] Not a directory: '/data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq/_trim.fastq'
  
  ```
  
  Which means that `cutadapt` tried to open `/data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq/` as a directory and then look for a file named `_trim.fastq` inside it. The only way I can think that this would happen is if you ran the command I gave above and not the one you show in your question.
  
  > **Comments:**
  > **username_0**: It works! Thank you username_1  
  
  ---
  
  ### Answer by username_2 on 2020-06-30. Score: -1
  
  There is a bug here
  
  ```
  /data/HTS_seq/*_read1.fastq 
  
  ```
  
  This will go to your root directory `/` and there is definiately no folder called `data` in the root. To prove it type `ls /` and that is where the command is pointing, then compare this to `ls ./`.
  
  To solve it go to the directory `HTS_seq` and type `pwd` then copy and paste the directory structure. I suspect `./data/HTS_seq` will solve it
  
  ```
   for infile in ./data/HTS_seq; ...
  
  ```
  
  This will look for the folder `data` in your current working directory rather than the root directory.
  
  ---
  
  Okay you've been assigned /data as root ... no biggie.
  
  ```
  PV589_03664AAB_AGGACT_read1.fastq/_trim.fastq
  
  ```
  
  Why is `/` in the file name? What happens if you `ls /data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq/_trim.fastq`?
  and `ls /data/HTS_seq/` Finally could you please `ls /data/HTS_seq/PV589_03664AAB_AGGACT_read1.fastq\/_trim.fastq`?
  
  The `\/` is important. What I think has happened is a `/` is in the file name and that will cause problems because it will think that `_trim.fastq` is a directory when its part of a file name, and would explain the error.
  
  Then do the same thing using `head` instead of `ls` see what happens.
  
  If the last `ls` and `head` works then rename the files by typing `rename` in the command line. If `rename` works it will be easy to remove `/` from all your files using the power of the `rename` function (its a Perl function BTW).
  
  > **Comments:**
  > **username_0**: Hi Michael, thanks you for your answer. I typed pwd in HTS_seq folder and I got this direction: /data/HTS_seq                                                                                                 Anyways I typed the code with the . :                                                                                                              for infile in ./data/HTS_seq/*_read1.fastq; do outfile=$infile\_trim.fastq cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC -e 0.1 -O 3 -m 30 --max-n 2 -o $outfile $infile; done and I got the same error. Which is my mistake? Thanks you  
  > **username_2**: Hi @AdriánP.L. please try the above, I should have read the error more carefully first time around  
  > **username_1**: You can never have a `/` in a file name. The `/` alone with `\0` are the _only_ two characters that can never be in file names.  
  
  ---
  
  