dayzerodx / counterr

GNU General Public License v3.0
30 stars 4 forks source link

unsupported operand type error #6

Open dcopetti opened 4 years ago

dcopetti commented 4 years ago

Hello,

I am running counterr to check the accuracy of ONT error-corrected reads as follows: $ counterr -bam NecatEC_to_ref.bam -genome ../reference.fa -output_dir CMS281_Necat_to_p3 -lim 1000 -mapq_thres 10 and I get this error:

The output directory does not exist. Creating one.
Traceback (most recent call last):
  File "/home/copettid/anaconda3/envs/py36/bin/counterr", line 12, in <module>
    sys.exit(main())
  File "/home/copettid/anaconda3/envs/py36/lib/python3.6/site-packages/counterr/counterr.py", line 105, in main
    means_in, stds_in, lens_in, means_out, stds_out, lens_out = mapQ_stats_aligned_readsegment(reads_pass, verbose=verbose)
  File "/home/copettid/anaconda3/envs/py36/lib/python3.6/site-packages/counterr/counters.py", line 95, in mapQ_stats_aligned_readsegment
    means_in.append(np.mean(Q_in))
  File "<__array_function__ internals>", line 6, in mean
  File "/home/copettid/anaconda3/envs/py36/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 3257, in mean
    out=out, **kwargs)
  File "/home/copettid/anaconda3/envs/py36/lib/python3.6/site-packages/numpy/core/_methods.py", line 163, in _mean
    ret = ret / rcount
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

This is how the output folder looks like:

-rwx------. 1 copettid mpb 5.2K Jan 31 17:56 CMS281_Necat_to_p3/report.pdf

CMS281_Necat_to_p3/stats:
total 0

CMS281_Necat_to_p3/figures:
total 3.0M
-rwx------. 1 copettid mpb 86K Jan 31 17:56 per_read_Q_mean_med_pass_vs_fail.png
-rwx------. 1 copettid mpb 82K Jan 31 17:56 per_read_Q_pass_fail_mean_vs_med.png
-rwx------. 1 copettid mpb 31K Jan 31 17:56 per_read_Q_pass_fail_mean_vs_std.png

The pdf file is corrupted and two of the three figures have all failed reads per_read_Q_pass_fail_mean_vs_med

The bam file was generated with minimap2, then filtered to remove unmapped, multimapped, and reads with supplementary alignments (samtools view -F 2052 -F 256).

I wonder if it is an issue with the tool/installation or the dataset. Thanks,

Dario

thomasculp commented 4 years ago

Thanks for bringing this up. I also had a similar problem recently, which I found strange because I did have counterr working previously.

The source of the error is the query_alignment_qualities attribute of the pysam.AlignedSegment object, which is part of pysam. query_alignment_qualities is None when there are no alignment qualities. However, I don't believe this is correct on the part of pysam. When I look at the SAM file for my alignments, I can find the mapping qualities column just fine, but when I use

import pysam
f = pysam.AlignmentFile('ont-1.bam')
reads = f.fetch()
not_none = 0
for aln in reads:
    if aln.query_alignment_qualities is not None:
        not_none += 1

not_none is 0. Not sure why that's happening.

Regardless, this should be fixed so the program doesn't altogether crash. I've created PR #7 to fix this issue, and it was just merged into master.

Keep in mind that this means that anything computed having to do with qualities won't be accurate if it's the case for you (as it is with me) that pysam continues with this errant behavior. Sorry if what you were looking for was information on quality scores, but you should now be able to see all of the other plots that counterr produces.