Facing issues in making a bash script work
1
0
Entering edit mode
8.9 years ago

I'm new to Bash scripting. My script intended role is to access a provided path and then apply some software (RTG - Real time Genomics) commands on the data provided in that path. However, when I try to execute the bash from CLI, it gives me following error

ERROR:There were invalid input file paths

The path I have provided in the script is accurate. That is, In the original directory, where the program 'RTG' resides, I have made folders accordingly like /data/reads/NA19240 and placed both *_1.fastq and *_2.fastq files inside NA19240.

Here is the script,

#!/bin/bash
for left_fastq in /data/reads/NA19240/*_1.fastq; do
     right_fastq=${left_fastq/_1.fastq/_2.fastq}
     lane_id=$(basename ${left_fastq/_1.fastq})
     rtg format -f fastq -q sanger -o ${lane_id} -l ${left_fastq} -r ${right_fastq} --sam-rg "@RG\tID:${lane_id}\tSM:NA19240\tPL:ILLUMINA"
done

I have tried many workarounds but still not being able to bypass this error. I will be really grateful if you guys can help me fixing this problem. Thanks

Here is the link for RTG Program: https://github.com/RealTimeGenomics/rtg-core

linux bash • 2.0k views
ADD COMMENT
0
Entering edit mode

run your script with the following line:

#!/bin/bash
set -eux

That way you can easily see what's going wrong, always use set -eu

ADD REPLY
0
Entering edit mode
8.9 years ago
Tej Sowpati ▴ 250

As far as I can see, there are several syntax errors in your script. Also, I assume you are trying to replace _1.fastq with _2.fastq to get your right fastq file? The syntax you used simply appends _2.fastq, does not substitute. Instead, a simpler although longer approach is as follows.

Step 1: Store your base fastq file names in a file

$ ls /data/reads/NA19240/*_1.fastq | perl -pe 's/_1.fastq//' > file_list

Step 2: Use the following script instead

#!/bin/bash                                                                                                                                                                                                  
for lane_id in `cat file_list`; do
    left_fastq=${lane_id}_1.fastq
    right_fastq=${lane_id}_2.fastq
    rtg format -f fastq -q sanger -o $lane_id -l $left_fastq -r $right_fastq --sam-rg "Blah Blah"
done

What you are essentially doing is having a list of base names, from which you will create your left and right files to run the command. Let me know if this works.

Cheers,

TEJ

ADD COMMENT

Login before adding your answer.

Traffic: 1479 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6