Question: extract part of the sample name (file name) and run bwa mem for all samples using loop script
0
gravatar for Ati
3.3 years ago by
Ati10
Ati10 wrote:

I'm new in bash scripting. I have some sample files in different directories and wanted to extract part of the filename or directory name and create a variable with that part and apply this variable on the other command. My directory and file name follow this pattern:

user/Sample_001_002_5/001_002_5_fgdfgh_hgf00_R1.fastq.gz

user/Sample_254_128_3/254_128_3_wserer_hgf00_R2.fastq.gz

May I know how I can setup a variable such as i with the number part of the directory name

i=001_002_5 

i=254_128_3

I wrote bellow script but i is not recognized in bwa mem command:

dir=/users/Sample_*

for DIR in $dir

do i= basename ${DIR} | cut -c 8-

echo $i               # run correctly#

R1="${DIR}/${i}*R1.fastq.gz"   # Run correctly#

R2="${DIR}/${i}*R2.fastq.gz"   # run  correctly#

BWA mem -M -t 24 -R '@RG\tID:UW\tSM:'${i}'\tPL:Illumina\tPU:'${i} ${Ref} $R1 $R2 > ${DIR}/BAM/TSH_${i}_aln.sam      

# i is not recoginzed here#

done
next-gen • 1.6k views
ADD COMMENTlink modified 3.3 years ago by genomax80k • written 3.3 years ago by Ati10
0
gravatar for WouterDeCoster
3.3 years ago by
Belgium
WouterDeCoster43k wrote:

Well today you discover that not all quotes are equal ;-) Could you try again the BWA mem command with double quotes? R1="${DIR}/${i}*R1.fastq.gz", but R1='${DIR}/${i}*R1.fastq.gz' doesn't.

ADD COMMENTlink modified 3.3 years ago • written 3.3 years ago by WouterDeCoster43k

Thanks for reply. But it wasn't the issue. Is there any way I can write the loop?

ADD REPLYlink written 3.3 years ago by Ati10

Then what's the issue? Can you check with echo '@RG\tID:UW\tSM:'${i}'\tPL:Illumina\tPU:'${i} ${Ref} $R1 $R2 > ${DIR}/BAM/TSH_${i}_aln.sam to confirm?

ADD REPLYlink written 3.3 years ago by WouterDeCoster43k

'@RG\tID:UW\tSM:''\tPL:Illumina\tPU:' > /users/az/Sample_697_876_4/BAM/TSH__aln.sam

#it couldn't substitute i with its value: here is should be 697_876_4 and I need to get:

'@RG\tID:UW\tSM:697-876_4''\tPL:Illumina\tPU:697_876_4' > /users/az/Sample_697_876_4/BAM/TSH_697_876_4_aln.sam

ADD REPLYlink modified 3.3 years ago • written 3.3 years ago by Ati10
0
gravatar for Ati
3.3 years ago by
Ati10
Ati10 wrote:

Is there any way I can write the loop?

ADD COMMENTlink modified 3.3 years ago • written 3.3 years ago by Ati10

Please use ADD COMMENT/ADD REPLY when responding to existing posts to keep threads logically organized.

ADD REPLYlink written 3.3 years ago by genomax80k
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: 1097 users visited in the last hour