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

[ENH] Allow label exclusion in remove_distance() #27

Merged
merged 2 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion abagen/correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def remove_distance(coexpression, atlas, atlas_info=None, labels=None):
# load atlas_info, if provided
atlas = check_niimg_3d(atlas)
if atlas_info is not None:
atlas_info = utils.check_atlas_info(atlas, atlas_info)
atlas_info = utils.check_atlas_info(atlas, atlas_info,
labels_of_interest=labels)

# check that provided coexpression array is symmetric
check_symmetric(coexpression, raise_exception=True)
Expand Down
9 changes: 9 additions & 0 deletions abagen/tests/test_correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def test_remove_distance(donor_expression):
assert np.allclose(out, out.T)
assert isinstance(out, np.ndarray)

# subset expression data + and atlas_info
coexpr = np.corrcoef(expr.iloc[:-1])
removed_label = pd.read_csv(atlas_info).iloc[:-1]
out = correct.remove_distance(coexpr, ATLAS.image, removed_label,
labels=removed_label.id)
assert np.allclose(out, out.T)
assert isinstance(out, np.ndarray)
assert len(out) == len(removed_label)

with pytest.raises(ValueError):
correct.remove_distance(expr, ATLAS.image, ATLAS.info)

Expand Down
11 changes: 9 additions & 2 deletions abagen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)


def check_atlas_info(atlas, atlas_info):
def check_atlas_info(atlas, atlas_info, labels_of_interest=None):
"""
Checks whether provided `info` on `atlas` is sufficient for processing

Expand All @@ -29,6 +29,9 @@ def check_atlas_info(atlas, atlas_info):
'structure' containing information mapping atlas IDs to hemisphere and
broad structural class (i.e., "cortex", "subcortex", "cerebellum").
Default: None
labels_of_interest : array_like, optional
List of values containing labels to compare between `atlas` and
`atlas_info`, if they don't all match. Default: None

Returns
-------
Expand All @@ -54,7 +57,11 @@ def check_atlas_info(atlas, atlas_info):
if 'id' in atlas_info.columns:
atlas_info = atlas_info.set_index('id')

ids = get_unique_labels(atlas)
if labels_of_interest is None:
ids = get_unique_labels(atlas)
else:
ids = labels_of_interest

cols = ['hemisphere', 'structure']
try:
assert all(c in atlas_info.columns for c in cols)
Expand Down