diff --git a/src/api_service/migrations/0061_alter_experiment_shared_users.py b/src/api_service/migrations/0061_alter_experiment_shared_users.py new file mode 100644 index 0000000..b7cfa5a --- /dev/null +++ b/src/api_service/migrations/0061_alter_experiment_shared_users.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.15 on 2024-10-23 13:51 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('api_service', '0060_experiment_shared_users'), + ] + + operations = [ + migrations.AlterField( + model_name='experiment', + name='shared_users', + field=models.ManyToManyField(blank=True, related_name='shared_users_correlation_analysis', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/src/api_service/mrna_service.py b/src/api_service/mrna_service.py index 16a59f3..d431f53 100644 --- a/src/api_service/mrna_service.py +++ b/src/api_service/mrna_service.py @@ -13,10 +13,28 @@ class MRNAService(object): def __init__(self): modulector_settings = settings.MODULECTOR_SETTINGS - self.url_modulector_prefix = f"http://{modulector_settings['host']}:{modulector_settings['port']}" + self.url_modulector_prefix = self.__build_url(modulector_settings) bioapi_settings = settings.BIOAPI_SETTINGS - self.url_bioapi_prefix = f"http://{bioapi_settings['host']}:{bioapi_settings['port']}" + self.url_bioapi_prefix = self.__build_url(bioapi_settings) + + @staticmethod + def __build_url(settings: Dict[str, Any]) -> str: + """ + Constructs the URL based on the settings provided. + If the port is the default for the protocol (80 for http, 443 for https), it is omitted. + Otherwise, the port is included in the URL. + @param settings: Dictionary containing protocol, host, and port information. + @return: Constructed URL as a string. + """ + protocol = settings['protocol'] + host = settings['host'] + port = settings['port'] + + if (protocol == 'http' and port == 80) or (protocol == 'https' and port == 443): + return f"{protocol}://{host}" + else: + return f"{protocol}://{host}:{port}" @staticmethod def __generate_rest_query_params(get_request: QueryDict) -> str: diff --git a/src/feature_selection/fs_algorithms_spark.py b/src/feature_selection/fs_algorithms_spark.py index bc2125b..fcec625 100644 --- a/src/feature_selection/fs_algorithms_spark.py +++ b/src/feature_selection/fs_algorithms_spark.py @@ -32,6 +32,8 @@ def __get_clustering_algorithm_value(cluster_algorithm: ClusteringAlgorithm) -> """Gets the corresponding string value for the parameter 'clustering-algorithm' of the EMR integration.""" if cluster_algorithm == ClusteringAlgorithm.SPECTRAL: return 'spectral' + if cluster_algorithm == ClusteringAlgorithm.BK_MEANS: + return 'bk_means' return 'k_means' # Default is kmeans diff --git a/src/feature_selection/fs_models.py b/src/feature_selection/fs_models.py index 4570b80..a8de8e1 100644 --- a/src/feature_selection/fs_models.py +++ b/src/feature_selection/fs_models.py @@ -1,6 +1,6 @@ from typing import Literal, Union, Optional from django.conf import settings -from sklearn.cluster import KMeans, SpectralClustering +from sklearn.cluster import KMeans, SpectralClustering, BisectingKMeans from sksurv.ensemble import RandomSurvivalForest from sksurv.svm import FastKernelSurvivalSVM from .models import ClusteringAlgorithm @@ -12,7 +12,7 @@ SVMOptimizerOptions = Literal["avltree", "rbtree"] # Available models for clustering -ClusteringModels = Union[KMeans, SpectralClustering] +ClusteringModels = Union[KMeans, SpectralClustering, BisectingKMeans] def get_clustering_model(clustering_algorithm: ClusteringAlgorithm, @@ -28,6 +28,8 @@ def get_clustering_model(clustering_algorithm: ClusteringAlgorithm, return KMeans(n_clusters=number_of_clusters, random_state=random_state, n_init='auto') elif clustering_algorithm == ClusteringAlgorithm.SPECTRAL: return SpectralClustering(n_clusters=number_of_clusters, random_state=random_state) + elif clustering_algorithm == ClusteringAlgorithm.BK_MEANS: + return BisectingKMeans(n_clusters=number_of_clusters, random_state=random_state) raise Exception(f'Invalid clustering_algorithm parameter: {clustering_algorithm}') diff --git a/src/feature_selection/migrations/0056_alter_clusteringparameters_algorithm_and_more.py b/src/feature_selection/migrations/0056_alter_clusteringparameters_algorithm_and_more.py new file mode 100644 index 0000000..53051cd --- /dev/null +++ b/src/feature_selection/migrations/0056_alter_clusteringparameters_algorithm_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.15 on 2024-10-23 13:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('feature_selection', '0055_alter_fsexperiment_app_name_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='clusteringparameters', + name='algorithm', + field=models.IntegerField(choices=[(1, 'K Means'), (2, 'Spectral'), (3, 'Bk Means')], default=1), + ), + migrations.AlterField( + model_name='clusteringtimesrecord', + name='algorithm', + field=models.IntegerField(choices=[(1, 'K Means'), (2, 'Spectral'), (3, 'Bk Means')]), + ), + ] diff --git a/src/feature_selection/models.py b/src/feature_selection/models.py index 1b99b92..0ad5b36 100644 --- a/src/feature_selection/models.py +++ b/src/feature_selection/models.py @@ -33,6 +33,7 @@ class ClusteringAlgorithm(models.IntegerChoices): """Clustering algorithm.""" K_MEANS = 1 SPECTRAL = 2 # TODO: implement in backend + BK_MEANS = 3 class ClusteringMetric(models.IntegerChoices): diff --git a/src/feature_selection/views.py b/src/feature_selection/views.py index 4739b87..6e93a05 100644 --- a/src/feature_selection/views.py +++ b/src/feature_selection/views.py @@ -209,7 +209,13 @@ def __get_clustering_parameters_columns(row: pd.Series) -> Tuple[int, Clustering parameters_desc = row['parameters'] params = parameters_desc.split('_') number_of_clusters, algorithm_description, scoring_method = params[0], params[2], params[4] - algorithm = ClusteringAlgorithm.K_MEANS if algorithm_description == 'k-means' else ClusteringAlgorithm.SPECTRAL + # algorithm = ClusteringAlgorithm.K_MEANS if algorithm_description == 'k-means' else ClusteringAlgorithm.SPECTRAL + if algorithm_description == 'k-means': + algorithm = ClusteringAlgorithm.K_MEANS + elif algorithm_description == 'spectral': + algorithm = ClusteringAlgorithm.SPECTRAL + else: + algorithm = ClusteringAlgorithm.BK_MEANS scoring = ClusteringScoringMethod.C_INDEX if scoring_method == 'concordance-index' \ else ClusteringScoringMethod.LOG_LIKELIHOOD return number_of_clusters, algorithm, scoring diff --git a/src/frontend/static/frontend/src/components/biomarkers/labels/ClusteringAlgorithmLabel.tsx b/src/frontend/static/frontend/src/components/biomarkers/labels/ClusteringAlgorithmLabel.tsx index 79c4153..5535b83 100644 --- a/src/frontend/static/frontend/src/components/biomarkers/labels/ClusteringAlgorithmLabel.tsx +++ b/src/frontend/static/frontend/src/components/biomarkers/labels/ClusteringAlgorithmLabel.tsx @@ -28,6 +28,10 @@ export const ClusteringAlgorithmLabel = (props: ClusteringAlgorithmLabelProps) = color = 'blue' description = 'Spectral' break + case ClusteringAlgorithm.BK_MEANS: + color = 'blue' + description = 'Bisecting KMeans' + break default: color = 'blue' description = '' diff --git a/src/frontend/static/frontend/src/components/biomarkers/types.ts b/src/frontend/static/frontend/src/components/biomarkers/types.ts index 2d26753..20b78bb 100644 --- a/src/frontend/static/frontend/src/components/biomarkers/types.ts +++ b/src/frontend/static/frontend/src/components/biomarkers/types.ts @@ -208,7 +208,8 @@ enum FitnessFunction { /** Clustering algorithm. */ enum ClusteringAlgorithm { K_MEANS = 1, - SPECTRAL = 2 + SPECTRAL = 2, + BK_MEANS = 3 } /** Clustering metric to optimize. */ diff --git a/src/frontend/static/frontend/src/components/biomarkers/utils.ts b/src/frontend/static/frontend/src/components/biomarkers/utils.ts index 971cd35..a51237a 100644 --- a/src/frontend/static/frontend/src/components/biomarkers/utils.ts +++ b/src/frontend/static/frontend/src/components/biomarkers/utils.ts @@ -36,7 +36,8 @@ const SVMKernelOptions: DropdownItemProps[] = [ /** Available options for a Clustering algorithm. */ const clusteringAlgorithmOptions: DropdownItemProps[] = [ { key: ClusteringAlgorithm.K_MEANS, text: 'K-Means', value: ClusteringAlgorithm.K_MEANS }, - { key: ClusteringAlgorithm.SPECTRAL, text: 'Spectral', value: ClusteringAlgorithm.SPECTRAL } + { key: ClusteringAlgorithm.SPECTRAL, text: 'Spectral', value: ClusteringAlgorithm.SPECTRAL }, + { key: ClusteringAlgorithm.BK_MEANS, text: 'BK-Means', value: ClusteringAlgorithm.BK_MEANS } ] /** Available options for a Clustering metric to optimize. */ diff --git a/src/multiomics_intermediate/settings.py b/src/multiomics_intermediate/settings.py index beaf510..3718507 100644 --- a/src/multiomics_intermediate/settings.py +++ b/src/multiomics_intermediate/settings.py @@ -299,14 +299,16 @@ # Modulector settings MODULECTOR_SETTINGS = { - 'host': os.getenv('MODULECTOR_HOST', '127.0.0.1'), - 'port': os.getenv('MODULECTOR_PORT', '8001') + 'host': os.getenv('MODULECTOR_HOST', 'modulector.multiomix.org'), + 'port': os.getenv('MODULECTOR_PORT', 443), + 'protocol': os.getenv('BIOAPI_PROTOCOL', 'https') } # BioAPI settings BIOAPI_SETTINGS = { - 'host': os.getenv('BIOAPI_HOST', '127.0.0.1'), - 'port': os.getenv('BIOAPI_PORT', '8002') + 'host': os.getenv('BIOAPI_HOST', 'bioapi.multiomix.org'), + 'port': os.getenv('BIOAPI_PORT', 443), + 'protocol': os.getenv('BIOAPI_PROTOCOL', 'https') } # Multiomix-aws-emr