I have created a sam file using bowtie2. I need to convert it to a bam file, index it an do downstream variant calling. However, every attempt I've made to make an index file results in an an unusable file.
One approach:
[guest@centos6 wu2]$ samtools view -h wu_0.sorted.bam | head
@HD VN:1.0 SO:coordinate
@SQ SN:Chr1 LN:29923332
@SQ SN:Chr2 LN:19386101
@SQ SN:Chr3 LN:23042017
@SQ SN:Chr4 LN:18307997
@SQ SN:Chr5 LN:26567293
@SQ SN:chloroplast LN:154478
@SQ SN:mitochondria LN:366924
@PG ID:bowtie2 PN:bowtie2 VN:2.2.5 CL:"/usr/local/bin/bowtie2-align-s --wrapper basic-0 -x wu_0_A/wu_0_A wu_0_A_wgs.fastq -s wu_0_bt2.sam"
unknown:2:60:1525:1235/1 0 Chr1 396 42 50M * 0 0 TTACTCCTTTGTGGAAATGTTTGTTCTATCAATTTATCTTTTGTGGGAAA CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC AS:i:0 XN:i:0 XM:i:0 XO:i:0 XG:i:0 NM:i:0 MD:Z:50 YT:Z:UU
I then enter the command to index the file...
$ samtools index wu_0.sorted.bam
I confirm I have a file with the appropriate extension:
wu_0.sorted.bam.bai
I try to run mpileup command and the following errors result:
$ samtools mpileup -v -u -f wu_0.v7.fas wu_0.sorted.bam.bai > wu.vcf
[E::hts_hopen] fail to open file 'wu_0.sorted.bam.bai'
[E::hts_open] fail to open file 'wu_0.sorted.bam.bai'
[mpileup] failed to open wu_0.sorted.bam.bai: Success
Then I tried the following:
[guest@centos6 wu2]$ samtools view -bS wu_0_bt2.sam > wu_0.bam
[guest@centos6 wu2]$ samtools sort wu_0.bam wu.sorted
[guest@centos6 wu2]$ samtools index wu.sorted.bam
[guest@centos6 wu2]$ ls
wu_0_A wu_0_A_wgs.fastq wu_0.bam wu_0_bt2.sam wu_0_local_bt2.sam wu_0.v7.fas wu.sorted.bam wu.sorted.bam.bai
[guest@centos6 wu2]$ samtools mpileup -v -u -f wu_0.v7.fas wu.sorted.bam.bai > wu.vcf
[fai_load] build FASTA index.
[E::hts_hopen] fail to open file 'wu.sorted.bam.bai'
[E::hts_open] fail to open file 'wu.sorted.bam.bai'
[mpileup] failed to open wu.sorted.bam.bai: No such file or directory
So what is going wrong?
Is the .bai file non-zero bytes (i.e. non empty) in both cases?