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

Implement metanetx service #1

Merged
merged 45 commits into from
Jun 25, 2019
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8816dfe
chore: update notification token
kvikshaug Jun 6, 2019
c3f154b
chore: update deployment, remove staging env
kvikshaug Jun 6, 2019
07495e4
docs: remove post-cookiecutter steps from docs
kvikshaug Jun 6, 2019
b0be905
docs: update description
kvikshaug Jun 6, 2019
96455e0
refactor: update import
kvikshaug Jun 6, 2019
5817005
docs: remove devel badges
kvikshaug Jun 6, 2019
348639c
feat: read metanetx source data into memory
kvikshaug Jun 6, 2019
4c91ef3
chore: allow all origins as this is a stateless service
kvikshaug Jun 6, 2019
edc57f2
feat: create initial reaction resource
kvikshaug Jun 6, 2019
714a5b4
feat: read metanetx files from external storage
kvikshaug Jun 7, 2019
6dd1cf8
chore: support older docker-compose versions
kvikshaug Jun 7, 2019
0b1b609
style: remove unused import
kvikshaug Jun 7, 2019
54d7211
test: remove test for unused endpoint
kvikshaug Jun 7, 2019
3100b8b
refactor: replace named tuples with classes
kvikshaug Jun 11, 2019
eb6520b
chore: deploy devel branch
kvikshaug Jun 11, 2019
7bb68b3
feat: include metabolite and compartment objects in response
kvikshaug Jun 11, 2019
bc23df8
feat: read cross-references
kvikshaug Jun 11, 2019
75f0228
refactor: move logic to ignore commented lines
kvikshaug Jun 11, 2019
25defe2
feat: add cross-reference annotations
kvikshaug Jun 11, 2019
4314026
feat: cache parsed equation as property
kvikshaug Jun 11, 2019
0432880
feat: include equation in string and parsed form
kvikshaug Jun 11, 2019
a6d5475
style: run black
kvikshaug Jun 11, 2019
19bcd47
style: flake8
kvikshaug Jun 11, 2019
7619d6c
style: sort imports
kvikshaug Jun 11, 2019
889d0e7
fix: handle fractional coefficients
kvikshaug Jun 11, 2019
182d05c
chore: add script to generate reaction names
kvikshaug Jun 11, 2019
c7ad745
docs: document reaction names
kvikshaug Jun 11, 2019
edfbdff
feat: read reaction names
kvikshaug Jun 12, 2019
f43dc66
feat: include reaction name in response
kvikshaug Jun 12, 2019
6c85d27
chore: add fuzzywuzzy dependency
kvikshaug Jun 12, 2019
08f50cb
feat: fuzzy search on id, name and ec fields
kvikshaug Jun 12, 2019
0989a20
refactor: generic search schema
kvikshaug Jun 12, 2019
6c61f5f
feat: metabolite search
kvikshaug Jun 12, 2019
53a8709
chore: ignore W503
kvikshaug Jun 12, 2019
1f8a74d
refactor: rename field `description` => `name`
kvikshaug Jun 13, 2019
2316331
refactor: use csv.DictReader to parse column names
kvikshaug Jun 13, 2019
0d447c3
feat: compare reaction name with "best partial" heuristic
kvikshaug Jun 17, 2019
41aabfd
refactor: parse all reaction equations on init
kvikshaug Jun 17, 2019
93fad2c
feat: filter reactions with inexact stoichiometry coefficients
kvikshaug Jun 17, 2019
6d5090b
style: run black
kvikshaug Jun 17, 2019
e9bf652
refactor: include data in repo
phantomas1234 Jun 24, 2019
539e30e
refactor: remove unused import (flake8)
phantomas1234 Jun 24, 2019
019248b
fix: sort imports in data.py (isort-check)
phantomas1234 Jun 24, 2019
ce396a6
doc: update README
phantomas1234 Jun 24, 2019
4db88ba
Merge pull request #2 from DD-DeCaF/move-data-into-repo
phantomas1234 Jun 25, 2019
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
Prev Previous commit
Next Next commit
feat: fuzzy search on id, name and ec fields
kvikshaug committed Jun 12, 2019

Verified

This commit was signed with the committer’s verified signature.
kvikshaug Ali Kaafarani
commit 08f50cb2c79f20a3cbd327cc587ef5d6e212ab94
20 changes: 18 additions & 2 deletions src/metanetx/resources.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

from flask_apispec import MethodResource, marshal_with, use_kwargs
from flask_apispec.extension import FlaskApiSpec
from fuzzywuzzy import fuzz

from . import data
from .schemas import ReactionResponseSchema, ReactionSearchSchema
@@ -49,8 +50,23 @@ class ReactionResource(MethodResource):
@use_kwargs(ReactionSearchSchema)
@marshal_with(ReactionResponseSchema(many=True), code=200)
def get(self, query):
# Search through the data store for matching reactions.
reactions = [r for r in data.reactions.values() if r.mnx_id == query]
# Search through the data store for matching reactions. Use Levenshtein
# Distance to match on ID, name or EC number.
reactions = sorted(
data.reactions.values(),
key=lambda r: max(
[
fuzz.ratio(query, r.mnx_id),
fuzz.ratio(query, r.name),
fuzz.ratio(query, r.ec),
]
),
reverse=True,
)

# Limit the results to the first 30.
reactions = reactions[:30]

# Collect all unique references to metabolites and compartments, and
# include the objects in the response.
results = []