Skip to content

Commit

Permalink
1.3.3
Browse files Browse the repository at this point in the history
Most of the "special outputs" code has been moved to byconaut -> services.
For legacy reasons (e.g. use by pgxRpi) the webserver configuration needed some
rewrites ... They only apply for the Progenetix use case and are not needed if
sticking to the Beacon formats or if following the use of the new apps like
`services/vcfvariants`).
  • Loading branch information
mbaudis committed Oct 25, 2023
1 parent 7d35aa1 commit 068c3c1
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 1,413 deletions.
4 changes: 1 addition & 3 deletions bycon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@
from cgi_parsing import *
from clustering_utils import *
from dataset_parsing import *
from datatable_utils import *
from handover_generation import *
from interval_utils import *
from file_utils import *
from filter_parsing import *
from query_execution import *
from query_generation import *
from read_specs import *
from response_remapping import *
from schema_parsing import *
from service_utils import *
from export_file_generation import *
# from export_file_generation import *
from variant_mapping import *
from variant_parsing import *

Expand Down
9 changes: 9 additions & 0 deletions bycon/config/datatable_mappings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,15 @@ definitions:
db_key: info.annotation_derived
default: False
indexed: True
aminoacid_changes:
type: array
items: string
db_key: molecular_attributes.aminoacid_changes
indexed: True
genomic_hgvs_id:
type: string
db_key: identifiers.genomicHGVS_id
indexed: True

# special pgxseg columns

Expand Down
6 changes: 3 additions & 3 deletions bycon/config/handover_definitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ h->o_types:
- biosample
- analysis
h->o_key: 'biosamples.id'
script_path_web: '/beacon/biosamples'
script_path_web: '/services/sampletable'

phenopackets:
handoverType:
Expand Down Expand Up @@ -104,7 +104,7 @@ h->o_types:
paginated_entities:
- all
h->o_key: 'variants._id'
script_path_web: '/beacon/genomicVariations'
script_path_web: '/services/pgxsegvariants'

vcf:
handoverType:
Expand All @@ -116,7 +116,7 @@ h->o_types:
paginated_entities:
- all
h->o_key: 'variants._id'
script_path_web: '/beacon/genomicVariations'
script_path_web: '/services/vcfvariants'

UCSClink:
handoverType:
Expand Down
102 changes: 3 additions & 99 deletions bycon/lib/beacon_response_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

from bycon_helpers import mongo_result_list, mongo_test_mode_query, return_paginated_list
from cgi_parsing import prdbug
from datatable_utils import export_datatable_download
from export_file_generation import *
from file_utils import ByconBundler, callset_guess_probefile_path
# from export_file_generation import *
from handover_generation import dataset_response_add_handovers
from query_execution import execute_bycon_queries
from query_generation import ByconQuery
Expand Down Expand Up @@ -584,30 +582,18 @@ def __init__(self, byc: dict):

def populatedResultSets(self):

# some methods for non-standard responses (i.e. beyond Beacon ...)
# first the methods which use data streaming, i.e. do not retrieve the data first
self.__check_datasets_0_results_pgxseg_export()
self.__check_datasets_0_results_vcf_export()
self.__check_result_sets_matrix_export()
# retrieving the data if not exited above
self.__retrieve_datasets_data()
self.__retrieve_variants_data()
# tables before reshaping ...
self.__check_datasets_data_table_export()
# self.__check_datasets_results_histoplot_delivery()
# self.__check_datasets_results_samplesplot_delivery()
self.__check_biosamples_map_delivery()
# finally populating the standard Beacon response
self.__populate_result_sets()
# if still here (i.e. non of the above was successful) now saving
# this could be separate ...
self.__result_sets_save_handovers()

return self.result_sets, self.record_queries

# -------------------------------------------------------------------------#

def datasetsData(self):
self.__retrieve_datasets_data()
self.__retrieve_variants_data()
return self.datasets_data


Expand Down Expand Up @@ -638,88 +624,6 @@ def __get_handover_access_key(self):
return


# -------------------------------------------------------------------------#

def __check_datasets_data_table_export(self):
if not "table" in self.output:
return

collated_results = []
for ds_id, data in self.datasets_data.items():
collated_results += data

export_datatable_download(collated_results, self.byc)


# -------------------------------------------------------------------------#

def __check_datasets_0_results_pgxseg_export(self):
"""
"""
if not "pgxseg" in self.output:
return

ds_id = list(self.datasets_results.keys())[0]
export_pgxseg_download(self.datasets_results, ds_id, self.byc)
return


