Skip to content

Commit

Permalink
mostly hot fix - protected external_references
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaudis committed Feb 21, 2024
1 parent 6d9cbc9 commit 5582b54
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 28 deletions.
12 changes: 6 additions & 6 deletions bycon/beaconServer/tests/GET-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

http://progenetix.test/beacon/biosamples/?datasetIds=progenetix&referenceName=refseq:NC_000009.12&variantType=EFO:0030067&start=21500000&start=21975098&end=21967753&end=22500000&filters=NCIT:C3058

http://progenetix.org/beacon/genomicVariations/?referenceName=NC_000017.11&start=7577120&referenceBases=G&alternateBases=A&debug=1
http://progenetix.org/beacon/genomicVariations/?referenceName=NC_000017.11&start=7577120&referenceBases=G&alternateBases=A

https://progenetix.org/beacon/g_variants/?filters=NCIT:C7712&output=pgxseg&debug=1
https://progenetix.org/beacon/g_variants/?filters=NCIT:C7712&output=pgxseg

https://progenetix.org/beacon/analyses/?referenceName=17&variantType=DEL&start=5000000&start=7676592&end=7669607&end=10000000&filters=&output=pgxmatrix&debug=1
https://progenetix.org/beacon/analyses/?referenceName=17&variantType=DEL&start=5000000&start=7676592&end=7669607&end=10000000&filters=&output=pgxmatrix

https://progenetix.org/beacon/analyses?referenceName=17&variantType=DEL&start=5000000&start=7676592&end=7669607&end=10000000&filters=cellosaurus&output=pgxmatrix&debug=1
https://progenetix.org/beacon/analyses?referenceName=17&variantType=DEL&start=5000000&start=7676592&end=7669607&end=10000000&filters=cellosaurus&output=pgxmatrix

http://progenetix.org/beacon/biosamples?filters=NCIT:C3697&output=table&debug=1
http://progenetix.org/beacon/biosamples?filters=NCIT:C3697&output=table

http://progenetix.org/beacon/biosamples?referenceName=9&start=10000000,12000000&end=12500000,15000000&variantType=DEL&filters=pgx:icdom-81703&debug=1
http://progenetix.org/beacon/biosamples?referenceName=9&start=10000000,12000000&end=12500000,15000000&variantType=DEL&filters=pgx:icdom-81703

http://progenetix.org/beacon/biosamples/onekgbs-HG00142/g_variants

Expand Down
2 changes: 1 addition & 1 deletion bycon/definitions/datatable_mappings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ definitions:
variant_state_id:
type: string
db_key: variant_state.id
indexed: True
indexed: True # might not beneeded if first in a compound index
compact: True
variant_state_label:
type: string
Expand Down
3 changes: 1 addition & 2 deletions bycon/lib/bycon_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def set_debug_state(debug=False) -> bool:
"""
Function to provide a text response header for debugging purposes, i.e. to
print out the error or test parameters to a browser session.
The common way would be to add either a `/debug=1/` part to a REST path or
to provide a `...&debug=1` query parameter.
The common way would be to add either a `?debugMode=true` query parameter.
"""
if BYC["DEBUG_MODE"] is True:
return True
Expand Down
8 changes: 1 addition & 7 deletions bycon/lib/cgi_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,17 @@ def rest_path_elements(byc):
| | | |
required required optional optional
"""

r_p_r = byc.get("request_path_root", "beacon")

if not environ.get('REQUEST_URI'):
return

r_p_r = byc.get("request_path_root", "beacon")
url_comps = urlparse(environ.get('REQUEST_URI'))
url_p = url_comps.path
p_items = re.split('/', url_p)

if not r_p_r in p_items:
return

for d_k in ["&debug=1", "debug=1", "debug=true"]:
if d_k in p_items:
p_items.remove(d_k)

p_items = list(filter(None, p_items))
r_i = p_items.index(r_p_r)

Expand Down
12 changes: 3 additions & 9 deletions bycon/lib/query_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,18 @@ def __query_from_variant_pars(self):
def __create_geneVariantRequest_query(self):
# query database for gene and use coordinates to create range query
vp = self.varguments

gene_data = GeneInfo().returnGene(vp["gene_id"])

# TODO: error report/warning
if not gene_data:
return

gene = gene_data[0]

# Since this is a pre-processor to the range request
self.varguments.update( {
"reference_name": "refseq:{}".format(gene["accession_version"]),
"start": [ gene["start"] ],
"end": [ gene["end"] ]
"reference_name": f'refseq:{gene.get("accession_version", "___none___")}',
"start": [ gene.get("start", 0) ],
"end": [ gene.get("end", 1) ]
} )

self.variant_request_type = "variantRangeRequest"


Expand All @@ -279,7 +275,6 @@ def __create_aminoacidChangeRequest_query(self):
vp = self.varguments
if not "aminoacid_change" in vp:
return

v_p_defs = self.argument_definitions
v_q = { v_p_defs["aminoacid_change"]["db_key"]: vp.get("aminoacid_change", "___none___")}

Expand All @@ -304,7 +299,6 @@ def __create_variantTypeRequest_query(self):
vp = self.varguments
if not "variant_type" in vp:
return

v_q = self.__create_in_query_for_parameter("variant_type", v_p_defs["variant_type"]["db_key"], vp)

return v_q
Expand Down
8 changes: 5 additions & 3 deletions bycon/lib/response_remapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def remap_biosamples(r_s_res, byc):
e_r = []
for r_k, r_v in bs_r.get("references", {}).items():
e_r.append(__reference_object_from_ontology_term(r_k, r_v, byc))

r_s_res[bs_i].update({
"sample_origin_type": {"id": "OBI:0001479", "label": "specimen from organism"},
"external_references": e_r
Expand All @@ -186,17 +187,15 @@ def remap_biosamples(r_s_res, byc):

def __reference_object_from_ontology_term(filter_type, ontology_term, byc):
if "label" in ontology_term:
ontology_term.update({"description": ontology_term.get("label")})
ontology_term.update({"description": ontology_term.get("label", "")})
ontology_term.pop("label", None)

f_t_d = byc["filter_definitions"].get(filter_type, {})
r_d = f_t_d.get("reference")
if not r_d:
return ontology_term
r_r = r_d.get("replace", [])
if len(r_r) == 2:
o_id = ontology_term.get("id", "___none___").replace(r_r[0], r_r[1])

ontology_term.update({"reference": f'{r_d.get("root")}{o_id}'})
return ontology_term

Expand Down Expand Up @@ -290,10 +289,13 @@ def phenopack_individual(ind, data_db, byc):
################################################################################

def clean_empty_fields(this_object):
protected = ["external_references"]
if not isinstance(this_object, dict):
return this_object

for k in list(this_object.keys()):
if k in protected:
continue
if isinstance(this_object[k], dict):
if not this_object[k]:
this_object.pop(k, None)
Expand Down
5 changes: 5 additions & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ through the Perl based [**PGX** project](http://github.com/progenetix/PGX/).

## Changes Tracker

### 2024-02-21 (v.1.5.1)

* hot fix: added "protected" status for `external_references` in general empty
field clean-up since the object is required by the front-end (even if empty list)

### 2024-02-20 (v.1.5.0)

* refactoring global configs into `bycon/config.py` to slowly get rid of some of
Expand Down

0 comments on commit 5582b54

Please sign in to comment.