-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #31: Implemented store, fetch, and alias record translation fo…
…r NCBI↔refseq, Ensembl↔ensembl, LRG↔lrg
- Loading branch information
Showing
4 changed files
with
96 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""translate namespaces | ||
Translates between namespaces exposed in the API and those in the DB. | ||
This is a temporary operation in order to create a smooth transition | ||
for clients. See biocommons.seqrepo#31 for background. | ||
Use cases: | ||
* Store: translate API namespace to DB namespace. e.g., "refseq" -> "NCBI" | ||
* Find: as with store for query argument, plus translate DB to API for | ||
returned records. | ||
All translations occur in seqaliasdb. | ||
""" | ||
|
||
import copy | ||
|
||
translations = [ | ||
# (DB namespace, API namespace) | ||
("NCBI", "refseq"), | ||
("Ensembl", "ensembl"), | ||
("LRG", "lrg"), | ||
] | ||
|
||
|
||
ns_db2api = {db: api for db, api in translations} | ||
ns_api2db = {api: db for db, api in translations} | ||
|
||
def translate_alias_records(aliases_itr): | ||
"""given an iterator of find_aliases results, return a stream with | ||
translated records""" | ||
|
||
for a in aliases_itr: | ||
yield a | ||
|
||
ns = a["namespace"] | ||
if ns in ns_db2api: | ||
a2 = copy.copy(a) | ||
a2["namespace"] = ns_db2api[ns] | ||
yield a2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters