santiago-es / Telometer

A simple regular expression based method for measuring telomere length from long-read sequencing
MIT License
0 stars 1 forks source link

calculate_telomere_length error #2

Closed YonkoBigMom closed 2 weeks ago

YonkoBigMom commented 1 month ago

I run a bam aligned by minimap2 to t2t-and-subtel.fa

telometer -b my_sample.telomere.bam -o my_sample.telometer.tsv -m 1000 -c r10

and it gave an error:

Traceback (most recent call last): File "/home/jj/anaconda3/bin/telometer", line 8, in sys.exit(calculate_telomere_length()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jj/anaconda3/lib/python3.11/site-packages/telometer/telometer.py", line 115, in calculate_telomere_length read_data_list = [{ ^^ File "/home/jj/anaconda3/lib/python3.11/site-packages/telometer/telometer.py", line 124, in 'reference_length': bam_file.get_reference_length(read.reference_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pysam/libcalignmentfile.pyx", line 1919, in pysam.libcalignmentfile.AlignmentFile.get_reference_length File "pysam/libcalignmentfile.pyx", line 509, in pysam.libcalignmentfile.AlignmentHeader.get_reference_length File "pysam/libcalignmentfile.pyx", line 531, in pysam.libcalignmentfile.AlignmentHeader.get_tid

Can you let me know what is the issue here?

santiago-es commented 1 month ago

Looks like the issue is arising when it tries to pull out the name / length of the contig the reads were aligned to. Has this bamfile been sorted and index by samtools already?

YonkoBigMom commented 1 month ago

Yes

samtools bam2fq -@ 5 -T '*' my_sample.unmapped.bam | minimap2 -ax map-ont -y -t 25 ./t2t-and-subtel.fa - | samtools sort -@ 10 -m 5G -o my_sample.telomere.bam

samtools index -@20  my_sample.telomere.bam
santiago-es commented 1 month ago

Reinstalling runs on my machine with an example set. Can you try adding -Y and -L flags to minimap2?

YonkoBigMom commented 1 month ago

I will do this and report back.

jleehan commented 1 month ago

I was having the same issue and tried the suggested steps and still received the same error

minimap2 -ax map-ont -Y -L -t 28 t2t-and-subtel.fa input.fastq.gz -o output.sam
samtools view -bho output.bam output.sam
samtools sort -o output_srt.bam output.bam
samtools index output_srt.bam
telometer -b output_srt.bam -o output_telLen.tsv

Traceback (most recent call last): File "/home/usr/miniconda3/bin/telometer", line 8, in sys.exit(calculate_telomere_length()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/usr/miniconda3/lib/python3.11/site-packages/telometer/telometer.py", line 115, in calculate_telomere_length read_data_list = [{ ^^ File "/home/usr/miniconda3/lib/python3.11/site-packages/telometer/telometer.py", line 124, in 'reference_length': bam_file.get_reference_length(read.reference_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pysam/libcalignmentfile.pyx", line 1919, in pysam.libcalignmentfile.AlignmentFile.get_reference_length File "pysam/libcalignmentfile.pyx", line 509, in pysam.libcalignmentfile.AlignmentHeader.get_reference_length File "pysam/libcalignmentfile.pyx", line 531, in pysam.libcalignmentfile.AlignmentHeader.get_tid TypeError: expected bytes, NoneType found

@santiago-es

santiago-es commented 1 month ago

It similarly looks like an issue identifying the reference contig name from the reference file.

Could both of you try running telometer on the presorted test bam in test_data

jleehan commented 1 month ago

It similarly looks like an issue identifying the reference contig name from the reference file.

Could both of you try running telometer on the presorted test bam in test_data

The presorted test bam works just fine. @santiago-es

santiago-es commented 1 month ago

Sounds like the issue must come from the reference file then. I would try recreating t2t-and-subtel.fa with cat and faidx again, and if that doesn't work, align to the chm13 reference fa alone. May miss some subtelomere alignments but should still work. I'm away from my computer for a week but when I'm back I'll try recreating the error by rebuilding reference from scratch

jleehan commented 1 month ago

Thanks, I'll give that a shot.

jleehan commented 1 month ago

Sounds like the issue must come from the reference file then. I would try recreating t2t-and-subtel.fa with cat and faidx again, and if that doesn't work, align to the chm13 reference fa alone. May miss some subtelomere alignments but should still work. I'm away from my computer for a week but when I'm back I'll try recreating the error by rebuilding reference from scratch

I attempted both of the bolded solutions and still received the same error.

jleehan commented 1 month ago

@santiago-es looks like the issue may be a python version compatibility issue. I noticed @YonkoBigMom and I were both using the same version of python (3.11) and having issues, while the program was generally working for your other, more recent issue submitter, but they were using version 3.8. I created a new environment in conda with python 3.8 and everything worked just fine.

santiago-es commented 1 month ago

Ahhh, I see. I'm surprised the python version created this error, maybe they changed the variable name for the reference contigs in pysam for the newest python version. This shouldn't be a difficult fix but for now I will add a warning to use python 3.8

jleehan commented 1 month ago

I should also add that I was using telometer v0.75 instead of 0.81 (as mentioned in my other issue report) so that may also have been a contributing factor. I haven't tested telometer 0.81 in python 3.11.

indapa commented 3 weeks ago

FWIW @jleehan, using python 3.11 worked fine with the example bam that comes in the repo for me.

jleehan commented 3 weeks ago

@indapa

It similarly looks like an issue identifying the reference contig name from the reference file. Could both of you try running telometer on the presorted test bam in test_data

The presorted test bam works just fine. @santiago-es

santiago-es commented 2 weeks ago

Checking back in on this, it sounds like you were able to get it to work @jleehan ?

jleehan commented 2 weeks ago

Yes, I've done a couple runs with it so far!

santiago-es commented 2 weeks ago

great! will work on issue in other thread