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

AttributeError: 'array.array' object has no attribute 'tostring' #207

Open
oliverartz opened this issue Jun 20, 2022 · 5 comments
Open

AttributeError: 'array.array' object has no attribute 'tostring' #207

oliverartz opened this issue Jun 20, 2022 · 5 comments

Comments

@oliverartz
Copy link

Dear developer,

I have been trying to simulate some in silico tumors using BAMSurgeon. After installing (check_dependencies.py not throwing any errors) and generating random sites using randomsites.py, I tried introducing SNVs with addsnv.py. I am running the following command

python3 -O /home/artzo/bin/bamsurgeon/bin/addsnv.py \
-v random_SNV_1k.txt \
-f [BAM FILE] \
-r [GENOME FILE] \
-o [OUTPUT FILE] \
--aligner mem \
--picardjar [PATH TO PICARD.JAR] \
--tagreads \
--seed 2010 \
-p 12 \
--insane 

I redacted the file paths in the above command. I got some errors regarding sanity checks, so I decided to use --insane. The script runs for about 20 min generating temporary files and a surprisingly small output BAM. The error.log is rather lengthy (>75k lines) and ends with

INFO 2022-06-20 14:41:34,076 loading donor reads into dictionary...

INFO 2022-06-20 14:41:34,774 secondary reads count:0
INFO 2022-06-20 14:41:34,774 supplementary reads count:0
INFO 2022-06-20 14:41:34,774 loaded 229926 reads, (144 excluded, 0 null or secondary or supplementary--> ignored)

Traceback (most recent call last):
  File "/home/artzo/bin/bamsurgeon/bin/addsnv.py", line 479, in <module>
    run()
  File "/home/artzo/bin/bamsurgeon/bin/addsnv.py", line 476, in run
    main(args)
  File "/home/artzo/bin/bamsurgeon/bin/addsnv.py", line 422, in main
    rr.replace_reads(args.bamFileName, outbam_mutsfile, args.outBamFile, keepqual=True, seed=args.seed)
  File "/lila/home/artzo/bin/bamsurgeon/bin/bamsurgeon/replace_reads.py", line 165, in replace_reads
    rdict[extqname].qual = read.qual
  File "pysam/calignedsegment.pyx", line 2182, in pysam.calignedsegment.AlignedSegment.qual.__get__
  File "pysam/cutils.pyx", line 45, in pysam.cutils.array_to_qualitystring
AttributeError: 'array.array' object has no attribute 'tostring'

I have read that the tostring issue might be due to incompatibilities with Python 3.9 (which I am using). However, tostring was deprecated in Python 3.2 and I find it hard to believe that all other users are using Python < 3.2. So, I was wondering whether a different issue might be at play here. I would greatly appreciate your help!

Thank you very much for the development and support of BAMSurgeon!
Best,
Oliver

@oliverartz
Copy link
Author

I do seem to get a similar error running the test dataset.

python3 -O bin/addsv.py \
-p 1 \
-v test_data/test_sv.txt \
-f test_data/testregion_realign.bam \
-r test_data/Homo_sapiens_chr22_assembly19.fasta \
-o test_data/testregion_sv_mut.bam \
--aligner mem \
--keepsecondary \
--seed 1234 \
--inslib test_data/test_inslib.fa

Results in

