Skip to content

Commit

Permalink
Merge pull request #151 from ajank/master
Browse files Browse the repository at this point in the history
Fix handling chimeric alignments in hicBuildMatrix
  • Loading branch information
fidelram authored Nov 24, 2017
2 parents 1d629d3 + d294956 commit 2f54528
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hicexplorer/hicBuildMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
from os import unlink
import os
import itertools

import pysam
from six.moves import xrange
Expand Down Expand Up @@ -475,7 +476,7 @@ def get_supplementary_alignment(read, pysam_obj):
supplementary_alignment = []
for i in range(len(other_alignments)):
_sup = pysam_obj.next()
if _sup.is_supplementary and _sup.qname == read.qname:
if _sup.qname == read.qname:
supplementary_alignment.append(_sup)

return supplementary_alignment
Expand Down Expand Up @@ -529,8 +530,11 @@ def get_correct_map(primary, supplement_list):
else:
cigartuples = read.cigartuples[:]

# For each read in read_list, calculate the position of the first match (operation M in CIGAR string) in the read sequence.
# The calculation is done by adding up the lengths of all the operations until the first match.
# CIGAR string is a list of tuples of (operation, length). Match is stored as CMATCH.
first_mapped.append(
[x for x, cig in enumerate(cigartuples) if cig[0] == 0][0])
sum(count for op, count in itertools.takewhile(lambda (op, count): op != pysam.CMATCH, cigartuples)))
# find which read has a cigar string that maps first than any of the
# others.
idx_min = first_mapped.index(min(first_mapped))
Expand Down

0 comments on commit 2f54528

Please sign in to comment.