Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • shashankgupta
    Member
    • Feb 2015
    • 35

    Using trimmomatic on multiple paired-end read files

    I need help to write a for loop to run Trimmomatic tool for quality trimming of paired end fastq files.
    I need to write a for loop so that I can run an executable for all multiple files.

    Input PE files looks like - C1_S1_L001_R1_001.fastq.gz
    C1_S1_L001_R2_001.fastq.gz

    C2_S39_L001_R1_001.fastq.gz
    C2_S39_L001_R2_001.fastq.gz

    T2_S41_L001_R1_001.fastq.gz
    T2_S41_L001_R2_001.fastq.gz

    T6_S45_L001_R1_001.fastq.gz
    T6_S45_L001_R2_001.fastq.gz

    To run trimmomatic for the paired reads corresponding to C1_S1_L001_R1_001.fastq.gz and C1_S1_L001_R2_001.fastq.gz, the following command works:

    java -jar ~/Trimmomatic-0.36/trimmomatic-0.36.jar PE -phred33 C1_S1_L001_R1_001.fastq.gz C1_S1_L001_R2_001.fastq.gz C1_R1_paired.fq.gz C1_R1_unpaired.fq.gz C1_R2_paired.fq.gz C1_R2_unpaired.fq.gz LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:35

    The framework provided by trimmomatic

    java -jar <path to trimmomatic.jar> PE [-threads <threads] [-phred33 | -phred64] [-trimlog <logFile>] <input 1> <input 2> <paired output 1> <unpaired output 1> <paired output 2> <unpaired output 2> <step 1> ...

    Any help please!
    Thanks!
    Last edited by shashankgupta; 02-14-2017, 04:49 AM.
  • wdecoster
    Member
    • Oct 2015
    • 97

    #2
    I would assume the following should work:
    (but obviously untested)

    Code:
    for f in $(ls *.fastq.gz | sed 's/?_001.fastq.gz//' | sort -u)
    do
    java -jar ~/Trimmomatic-0.36/trimmomatic-0.36.jar PE -phred33 ${f}1_001.fastq.gz ${f}1_002.fastq.gz  ${f}_R1_paired.fq.gz ${f}1_unpaired.fq.gz ${f}_2_paired.fq.gz ${f}2_unpaired.fq.gz LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:35
    done
    You can easily check if the commands look alright be adding in an echo statement:
    Code:
    for f in $(ls *.fastq.gz | sed 's/?_001.fastq.gz//' | sort -u)
    do
    echo java -jar ~/Trimmomatic-0.36/trimmomatic-0.36.jar PE -phred33 ${f}1_001.fastq.gz ${f}1_002.fastq.gz  ${f}_R1_paired.fq.gz ${f}1_unpaired.fq.gz ${f}_2_paired.fq.gz ${f}2_unpaired.fq.gz LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:35
    done

    Comment

    • shashankgupta
      Member
      • Feb 2015
      • 35

      #3
      Originally posted by wdecoster View Post
      I would assume the following should work:
      (but obviously untested)

      Code:
      for f in $(ls *.fastq.gz | sed 's/?_001.fastq.gz//' | sort -u)
      do
      java -jar ~/Trimmomatic-0.36/trimmomatic-0.36.jar PE -phred33 ${f}1_001.fastq.gz ${f}1_002.fastq.gz  ${f}_R1_paired.fq.gz ${f}1_unpaired.fq.gz ${f}_2_paired.fq.gz ${f}2_unpaired.fq.gz LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:35
      done
      You can easily check if the commands look alright be adding in an echo statement:
      Code:
      for f in $(ls *.fastq.gz | sed 's/?_001.fastq.gz//' | sort -u)
      do
      echo java -jar ~/Trimmomatic-0.36/trimmomatic-0.36.jar PE -phred33 ${f}1_001.fastq.gz ${f}1_002.fastq.gz  ${f}_R1_paired.fq.gz ${f}1_unpaired.fq.gz ${f}_2_paired.fq.gz ${f}2_unpaired.fq.gz LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:35
      done
      Thank you for helping me.
      But, somehow it is showing some error as shown below-

      TrimmomaticPE: Started with arguments:
      0*_R1_001.fastq.gz 0*_R2_001.fastq.gz 0_R1.trimmed_PE.fastq 0_R1.trimmed_SE.fastq 0_R2.trimmed_PE.fastq 0_R2.trimmed_SE.fastq LEADING:3 TRAILING:3 SLIDINGWINDOW:3:20 MINLEN:30
      Exception in thread "main" java.io.FileNotFoundException: 0*_R1_001.fastq.gz (No such file or directory)
      at java.io.FileInputStream.open0(Native Method)
      at java.io.FileInputStream.open(FileInputStream.java:195)
      at java.io.FileInputStream.<init>(FileInputStream.java:138)
      at org.usadellab.trimmomatic.fastq.FastqParser.parse(FastqParser.java:135)
      at org.usadellab.trimmomatic.TrimmomaticPE.process(TrimmomaticPE.java:264)
      at org.usadellab.trimmomatic.TrimmomaticPE.run(TrimmomaticPE.java:539)
      at org.usadellab.trimmomatic.Trimmomatic.main(Trimmomatic.java:80)
      0
      TrimmomaticPE: Started with arguments:
      0*_R1_001.fastq.gz 0*_R2_001.fastq.gz 0_R1.trimmed_PE.fastq 0_R1.trimmed_SE.fastq 0_R2.trimmed_PE.fastq 0_R2.trimmed_SE.fastq LEADING:3 TRAILING:3 SLIDINGWINDOW:3:20 MINLEN:30
      Exception in thread "main" java.io.FileNotFoundException: 0*_R1_001.fastq.gz (No such file or directory)
      at java.io.FileInputStream.open0(Native Method)
      at java.io.FileInputStream.open(FileInputStream.java:195)
      at java.io.FileInputStream.<init>(FileInputStream.java:138)
      at org.usadellab.trimmomatic.fastq.FastqParser.parse(FastqParser.java:135)
      at org.usadellab.trimmomatic.TrimmomaticPE.process(TrimmomaticPE.java:264)
      at org.usadellab.trimmomatic.TrimmomaticPE.run(TrimmomaticPE.java:539)
      at org.usadellab.trimmomatic.Trimmomatic.main(Trimmomatic.java:80)
      0




      As I understand, above script unable to find the file. So to simplify it, I rename all the file names, and now it looks like-


      C1_R1.fastq
      C1_R2.fastq

      C2_R1.fastq
      C2_R2.fastq

      C3_R1.fastq
      C3_R2.fastq

      T1_R1.fastq
      T1_R2.fastq

      T2_R1.fastq
      T2_R2.fastq

      T3_R1.fastq
      T3_R2.fastq

      Therefore, the working trimmomatic command looks like,

      java -jar ~/Trimmomatic-0.36/trimmomatic-0.36.jar PE -phred33 C1_R1.fastq C1_R2.fastq C1_R1_paired.fastq C1_R1_unpaired.fastq C1_R2_paired.fastq C1_R2_unpaired.fastq LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:35
      Last edited by shashankgupta; 02-15-2017, 01:04 AM.

      Comment

      • carmarbla
        Junior Member
        • Jul 2017
        • 2

        #4
        Thanks, this helped me!

        Comment

        • Louloute
          Junior Member
          • Aug 2017
          • 2

          #5
          Hello all,

          This code work on multiple single-end read files??

          Any help please??

          Many thanks

          Comment

          • carmarbla
            Junior Member
            • Jul 2017
            • 2

            #6
            #!/bin/bash

            for f1 in /path_to_your_raw_data/*.fastq.gz

            do
            java -jar /path_to_trimmomatic_folder/trimmomatic-0.36.jar SE -phred33 $f1 ${f1%%.fastq.gz}"trimmed_minleng50.fq.gz" ILLUMINACLIP:/path_to_trimmomatic_folder/adapters/TruSeq2-SE.fa:2:30:10 LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:50

            done


            This is what I used for the different SE files I have, basically it changes .fastq.gz for "trimmed_minleng50.fq.gz" once it is trimmed. You can edit the order and the value of the parameters. (Minimun_length, minimun quality at the end or start of the reads, different adapter files...).
            Last edited by carmarbla; 08-08-2017, 06:37 AM.

            Comment

            • Louloute
              Junior Member
              • Aug 2017
              • 2

              #7
              Many thanks Carmarbla for your reply!
              Best

              Comment

              • wnegara
                Junior Member
                • Sep 2017
                • 2

                #8
                Hi All,
                just found these threads. Does the code
                or f in $(ls *.fastq.gz | sed 's/?_001.fastq.gz//' | sort -u)
                do
                java -jar ~/Trimmomatic-0.36/trimmomatic-0.36.jar PE -phred33 ${f}1_001.fastq.gz ${f}1_002.fastq.gz ${f}_R1_paired.fq.gz ${f}1_unpaired.fq.gz ${f}_2_paired.fq.gz ${f}2_unpaired.fq.gz LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:35
                done
                is need modification prior to use or it will work for any PE files?
                cheers

                Comment

                Latest Articles

                Collapse

                • SEQadmin2
                  Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                  by SEQadmin2


                  I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

                  Here are nine questions we think about, in roughly the order they matter, before...
                  06-18-2026, 07:11 AM
                • SEQadmin2
                  From Collection to Sequencing: Why Sample Preparation and Preservation Define Sequencing Data
                  by SEQadmin2


                  Data variability is still an issue in sequencing technologies despite the advances in reproducibility and accuracy of these platforms. But the problem does not originate in the sequencing itself, but in the previous steps, before the sample reaches the sequencer.


                  The first step is collection, followed by preservation and sample preparation for analysis. Most scientists overlook those steps, but not being careful might just be skewing the experiment’s results.
                  ...
                  06-02-2026, 10:05 AM

                ad_right_rmr

                Collapse

                News

                Collapse

                Topics Statistics Last Post
                Started by SEQadmin2, Yesterday, 11:10 AM
                0 responses
                7 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 06-17-2026, 06:09 AM
                0 responses
                42 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 06-09-2026, 11:58 AM
                0 responses
                103 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 06-05-2026, 10:09 AM
                0 responses
                125 views
                0 reactions
                Last Post SEQadmin2  
                Working...