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

Add predicted WikiPathways orthologs #59

Merged
merged 6 commits into from
May 23, 2022
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
57 changes: 57 additions & 0 deletions scripts/generate_wikipathways_orthologs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-

"""Generate orthologous relations between WikiPathways."""

import itertools as itt
from typing import Iterable

import pyobo
from gilda.process import normalize
from tqdm import tqdm

from biomappings.resources import PredictionTuple, append_prediction_tuples
from biomappings.utils import get_script_url


def _lexical_exact_match(name1: str, name2: str) -> bool:
return normalize(name1) == normalize(name2)


def iterate_orthologous_lexical_matches(prefix: str = "wikipathways") -> Iterable[PredictionTuple]:
"""Generate orthologous relations between lexical matches from different species."""
names = pyobo.get_id_name_mapping(prefix)
species = pyobo.get_id_species_mapping(prefix)
provenance = get_script_url(__file__)

count = 0
it = itt.combinations(sorted(names.items()), 2)
it = tqdm(
it,
unit_scale=True,
unit="pair",
total=len(names) * (len(names) - 1) / 2,
)
for (source_id, source_name), (target_id, target_name) in sorted(it):
source_species = species[source_id]
target_species = species[target_id]
if source_species == target_species:
continue
if _lexical_exact_match(source_name, target_name):
count += 1
yield PredictionTuple(
prefix,
source_id,
source_name,
"RO:HOM0000017",
prefix,
target_id,
target_name,
"lexical",
0.95,
provenance,
)
tqdm.write(f"Identified {count:,} orthologs")


if __name__ == "__main__":
append_prediction_tuples(iterate_orthologous_lexical_matches())
Loading