Question: while read loop shell command
0
gravatar for juncheng
5.3 years ago by
juncheng190
köln
juncheng190 wrote:

I'm writing a shell stript for alignment. 

Where sample ID stored in "SampleID.txt", for this I use a example "SRR534526", fastq file names are SRR534526_1.fastq.gz SRR534526_2.fastq.gz

My command:

while read -r line; 
  do name=$line; 
  # Rum alignment using STAR, this gives SAM file
  /software/STAR/STAR_2.3.1z12/STAR --genomeDir ~/Homo_sapiens_assembly19_STAR/ --readFilesIn $name_1.fastq.gz $name_2.fastq.gz --readFilesCommand zcat --runThreadN 20 --outFileNamePrefix $name
  cd ..
done < 'SampleID.txt'

 

Error report: gzip: .fastq.gz: No such file or directory

 

Apparently, the problem is "$name_1.fastq.gz" is not recognized as "SRR534526_1.fastq.gz"

 

Could anyone help? Thanks.

 

bash • 2.4k views
ADD COMMENTlink modified 5.3 years ago by Alex Reynolds29k • written 5.3 years ago by juncheng190
1

Try using quotes for _1.fastq.gz like $sample"_1.fastq.gz"

ADD REPLYlink written 5.3 years ago by Vivek2.3k

Thanks, seams working!

ADD REPLYlink written 5.3 years ago by juncheng190
3
gravatar for RamRS
5.3 years ago by
RamRS24k
Houston, TX
RamRS24k wrote:

It's a good practice to always enclose bash variables within {}, like, in your case, ${name}_1.fastq.gz

By following this, you make it explicit which part of your string is a variable name and which part is the actual literal string.

ADD COMMENTlink modified 5.3 years ago • written 5.3 years ago by RamRS24k

Thanks, you both gave good suggestions.

ADD REPLYlink written 5.3 years ago by juncheng190
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: 770 users visited in the last hour