-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Harmonization): Add heterogeneity scores
- Loading branch information
Showing
8 changed files
with
83 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
modules/oncoliner_harmonization/src/harmonizator/heterogeneity_metrics.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import List, Tuple | ||
import sys | ||
import os | ||
|
||
import pandas as pd | ||
import numpy as np | ||
|
||
# Add vcf-ops to the path | ||
sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', '..', '..', '..', 'shared', 'vcf_ops', 'src')) | ||
from vcf_ops.genes import GENE_SPLIT_SYMBOL # noqa | ||
|
||
def compute_h_score(metrics: List[Tuple[float, float]]) -> float: | ||
# Compute the centroid | ||
centroid = np.mean(metrics, axis=0) | ||
# Compute the distance from the centroid to each point | ||
distances = [] | ||
for point in metrics: | ||
distances.append(np.linalg.norm(point - centroid)) | ||
# Compute the h-score | ||
h_score = np.mean(distances) | ||
return h_score | ||
|
||
|
||
def compute_gdr(genes_list: List[str]) -> float: | ||
intersect_genes = None | ||
union_genes = None | ||
for genes in genes_list: | ||
if type(genes) == float: | ||
continue | ||
curr_genes = set(genes.split(GENE_SPLIT_SYMBOL)) | ||
if intersect_genes is None: | ||
intersect_genes = curr_genes | ||
union_genes = curr_genes | ||
continue | ||
intersect_genes = intersect_genes.intersection(curr_genes) | ||
union_genes = union_genes.union(curr_genes) | ||
if union_genes is None or len(union_genes) == 0: | ||
return 0 | ||
return 1 - (len(intersect_genes) / len(union_genes)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +0,0 @@ | ||
# Copyright 2023 - Barcelona Supercomputing Center | ||
# Author: Rodrigo Martín | ||
# BSC Dual License | ||
|
||
# Export VariantType from VariantExtractor | ||
from variant_extractor.variants import VariantType | ||
|
||
__version__ = '0.0.1' | ||
__author__ = 'Rapsssito' | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters