Error with samtools index command
2
1
Entering edit mode
5.9 years ago
owenz ▴ 20

Hello everyone,

I am fairly new to bioinformatics. I am currently learning the command line and was writing a very simple script to align multiple files (Hepatitis C viral DNA sequencing) to reference genome using BWA, and then using samtools to align to the reference.

I seem to be getting a problem in the index step.

I keep getting the same error:

[E::hts_open_format] Failed to open file HCV242.sorted.bam
samtools index: failed to open "HCV242.sorted.bam": No such file or directory

Below is the whole script:

SAMPLE_LIST="HCV176 HCV242"
for SAMPLE_ID in $SAMPLE_LIST

do
    #Index the aligner with the reference genome
    bwa index -a is HCV1.fasta
    # Align reads 1 of samples to ref genome
    bwa aln HCV1.fasta $SAMPLE_ID.1.fastq >$SAMPLE_ID.1.sai
    # Align reads 2 of samples to ref genome
    bwa aln HCV1.fasta $SAMPLE_ID.2.fastq >$SAMPLE_ID.2.sai
    # Merge and change into SAM format for both samples
    bwa sampe HCV1.fasta $SAMPLE_ID.1.sai $SAMPLE_ID.2.sai $SAMPLE_ID.1.fastq $SAMPLE_ID.2.fastq > $SAMPLE_ID.sam
    bwa sampe HCV1.fasta $SAMPLE_ID.1.sai $SAMPLE_ID.2.sai $SAMPLE_ID.1.fastq $SAMPLE_ID.2.fastq > $SAMPLE_ID.sam
    # Change the SAM to BAM format for both samples
    samtools view -bt HCV1.fasta $SAMPLE_ID.sam>$SAMPLE_ID.bam
    # Sort the BAM files
    samtools sort $SAMPLE_ID.bam -o $SAMPLE_ID.sorted
    # Create the index file for the BAM files
    samtools index -b  $SAMPLE_ID.sorted.bam
done

I've tested the code and everything works until the index command. All the necessary files are generated as expected up until that step. Any help much appreciated.

next-gen sequencing software error • 3.8k views
ADD COMMENT
3
Entering edit mode
5.9 years ago

While very old versions of samtools sort would add the .bam at the end of the output file, I'm pretty sure yours does not. It should be easy enough to verify that you have $SAMPLE_ID.sorted, and not $SAMPLE_ID_sorted.bam

ADD COMMENT
2
Entering edit mode
5.9 years ago
GenoMax 141k

Are you getting a truncated file name after the sort step, like HCV242.sorted? In that case you should change samtools sort $SAMPLE_ID.bam -o $SAMPLE_ID.sorted to samtools sort $SAMPLE_ID.bam -o $SAMPLE_ID.sorted.bam and see if that fixes the issue.

ADD COMMENT

Login before adding your answer.

Traffic: 2510 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6