Commit d76fd38d authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Fix failing test. Adapt to general dbxref requirements

parent d17d7f0a
......@@ -43,7 +43,7 @@ def main():
print(json.dumps(documents, sort_keys=True, indent=4))
def retrieve(dbxrefs, basics, abstract, date, pssmlength, structure, status):
def retrieve(dbxrefs, basics=True, abstract=False, date=False, pssmlength=False, structure=False, status=False):
"""Retrieve json document from InterPro REST api, filter information by selected Options and parse into new json"""
resolved = dbxref.resolver.resolve(dbxrefs, check_existence=False)
documents = []
......@@ -56,22 +56,24 @@ def retrieve(dbxrefs, basics, abstract, date, pssmlength, structure, status):
cdd_json = json.loads(r.text)
# parse retrieved json file by selected options
output = {}
output = {"id": entry["dbxref"]}
acc_id = str(resolved[0]["dbxref"][4:])
if basics:
try:
output.update({"dbxref_id": "CDD:" + acc_id, "accession_id": cdd_json["result"][acc_id]["accession"],
output.update({"dbxref": "CDD:" + acc_id, "accession": cdd_json["result"][acc_id]["accession"],
"scientific_name": cdd_json["result"][acc_id]["title"],
"database": cdd_json["result"][acc_id]["database"],
"associated_organism": cdd_json["result"][acc_id]["organism"]
})
except KeyError:
print("One or more basic information were not available for the given entry. Please check your data.")
raise
if abstract:
try:
output.update({"abstract": cdd_json["result"][acc_id]["abstract"]})
except KeyError:
print("An abstract was not available for the given entry.")
raise
if date:
try:
output.update({"publication_date": cdd_json["result"][acc_id]["pubdate"],
......@@ -79,21 +81,25 @@ def retrieve(dbxrefs, basics, abstract, date, pssmlength, structure, status):
except KeyError:
print("The date of publishment and/or day of addition to Entrez were not available for the given "
"entry.")
raise
if pssmlength:
try:
output.update({"pssmlength": cdd_json["result"][acc_id]["pssmlength"]})
except KeyError:
print("Information about PSSM was not available for the given entry.")
raise
if structure:
try:
output.update({"representative_structure": cdd_json["result"][acc_id]["structurerepresentative"]})
except KeyError:
print("There was no representative structure available for the given entry.")
raise
if status:
try:
output.update({"status": cdd_json["result"][acc_id]["status"]})
except KeyError:
print("Status information was not available for the given entry. Please check your data.")
raise
documents.append(output)
return documents
......
......@@ -4,7 +4,7 @@ from dbxref.retrieve import cdd
class TestCDD(unittest.TestCase):
def test_output(self):
documents = cdd.retrieve({"db": "CDD", "id": "351793"}, basics=True, abstract=True, date=True, pssmlength=True,
documents = cdd.retrieve([{"db": "CDD", "id": "351793"}], basics=True, abstract=True, date=True, pssmlength=True,
status=True, structure=True)
self.assertTrue(documents)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment