This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Multiple fastq alignment with bowtie2

Hi! I'm trying to perform a multiple alignment with bowtie2. In particular I'm looking for a cycle that can execute the alignment of more fastq files into sam files.

I try this shell code

for i in $(path_to_my_fastq_file/*.fastq)
do 
bowtie2 -p4- -x hg19 path_to_my_fastq_file/*.fastq ${i}.fastq -S $i.sam
done

but I receive this error

bash: path_to_my_fastq_file.file.fistq permission denied

How can I resolve this?

Thanks in advance

fastq bowtie2 alignment

......... -q $i -S $i.sam instead of:

path_to_my_fastq_file/*.fastq ${i}.fastq

2 answers

Doing stuff like this in bash is somewhat annoying, that's why things like snakemake are around:

rule bowtie2:
    input: "path/{sample}.fastq"
    output: "{sample}.bam"
    threads: 4
    shell: """
        bowtie2 -p {threads} -x hg19 {input} | samtools view -bo {output} -
        """

Having said that, you presumably wanted something like:

for i in $(path_to_my_fastq_file/*.fastq)
do
bowtie2 -p 4 -x hg19 ${i} | samtools view -bo ${i%%.fastq}.bam -
done

I've taken the liberty of removing the SAM intermediate.

While we're at it, let's produce a sorted bam:

for i in $(path_to_my_fastq_file/*.fastq)
do
bowtie2 -p 4 -x hg19 ${i} | samtools sort -o ${i%%.fastq}.bam -
done

Hi! I tryed your code, but my error is still: permission denied. Any idea?

Does the file exist and do you have read access to it?

-rw-r--r-- this are the permission of my 31 files in the directory of the path that I use in $(path_to_my_fastq_file).

If I type the command with only one file it works (simple bowtie 2 -x hg19 in.fastq | samtools sort -o out.bam), with a for instruction doesn't work anymore .-.

Check if the command looks okay by adding "echo":

for i in $(path_to_my_fastq_file/*.fastq)
do
echo bowtie2 -p 4 -x hg19 ${i} | samtools sort -o ${i%%.fastq}.bam -
done

the output is still pemission denied .-.

The echo should just print the commands without executing them. So you shouldn't get output nor "permission denied".

I think there needs to be a quote around the command after echo. As is, echo is piping to samtools and that should then be written to disk.

Yes, it appears you're right.

for i in $(path_to_my_fastq_file/*.fastq)
do
echo "bowtie2 -p 4 -x hg19 ${i} | samtools sort -o ${i%%.fastq}.bam -"
done

It's still permission denied. Where I'm wrong? ç_ç

could you do a ls -l on the directory where you want to output your data please ?

-rw-rw-rw- 1 utente utente 1716298636 dic 11 11:18 bam012.fastq
-rw-rw-rw- 1 utente utente 1694712150 dic 11 11:19 bam004.fastq

I tried with -r--r--r- permission too and still the same error!

could you do the ls -l on the directory not on the fastq please

drwxr-xr-x 2 utente utente       4096 dic 11 11:19 test_fastq

This is the output directory (the same of the input files)

Try to chmod the directory. chmod 755 output_dir. Then retry the alignment

I done:

chmod 755 out/
drwxr-xr-x 2 utente utente       4096 dic 11 11:59 out

Then

for i in $(/home/utente/test/test_fastq/*.fastq)
> do
> bowtie2 -p 4 -x /home/utente/bowtie2/hg19 ${i} | samtools sort -o ${i%%.fastq}.bam -
> done

and

Permission denied

Why ? ç_ç

How does this look like?

for i in $(/home/utente/test/test_fastq/*.fastq)
do
echo ${i}
echo ${i%%.fastq}.bam
done

What about ls - l /home/utente/test/test_fastq/*.fastq?
Perhaps you don't have reading permissions to those? Would be odd.

This is the output of ls -l /home/utente/test/test_fastq/*.fastq

drwxr-xr-x 2 utente utente       4096 dic 11 11:59 out
-rw-rw-rw- 1 utente utente 1716298636 dic 11 11:18 bam012.fastq
-rw-rw-rw- 1 utente utente 1694712150 dic 11 11:19 bam004.fastq

where out is the output directory.

And this is the code:

for i in $(/home/utente/test/test_fastq/*.fastq)
> do
> echo ${i}
> echo ${i%%.fastq}.bam
> done
bash: /home/utente/test/test_fastq bam012.fastq: Permission denied

The same output if I use echo "${i}" and echo "${i%%.fastq}.bam"

Did you find a solution to this "permission denied" problem? I am facing similar problem while trying to run multiple alignment in server

Here is my script

#!/bin/bash
#BATCH --job-name=ERR1135336.clean.reads.Assembly
#SBATCH -N 1                    # Number of nodes, not cores
#SBATCH -t 2-00:00:00           # Walltime
#SBATCH --ntasks-per-node 40    # Number of cores
#SBATCH --output=out-%j.log     # Output (console)
#SBATCH --partition=test       # Queue

module use /gpfs/shared/modulefiles_local
module use /gpfs/shared/modulefiles_local/bio
module load bio/bowtie2/2.3.4

for i in $(path/to/*.fastq)
do
bowtie2 -x PC_805 --threads 40 -U ${i} -S path/to/${i%%.fastq}.sam
done

Any help will be much appreciated

Maybe with xargs (not tested)

ls path_to_my_fastq_files/*.fastq | xargs -I fastq bowtie2 -p4 -x hg19 fastq -S fastq.sam

Log in to answer this question.