Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fs selection #56

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/api_service/migrations/0061_alter_experiment_shared_users.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
22 changes: 20 additions & 2 deletions src/api_service/mrna_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/feature_selection/fs_algorithms_spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 4 additions & 2 deletions src/feature_selection/fs_models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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}')

Expand Down
Original file line number Diff line number Diff line change
@@ -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')]),
),
]
1 change: 1 addition & 0 deletions src/feature_selection/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ClusteringAlgorithm(models.IntegerChoices):
"""Clustering algorithm."""
K_MEANS = 1
SPECTRAL = 2 # TODO: implement in backend
BK_MEANS = 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Siempre que se cambia un campo que va hacia un modelo se tiene que correr el comando python3 manage.py makemigrations y luego python3 manage.py migrate así la DB se entera.
Ese archivo .py que es la migración también pusheala a este PR por fa!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se agregaron las migraciones faltantes 👨‍💻



class ClusteringMetric(models.IntegerChoices):
Expand Down
8 changes: 7 additions & 1 deletion src/feature_selection/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ enum FitnessFunction {
/** Clustering algorithm. */
enum ClusteringAlgorithm {
K_MEANS = 1,
SPECTRAL = 2
SPECTRAL = 2,
BK_MEANS = 3
}

/** Clustering metric to optimize. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
10 changes: 6 additions & 4 deletions src/multiomics_intermediate/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading