Menu

AttributeError: 'pysam.csamfile.Samfile' object has no attribute '_hasIndex'

2015-11-25
2018-06-06
  • David Stanek

    David Stanek - 2015-11-25

    Hello,
    you made very good tool, I am new user of CoNIFER and I try to run conifer.py rpkm. When I try call this:
    python conifer.py rpkm --probes rpkm/probes.txt --input rpkm/sample1667.sorted.bam --output rpkm/1998.rpkm.txt
    I will get this error:

    [INIT] Successfully read in 194080 probes from rpkm/probes.txt
    [RUNNING] Counting total number of reads in bam file...
    [RUNNING] Found 751008 reads
    Traceback (most recent call last):
      File "conifer.py", line 682, in <module>
        args.func(args)
      File "conifer.py", line 564, in CF_bam2RPKM
        if not f._hasIndex():
    AttributeError: 'pysam.csamfile.Samfile' object has no attribute '_hasIndex'
    

    I also tried other way, with calling bai file as was mentioned in pysam.SamtoolsError: 'csamtools returned with error 1: ' thread, but then I have this error:

    lab@VBdna:~/galaxy-Win-Lin/David/conifer/conifer_v0.2.2$ sudo python conifer.py rpkm --probes rpkm/probes.txt --input rpkm/sample1667.sorted.bam.bai --output rpkm/1998.rpkm.txt
    [INIT] Successfully read in 194080 probes from rpkm/probes.txt
    [RUNNING] Counting total number of reads in bam file...
    [E::hts_hopen] fail to open file 'rpkm/sample1667.sorted.bam.bai'
    [E::hts_open] fail to open file 'rpkm/sample1667.sorted.bam.bai'
    Traceback (most recent call last):
      File "conifer.py", line 682, in <module>
        args.func(args)
      File "conifer.py", line 559, in CF_bam2RPKM
        total_reads = float(pysam.view("-c", args.input[0])[0].strip("\n"))
      File "/usr/local/lib/python2.7/dist-packages/pysam/__init__.py", line 79, in __call__
        (retval, "\n".join(stderr)))
    pysam.SamtoolsError: 'csamtools returned with error 1: '
    

    In my folder I have three files - sample1667.sorted.bam, sample1667.sorted.bam.bai, sample1667.sorted.bam.tdf
    What should I do to get .hdf5 file properly?

    Thank you

    Sincerely

    David S.

     

    Last edit: David Stanek 2015-11-25
  • Stuart Tompson

    Stuart Tompson - 2016-02-02

    I'm having the same problem too. Still no fix?

    python conifer.py rpkm \
    --probes probes.txt \ --input Bam_Files/1249TLY0003.bam \ --output rpkm_files/1249TLY0003.rpkm.txt
    [INIT] Successfully read in 194080 probes from probes.txt
    [RUNNING] Counting total number of reads in bam file...
    [RUNNING] Found 209170362 reads
    Traceback (most recent call last):
    File "conifer.py", line 682, in <module>
    args.func(args)
    File "conifer.py", line 564, in CF_bam2RPKM
    if not f._hasIndex():
    AttributeError: 'pysam.csamfile.Samfile' object has no attribute '_hasIndex'

    I'm using Ubuntu 14.04 LTS.

    Hope help comes soon!

     
  • simonzee

    simonzee - 2016-04-28

    It's a very simple fix. Just change line 564 of conifer.py from:

    if not f._hasIndex():
    

    to

    if not f.has_index():
    

    Then it should work.

     
  • Tim Webster

    Tim Webster - 2016-06-03

    Hi all,

    I ran into the same issue and simonzee's suggestion didn't work for me. I did, however, come across this discussion of another program with the same Pysam error: https://github.com/hammerlab/varlens/issues/1

    Their suggestion of downgrading Pysam to version 0.8.3 solved this problem for me.

    Cheers,
    Tim

     
  • Damian Loska

    Damian Loska - 2018-06-06

    this code is as old as greek's piramides.
    now it should be f.check_index()

     

Log in to post a comment.