1

In a forked shell, I’m trying to run a code that takes two input files and outputs four files. Here's an example of what I'm trying to execute within the for loop -- it does produce the results I expect:

sudo java -jar ~/Trimmomatic-0.36/trimmomatic-0.36.jar PE -phred33 \
my_dir/sample_1/77504_S11_L003_R1_001.fastq.gz \
my_dir/sample_1/77504_S11_L003_R2_001.fastq.gz \
my_dir/sample_1/77504_S11_L003_PE1_001_Adapter_Removed.fastq.gz \
my_dir/sample_1/77504_S11_L003_PE1_001_Adapter_Removed_U.fastq.gz \
my_dir/sample_1/77504_S11_L003_PE2_001_Adapter_Removed.fastq.gz \
my_dir/sample_1/776504_S11_L003_PE2_001_Adapter_Removed_U.fastq.gz \
ILLUMINACLIP:~/Trimmomatic-0.36/adapters/TruSeq3-PE.fa:2:30:10 \
LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:36

While all my input files are in the same directory and each pair of inputs are in the same subdirectory, no two separate pairs of input are within the same subdirectory, e.g.

Pair 1:
my_dir/sample_1/77504_S11_L003_R1_001.fastq.gz
my_dir/sample_1/77504_S11_L003_R2_001.fastq.gz

Pair 2:
my_dir/sample_2/77505_S11_L003_R1_001.fastq.gz
my_dir/sample_2/77505_S11_L003_R2_001.fastq.gz

I need to run my code in the first block against ~50 files. Here’s what I’ve got so far, but I know it’s not correct, because the code isn’t finding the adapter

ILLUMINACLIP:~/Trimmomatic-0.36/adapters/TruSeq3-PE.fa:2:30:10

Again, this line runs fine in the first block of code that I posted.

AdapterQCTrim () {
# Make base1
base=$(basename $filename .fastq.gz)
echo $base

# Make base2
baseR2=${base/_R1_/_R2_}
echo $baseR2

# Run Trimmomatic
sudo java -jar ~/Trimmomatic-0.36/trimmomatic-0.36.jar PE -phred33 \
${base}.fastq.gz \
${baseR2}.fastq.gz \
${base}.qc.fq.gz \
s1_UP \
${baseR2}.qc.fq.gz \
s2_UP \
ILLUMINACLIP:~/Trimmomatic-0.36/adapters/TruSeq3-PE.fa:2:30:10 \
LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:36

# Save
gzip -11c s1_UP s2_PE >> paired.qc.fq.gz
gzip -11c s1_UP s2_UP >> orphans.qc.fq.gz
}

for filename in *_R1_*.fastq.gz; do AdapterQCTrim & done

If there's a way to simplify this, I'm open to other ideas.

  • Can you explain this more, please - "I know it’s not correct, because the code isn’t finding the adapter". I'm not familiar with your subject domain so I don't know which bit of your code refers to an "adapter". If you can phrase the question in terms of your script ("The code runs but doesn't find file X in directory Y...") it would be easier to understand what you're wanting. – roaima Jul 1 '17 at 10:01
0

Your code looks fine but for one line.

for filename in *_R1_*.fastq.gz; do AdapterQCTrim & done

Here *_R1_* won't expand into what you expect. As you write, the pairs are in separate directories, so to apply the function for the subfolders, you need */_R1_*.fastq.gz in the for structure. Notice the slash. You should execute this in the location that contains the subfolders. You can make sure this is taking place by putting before the for loop something like this:

cd theRightDirectory || exit 1

for is not forked, btw. It's executed in the main process.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.