INFO 2022-06-21 12:11:49,433 starting bin/addsv.py called with args: bin/addsv.py -p 1 -v test_data/test_sv.txt -f test_data/testregion_realign.bam -r test_data/Homo_sapiens_chr22_assembly19.fasta -o test_data/testregion_sv_mut.bam --aligner mem --keepsecondary --seed 1234 --inslib test_data/test_inslib.fa
INFO 2022-06-21 12:11:49,435 loading insertion library from test_data/test_inslib.fa
WARNING 2022-06-21 12:11:49,452 22 33871043 33884754 DEL 0.75 is over 10kbp long: converting to use BIGDEL instead.
WARNING 2022-06-21 12:11:49,452 22 34071043 34084754 INV 0.5 is over 10kbp long: converting to use BIGINV instead.
WARNING 2022-06-21 12:11:49,452 22 34271043 34284754 DUP 3 0.9 is over 10kbp long: converting to use BIGDUP instead.
WARNING 2022-06-21 12:11:49,453 22 34271043 34284754 DUP 0.9: using BIGDUP requires specifying a --donorbam and none was provided, using test_data/testregion_realign.bam
INFO 2022-06-21 12:11:49,538 22_33609508_33611508_INS interval: 22 33609508 33611508 INS INSLIB:10_9258941_9259251_AluYa5_+ 8
INFO 2022-06-21 12:11:49,538 22_33609508_33611508_INS length: 2000
INFO 2022-06-21 12:11:49,543 22_33609508_33611508_INS discordant fraction: 0.000000
concurrent.futures.process._RemoteTraceback:
"""
Traceback (most recent call last):
  File "/home/artzo/miniconda3/lib/python3.9/concurrent/futures/process.py", line 243, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/lila/home/artzo/bin/bamsurgeon/bin/addsv.py", line 416, in makemut
    contigs = ar.asm(chrom, start, end, args.bamFileName, reffile, int(args.kmersize), args.tmpdir, mutid=mutid, debug=args.debug)
  File "/lila/home/artzo/bin/bamsurgeon/bin/bamsurgeon/asmregion.py", line 193, in asm
    rquals.append(mate.qual)
  File "pysam/calignedsegment.pyx", line 2182, in pysam.calignedsegment.AlignedSegment.qual.__get__
  File "pysam/cutils.pyx", line 45, in pysam.cutils.array_to_qualitystring
AttributeError: 'array.array' object has no attribute 'tostring'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/lila/home/artzo/bin/bamsurgeon/bin/addsv.py", line 1129, in <module>
    main(args)
  File "/lila/home/artzo/bin/bamsurgeon/bin/addsv.py", line 957, in main
    tmpbam, exclfn, mutinfo = result.result()
  File "/home/artzo/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 446, in result
    return self.__get_result()
  File "/home/artzo/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
AttributeError: 'array.array' object has no attribute 'tostring'
INFO 2022-06-21 12:11:49,561 22_34171055_34173700_INS interval: 22 34171055 34173700 INS ACTAACCTGCACAATGTGCACATGTACCCTAAAACTTAGAGTATAATAAAAAAAA 13 AA^TTTT 0.8
INFO 2022-06-21 12:11:49,562 22_34171055_34173700_INS length: 2645
INFO 2022-06-21 12:11:49,568 22_34171055_34173700_INS discordant fraction: 0.000000
INFO 2022-06-21 12:11:49,580 22_33607508_33607508_TRN interval: 22 33607508 33607508 TRN 22 34314981 34314981 ++ 1.0
INFO 2022-06-21 12:11:49,581 22_33607508_33607508_TRN length: 8000
INFO 2022-06-21 12:11:49,584 22_33607508_33607508_TRN discordant fraction: 0.000000
INFO 2022-06-21 12:11:49,593 22_33871043_33871043_BIGDEL interval: 22 33871043 33871043 BIGDEL 22 33884754 33884754 ++ 0.750000
INFO 2022-06-21 12:11:49,593 22_33871043_33871043_BIGDEL length: 8000
INFO 2022-06-21 12:11:49,597 22_33871043_33871043_BIGDEL discordant fraction: 0.000000
INFO 2022-06-21 12:11:49,608 22_33891043_33891043_BIGDEL interval: 22 33891043 33891043 BIGDEL 22 33902689 33902689 ++ 0.500000
INFO 2022-06-21 12:11:49,608 22_33891043_33891043_BIGDEL length: 8000
INFO 2022-06-21 12:11:49,613 22_33891043_33891043_BIGDEL discordant fraction: 0.000000
INFO 2022-06-21 12:11:49,627 22_34071043_34071043_BIGINV interval: 22 34071043 34071043 BIGINV 22 34084754 34084754 +- 0.500000
INFO 2022-06-21 12:11:49,627 22_34071043_34071043_BIGINV length: 8000
INFO 2022-06-21 12:11:49,632 22_34071043_34071043_BIGINV discordant fraction: 0.000000
INFO 2022-06-21 12:11:49,646 22_34071043_34071043_BIGINV interval: 22 34071043 34071043 BIGINV 22 34084754 34084754 -+ 0.500000
INFO 2022-06-21 12:11:49,646 22_34071043_34071043_BIGINV length: 8000
INFO 2022-06-21 12:11:49,651 22_34071043_34071043_BIGINV discordant fraction: 0.000000
INFO 2022-06-21 12:11:49,669 22_34284754_34284754_BIGDUP interval: 22 34284754 34284754 BIGDUP 22 34271043 34271043 ++ 1.000000
INFO 2022-06-21 12:11:49,669 22_34284754_34284754_BIGDUP length: 8000
INFO 2022-06-21 12:11:49,674 22_34284754_34284754_BIGDUP discordant fraction: 0.000000

Again, I am seeing the tostring issue popping up. I feel like I am missing something obvious since the issue was not reported before. Thanks for your help!

Oliver

@ZSJSL
Copy link

ZSJSL commented Jun 23, 2022

Did you solve your problem? I had the same problem

@adamewing
Copy link
Owner

Hi, sorry for the delay. My initial suspicion is that this is an issue with pysam - could you let me know which version of pysam you are using (echo "import pysam; print(pysam.__version__)" | python) and which version of python (appears to be 3.9 but please double check). Thanks.

@oliverartz
Copy link
Author

Thanks for getting back to me.
python3 --version prints Python 3.9.12
echo "import pysam; print(pysam.__version__)" | python prints 0.9.1.
I have tried updating pysam using conda and mamba (following instructions on https://pysam.readthedocs.io/en/latest/installation.html), but that didn't solve it.

@Rapsssito
Copy link
Collaborator

@oliverartz, I strongly recommend that you update pysam to at least version 0.18.0. It should fix your issue.

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