phasegenomics / hic_qc

A (very) simple script to QC Hi-C data.
GNU Affero General Public License v3.0
25 stars 5 forks source link

AttributeError: 'dict' object has no attribute 'references' #47

Closed aakashsur closed 5 years ago

aakashsur commented 5 years ago

I encountered the following error:

Traceback (most recent call last):
  File "/path/hic_qc/hic_qc.py", line 1182, in <module>
    QC.parse_bam(args.bam_file, max_read_pairs=args.num_reads)
  File "/path/hic_qc/hic_qc.py", line 235, in parse_bam
    self.extract_header_info(bam_fh.header)
  File "/path/hic_qc/hic_qc.py", line 285, in extract_header_info
    self.refs = header.references
AttributeError: 'dict' object has no attribute 'references'

Which traces back to: https://github.com/phasegenomics/hic_qc/blob/1e132fb24fefbe4f27484a4ef35b281b892dcd06/hic_qc.py#L285

Changing line 285 to:

self.refs = header['SQ']

appears to remedy the issue.

shawnpg commented 5 years ago

What version of pysam do you have installed? We are currently using 0.15.3 with this code and it seems to work. header is the result of calling pysam.AlignmentFile.header, which is a supported API into the object in the version we are using. We'd prefer to keep using the API if it's compatible with the current version of pysam to avoid interrogating its internal data structures directly.

aakashsur commented 5 years ago

Looks like that was it, I was in a slurm environment and loading one of the modules switched my python (rude!) which had pysam==0.8.4. Using the latest pysam changes the header format and works as written.