Skip to content

Commit

Permalink
Fix the assignment of multiple quantification window coordinates (#38) (
Browse files Browse the repository at this point in the history
pinellolab#403)

* Mckay/pd warnings (#45)

* refactor errors='ignore' to try except

* refactored integer slice to iloc[]

* moved to_numeric try except to function

* Refactor to_numeric_ignore_errors to to_numeric_ignore_columns

This change is slightly cleaner because it addresses the root issue that some
columns are strings (and can therefore not be converted to numeric types). Now
if an error does occur when converting the dfs to numeric types it won't be
swallowed up.

* Add documentation to to_numeric_ignore_columns

---------

* Extract out quantification window coordinate function

* Refactor get_quant_window_coordinates function into two

The rationale behind this is that the behavior around the cloned amplicon is
quite different than if the qwc are specified directly for the amplicon.

* Handling qwc: add unit tests, refactor some more and add documentation

* Extract out get_relative_coordinates function

This function just computes the relative indexes without doing an alignment.

* Add clarifying unit tests for `get_relative_coordinates`

* Refactor cloned indexes to use ref_positions instead of s1inds

* fixed function for getting cloned qwc idxs

* added tests for cloned qwc function

* Introduce pandas sorting in CRISPRessoCompare (#47)

* Fix interleaved fastq input in CRISPRessoPooled and suppress CRISPRessoWGS params (#42)

* Extract out split_interleaved_fastq function to CRISPRessoShared

* Implement splitting interleaved fastq files in CRISPRessoPooled

* Suppress split_interleaved_input from CRISPRessoWGS parameters

* Suppress other parameters in CRISPRessoWGS

* Move where interleaved fastq files are split to be trimmed properly

* Bug Fix - 367 (#35)

* - Fixed references to ref_names_for_pe

* removed extra tabs

* trying to match empty line, no tabs

* - changed references to ref_names[0]

* Mckay/pd warnings (#45)

* refactor errors='ignore' to try except

* refactored integer slice to iloc[]

* moved to_numeric try except to function

* Refactor to_numeric_ignore_errors to to_numeric_ignore_columns

This change is slightly cleaner because it addresses the root issue that some
columns are strings (and can therefore not be converted to numeric types). Now
if an error does occur when converting the dfs to numeric types it won't be
swallowed up.

* Add documentation to to_numeric_ignore_columns

---------

---------

* removed if check

* implemented last test

* changed NT to BadParameterException

* changed tests, NT to BadParameter exceptions

* Uncomment and correct tests for `get_relative_coordinates`

* finished qwc tests

* 0 is an acceptable qwc

* new get_relative_coords function

* added relative coordinate tests

* removed unused functions

* formatting

* check for 0 qwc

* remove test code

* remove comment

* Move read filtering to after merging in CRISPResso (#39)

* Move read filtering to after merging

This is in an effort to be consistent with the behavior and results of
CRISPRessoPooled.

* Properly assign the correct file names for read filtering

* Add space around operators

* GitHub actions on pr (#51)

* Run integration tests on pull_request

* Run pytest on pull_request

* Run pylint on pull_request

* Run tests on PR only when opening PR (#53)

* Update reports (#52)

* Update report changes

* Switch branch of integration test repo

* Remove extraneous `crispresso_data_path`

* Point integration tests back to master

---------

Co-authored-by: mbowcut2 <[email protected]>
Co-authored-by: McKay <[email protected]>
Co-authored-by: Samuel Nichols <[email protected]>
  • Loading branch information
4 people committed Nov 8, 2024
1 parent b772568 commit 7763265
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
22 changes: 8 additions & 14 deletions CRISPResso2/CRISPRessoCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def get_cloned_include_idxs_from_quant_window_coordinates(quant_window_coordinat
idxs[i] = -1 * abs(idxs[i])
for coord in split_quant_window_coordinates(quant_window_coordinates):
include_idxs.extend(idxs[coord[0]:coord[1] + 1])

return list(filter(lambda x: x >= 0, include_idxs))


Expand Down Expand Up @@ -2205,21 +2205,15 @@ def get_prime_editing_guides(this_amp_seq, this_amp_name, ref0_seq, prime_edited
refs[ref_name]['contains_guide'] = refs[clone_ref_name]['contains_guide']

#quantification window coordinates override other options
if amplicon_quant_window_coordinates_arr[clone_ref_idx] != "":
if amplicon_quant_window_coordinates_arr[clone_ref_idx] != "" and amplicon_quant_window_coordinates_arr[this_ref_idx] != '0':
if amplicon_quant_window_coordinates_arr[this_ref_idx] != "":
this_quant_window_coordinates = amplicon_quant_window_coordinates_arr[this_ref_idx]
this_include_idxs = get_include_idxs_from_quant_window_coordinates(amplicon_quant_window_coordinates_arr[this_ref_idx])
else:
this_quant_window_coordinates = amplicon_quant_window_coordinates_arr[clone_ref_idx]
this_include_idxs = []
these_coords = this_quant_window_coordinates.split("_")
for coord in these_coords:
coordRE = re.match(r'^(\d+)-(\d+)$', coord)
if coordRE:
start = s1inds[int(coordRE.group(1))]
end = s1inds[int(coordRE.group(2)) + 1]
this_include_idxs.extend(range(start, end))
else:
raise NTException("Cannot parse analysis window coordinate '" + str(coord))
this_include_idxs = get_cloned_include_idxs_from_quant_window_coordinates(
amplicon_quant_window_coordinates_arr[clone_ref_idx],
s1inds.copy(),
)

#subtract any indices in 'exclude_idxs' -- e.g. in case some of the cloned include_idxs were near the read ends (excluded)
this_exclude_idxs = sorted(list(set(refs[ref_name]['exclude_idxs'])))
this_include_idxs = sorted(list(set(np.setdiff1d(this_include_idxs, this_exclude_idxs))))
Expand Down
42 changes: 41 additions & 1 deletion CRISPResso2/CRISPRessoShared.py
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,47 @@ def set_guide_array(vals, guides, property_name):
for idx, val in enumerate(vals_array):
if val != '':
ret_array[idx] = int(val)
return ret_array
return ret_array
def get_relative_coordinates(to_sequence, from_sequence):
"""Given an alignment, get the relative coordinates of the second sequence to the first.

For example, from_sequence[i] matches to to_sequence[inds[i]]. A `-1`
indicates a gap at the beginning of `to_sequence`.

Parameters
----------
to_sequence : str
The alignment of the first sequence (where the coordinates are relative to)
from_sequence : str
The alignment of the second sequence

Returns
-------
s1inds_gap_left : list of int
The relative coordinates of the second sequence to the first, where gaps
in the first sequence are filled with the left value.
s1inds_gap_right : list of int
The relative coordinates of the second sequence to the first, where gaps
in the first sequence are filled with the right value.
"""
s1inds_gap_left = []
s1inds_gap_right = []
s1idx_left = -1
s1idx_right = 0
s2idx = -1
for ix in range(len(to_sequence)):
if to_sequence[ix] != "-":
s1idx_left += 1
if from_sequence[ix] != "-":
s2idx += 1
s1inds_gap_left.append(s1idx_left)
s1inds_gap_right.append(s1idx_right)
if to_sequence[ix] != "-":
s1idx_right += 1
return s1inds_gap_left, s1inds_gap_right
def get_relative_coordinates(to_sequence, from_sequence):
Expand Down

0 comments on commit 7763265

Please sign in to comment.