Skip to content

Commit

Permalink
1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaudis committed Feb 7, 2024
1 parent d9d518d commit c1cc13e
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 111 deletions.
17 changes: 11 additions & 6 deletions bin/housekeeping.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def main():
def housekeeping():

initialize_bycon_service(byc, "housekeeping")

mdb_c = byc.get("db_config", {})
db_host = mdb_c.get("host", "localhost")

select_dataset_ids(byc)
if len(byc["dataset_ids"]) != 1:
Expand All @@ -53,7 +56,7 @@ def housekeeping():
"datasets_counts": input("Recalculate counts for all datasets?\n(y|N): ")
}

data_db = MongoClient(host=environ.get("BYCON_MONGO_HOST", "localhost"))[ ds_id ]
data_db = MongoClient(host=db_host)[ ds_id ]

#>-------------------- MongoDB index updates -----------------------------<#

Expand Down Expand Up @@ -101,18 +104,18 @@ def housekeeping():

if "y" in todos.get("datasets_counts", "n").lower():

i_db = byc["housekeeping_db"]
i_coll = byc["beacon_info_coll"]
info_db = mdb_c.get("housekeeping_db")
i_coll = mdb_c.get("beacon_info_coll")

print(f'\n{__hl()}==> Updating dataset statistics in "{i_db}.{i_coll}"')
print(f'\n{__hl()}==> Updating dataset statistics in "{info_db}.{i_coll}"')

b_info = __dataset_update_counts(byc)

info_coll = MongoClient(host=environ.get("BYCON_MONGO_HOST", "localhost"))[ i_db ][ i_coll ]
info_coll.delete_many( { "date": b_info["date"] } ) #, upsert=True
info_coll.insert_one( b_info ) #, upsert=True

print(f'\n{__hl()}==> updated entry {b_info["date"]} in {i_db}.{i_coll}')
print(f'\n{__hl()}==> updated entry {b_info["date"]} in {info_db}.{i_coll}')

#>--------------------- / info db update ---------------------------------<#

Expand All @@ -138,8 +141,10 @@ def housekeeping():

def __dataset_update_counts(byc):

mdb_c = byc.get("db_config", {})
db_host = mdb_c.get("host", "localhost")
b_info = { "date": date_isoformat(datetime.datetime.now()), "datasets": { } }
mongo_client = MongoClient(host=environ.get("BYCON_MONGO_HOST", "localhost"))
mongo_client = MongoClient(host=db_host)

# this is independend of the dataset selected for the script & will update
# for all in any run
Expand Down
5 changes: 4 additions & 1 deletion bin/lib/mongodb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

def mongodb_update_indexes(ds_id, byc):

mdb_c = byc.get("db_config", {})
db_host = mdb_c.get("host", "localhost")

dt_m = byc["datatable_mappings"]
b_rt_s = byc["service_config"]["indexed_response_types"]
mongo_client = MongoClient(host=environ.get("BYCON_MONGO_HOST", "localhost"))
mongo_client = MongoClient(host=db_host)
data_db = mongo_client[ds_id]
coll_names = data_db.list_collection_names()
for r_t, r_d in b_rt_s.items():
Expand Down
4 changes: 2 additions & 2 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ api_web_root: https://progenetix.org
###############################################################################

nav:
- Insttallation & Overview: /
- Installation & Overview: /
- Helper Applications: applications
- Plotting: plotting
- Changes & To Do: changes-todo
- bycon Documentation: http://progenetix.org
- bycon Documentation: http://bycon.progenetix.org
- Progenetix Site: http://progenetix.org
- Baudisgroup: http://info.baudisgroup.org

Expand Down
6 changes: 3 additions & 3 deletions services/collationplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def main():
################################################################################

def collationplots():

initialize_bycon_service(byc, "collationplots")
run_beacon_init_stack(byc)
generate_genome_bins(byc)
Expand All @@ -57,8 +56,9 @@ def collationplots():
byc[ "filters" ] = [ {"id": byc["form_data"]["id"]} ]

if not "filters" in byc:
response_add_error(byc, 422, "No value was provided for collation `id` or `filters`.")
cgi_break_on_errors(byc)
e_m = "No value was provided for collation `id` or `filters`."
e_r = BeaconErrorResponse(byc).error(e_m, 422)
print_json_response(e_r, byc["env"])

pdb = ByconBundler(byc).collationsPlotbundles()
ByconPlot(byc, pdb).svgResponse()
Expand Down
9 changes: 1 addition & 8 deletions services/collations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,11 @@ def main():
################################################################################

def collations():

initialize_bycon_service(byc, "collations")
run_beacon_init_stack(byc)

r = ByconautServiceResponse(byc)
print_json_response(r.collationsResponse(), byc["env"])

