Question: Facing issues in making a bash script work
0
gravatar for adnan.haider.ra
3.7 years ago by
Pakistan
adnan.haider.ra10 wrote:

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 work arounds 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 • 1.1k views
ADD COMMENTlink modified 3.7 years ago • written 3.7 years ago by adnan.haider.ra10

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 REPLYlink written 3.7 years ago by Michael Dondrup46k
0
gravatar for Tej Sowpati
3.7 years ago by
Tej Sowpati250
India
Tej Sowpati250 wrote:

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 COMMENTlink written 3.7 years ago by Tej Sowpati250
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1116 users visited in the last hour