Hello,
I recently used HISAT2 to align my paired-end reads to a reference genome. The command I used was
hisat2 -q -p 4 -x path_to_index -1 reads_1.fastq -2 reads_2.fastq -S out.sam.
This produced a SAM file that was ~14 GB and had headers that matched the ones I looked up online for this type of file.
I am having trouble converting my SAM output file to a BAM file using the following command samtools view -bS out.sam > out.bam. I should mention that the samtools version I am using is 1.4.1 and the syntax should be ok.
The out.bam file is only 45 bytes and when I try to check it with samtools flagstat samtools flagstat out.bam, I get the following errors:
[W::sam_read1] parse error at line 1
[bam_flagstat_core] Truncated file? Continue anyway.
I have tried looking into this problem but couldn't find an answer that related specifically to my issue. Any help would be greatly appreciated. Cheers, Fjodor
1 answer
Hello,
I think I might have solved the problem. I used samtools sort to sort the SAM file and output it to BAM format with the command samtools sort -o out_sorted.bam out.sam. This seems to have created a BAM file that has a reasonable size ~2.9 GB (relative to the SAM file) and that I can view with samtools view out_sorted.bam.
This post was particularly helpful - htseq-count: error when reading beginning of SAM/BAM file.
I still don't understand why it wasn't working when I used samtools view -bS out.sam > out.bam, but it seems fine for now. Thank you for all your help :)
Log in to answer this question.
Output if
head out.samandsamtools view out.bam | head? Did you use something likenohupduring alignment?Hi, I did not use
nohup. I am running hisat2 on a cluster and I received an output describing the alignment rate (overall alignment ~92%). I did not see other files, like the various .log files you would get if you ran Tophat. The output I get withhead out.samis listed below.When I run
samtools view out.bam | head, I getnote how above you run
which is empty so will, of course, raise an error. See what
prints
I think your BAM file is empty, for whatever reason, you would need to run the conversion again and see why it failed. I think it ran of out "something" and truncated the BAM file but the SAM file should be fine.
You mean samtools sort -o out_sorted.bam out.sam worked for you? My problem is this generated .sam file which contains some alignments but when i ran samtools view -bS out.sam > out.bam both the out.sam and out.bam seem to corrupt the alignments such that nothing is both files
Curious to know how you went straight from samtools sort -o out_sorted.bam out.sam Did you sort bam first and then used sort first? Can you please be more detailed in your solution?
Please open a new question for this if you have trouble after using the search function and reading the manual. If opening a question, please make sure to include all commands you used.