Thank you.
I am able to run trimmomatic for one file using the following in the windows cd (tasking one sample CSM020 as an example):
java -jar C:\Users\Shared\CheeseStudy\Trimmomatic\Trimmomatic-0.39\Trimmomatic-0.39\trimmomatic-0.39.jar PE -phred33 -trimlog C:\Users\Shared\CheeseStudy\Trimmomatic\TrimmoLog\CSM020_v1Log -basein C:\Users\Shared\CheeseStudy\Trimmomatic\RawCheesefastq\CSM020_v1_S1_L001_R1_001.fastq.gz -baseout C:\Users\Shared\CheeseStudy\Trimmomatic\TrimmoOutputs\CSM020_v1.fq.gz ILLUMINACLIP:Trimmomatic-0.39\Trimmomatic-0.39\adapters\NexteraPE-PEUpdated.fa:2:30:10:5
I have a number of fastq files - I have 69 participant IDs (e.g., CSM020) and two timepoints for each participant (v1 or v2), and then R1 nd R2 files - so each participant ID has 4 sets of fastqs. Here is an example of what the fastqs look like for one participant:
"C:\Users\Shared\CheeseStudy\Trimmomatic\RawCheesefastq\CSM020_v1_S1_L001_R1_001.fastq.gz"
"C:\Users\Shared\CheeseStudy\Trimmomatic\RawCheesefastq\CSM020_v1_S1_L001_R2_001.fastq.gz"
"C:\Users\Shared\CheeseStudy\Trimmomatic\RawCheesefastq\CSM020_v2_S72_L001_R1_001.fastq.gz"
"C:\Users\Shared\CheeseStudy\Trimmomatic\RawCheesefastq\CSM020_v2_S72_L001_R2_001.fastq.gz"
I am trying to set up a .bat file to run the above trimmomatic settings through all of the fastq files I have in the directory "C:\Users\Shared\CheeseStudy\Trimmomatic\RawCheesefastq" which contains all the files. I am struggling to get it set up correctly in terms of identifying the R1 and R2 file pairs correctly, while also considering the v1 and v2 parameters. I have been trying with code like this (writing .bat file in notepad and running it in cd) but it's constructing the R2 file incorrectly and of course failing . Any ideas?
@echo off
setlocal EnableDelayedExpansion
rem Define base path
set "BASE_PATH=C:\Users\Shared\CheeseStudy\Trimmomatic"
rem Define paths relative to the base path
set "TRIMMOMATIC_PATH=%BASE_PATH%\Trimmomatic-0.39\Trimmomatic-0.39\trimmomatic-0.39.jar"
set "ADAPTERS_PATH=Trimmomatic-0.39\Trimmomatic-0.39\adapters\NexteraPE-PEUpdated.fa"
set "INPUT_DIR=%BASE_PATH%\RawCheesefastq"
set "OUTPUT_DIR=%BASE_PATH%\TrimmoOutputs"
set "LOG_DIR=%BASE_PATH%\TrimmoLog"
rem Create output and log directories if they don't exist
if not exist "%OUTPUT_DIR%" mkdir "%OUTPUT_DIR%"
if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"
rem Change to the base directory to use relative paths
pushd "%BASE_PATH%"
rem Loop through R1 files in the input directory
for %%f in ("%INPUT_DIR%\*R1_001.fastq.gz") do (
rem Extract base name by removing _R1_001.fastq.gz
set "FILENAME=%%~nf"
set "BASE=!FILENAME:_R1_001=!"
rem Construct the corresponding R2 file path
set "FILE_R2=%INPUT_DIR%\!BASE!_R2_001.fastq.gz"
rem Define output file names
set "OUTPUT_R1_PAIRED=%OUTPUT_DIR%\!BASE!_R1_paired.fastq.gz"
set "OUTPUT_R1_UNPAIRED=%OUTPUT_DIR%\!BASE!_R1_unpaired.fastq.gz"
set "OUTPUT_R2_PAIRED=%OUTPUT_DIR%\!BASE!_R2_paired.fastq.gz"
set "OUTPUT_R2_UNPAIRED=%OUTPUT_DIR%\!BASE!_R2_unpaired.fastq.gz"
set "LOG_FILE=%LOG_DIR%\!BASE!.log"
rem Debug: Echo the file paths
echo Processing R1 file: %%f
echo Looking for R2 file: !FILE_R2!
rem Check if the R2 file exists
if exist "!FILE_R2!" (
rem Run Trimmomatic
java -jar "%TRIMMOMATIC_PATH%" PE -phred33 "%%f" "!FILE_R2!" "!OUTPUT_R1_PAIRED!" "!OUTPUT_R1_UNPAIRED!" "!OUTPUT_R2_PAIRED!" "!OUTPUT_R2_UNPAIRED!" ILLUMINACLIP:"%ADAPTERS_PATH%":2:30:10:5 > "!LOG_FILE!"
rem Log completion
echo Done with %%f
) else (
echo File not found: !FILE_R2!
echo Skipping this pair.
echo Skipping this pair. >> "%LOG_DIR%\missing_files.log"
)
)
rem Return to the original directory
popd
endlocal