Error after trimming illumina adapters 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 &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'

Which is my error?
Thank you in advance.
First of all, you aren't actually setting the $outfile variable. Your loop has this basic format:
for var in *; do newVar=&quot;something&quot; command $newVar; done

For example:
$ for var in 1 2 3 4; do newVar="new:$var&quot; echo &quot;$var: $newVar&quot;; 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 &amp;, or a newline, and then run your cutadapt:
$ for var in 1 2 3 4; do newVar="new:$var&quot;; echo &quot;$var: $newVar&quot;; 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=&quot;$infile"_trim.fastq 
    cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC \ 
      -e 0.1 -O 3 -m 30 --max-n 2 -o "$outfile&quot; &quot;$infile&quot;
done


for infile in /data/HTS_seq/*_read2.fastq; do 
    outfile=&quot;$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=&quot;${infile%.fastq}"_trim.fastq
    cutadapt -a AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC \ 
      -e 0.1 -O 3 -m 30 --max-n 2 -o "$outfile&quot; &quot;$infile&quot;
done


for infile in /data/HTS_seq/*_read2.fastq; do 
    outfile=&quot;${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.