-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
8 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 |
---|---|---|
@@ -1,16 +1,33 @@ | ||
from biothings.utils.dataload import open_anyfile, unlist | ||
from collections import defaultdict | ||
|
||
from biothings.utils.dataload import open_anyfile, unlist | ||
|
||
|
||
def parse_tdl(input_file): | ||
with open_anyfile(input_file) as f: | ||
result = {} | ||
for line in f: | ||
( | ||
_, | ||
_, | ||
_id, | ||
tdl, | ||
) = line.strip().split(",") | ||
if _id and _id != "NCBI_id" and _id != "0": | ||
result[str(_id)] = tdl | ||
return result | ||
|
||
|
||
def load_data(input_file): | ||
def load_data(input_file, tdl_file): | ||
entrez_tdls = parse_tdl(tdl_file) | ||
|
||
with open_anyfile(input_file) as in_f: | ||
result = defaultdict(list) | ||
for line in in_f: | ||
pharos_id, _id = line.strip().split(',') | ||
if _id != 'entrez_gene_id' and _id != '0': | ||
pharos_id, _id = line.strip().split(",") | ||
if _id != "entrez_gene_id" and _id != "0": | ||
result[str(_id)].append(int(pharos_id)) | ||
for k, v in result.items(): | ||
json_doc = {'_id': str(k), | ||
'pharos': {"target_id": v}} | ||
if tdl := entrez_tdls.get(k): | ||
json_doc = {"_id": str(k), "pharos": {"target_id": v}, "tdl": tdl} | ||
yield unlist(json_doc) |
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