Skip to content

Commit

Permalink
Merge pull request #144 from gymreklab/develop
Browse files Browse the repository at this point in the history
Fix bug #143
  • Loading branch information
gymreklab authored Oct 21, 2021
2 parents 893c4de + 83421e1 commit eac7523
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
8 changes: 8 additions & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
4.0.1
-----

Bug fixes:

* https://github.com/gymreklab/TRTools/issues/143 Fix HipstrMinSuppReads filter when
there are called samples but none have ALLREADS

4.0.0
-----

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
curdir = os.path.abspath(os.path.dirname(__file__))
MAJ = 4
MIN = 0
REV = 0
REV = 1
VERSION = '%d.%d.%d' % (MAJ, MIN, REV)
with open(os.path.join(curdir, 'trtools/version.py'), 'w') as fout:
fout.write(
Expand Down
20 changes: 16 additions & 4 deletions trtools/dumpSTR/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,27 @@ def __call__(self, record: trh.TRRecord):
return np.full((record.GetNumSamples()), np.nan)

if "ALLREADS" not in record.format:
sample_filter = np.zeros((record.GetNumSamples()), dtype=float)
return sample_filter
return np.zeros((record.GetNumSamples()), dtype=float)
samples_to_check = (called_samples &
(record.format["ALLREADS"] != '') &
(record.format["ALLREADS"] != '.'))

delim = "|"
if not np.any(samples_to_check):
# all samples were either not called or were missing ALLREADS
# say that we filtered all the samples which were missing ALLREADS
sample_filter = np.full((record.GetNumSamples()), np.nan)
sample_filter[called_samples] = 0
return sample_filter

# Going to assume that either all samples are phased or none are
if "/" in record.format["GB"][samples_to_check][0]: delim = "/"
first_gb = record.format["GB"][samples_to_check][0]
if "/" in first_gb:
delim = "/"
elif "|" in first_gb:
delim = '|'
else:
raise ValueError("Cant't identify phasing char ('|' or '/') in GB field")

gb = np.char.split(record.format["GB"][samples_to_check], delim)
gb = np.stack(gb).astype(int)
# Format allreads like a python dict literal so we can interpret it
Expand Down
32 changes: 28 additions & 4 deletions trtools/dumpSTR/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ class TestRec(DummyRecBase):
def __init__(self):
super().__init__()
self.format['ALLREADS'] = np.array([
'0|23;1|123;2|5', '0|165;1|23;2|7',
'0|23;1|123;2|5', '0|15;1|23;2|7',
'0|23;1|444;2|12', '0|23;1|32;2|66',
'0|867;1|23;2|13', '0|848;1|92;2|483',
'', '', '.'])
self.format['GB'] = np.array(['1|1', '1|1', '0|2', '0|2', '0|2',
'0|2', '', '', '.'])
self.format['GB'] = np.array(['1|1', '1|1', '1|2', '2|1', '2|0',
'0|2', '1|1', '0|0', '1|0'])
def GetNumSamples(self):
return 9
def GetCalledSamples(self):
Expand All @@ -330,13 +330,37 @@ def GetCalledSamples(self):
assert np.isnan(out[0])
assert out[1] == 23
assert out[2] == 12
assert out[3] == 23
assert out[3] == 32
assert out[4] == 13
assert np.isnan(out[5])
assert out[6] == 0 # If ALLREADS is missing, filter
assert np.isnan(out[7]) # don't apply filter to nocalls
assert np.isnan(out[8]) # don't apply filter to nocalls

def test_HipstrMinSuppReads_no_called_samples_with_reads(tmpdir):
class TestRec(DummyRecBase):
def __init__(self):
super().__init__()
self.format['ALLREADS'] = np.array([
'0|23;1|123;2|5', '0|15;1|23;2|7',
'0|23;1|444;2|12', '0|23;1|32;2|66',
'0|867;1|23;2|13', '0|848;1|92;2|483',
'', '', '.'])
self.format['GB'] = np.array(['1|1', '1|1', '1|2', '2|1', '2|0',
'0|2', '1|1', '0|0', '1|0'])
def GetNumSamples(self):
return 9
def GetCalledSamples(self):
return np.array([False, False, False, False, False, False, True, False, True])

args = base_argparse(tmpdir)
args.hipstr_min_supp_reads = 50
call_filters = BuildCallFilters(args)
assert len(call_filters) == 1
out = call_filters[0](TestRec())
assert out.shape == (9,)
assert np.all(out[[6,8]] == 0)
assert np.all(np.isnan(out[[0,1,2,3,4,5,7]]))

def test_HipstrDP(tmpdir):
class TestRec(DummyRecBase):
Expand Down
2 changes: 1 addition & 1 deletion trtools/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# THIS FILE IS GENERATED FROM SETUP.PY
version = '4.0.0'
version = '4.0.1'
__version__ = version

0 comments on commit eac7523

Please sign in to comment.