Skip to content

Commit

Permalink
ids forwarding service
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaudis committed Oct 2, 2020
1 parent 862b078 commit deef74e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 8 deletions.
70 changes: 70 additions & 0 deletions bin/ids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/local/bin/python3

import cgi, cgitb
import re, json
import sys, os
from urllib.parse import urlparse

# local
dir_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(os.path.abspath(dir_path), '..'))
from bycon.read_specs import *

"""podmd
The `ids` service forwards compatible, prefixed ids (see `config/ids.yaml`) to specific
website endpoints. There is no check if the id exists; this is left to the web
page handling itself.
Stacking with the "pgx:" prefix is allowed.
* <https://progenetix.org/services/ids/NCIT:C3262>
podmd"""

################################################################################
################################################################################
################################################################################

def main():

ids("ids")

################################################################################

def ids(service):

# config = read_bycon_config( os.path.abspath( dir_path ) )
these_prefs = read_named_prefs( service, dir_path )

url_comps = urlparse( environ.get('REQUEST_URI') )
p_items = re.split(r'\/|\&', url_comps.path)
i = 0
id_in = ""

for p in p_items:
i += 1
if len(p_items) > i:
if p == "ids":
id_in = p_items[ i ]
break

for f_p in these_prefs["format_patterns"]:
pat = re.compile( f_p["pattern"] )
link = f_p["link"]
if pat.match(id_in):
lid = pat.match(id_in).group(2)
print("Status: 302")
print("Location: {}{}".format(link, lid))
print()
exit()

print('Content-Type: text')
print('status:422')
print()
print("No correct id provided. Please refer to the documentation at http://info.progenetix.org/tags/services/")
exit()

################################################################################
################################################################################

if __name__ == '__main__':
main()
12 changes: 4 additions & 8 deletions bin/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from bin.deliveries import deliveries
from bin.genespans import genespans
from bin.geolocations import geolocations
from bin.ids import ids
from bin.ontologymaps import ontologymaps
from bin.phenopackets import phenopackets
from bin.publications import publications
Expand Down Expand Up @@ -44,11 +45,12 @@
def main():
services = {
"biosamples": biosamples,
"byconplus": byconplus,
"cytomapper": cytomapper,
"dbstats": dbstats,
"deliveries": deliveries,
"geolocations": geolocations,
"byconplus": byconplus,
"ids": ids,
"publications": publications,
"genespans": genespans,
"ontologymaps": ontologymaps,
Expand All @@ -75,13 +77,7 @@ def main():
f = p_items[ i ]
# TODO: dynamic loader, then call
services[f](f)

_return_error()

################################################################################
################################################################################

def _return_error():
exit()

print('Content-Type: text')
print('status:422')
Expand Down
11 changes: 11 additions & 0 deletions config/ids.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
format_patterns:
- pattern: '^(pgx\:)?(pgxbs\-[\w\-\.]{4,128})$'
link: '/samples/details?datasetIds=progenetix&id='
- pattern: '^(pgx\:)?(NCIT(\:C[\d]{4,8})?)$'
link: '/subsets/list?datasetIds=progenetix&filters='
- pattern: '^(pgx\:)?(icdom(\-[\d]{5})?)$'
link: '/subsets/list?datasetIds=progenetix&filters='
- pattern: '^(pgx\:)?(icdot(\-C\d\d?\.\d)?)$'
link: '/subsets/list?datasetIds=progenetix&filters='
- pattern: ^(pgx\:)?(PMID\:\d{5,10})$'
link: '/publications/details?id='

0 comments on commit deef74e

Please sign in to comment.