-
Notifications
You must be signed in to change notification settings - Fork 24
Add query to ref coord mapping #120
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| ) | ||
| QUERY_OPS = np.array([True, True, False, False, True, False, False, True, True]) | ||
| REF_OPS = np.array([True, False, True, True, False, False, False, True, True]) | ||
| REFCOORD_OPS = np.array([True, False, True, False, False, False, False, True, True]) | ||
| CIGAR_CODES = ["M", "I", "D", "N", "S", "H", "P", "=", "X"] | ||
| CODE_TO_OP = { | ||
| "M": 0, | ||
|
|
@@ -98,11 +99,28 @@ def make_sequence_coordinate_mapping(cigar): | |
| query_knots = np.concatenate( | ||
| [[0], (query_knots[is_match] - offsets).T.flatten(), [query_knots[-1]]] | ||
| ) | ||
| knots = np.interp(np.arange(ref_knots[-1] + 1), ref_knots, query_knots) | ||
| ref_coords = get_ref_coords(ops, lens) | ||
| knots = np.interp(np.concatenate([[0], ref_coords]), ref_knots, query_knots) | ||
|
|
||
| return knots | ||
|
|
||
|
|
||
| def get_ref_coords(ops, lens): | ||
| ''' | ||
| Map query base to reference coordinates (1-based). | ||
| Returns | ||
| array shape (ref_len,); ref_len = len(aln.get_reference_sequences()) | ||
| ''' | ||
| starts = np.cumsum(np.where(REF_OPS[ops], lens, 0)) - np.where(REF_OPS[ops], lens, 0) | ||
| ranges = [ | ||
| np.arange(start, start + l) | ||
| for op, start, l in zip(ops, starts, lens) | ||
| if REFCOORD_OPS[op] | ||
| ] | ||
| ref_coords = np.concatenate(ranges) + 1 | ||
|
||
| return ref_coords | ||
|
|
||
|
|
||
| def compute_ref_to_signal(query_to_signal, cigar): | ||
| ref_to_read_knots = make_sequence_coordinate_mapping(cigar) | ||
| assert query_to_signal.size == ref_to_read_knots[-1].astype(int) + 1, ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dumb version of this function is: