diff --git a/vis_phewas/som/som_utils.py b/vis_phewas/som/som_utils.py index ad90da4..00c8b49 100644 --- a/vis_phewas/som/som_utils.py +++ b/vis_phewas/som/som_utils.py @@ -118,12 +118,12 @@ def initialise_som(x_normalised, som_x=None, som_y=None, sigma=1.0, learning_rat """ # Use rule of 10 sqrt(n) for the number of neurons if not specified if som_x is None: - som_x = int(np.sqrt(5 * np.sqrt(x_normalised.shape[0]))) + som_x = int(np.sqrt(10 * np.sqrt(x_normalised.shape[0]))) if som_y is None: - som_y = int(np.sqrt(5 * np.sqrt(x_normalised.shape[0]))) + som_y = int(np.sqrt(10 * np.sqrt(x_normalised.shape[0]))) - print( - f"Training SOM with {som_x}x{som_y} grid, sigma={sigma}, learning_rate={learning_rate}, num_iterations={num_iterations}") + print(f"Training SOM with {som_x}x{som_y} grid, sigma={sigma}, learning_rate={learning_rate}, " + f"num_iterations={num_iterations}") # Initialise the SOM input_len = x_normalised.shape[1] @@ -144,7 +144,6 @@ def clean_filters(filters, som_type): :param som_type: Type of the SOM (SNP or disease) :return: Cleaned and formatted filters string """ - print(f"Filters: {filters}") # If no filters are provided, return "All Genes" or "All Categories" as appropriate if not filters: return "All Genes" if som_type == 'snp' else "All Categories" @@ -265,6 +264,7 @@ def plot_metrics_on_som(positions, som_type): silhouette_scores = [] range_n_clusters = range(2, 11) # Trying 2 to 10 clusters + # Perform KMeans clustering for each number of clusters for n_clusters in range_n_clusters: kmeans = KMeans(n_clusters=n_clusters, random_state=42) cluster_labels = kmeans.fit_predict(positions) # Use the SOM positions for clustering diff --git a/vis_phewas/som/views.py b/vis_phewas/som/views.py index 4dccb99..ff58db5 100644 --- a/vis_phewas/som/views.py +++ b/vis_phewas/som/views.py @@ -160,6 +160,9 @@ def process_and_visualise_som(self, data_id, num_clusters, filters, som_type, te filter_list = cleaned_filters.lower() filter_list = filter_list.replace('
', ',').split(',') filter_list = [f.strip() for f in filter_list] + # Uppercase is type is SNP + if som_type == 'snp': + filter_list = [f.upper() for f in filter_list] # Render the visualisation graph_div = pio.to_html(fig, full_html=False) diff --git a/vis_phewas/static/som/js/som.js b/vis_phewas/static/som/js/som.js index a939ac7..c618656 100644 --- a/vis_phewas/static/som/js/som.js +++ b/vis_phewas/static/som/js/som.js @@ -5,7 +5,6 @@ * @param {number} [num_clusters] - The number of clusters to generate. Defaults to 5 for 'disease' and 7 for 'allele'. */ function generateSOM(filters, type, num_clusters) { - console.log("Generating SOM with filters: " + filters + ", type: " + type + ", num_clusters: " + num_clusters); // Validate the type parameter if (type !== "snp" && type !== "disease") { alert("Invalid SOM type specified. Must be 'snp' or 'disease'."); diff --git a/vis_phewas/templates/mainapp/tools.html b/vis_phewas/templates/mainapp/tools.html index 5cd3bfb..5bd3198 100644 --- a/vis_phewas/templates/mainapp/tools.html +++ b/vis_phewas/templates/mainapp/tools.html @@ -3,8 +3,8 @@

Generate Self Organising Map

- - + +
diff --git a/vis_phewas/templates/som/som_view.html b/vis_phewas/templates/som/som_view.html index 437b2fd..a456bc2 100644 --- a/vis_phewas/templates/som/som_view.html +++ b/vis_phewas/templates/som/som_view.html @@ -42,7 +42,7 @@

Filter by Gene Name

Filter by Gene Name