Skip to content

Commit

Permalink
Merge branch 'testapi'
Browse files Browse the repository at this point in the history
  • Loading branch information
lzy7071 committed Jun 11, 2020
2 parents 4607195 + 7aa4db2 commit 94e0cbc
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 192 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ ENV REST_FTX_AWS_ACCESS_KEY_ID=$REST_FTX_AWS_ACCESS_KEY_ID
ENV REST_FTX_AWS_SECRET_ACCESS_KEY=$REST_FTX_AWS_SECRET_ACCESS_KEY
ENV REST_FTX_AWS_DEFAULT_REGION=$REST_FTX_AWS_DEFAULT_REGION
ENV READ_PREFERENCE=$READ_PREFERENCE
ENV MONGO_ATLAS_SERVER=$MONGO_ATLAS_SERVER
ENV MONGO_ATLAS_PORT=$MONGO_ATLAS_PORT
ENV MONGO_ATLAS_REPL=$MONGO_ATLAS_REPL
ENV MONGO_ATLAS_READPREFERENCE=$MONGO_ATLAS_READPREFERENCE
ENV MONGO_ATLAS_AUTHDB=$MONGO_ATLAS_AUTHDB

EXPOSE 80/tcp

# clean up
RUN apt-get purge -y --autoremove git ca-certificates \
RUN apt-get purge -y --autoremove git \
&& rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list \
&& if [ -n "$tempDir" ]; then \
apt-get purge -y --auto-remove \
Expand Down
166 changes: 83 additions & 83 deletions Pipfile.lock

Large diffs are not rendered by default.

66 changes: 30 additions & 36 deletions datanator_rest_api/routes/metabolites.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


ey_manager = query_manager.Manager().eymdb_manager()
m_manager = query_manager.Manager().metabolite_manager()
mm_manager = query_manager.metabolites_meta_manager()
mc_manager = query_manager.Manager().metabolite_concentration_manager()
dist_manager = taxon_distance.TaxonDist()
Expand All @@ -40,7 +39,7 @@ class concentrations:

def get(inchikey, species='Escherichia coli', taxon_distance=False):
query = {'inchikey': inchikey}
result = m_manager.db_obj['metabolite_concentrations'].find_one(filter=query, projection={'_id': 0})
result = mm_manager.db_obj['metabolite_concentrations'].find_one(filter=query, projection={'_id': 0})
if not result:
return {}
if taxon_distance:
Expand Down Expand Up @@ -88,36 +87,38 @@ def get():

class ecmdb_ref_count():
def get():
docs = ey_manager.collection_ecmdb.aggregate([
{"$project": {"concentrations": 1}},
{"$match": {"concentrations": {"$ne": None}}},
{"$unwind": "$concentrations"},
{"$group": {
"_id": "$concentrations.reference.pubmed_id",
"count": {"$sum": 1}
}}
])
count = 0
for doc in docs:
count += 1
return count
# docs = ey_manager.collection_ecmdb.aggregate([
# {"$project": {"concentrations": 1}},
# {"$match": {"concentrations": {"$ne": None}}},
# {"$unwind": "$concentrations"},
# {"$group": {
# "_id": "$concentrations.reference.pubmed_id",
# "count": {"$sum": 1}
# }}
# ])
# count = 0
# for doc in docs:
# count += 1
# return count
return 43


class ymdb_ref_count():
def get():
docs = ey_manager.collection_ymdb.aggregate([
{"$project": {"concentrations": 1}},
{"$match": {"concentrations": {"$ne": None}}},
{"$unwind": "$concentrations"},
{"$group": {
"_id": "$concentrations.reference.pubmed_id",
"count": {"$sum": 1}
}}
])
count = 0
for doc in docs:
count += 1
return count
# docs = ey_manager.collection_ymdb.aggregate([
# {"$project": {"concentrations": 1}},
# {"$match": {"concentrations": {"$ne": None}}},
# {"$unwind": "$concentrations"},
# {"$group": {
# "_id": "$concentrations.reference.pubmed_id",
# "count": {"$sum": 1}
# }}
# ])
# count = 0
# for doc in docs:
# count += 1
# return count
return 1462


class curated_ref_count():
Expand All @@ -139,14 +140,7 @@ def get():

class get_distinct():
def get(_input):
return len(m_manager.db_obj['metabolite_concentrations'].distinct(_input))



class concentration:

def get(metabolite, species='Escherichia coli', abstract=False):
return m_manager.molecule_name_query(metabolite, species, abstract_default=abstract)
return len(mm_manager.db_obj['metabolite_concentrations'].distinct(_input))


class meta:
Expand Down
31 changes: 0 additions & 31 deletions datanator_rest_api/spec/DatanatorAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -482,37 +482,6 @@ paths:
summary: Add a new metabolite
tags:
- Metabolites
/metabolites/concentration/:
get:
description: Some description
parameters:
- in: query
name: abstract
required: false
schema:
type: boolean
- in: query
name: species
required: false
schema:
default: Escherichia coli
type: string
- in: query
name: metabolite
required: true
schema:
type: string
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/MetaboliteConcentration'
description: OK
summary: Get metabolite concentration based on species and metabolite name
tags:
- Metabolites
- Concentration
/metabolites/concentration_only/:
get:
description: see summary
Expand Down
32 changes: 0 additions & 32 deletions datanator_rest_api/spec/paths/metabolites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,38 +147,6 @@ similar_compounds:
schema:
$ref: "#/components/schemas/SimilarMetaboliteConcentration"

concentration:
get:
parameters:
- in: query
name: abstract
schema:
type: boolean
required: false
- in: query
name: species
schema:
type: string
default: Escherichia coli
required: false
- in: query
name: metabolite
schema:
type: string
required: true
tags:
- Metabolites
- Concentration
summary: Get metabolite concentration based on species and metabolite name
description: Some description
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/MetaboliteConcentration"

num_conc:
get:
tags:
Expand Down
2 changes: 0 additions & 2 deletions datanator_rest_api/spec/root.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ paths:
$ref: paths/metabolites.yaml#/get_distinct
/metabolites/meta/:
$ref: paths/metabolites.yaml#/meta
/metabolites/concentration/:
$ref: paths/metabolites.yaml#/concentration
/metabolites/concentration_only/:
$ref: paths/metabolites.yaml#/concentration_only
/proteins/precise_abundance/:
Expand Down
5 changes: 5 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ http {
client_max_body_size 4G;
keepalive_timeout 5;

gzip on;
gzip_types text/plain application/xml text/html;
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 1000;

location / {
proxy_pass http://127.0.0.1:8001;
proxy_http_version 1.1;
Expand Down
7 changes: 0 additions & 7 deletions tests/routes/test_metabolites.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ def setUp(self):
"datanator_rest_api.routes"), validate_responses=True)
self.client = self.app.app.test_client()
self.client.testing = True

@unittest.skip('need front_end_query to be fixed')
def test_concentration(self):
result_1 = self.client.get("/metabolites/concentration/?species=homo sapiens&metabolite=atp")
dic_1 = json.loads(result_1.data)
self.assertEqual(result_1.status_code, 200)
self.assertTrue('concentrations' in dic_1[0][0])

# def test_get(self):
# result_0 = json.loads(self.client.get('/metabolites/?inchi_key=test_inchi_key').data)
Expand Down

0 comments on commit 94e0cbc

Please sign in to comment.