This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error : Could not build fai index

USED ​​BWA VERSION 0.7 FOR INDEX.

soon after I used the command samtools faidex and got the following message:

Could not build fai index.

I noticed a fasta.sa file that in no other indexing before this one was generated and fa.fai was not generated.

How can I solve this problem?

bwa samtools

Hello,

please take some more time to present your post better. Using the format bar and choose the right post tags are some of the easy action. This time I've done it for you.

Could you please post the exact command you were using? Also the output of head your.fa would be useful for us.

Thanks.

fin swimmer

Is this the whole error message or just a part of it?

I used this command:

bwa index /home/ims.santos06/Ref_crhumano/GRCh38.chr.11.fa.gz


   [bwa_index] Pack FASTA... 2.33 sec
    [bwa_index] Construct BWT for the packed sequence...
    [BWTIncCreate] textLength=270173244, availableWord=31010396
    [BWTIncConstructFromPacked] 10 iterations done. 51153116 characters processed.
    [BWTIncConstructFromPacked] 20 iterations done. 94501340 characters processed.
    [BWTIncConstructFromPacked] 30 iterations done. 133025356 characters processed.
    [BWTIncConstructFromPacked] 40 iterations done. 167261564 characters processed.
    [BWTIncConstructFromPacked] 50 iterations done. 197686764 characters processed.
    [BWTIncConstructFromPacked] 60 iterations done. 224724716 characters processed.
    [BWTIncConstructFromPacked] 70 iterations done. 248752076 characters processed.
    [BWTIncConstructFromPacked] 80 iterations done. 270103628 characters processed.
    [bwt_gen] Finished constructing BWT in 81 iterations.
    [bwa_index] 81.98 seconds elapse.
    [bwa_index] Update BWT... 1.04 sec
    [bwa_index] Pack forward-only FASTA... 1.75 sec
    [bwa_index] Construct SA from BWT and Occ... 29.60 sec
    [main] Version: 0.7.17-r1188
    [main] CMD: bwa index /home/ims.santos06/Ref_crhumano/GRCh38.chr.11.fa.gz
    [main] Real time: 119.622 sec; CPU: 116.702 sec

and then I used the command:

samtools faidx /home/ims.santos06/Ref_crhumano/GRCh38.chr.11.fa.gz
[E::fai_build3_core] Cannot index files compressed with gzip, please use bgzip
[faidx] Could not build fai index /home/ims.santos06/Ref_crhumano/GRCh38.chr.11.fa.gz.fai

I got these files:

    GRCh38.chr.11.fa.gz.ann  GRCh38.chr.11.fa.gz.sa
    GRCh38.chr.11.fa.gz      GRCh38.chr.11.fa.gz.bwt  GRCh38.chr.20.fa.gz
    GRCh38.chr.11.fa.gz.amb  GRCh38.chr.11.fa.gz.pac

Do not add an answer unless you're answering the top level post. Please delete this comment and add it as a reply at the appropriate location.

I used this command :

bwa index -a bwtsw /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta

I got this :

[bwa_index] Pack FASTA... [bns_fasta2bntseq] fail to open file '/Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta.pac' : Read-only file system
(base) Air-de-mac:~ mac$ bwa index -p/Users/mac/NGS   -a bwtsw /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta 
[bwa_index] Pack FASTA... 0.74 sec
[bwa_index] Construct BWT for the packed sequence...
[BWTIncCreate] textLength=65710806, availableWord=16623368
[BWTIncConstructFromPacked] 10 iterations done. 27420310 characters processed.
[BWTIncConstructFromPacked] 20 iterations done. 50654934 characters processed.
[bwt_gen] Finished constructing BWT in 28 iterations.
[bwa_index] 18.56 seconds elapse.
[bwa_index] Update BWT... 0.31 sec
[bwa_index] Pack forward-only FASTA... 0.17 sec
[bwa_index] Construct SA from BWT and Occ... 6.97 sec
[main] Version: 0.7.17-r1188
[main] CMD: bwa index -p/Users/mac/NGS -a bwtsw /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta
[main] Real time: 68.784 sec; CPU: 26.742 sec

and then I used this command :

[E::fai_build3_core] Failed to open the file /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta
[faidx] Could not build fai index /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta.fai

I got this :

[E::fai_build3_core] Failed to open the file /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta
[faidx] Could not build fai index /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta.fai

and then I used this command and I got this contents don't make sense. Those are not commands you used but error messages.

It looks like your genome indexes were built correctly. So what alignment commands did you use? Edit: See below.

Please don't post new questions using SUBMIT ANSWER.

If you need to create a new .fai index for the genome file you could directly do samtools faidx yourfile.fa. If it complains that the file needs to be zipped then use @finswimmer's answer below to bgzip.

the command is

samtools faidx /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta

Looking at your original posting carefully it looks like the directory you are trying to work in is marked as read-only so bwa is not able to write the index files in that directory.

[bwa_index] Pack FASTA... [bns_fasta2bntseq] fail to open file '/Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta.pac' : Read-only file system
(base) Air-de-mac:~ mac$ bwa index -p/Users/mac/NGS   -a bwtsw /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta

So you should use an area/directory where you have write permissions. Use -p option to specify that location.

bwa index -a bwtsw -p some_dir_where_you_can_write/BasenameForIndex /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta

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

I used this command : bwa index -a bwtsw /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta

I got this :

[bwa_index] Pack FASTA... [bns_fasta2bntseq] fail to open file '/Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta.pac' : Read-only file system (base) Air-de-mac:~ mac$ bwa index -p/Users/mac/NGS -a bwtsw /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta [bwa_index] Pack FASTA... 0.74 sec [bwa_index] Construct BWT for the packed sequence... [BWTIncCreate] textLength=65710806, availableWord=16623368 [BWTIncConstructFromPacked] 10 iterations done. 27420310 characters processed. [BWTIncConstructFromPacked] 20 iterations done. 50654934 characters processed. [bwt_gen] Finished constructing BWT in 28 iterations. [bwa_index] 18.56 seconds elapse. [bwa_index] Update BWT... 0.31 sec [bwa_index] Pack forward-only FASTA... 0.17 sec [bwa_index] Construct SA from BWT and Occ... 6.97 sec [main] Version: 0.7.17-r1188 [main] CMD: bwa index -p/Users/mac/NGS -a bwtsw /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta [main] Real time: 68.784 sec; CPU: 26.742 sec

and then I used this command :

[E::fai_build3_core] Failed to open the file /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta [faidx] Could not build fai index /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta.fai

I got this : [E::fai_build3_core] Failed to open the file /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta [faidx] Could not build fai index /Volumes/DATASETS/LmjFwholegenome_20070731_V5.2.fasta.fai

1 answer

Much better these information.

samtools is complaining about the way your fasta file compressed. You have to use bgzip instead of gzip

$ bgzip -c input.fa > output.fa.gz

Or uncompress the wrong compressed file and recompress with the correct program

$ zcat GRCh38.chr.11.fa.gz | bgzip -c > output.fa.gz

Log in to answer this question.