I recently used samtools in order to downsample some bam files I have from a sequencing run as such:
Samtools view -h -s 0.5 file.bam > ds_file.bam
I was then going to go through a normalization protocol I have to average the reads to reads per million, which first requires me to remove mitochondrial reads, which I normally do with idxstats:
Samtools index ds_file.bam Samtools idxstats ds_file.bam | cut -f 1 | grep -v MT | xargs samtools view -b ds_file.bam > dsfile_rmMT.bam
However, when running idxstats with these downsampled files, I am getting an error message saying that the index has failed to load. I checked the downsampled bam file and it is definitely still sorted by coordinates. Does anyone know why I am failing to generate a useable index?