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

Fix handling chimeric alignments in hicBuildMatrix #151

Merged
merged 3 commits into from
Nov 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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