From 4872ce9c22cc3c7024075f66409efdaf8860e9b8 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Wed, 11 May 2022 12:43:38 +1000 Subject: Do minor code cleanup --- backend/data/downloadImgsForReview.py | 4 ++-- backend/data/genOtolData.py | 16 ++++++++-------- backend/server.py | 4 +--- 3 files changed, 11 insertions(+), 13 deletions(-) (limited to 'backend') diff --git a/backend/data/downloadImgsForReview.py b/backend/data/downloadImgsForReview.py index 03e22a8..d5ccf62 100755 --- a/backend/data/downloadImgsForReview.py +++ b/backend/data/downloadImgsForReview.py @@ -66,10 +66,10 @@ if not os.path.exists(outDir): print("Finding next ID to download for") nextIdx = 0 fileList = os.listdir(outDir) -ids = list(map(lambda filename: int(filename.split(" ")[0]), fileList)) +ids = [int(filename.split(" ")[0]) for filename in fileList] if len(ids) > 0: ids.sort() - nextIdx = eolIds.index(ids[-1]) + nextIdx = eolIds.index(ids[-1]) + 1 if nextIdx == len(eolIds): print("No IDs left. Exiting...") sys.exit(0) diff --git a/backend/data/genOtolData.py b/backend/data/genOtolData.py index 7dfac54..9298106 100755 --- a/backend/data/genOtolData.py +++ b/backend/data/genOtolData.py @@ -1,12 +1,12 @@ #!/usr/bin/python3 -import sys, re, json, sqlite3 -import os.path +import sys, os.path, re +import json, sqlite3 usageInfo = f"usage: {sys.argv[0]}\n" -usageInfo += "Reads labelled_supertree_ottnames.tre & annotations.json (from an Open Tree of Life release), \n" +usageInfo += "Reads labelled_supertree_ottnames.tre & annotations.json (from an Open Tree of Life release),\n" usageInfo += "and creates a sqlite database, which holds entries of the form (name text, data text).\n" -usageInfo += "Each row holds a tree-of-life node's name, JSON-encoded child name array, a parent name or '', \n" +usageInfo += "Each row holds a tree-of-life node's name, JSON-encoded child name array, a parent name or '',\n" usageInfo += "number of descendant 'tips', and a 1 or 0 indicating phylogenetic-support.\n" usageInfo += "\n" usageInfo += "Expected labelled_supertree_ottnames.tre format:\n" @@ -30,10 +30,10 @@ idToName = {} # Maps node IDs to names nameToFirstId = {} # Maps node names to first found ID (names might have multiple IDs) dupNameToIds = {} # Maps names of nodes with multiple IDs to those node IDs -## Check for existing db -#if os.path.exists(dbFile): -# print("ERROR: Existing {} db".format(dbFile), file=sys.stderr) -# sys.exit(1) +# Check for existing db +if os.path.exists(dbFile): + print("ERROR: Existing {} db".format(dbFile), file=sys.stderr) + sys.exit(1) # Parse treeFile print("Parsing tree file") data = None diff --git a/backend/server.py b/backend/server.py index e778c2f..9c9764b 100755 --- a/backend/server.py +++ b/backend/server.py @@ -94,9 +94,7 @@ def lookupName(name): results = [] hasMore = False for row in cur.execute( - "SELECT DISTINCT names.name, names.alt_name, nodes.tips FROM" \ - " names INNER JOIN nodes ON names.name = nodes.name " \ - " WHERE alt_name LIKE ? ORDER BY length(alt_name) LIMIT ?", + "SELECT DISTINCT name, alt_name FROM names WHERE alt_name LIKE ? ORDER BY length(alt_name) LIMIT ?", (name + "%", SEARCH_SUGG_LIMIT)): results.append({"name": row[0], "altName": row[1]}) if len(results) > SEARCH_SUGG_LIMIT: -- cgit v1.2.3