byc.update({
"service_response": r.collationsResponse(),
"error_response": r.errorResponse()
})

cgi_print_response( byc, 200 )

################################################################################
################################################################################
Expand Down
16 changes: 7 additions & 9 deletions services/cytomapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,18 @@ def cytomapper():
results = __return_cytobands_results(byc)

r = ByconautServiceResponse(byc)
byc.update({
"service_response": r.populatedResponse(results),
"error_response": r.errorResponse()
})
response = r.populatedResponse(results)

if len( results ) < 1:
response_add_error(byc, 422, "No matching cytobands!" )
cgi_break_on_errors(byc)
e_m = "No matching cytobands!"
e_r = BeaconErrorResponse(byc).error(e_m, 422)
print_json_response(e_r, byc["env"])
if "cyto_bands" in byc["varguments"]:
byc["service_response"]["meta"]["received_request_summary"].update({ "cytoBands": byc["varguments"]["cyto_bands"] })
response["meta"]["received_request_summary"].update({ "cytoBands": byc["varguments"]["cyto_bands"] })
elif "chro_bases" in byc["varguments"]:
byc["service_response"]["meta"]["received_request_summary"].update({ "chroBases": byc["varguments"]["chro_bases"] })
response["meta"]["received_request_summary"].update({ "chroBases": byc["varguments"]["chro_bases"] })

cgi_print_response( byc, 200 )
print_json_response(response, byc["env"])


################################################################################
Expand Down
20 changes: 9 additions & 11 deletions services/dbstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ def main():
def dbstats():

initialize_bycon_service(byc)
select_dataset_ids(byc)

run_beacon_init_stack(byc)
r = ByconautServiceResponse(byc)
byc.update({
"service_response": r.emptyResponse(),
"error_response": r.errorResponse()
})

info_db = byc["housekeeping_db"]
coll = byc["beacon_info_coll"]
stats = MongoClient(host=environ.get("BYCON_MONGO_HOST", "localhost"))[ info_db ][ coll ].find( { }, { "_id": 0 } ).sort( "date", -1 ).limit( 1 )
mdb_c = byc.get("db_config", {})
db_host = mdb_c.get("host", "localhost")
info_db = mdb_c.get("housekeeping_db")
i_coll = mdb_c.get("beacon_info_coll")

stats = MongoClient(host=db_host)[ info_db ][ i_coll ].find( { }, { "_id": 0 } ).sort( "date", -1 ).limit( 1 )

results = [ ]
for stat in stats:
Expand All @@ -52,8 +50,8 @@ def dbstats():
dbs.update({"counts":ds_vs["counts"]})
results.append( dbs )

byc.update({"service_response": r.populatedResponse(results)})
cgi_print_response( byc, 200 )
print_json_response(r.populatedResponse(results), byc["env"])


################################################################################
################################################################################
Expand Down
25 changes: 11 additions & 14 deletions services/genespans.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,33 @@ def genespans():
"service_response": r.emptyResponse(),
"error_response": r.errorResponse()
})
dbpars = {
"mongohost": byc.get("mongohost", "localhost"),
"services_db": byc.get("services_db", "___none___"),
"genes_coll": byc.get("genes_coll", "___none___")
}
db_config = byc.get("db_config", {})
form = byc.get("form_data", {})

gene_id = rest_path_value("genespans")
if gene_id:
# REST path id assumes exact match
results, e = GeneInfo(dbpars).returnGene(gene_id)
results, e = GeneInfo(db_config).returnGene(gene_id)
else:
gene_id = byc[ "form_data" ].get("gene_id")
results, e = GeneInfo(dbpars).returnGenelist(gene_id)
results, e = GeneInfo(db_config).returnGenelist(gene_id)

response_add_error(byc, 422, e )
cgi_break_on_errors(byc)
if e:
e_r = BeaconErrorResponse(byc).error(e, 422)
print_json_response(e_r, byc["env"])

for gene in results:
_gene_add_cytobands(gene, byc)

e_k_s = byc["service_config"]["method_keys"]["genespan"]

if "genespan" in byc.get("method", "___none___"):
if "genespan" in str(form.get("method", "___none___")):
for i, g in enumerate(results):
g_n = {}
for k in byc["service_config"]["method_keys"]["genespan"]:
g_n.update({k: g.get(k, "")})
results[i] = g_n

if "text" in byc.get("output", "___none___"):
if "text" in form.get("output", "___none___"):
open_text_streaming(byc["env"])
for g in results:
s_comps = []
Expand All @@ -81,8 +78,8 @@ def genespans():
print("\t".join(s_comps))
exit()

byc.update({"service_response": r.populatedResponse(results)})
cgi_print_response( byc, 200 )
print_json_response(r.populatedResponse(results), byc["env"])


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

Expand Down
28 changes: 15 additions & 13 deletions services/geolocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,22 @@ def geolocations():
"error_response": r.errorResponse()
})

services_db = byc.get("services_db")
geo_coll = byc.get("geolocs_coll")
mdb_c = byc.get("db_config", {})
services_db = mdb_c.get("services_db")
geo_coll = mdb_c.get("geolocs_coll")

if "inputfile" in byc["form_data"]:
results = read_geomarker_table_web(byc)
else:
query, geo_pars = geo_query(byc)

if len(query.keys()) < 1:
response_add_error(byc, 422, "No query generated - missing or malformed parameters" )
cgi_break_on_errors(byc)

results, e = mongo_result_list( services_db, geo_coll, query, { '_id': False } )
response_add_error(byc, 422, e)
e_m = "No query generated - missing or malformed parameters"
else:
results, e_m = mongo_result_list(mdb_c, services_db, geo_coll, query, { '_id': False } )
if e_m:
e_r = BeaconErrorResponse(byc).error(e_m, 422)
print_json_response(e_r, byc["env"])

print_map_from_geolocations(byc, results)

Expand All @@ -69,10 +71,10 @@ def geolocations():
"geo_distance": int(byc["form_data"]["geo_distance"])
}
query = return_geo_longlat_query(geo_root, geo_pars)
results, e = mongo_result_list( services_db, geo_coll, query, { '_id': False } )
response_add_error(byc, 422, e)

cgi_break_on_errors(byc)
results, e_m = mongo_result_list(mdb_c, services_db, geo_coll, query, { '_id': False } )
if e_m:
e_r = BeaconErrorResponse(byc).error(e_m, 422)
print_json_response(e_r, byc["env"])

if "text" in byc["output"]:
open_text_streaming(byc["env"], "browser")
Expand All @@ -86,8 +88,8 @@ def geolocations():
print("\t".join(s_comps))
exit()

byc.update({"service_response": r.populatedResponse(results)})
cgi_print_response( byc, 200 )
print_json_response(r.populatedResponse(results), byc["env"])


################################################################################
################################################################################
Expand Down
6 changes: 3 additions & 3 deletions services/intervalFrequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def interval_frequencies():
byc[ "filters" ] = [ {"id": byc["form_data"]["id"]} ]

if not "filters" in byc:
response_add_error(byc, 422, "No value was provided for collation `id` or `filters`.")
cgi_break_on_errors(byc)
e_m = "No value was provided for collation `id` or `filters`."
e_r = BeaconErrorResponse(byc).error(e_m, 422)
print_json_response(e_r, byc["env"])

file_type = byc["form_data"].get("output", "pgxfreq")
if file_type not in ["pgxfreq", "pgxmatrix"]:
Expand All @@ -66,7 +67,6 @@ def interval_frequencies():
pdb = ByconBundler(byc).collationsPlotbundles()
check_pgxseg_frequencies_export(byc, pdb.get("interval_frequencies_bundles", []))
check_pgxmatrix_frequencies_export(byc, pdb.get("interval_frequencies_bundles", []))
# ByconPlot(byc, pdb).svgResponse()

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

Expand Down
4 changes: 2 additions & 2 deletions services/lib/bycon_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, byc):
self.datatable_mappings = byc.get("datatable_mappings", {})
self.filters = byc.get("filters", [])
self.min_number = byc["form_data"].get("min_number", 0)
self.method = byc.get("method", "___none___")
self.delivery_method = byc["form_data"].get("method")
self.header = []
self.data = []
self.fieldnames = []
Expand Down Expand Up @@ -441,7 +441,7 @@ def __isetBundlesFromCollationParameters(self):
return

fmap_name = "frequencymap"
if "codematches" in self.method:
if "codematches" in str(self.delivery_method):
fmap_name = "frequencymap_codematches"

mongo_client = MongoClient(host=environ.get("BYCON_MONGO_HOST", "localhost"))
Expand Down
8 changes: 4 additions & 4 deletions services/lib/service_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

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

def set_selected_delivery_keys(method, method_keys, form_data):
def set_selected_delivery_keys(method_keys, form_data):
# the method keys can be overriden with "deliveryKeys"

d_k = []
delivery_method = form_data.get("method", "___none___")

if "delivery_keys" in form_data:
d_k = re.split(",", form_data.get("delivery_keys", []))
if len(d_k) > 0:
return d_k

if not method:
if not delivery_method:
return d_k

if not method_keys:
return d_k

d_k = method_keys.get(method, [])
d_k = method_keys.get(str(delivery_method), [])

return d_k

Expand Down
Loading

0 comments on commit c1cc13e

Please sign in to comment.