Skip to content

Commit

Permalink
2.2.1
Browse files Browse the repository at this point in the history
Major query stack rewrite; for more see

https://bycon.progenetix.org/changes/
  • Loading branch information
mbaudis committed Feb 21, 2025
1 parent f6ef6dd commit c6164cd
Show file tree
Hide file tree
Showing 108 changed files with 371,711 additions and 288,389 deletions.
Empty file modified MANIFEST.in
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified beaconplusWeb/public/img/progenetix-logo.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 23 additions & 16 deletions bycon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# __init__.py
import sys, traceback
from os import environ, path
from pathlib import Path
from os import path

pkg_path = path.dirname( path.abspath(__file__) )
bycon_lib_path = path.join( pkg_path, "lib" )
sys.path.append( pkg_path )
sys.path.append( bycon_lib_path )

from config import *

bycon_lib_path = path.join( pkg_path, "lib" )
sys.path.append( bycon_lib_path )

# try block to give at least some feedback on errors
try:

from beacon_auth import *
from beacon_response_generation import *
from bycon_helpers import *
from cytoband_parsing import *
from dataset_parsing import *
from genome_utils import *
from handover_generation import *
from parameter_parsing import *
Expand All @@ -25,20 +24,26 @@
from read_specs import *
from response_remapping import *
from schema_parsing import *
from service_utils import *
from variant_mapping import *

# import byconServiceLibs

read_service_definition_files()
update_rootpars_from_local_or_HOST()
rest_path_elements()
set_beacon_defaults()
arguments_set_defaults()
parse_arguments()
set_entities()
initialize_bycon_service()
parse_filters()

if (defaults := BYC["beacon_defaults"].get("defaults", {})):
for d_k, d_v in defaults.items():
BYC.update( { d_k: d_v } )

ByconParameters().set_parameters()
ByconEntities().set_entities()
ByconDatasets().set_dataset_ids()

if (tm := BYC_PARS.get("test_mode")):
BYC.update({"TEST_MODE": test_truthy(tm)})
if BYC.get("TEST_MODE") is True:
BYC_PARS.update({"include_handovers": True})

set_user_name()
set_returned_granularities()

except Exception:
if not "___shell___" in ENV:
Expand All @@ -49,3 +54,5 @@
print(traceback.format_exc())
print()
exit()


6 changes: 3 additions & 3 deletions bycon/byconServiceLibs/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
sys.path.append( services_lib_path )

try:
from bycon_bundler import *
from bycon_bundler import ByconBundler
from bycon_cluster import ByconCluster
from bycon_importer import ByconImporter
from bycon_plot import *
from clustering_utils import *
from collation_utils import *
from cytoband_utils import *
from datatable_utils import *
from export_file_generation import *
from file_utils import *
from geoloc_utils import *
from importer_helpers import *
from interval_utils import *
from ontology_utils import *
from service_helpers import *
Expand Down
8 changes: 5 additions & 3 deletions bycon/byconServiceLibs/bycon_bundler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import csv, datetime, re, sys
import csv, re, sys

from datetime import datetime

from os import environ, path
from pymongo import MongoClient
Expand Down Expand Up @@ -365,7 +367,7 @@ def __keyed_bundle_add_variants_from_lines(self):
update_v = import_datatable_dict_line(update_v, fieldnames, v, "genomicVariant")
update_v = ByconVariant().pgxVariant(update_v)
update_v.update({
"updated": datetime.datetime.now().isoformat()
"updated": datetime.now().isoformat()
})
vars_ided[cs_id].append(update_v)

Expand All @@ -374,7 +376,7 @@ def __keyed_bundle_add_variants_from_lines(self):
cs_ided[cs_id].update({"cnv_statusmaps": maps})
cs_ided[cs_id].update({"cnv_stats": cs_cnv_stats})
cs_ided[cs_id].update({"cnv_chro_stats": cs_chro_stats})
cs_ided[cs_id].update({"updated": datetime.datetime.now().isoformat()})
cs_ided[cs_id].update({"updated": datetime.now().isoformat()})

self.keyedBundle.update({
"individuals_by_id": inds_ided,
Expand Down
84 changes: 84 additions & 0 deletions bycon/byconServiceLibs/bycon_cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import scipy.cluster

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

class ByconCluster():
def __init__(self, plv):
self.plv = plv
self.data = plv.get("results", [])
self.cluster_metric = plv.get("plot_cluster_metric", "complete")
self.samples_cluster_type = plv.get("plot_samples_cluster_type", "")
self.tree_side = "right"
self.matrix = []
self.dendrogram = {}
self.new_order = []


# -------------------------------------------------------------------------#
# ----------------------------- public ------------------------------------#
# -------------------------------------------------------------------------#

def cluster_frequencies(self):
self.__matrix_from_interval_frequencies()
self.__make_dendrogram()
return self.dendrogram


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

def cluster_samples(self):
self.__matrix_from_samples()
self.__make_dendrogram()
return self.dendrogram


# -------------------------------------------------------------------------#
# ----------------------------- private -----------------------------------#
# -------------------------------------------------------------------------#

def __matrix_from_interval_frequencies(self):
for f_set in self.data:
i_f = f_set.get("interval_frequencies", [])
if_line = []
for i_f in f_set.get("interval_frequencies", []):
if_line.append( i_f.get("gain_frequency", 0) )
for i_f in f_set.get("interval_frequencies", []):
if_line.append( i_f.get("loss_frequency", 0) )
self.matrix.append(if_line)


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

def __matrix_from_samples(self):
for s in self.data:
s_line = []
if "intcoverage" in self.samples_cluster_type:
c_m = s.get("cnv_statusmaps", {})
dup_l = c_m.get("dup", [])
del_l = c_m.get("del", [])
for i_dup in dup_l:
s_line.append(i_dup)
for i_del in del_l:
s_line.append(i_del)
else:
c_s = s.get("cnv_chro_stats", {})
for c_a, c_s_v in c_s.items():
s_line.append(c_s_v.get("dupfraction", 0))
for c_a, c_s_v in c_s.items():
s_line.append(c_s_v.get("delfraction", 0))
self.matrix.append(s_line)


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

def __make_dendrogram(self):
linkage = scipy.cluster.hierarchy.linkage(self.matrix, method=self.cluster_metric)
self.new_order = scipy.cluster.hierarchy.leaves_list(linkage)
self.dendrogram = scipy.cluster.hierarchy.dendrogram(linkage, no_plot=True, orientation=self.tree_side)


################################################################################
################################################################################
################################################################################
Loading

0 comments on commit c6164cd

Please sign in to comment.