# -------------------------------------------------------------------------#

def __check_datasets_0_results_vcf_export(self):
"""
"""
if not "vcf" in self.output:
return

ds_id = list(self.datasets_results.keys())[0]
export_vcf_download(self.datasets_results, ds_id, self.byc)

return


# -------------------------------------------------------------------------#

def __check_result_sets_matrix_export(self):
if not "pgxmatrix" in self.output:
return

ds_id = list(self.datasets_results.keys())[0]
export_callsets_matrix(self.datasets_results, ds_id, self.byc)
return


# -------------------------------------------------------------------------#

def __check_biosamples_map_delivery(self):
"""
TBD
"""


return


# -------------------------------------------------------------------------#

def __check_datasets_results_samplesplot_delivery(self):
if not "samplesplot" in self.output:
return
self.__datasets_results_samplesplot_generation()
print_svg_response(self.svg, self.env)


# -------------------------------------------------------------------------#

def __check_datasets_results_histoplot_delivery(self):
if not "histo" in self.output:
return
self.__datasets_results_histoplot_generation()
print_svg_response(self.svg, self.env)


# -------------------------------------------------------------------------#

def __result_sets_save_handovers(self):
Expand Down
105 changes: 105 additions & 0 deletions bycon/lib/bycon_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,108 @@ def mongo_test_mode_query(db_name, coll_name, test_mode_count=5):

return query, error

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

def assign_nested_value(parent, dotted_key, v, parameter_definitions={}):

parameter_type = parameter_definitions.get("type", "string")
parameter_default = parameter_definitions.get("default")

if v is None:
if parameter_default:
v = parameter_default

if v is None:
return parent

if "num" in parameter_type:
if str(v).strip().lstrip('-').replace('.','',1).isdigit():
v = float(v)
elif "integer" in parameter_type:
if str(v).strip().isdigit():
v = int(v)
else:
v = str(v)

ps = dotted_key.split('.')

if len(ps) == 1:
if "array" in parameter_type:
parent.update({ps[0]: v.split(',')})
else:
parent.update({ps[0]: v })
return parent

if ps[0] not in parent or parent[ ps[0] ] is None:
parent.update({ps[0]: {}})

if len(ps) == 2:
if "array" in parameter_type:
parent[ ps[0] ].update({ps[1]: v.split(',')})
else:
parent[ ps[0] ].update({ps[1]: v })
return parent

if ps[1] not in parent[ ps[0] ] or parent[ ps[0] ][ ps[1] ] is None:
parent[ ps[0] ].update({ps[1]: {}})
if len(ps) == 3:
if "array" in parameter_type:
parent[ ps[0] ][ ps[1] ].update({ps[2]: v.split(',')})
else:
parent[ ps[0] ][ ps[1] ].update({ps[2]: v })
return parent

if ps[2] not in parent[ ps[0] ][ ps[1] ] or parent[ ps[0] ][ ps[1] ][ ps[2] ] is None:
parent[ ps[0] ][ ps[1] ].update({ps[2]: {}})
if len(ps) == 4:
if "array" in parameter_type:
parent[ ps[0] ][ ps[1] ][ ps[2] ].update({ps[3]: v.split(',')})
else:
parent[ ps[0] ][ ps[1] ][ ps[2] ].update({ps[3]: v })
return parent

if len(ps) > 4:
print("¡¡¡ Parameter key "+dotted_key+" nested too deeply (>4) !!!")
return '_too_deep_'

return parent

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

def get_nested_value(parent, dotted_key, parameter_type="string"):

ps = dotted_key.split('.')

v = ""

if len(ps) == 1:
try:
v = parent[ ps[0] ]
except:
v = ""
elif len(ps) == 2:
try:
v = parent[ ps[0] ][ ps[1] ]
except:
v = ""
elif len(ps) == 3:
try:
v = parent[ ps[0] ][ ps[1] ][ ps[2] ]
except:
v = ""
elif len(ps) == 4:
try:
v = parent[ ps[0] ][ ps[1] ][ ps[2] ][ ps[3] ]
except:
v = ""
elif len(ps) == 5:
try:
v = parent[ ps[0] ][ ps[1] ][ ps[2] ][ ps[3] ][ ps[4] ]
except:
v = ""
elif len(ps) > 5:
print("¡¡¡ Parameter key "+dotted_key+" nested too deeply (>5) !!!")
return '_too_deep_'

return v

Loading

0 comments on commit 068c3c1

Please sign in to comment.