Code Monkey home page Code Monkey logo

ontology-exercise's Introduction

Ontology Mapping Exercise

This repository is a programming exercise whose aim it is to map ontology terms and ids when given an existing ontology file. Documentation will exist in this README, and a Jupyter Notebook within the folder /documentation/ will walk through the whole exerecise. The standalone script is called exercise.py

Original Exercise Prompt

  • The task is to write a script / a set of scripts in Python 3.x that takes an ontology file as an input and provides a table with mappings for each concept to terms from specified ontologies.

The script(s) should do the following steps:

  1. Read in the provided sample turtle file
  2. Load into an appropriate data structure
  3. Extract IDs and Preferred Labels (preferably using SPARQL) from concepts only in the “skin cancer” branch!
  4. For each concept, retrieve mappings (using APIs)
  5. Write the combined result into a tab delimited file, in which you list the mappings you retrieved for the different target ontologies using the different methods. One line per concept. Use ‘;’ for concatenating multiple mappings into one field – if applicable
  • A sample output file could look like this:
Concept PT OLS_mappings OXO_mappings
DOID:162 cancer MeSH:D009369; EFO:0000311 MeSH:D009369; EFO:0000311

How to run exercise.py

This script was run using Anaconda. You will need the same environment to run the script.
Steps to run the script:

  • Install Anaconda for Python 3.8.
  • Then, on the command line run:
    conda env create -f environment.yml
  • Make sure you conda activate the environment you just created
  • Run the python program as usual:
    python exercise.py

Additional info: the package rdfpandas

The pandas package of course has many built-in functions to convert csv and other delimited data to DataFrames. But it does not handle RDF serializations well.

The rdfpandas package addresses this issue by being able to handle Turtle RDF files, which is the file we are using in this exercise.

from rdfpandas.graph import to_dataframe
import pandas as pd
import rdflib

g = rdflib.Graph()
g.parse('to_df_test.ttl', format = 'ttl')
df = to_dataframe(g)
df.to_csv('test.csv', index = True, index_label = "@id")

ontology-exercise's People

Contributors

remerjohnson avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.