Question: Error: [bwa_idx_load_from_disk] fail to locate index
0
gravatar for kchenforyou
6 weeks ago by
kchenforyou0 wrote:

Hey all, I've been working on Bash script to map some genes to a reference sequence. I'm using BWA for that, and I keep getting an error message that BWA has failed to locate the index.

Here's my code below:

#!/bin/bash
bwa index $1
samtools faidx $1
bwa mem -t $1 *fastq.gz > aln_se.sam
samtools view -bt *fasta.fai aln_se.sam > aln_se.bam
samtools sort aln_se.bam -o aln.sorted.bam
samtools index aln.sorted.bam
samtools flagstat aln.sorted.bam

I've already indexed the fasta file containing my sequence. And during the first few times I've tried this, all the indexes generated by BWA index and samtools faidx were inside the same directory /mnt/c/Users/#name/Documents/Project/Data.

Based on what I was reading on other bioinformatics forums, some have said moving their indexes to another directory has worked for them. Unfortunately it hasn't worked for me.

If anybody knows what's up with this error, or what is wrong with my code, I'd love to know. And do feel free to tell me if I can add more information to help clarify. Thanks for your help!

bash bwa software error • 186 views
ADD COMMENTlink modified 6 weeks ago by Kevin Blighe46k • written 6 weeks ago by kchenforyou0
1

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.
code_formatting

ADD REPLYlink written 6 weeks ago by RamRS23k

Thanks for doing so. This was my first time posting here let alone posting my own code, so I'll be aware of that the next time.

ADD REPLYlink written 6 weeks ago by kchenforyou0

At what step do you get the error? Have you tried running the script line by line to see what happens? Add set -eo pipefail to the top of a script to ensure that it quits when a line fails.

ADD REPLYlink written 6 weeks ago by RamRS23k
1
gravatar for Kevin Blighe
6 weeks ago by
Kevin Blighe46k
Kevin Blighe46k wrote:

It seems that you just need to change your bwa mem command. The -t parameter is used to specify number of threads, but you have not specified anything. So, BWA will try to interpret your FASTA reference ($1) as the number of threads (which makes no sense).

You could just try:

bwa mem -t 4 $1 *fastq.gz > aln_se.sam

I will assume that you are comfortable using an asterisk in a command like this. I have never run a command like this, just for the record.

Kevin

ADD COMMENTlink written 6 weeks ago by Kevin Blighe46k
1

Agreed. It is recommended to use Unix pipes to avoid unnecessary intermediate files:

bwa mem (options...) | samtools sort -o sorted.bam

There is also no need to index the reads you align, only the reference genome needs indexing by bwa itself.

ADD REPLYlink modified 6 weeks ago • written 6 weeks ago by ATpoint21k
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: 1693 users visited in the last hour