Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculate_telomere_length error #2

Closed
YonkoBigMom opened this issue Jul 25, 2024 · 18 comments
Closed

calculate_telomere_length error #2

YonkoBigMom opened this issue Jul 25, 2024 · 18 comments

Comments

@YonkoBigMom
Copy link

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
Copy link
Owner

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
Copy link
Author

YonkoBigMom commented Jul 25, 2024

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
Copy link
Owner

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

@YonkoBigMom
Copy link
Author

I will do this and report back.

@jleehan
Copy link

jleehan commented Jul 26, 2024

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
Copy link
Owner

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
Copy link

jleehan commented Jul 29, 2024

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
Copy link
Owner

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
Copy link

jleehan commented Jul 29, 2024

Thanks, I'll give that a shot.

@jleehan
Copy link

jleehan commented Jul 29, 2024

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
Copy link

jleehan commented Aug 5, 2024

@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
Copy link
Owner

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
Copy link

jleehan commented Aug 5, 2024

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
Copy link

indapa commented Aug 16, 2024

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

@jleehan
Copy link

jleehan commented Aug 16, 2024

@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
Copy link
Owner

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

@jleehan
Copy link

jleehan commented Aug 20, 2024

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

@santiago-es
Copy link
Owner

great! will work on issue in other thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants