Question: Error with samtools index command
0
gravatar for owenz
2.2 years ago by
owenz10
owenz10 wrote:

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.

ADD COMMENTlink modified 2.2 years ago • written 2.2 years ago by owenz10

Thanks for your reply. I didn't seem to notice this little detail

The issue has been fixed

ADD REPLYlink written 2.2 years ago by owenz10

Details always matter in bioinformatics :-)

You should accept the answers below since they solved your problem.
Upvote|Bookmark|Accept

ADD REPLYlink modified 2.2 years ago • written 2.2 years ago by genomax87k
2
gravatar for swbarnes2
2.2 years ago by
swbarnes28.1k
United States
swbarnes28.1k wrote:

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 COMMENTlink modified 2.2 years ago • written 2.2 years ago by swbarnes28.1k
1
gravatar for genomax
2.2 years ago by
genomax87k
United States
genomax87k wrote:

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 COMMENTlink modified 2.2 years ago • written 2.2 years ago by genomax87k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1644 users visited in the last hour