Question: Connor Deduplication - AttributeError: 'module' object has no attribute 'AlignmentFile'
0
gravatar for jsneaththompson
9 weeks ago by
jsneaththompson0 wrote:

I'm attempting to use Connor to deduplicate some bam files in my variant calling pipeline, but so far whenever I attempt to run Connor I get the following error message:

2017-07-17 10:32:28|ERROR|An unexpected error occurred
2017-07-17 10:32:28|ERROR|Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/connor/connor.py", line 498, in main
    command_validator.preflight(args, log)
  File "/usr/local/lib/python2.7/dist-packages/connor/command_validator.py", line 190, in preflight
    validate(args, log)
  File "/usr/local/lib/python2.7/dist-packages/connor/command_validator.py", line 76, in _check_input_bam_valid
    bamfile = samtools.alignment_file(args.input_bam, 'rb')
  File "/usr/local/lib/python2.7/dist-packages/connor/samtools.py", line 527, in alignment_file
    return pysam.AlignmentFile(filename, mode, template)
AttributeError: 'module' object has no attribute 'AlignmentFile'

I installed Connor using pip, and have since tried updating pysam (which in turn required installation of liblzma-dev via apt-get), but I'm still getting the same error.

I've also tried using sorted, indexed bam files but that doesn't help either.

If anyone has any suggestions it would be much appreciated.

ADD COMMENTlink written 9 weeks ago by jsneaththompson0

What's your pysam version? It's probably that.

It's possible that Connor imports an older pysam module (while you installed the latest).

ADD REPLYlink written 9 weeks ago by WouterDeCoster21k

According to pip, I'm using v 0.11.2.2

Connor says it requires pysam>=0.8.4,<0.9.1, how would I go about changing the pysam version?

ADD REPLYlink modified 9 weeks ago • written 9 weeks ago by jsneaththompson0

Do you know a bit of Python?

ADD REPLYlink written 9 weeks ago by WouterDeCoster21k

I managed to switch to pysam 0.8.4 with pip, but I'm still getting the same error message when I try to run Connor

ADD REPLYlink written 9 weeks ago by jsneaththompson0

I managed to switch to pysam 0.8.4 with pip

That's insufficient.
Pysam made some changes (I believe around 0.10.0) which make it non-compatible to older versions.

But it's not impossible to fix.

Sooo... do you know a bit of Python?

ADD REPLYlink written 9 weeks ago by WouterDeCoster21k

Ah, fair enough. Yes I know some python.

ADD REPLYlink written 9 weeks ago by jsneaththompson0

Cool. Let's start with checking which version of pysam is used by connor.
Look for the import statement import pysam and add print(pysam.__version__) afterwards.

ADD REPLYlink written 9 weeks ago by WouterDeCoster21k

Connor is using pysam 0.7.5

ADD REPLYlink modified 9 weeks ago • written 9 weeks ago by jsneaththompson0

What a bastard. Okay - so it uses an outdated pysam.
Let's figure out where it comes from. If you just add the following:
print(pysam)
That will tell you the path it used to import from.

Also, let's have a look at your sys.path
import sys
print(sys.path)

That tells the python interpreter where it can get its modules. We'll need to hack it slightly to make sure Connor imports the correct pysam.

ADD REPLYlink modified 9 weeks ago • written 9 weeks ago by WouterDeCoster21k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 653 users visited in the last hour