I am trying to index sorted bam files using samtools index. I created the sorted bam files by downsampling from higher depth sorted bam files using samtools depthandsamtools view. Samtools index works on the original high depth sorted bam files but it gives an error for downsampled sorted bam file:
samtools index: example is in a format that cannot be usefully indexed
Are you sure that you've output a BAM file from samtools view? You can confirm with samtools quickcheck [bam]; see here. Additionally, sometimes people forget to include the -h flag in view to include the header - just a thought.