bash bowtie script output with prefix
2
0
Entering edit mode
11 months ago

So I have this bowtie bash script that is working:

#!bin/bash

for a in /Volumes/Norwegian_woods/*.fastq;
do
  Reference=/Volumes/Norwegian_woods/Phaw_5.0;
  bowtie2  -N 1 -p 8 --no-unal -x  ${Reference} -q $a --al ${a%.fastq}_bowtie2.fq -S ${a%.fastq}_bowtie2.sam
done

However, I would like to change the output name and have bowtie2 written as a prefix, looking like this:

bowtie2_${a%.fastq}.fq, bowtie2_${a%.fastq}.sam.

But this is not working. Any suggestion would be appreciated! Thanks

bash script unix • 347 views
ADD COMMENT
2
Entering edit mode

Nextflow/wdl/snakemake future you will thank you.

ADD REPLY
0
Entering edit mode

Soft quote your variables.

ADD REPLY
0
Entering edit mode

I tried that ('bowtie2_${a%.fastq}.fq') but the outputs now look like this: bowtie2_${a%.fastq}.fq

ADD REPLY
1
Entering edit mode

That's because that's a hard quote, not a soft quote.

I'd advise you to stop here and familiarise yourself with quotes in the shell. It's super important to get this right, especially if this code is going to be run on lots of files by others, or you won't know the input files well. At the moment, any white space in the file names would break this.

http://www.acadix.biz/Unix-guide/HTML/ch02s12.html

ADD REPLY
1
Entering edit mode
11 months ago
Joe 19k

Untested, but what you were trying to achieve is:

#!bin/bash

for a in /Volumes/Norwegian_woods/*.fastq;
do
  Reference=/Volumes/Norwegian_woods/Phaw_5.0;
  bowtie2  -N 1 -p 8 --no-unal -x  "${Reference}" -q "$a" --al "${a%.fastq}"_bowtie2.fq -S "${a%.fastq}"_bowtie2.sam
done
ADD COMMENT
0
Entering edit mode
11 months ago
JC 12k
#!/bin/bash

for a in /Volumes/Norwegian_woods/*.fastq;
do
  Reference=/Volumes/Norwegian_woods/Phaw_5.0
  bowtie2  -N 1 -p 8 --no-unal -x  ${Reference} -q $a --al bowtie2_$(basename $a .fastq).fq -S bowtie2_$(basename $a .fastq).sam
done

Explanation: man basename

Why are you renaming your *fastq to *fq? Sound a bad thing.

ADD COMMENT
0
Entering edit mode

Because I will loop again and that makes it easier to recognise just the new files in that folder. Thanks !

ADD REPLY

Login before adding your answer.

Traffic: 2199 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