text: user7430: 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.
  
  user298: 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.
  
original_text: 7430: <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>
   298: <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>
  