Skip to content

Commit

Permalink
Merge pull request #29 from monarch-initiative/mapping-flip
Browse files Browse the repository at this point in the history
Changed assumption about direction of replacement in mapping files.
  • Loading branch information
kevinschaper committed Sep 24, 2022
2 parents a95f1c5 + 49c86dd commit 3c5962a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions cat_merge/mapping_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
def apply_mappings(edges: DataFrame, mapping: DataFrame):

edges.rename(columns={'subject':'original_subject'}, inplace=True)
subject_mapping = mapping.rename(columns={'object_id':'subject'})
subject_mapping = subject_mapping[["subject","subject_id"]]
edges = edges.merge(subject_mapping, how='left', left_on='original_subject', right_on='subject_id').drop(['subject_id'],axis=1)
subject_mapping = mapping.rename(columns={'subject_id':'subject'})
subject_mapping = subject_mapping[["subject","object_id"]]
edges = edges.merge(subject_mapping, how='left', left_on='original_subject', right_on='object_id').drop(['object_id'],axis=1)
edges['subject'] = np.where(edges.subject.isnull(), edges.original_subject, edges.subject)
edges['original_subject'] = np.where(edges.subject == edges.original_subject, None, edges.original_subject)

edges.rename(columns={'object':'original_object'}, inplace=True)
object_mapping = mapping.rename(columns={'object_id':'object'})
object_mapping = object_mapping[["object", "subject_id"]]
edges = edges.merge(object_mapping, how='left', left_on='original_object', right_on='subject_id').drop(['subject_id'],axis=1)
object_mapping = mapping.rename(columns={'subject_id':'object'})
object_mapping = object_mapping[["object", "object_id"]]
edges = edges.merge(object_mapping, how='left', left_on='original_object', right_on='object_id').drop(['object_id'],axis=1)
edges['object'] = np.where(edges.object.isnull(), edges.original_object, edges.object)
edges['original_object'] = np.where(edges.object == edges.original_object, None, edges.original_object)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cat-merge"
version = "0.1.15"
version = "0.1.16"
description = ""
authors = [
"Monarch Initiative <info@monarchinitiative.org>",
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_apply_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def edges():
def mapping():
mapping = u"""\
subject_id predicate object_id
XGene:1 skos:exactMatch Gene:1
XGene:2 skos:exactMatch Gene:2
XGene:3 skos:exactMatch Gene:3
XDisease:1 skos:exactMatch Disease:1
XDisease:2 skos:exactMatch Disease:2
XDisease:3 skos:exactMatch Disease:3
XDisease:4 skos:exactMatch Disease:4
Gene:1 skos:exactMatch XGene:1
Gene:2 skos:exactMatch XGene:2
Gene:3 skos:exactMatch XGene:3
Disease:1 skos:exactMatch XDisease:1
Disease:2 skos:exactMatch XDisease:2
Disease:3 skos:exactMatch XDisease:3
Disease:4 skos:exactMatch XDisease:4
"""
return string_df(mapping)

Expand Down

0 comments on commit 3c5962a

Please sign in to comment.