Multiple fastq alignment with bowtie2
2
0
Entering edit mode
6.4 years ago
martyferr90 ▴ 30

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 • 7.1k views
ADD COMMENT
0
Entering edit mode

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

path_to_my_fastq_file/*.fastq ${i}.fastq
ADD REPLY
5
Entering edit mode
6.4 years ago

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.

ADD COMMENT
2
Entering edit mode

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
ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

-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 .-.

ADD REPLY
0
Entering edit mode

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
ADD REPLY
0
Entering edit mode

the output is still pemission denied .-.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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
ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
-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!

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
drwxr-xr-x 2 utente utente       4096 dic 11 11:19 test_fastq

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 ? ç_ç

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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"

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
6.4 years ago

Maybe with xargs (not tested)

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

Login before adding your answer.

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