BinPro / CONCOCT

Clustering cONtigs with COverage and ComposiTion
Other
122 stars 48 forks source link

ERROR: fail to open index BAM file #277

Open SarahIsme opened 4 years ago

SarahIsme commented 4 years ago

Hello,

I installed the concoct using conda create -n concoct_env python=3 concoct as the manual.

The .bam file were generated by samtools 1.9 using samtools sort -@ 10 -o sorted.bam unsorted.sam

The script cut_up_fasta.py worked well.

However, when running concoct_coverage_table.py contigs_10K.bed sorted.bam > coverage_table.tsv, it showed

[E::hts_hopen] Failed to open file /media/hawoen/Windows/114_4_spades_default.bam.bai [E::hts_open_format] Failed to open file /media/hawoen/Windows/114_4_spades_default.bam.bai ERROR: fail to open index BAM file '/media/hawoen/Windows/114_4_spades_default.bam.bai' Traceback (most recent call last): File "/home/hawoen/miniconda3/envs/concoct_env/bin/concoct_coverage_table.py", line 91, in generate_input_table(args.bedfile, args.bamfiles, samplenames=samplenames) File "/home/hawoen/miniconda3/envs/concoct_env/bin/concoct_coverage_table.py", line 41, in generate_input_table sys.stderr.write(out) TypeError: write() argument must be str, not bytes

Could you please solve this problem?

Thanks!

thanhleviet commented 4 years ago

It seems bam index was missing, after sorting the bam file, run samtools index sorted.bam

alneberg commented 4 years ago

Hi @SarahIsme.

Yes, I would agree with @thanhleviet. It's most likely the missing .bai files which is causing the problem.

larssnip commented 3 years ago

I have a similar problem, except I have the sorted and indexed bam-file. The file has been created by bowtie2 (mapping) and samtools (view, sort, index) to get a sorted and indexed file ending with .bam.bai. Still, the concoct_coverage_table.py produces the same error as reported above. Could someone provide the exact code (samtools statements) that takes us from the .sam file to the proper sorted and indexed .bam-file that this python script requires?

yujulian0168 commented 3 years ago

What worked for me was moving the sorted .bam file and the indexed .bai file into the same directory and then running the concoct_coverage_table.py script.

mmaeke commented 3 years ago

I also experience the same issue. I do have the sorted (Sample.sorted.bam) and the indexed bam file (Sample.bam.bai). Both of these are in the same directory, still I run into the error as reported above. What worked for me was renaming the sorted bam file from Sample.sorted.bam to Sample.bam. Then the concoct_coverage_table.py script ran, but still this is quite inconvenient. Could you help with this problem?

michaelwoodworth commented 3 years ago

thanks @mmaeke, your workaround helped though agree it would have been hard to figure this out by following the tutorial.

@larssnip, here is the code I used for getting my bowtie2 bam files sorted and indexed, which worked with the workaround from mmaeke:

samtools sort -o ${ID}.sorted.bam -@ 20 ${ID}_${ID}.bam
# sorting mapped $ID reads vs $ID assembled contigs with 20 threads

samtools index -@ 20 ${ID}.sorted.bam ${ID}.bam.bai
# index sorted bam with 20 threads

I then renamed the ${ID}.sorted.bam files to ${ID}.bam and reran concoct_coverage_table.py as suggested, which seems to work.

howla1ke commented 1 year ago

Hello, can anyone help me with this? I keep getting this error: I even redid my index file concoct_coverage_table.py contigs_10K.bed Sample.sorted.bam* > coverage_table.tsv [E::hts_hopen] Failed to open file Sample.sorted.bam.bai [E::hts_open_format] Failed to open file "Sample.sorted.bam.bai" : Exec format error ERROR: fail to open index BAM file 'Sample.sorted.bam.bai' Traceback (most recent call last): File "/opt/software/CONCOCT/1.1.0-foss-2020b-Python-2.7.18/bin/concoct_coverage_table.py", line 91, in generate_input_table(args.bedfile, args.bamfiles, samplenames=samplenames) File "/opt/software/CONCOCT/1.1.0-foss-2020b-Python-2.7.18/bin/concoct_coverage_table.py", line 42, in generate_input_table sys.stderr.write(err) TypeError: expected a string or other character buffer object [howla1keCMICH@dev-intel14-k20 E58_Concoct2]$

arijitnus commented 1 year ago

@howla1ke For me, creating the sam files using bwa tools (rather than bowtie) worked. What I did is provided below- Tutorial followed for bwa tools- https://www.youtube.com/watch?v=1wcFavYt6uU&ab_channel=BioinformaticsCoach

  1. create bwa index files
  2. map the bwa index files to generate sam files
  3. convert sam to bam using samtools (santools view )
  4. sort bam files (samtools sort)
  5. index these bam files again using samtools (samtools index command) Finally keep all sorted bam files and .bai files in the same folder and run concoct_coverage_table.py. Note: Remove the phrase 'sorted' from your bam files and bai files.

I hope it works for you as well. Let me know if any further information is needed.