Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new API plugin for AGR #32

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions plugins/agr/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.1",
"__metadata__": {
"url": "https://www.alliancegenome.org/downloads",
"license_url": "https://creativecommons.org/licenses/by/4.0/",
"license": "CC BY 4.0"
},
"dumper": {
"data_url": "https://download.alliancegenome.org/4.0.0/DISEASE-ALLIANCE/COMBINED/DISEASE-ALLIANCE_COMBINED_47.tsv.gz",
"uncompress": false,
"release": "version:get_release"
},
"uploader": {
"parser": "parser:load_data",
"on_duplicates": "merge"
}
}
66 changes: 66 additions & 0 deletions plugins/agr/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import re
import os.path
import json
from collections import defaultdict
from biothings.utils.common import open_anyfile
from biothings.utils.dataload import dict_sweep

SKIP_ROWS = 15 # number of rows to skip
HEADER_ROW = 15 # zero-indexed header row
DESIRED_OBJECT_TYPES = [
"gene"
]

def load_data(data_folder):
agr_file = os.path.join(data_folder, "DISEASE-ALLIANCE_COMBINED_47.tsv.gz")
i = -1
entries = defaultdict(dict)


with open_anyfile(agr_file, "r") as file:
for line in file:
i += 1
if i < SKIP_ROWS:
continue
elif i == HEADER_ROW:
# convert headers to lowercase, underscore_delimited
header = [
re.sub(r"(.)([A-Z])", r"\1_\2", colname).lower()
for colname in
line.rstrip('\n').split('\t')
]
continue

row = line.rstrip('\n').split('\t')
if row[2] not in DESIRED_OBJECT_TYPES:
continue

# Comments below correspond to original column names
entries[row[3]]["_id"] = row[3] # DBObjectID
if "agr" not in entries[row[3]]:
entries[row[3]]["agr"] = {}
entry = entries[row[3]]["agr"]
entry[header[0]] = row[0] # Taxon
entry[header[1]] = row[1] # SpeciesName
entry["symbol"] = row[4] # originally DBObjectSymbol

if row[5] not in entry:
entry[row[5]] = []

entry[row[5]].append(dict_sweep({ # AssociationType
"doid": row[6], # DOID
"term_name": row[7], # DOtermName
header[8]: list(
filter(len, row[8].split("|"))
), # WithOrthologs
"inferred_from_id": row[9], # InferredFromID
header[10]: row[10], # InferredFromSymbol
header[11]: row[11], # EvidenceCode
header[12]: row[12], # EvidenceCodeName
header[13]: row[13], # Reference
header[14]: row[14], # Date
header[15]: row[15] # Source
}, remove_invalid_list=True))

for doc in entries.values():
yield dict_sweep(doc, remove_invalid_list=True)
3 changes: 3 additions & 0 deletions plugins/agr/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def get_release(self):
# hard-coded due to hard-coded file download
return "4.0.0"