File size: 5,340 Bytes
41c3310
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from fastapi import APIRouter, HTTPException
from typing import List, Dict, Optional
from pydantic import BaseModel

router = APIRouter(prefix="/explorer", tags=["Explorer"])


# -----------------------------
# DATA MODELS
# -----------------------------

class DatasetMeta(BaseModel):
    nGenes: int
    nCells: int
    isSingleCell: bool
    isBulk: bool
    sparsity: Optional[float] = None
    hasTFList: Optional[bool] = None
    isTimeSeries: Optional[bool] = None


class Dataset(BaseModel):
    id: str
    name: str
    organism: str
    description: str
    meta: DatasetMeta


class AlgoProfile(BaseModel):
    name: str
    minGenes: Optional[int] = None
    maxGenes: Optional[int] = None
    requiresSingleCell: Optional[bool] = None
    requiresBulk: Optional[bool] = None
    requiresTFList: Optional[bool] = None
    requiresTimeSeries: Optional[bool] = None
    undirected: Optional[bool] = None
    maxCells: Optional[int] = None
    minCells: Optional[int] = None
    dynamic: Optional[bool] = None
    edgeSparsity: float


# -----------------------------
# MOCK DATASETS (replace later with HF)
# -----------------------------

DATASETS = [
    {
        "id": "dyn-bf",
        "name": "dyn-BF",
        "organism": "Synthetic",
        "description": "Bifurcating synthetic GRN",
        "meta": {
            "nGenes": 100,
            "nCells": 500,
            "isSingleCell": True,
            "isBulk": False,
            "hasTFList": True,
            "isTimeSeries": True,
            "sparsity": 0.7,
        },
    },
    {
        "id": "gsd",
        "name": "GSD",
        "organism": "Human",
        "description": "Gonadal sex determination GRN",
        "meta": {
            "nGenes": 2000,
            "nCells": 300,
            "isSingleCell": True,
            "isBulk": False,
            "hasTFList": True,
            "isTimeSeries": False,
        },
    },
]


ALGORITHMS: List[AlgoProfile] = [
    AlgoProfile(name="GENIE3", requiresTFList=True, maxGenes=20000, edgeSparsity=0.88),
    AlgoProfile(name="GRNBoost2", requiresSingleCell=True, requiresTFList=True, maxGenes=25000, edgeSparsity=0.92),
    AlgoProfile(name="Arboreto", requiresSingleCell=True, requiresTFList=True, maxGenes=30000, edgeSparsity=0.93),

    AlgoProfile(name="PIDC", requiresSingleCell=True, minGenes=50, maxGenes=8000, undirected=True, edgeSparsity=0.65),
    AlgoProfile(name="ARACNE", requiresBulk=True, minGenes=50, maxGenes=10000, undirected=True, edgeSparsity=0.60),

    AlgoProfile(name="Pearson", minGenes=10, undirected=True, edgeSparsity=0.95),
    AlgoProfile(name="Spearman", minGenes=10, undirected=True, edgeSparsity=0.95),

    AlgoProfile(name="SCODE", requiresSingleCell=True, requiresTimeSeries=True, maxGenes=5000, dynamic=True, edgeSparsity=0.55),
    AlgoProfile(name="SINGE", requiresSingleCell=True, requiresTimeSeries=True, dynamic=True, edgeSparsity=0.50),
    AlgoProfile(name="LEAP", requiresSingleCell=True, requiresTimeSeries=True, dynamic=True, edgeSparsity=0.70),

    AlgoProfile(name="GRNVBEM", requiresSingleCell=True, maxGenes=8000, edgeSparsity=0.75),
    AlgoProfile(name="GRISLI", requiresSingleCell=True, requiresTimeSeries=True, dynamic=True, edgeSparsity=0.60),
    AlgoProfile(name="SNS", requiresSingleCell=True, maxGenes=10000, edgeSparsity=0.72),
]


# -----------------------------
# CORE LOGIC (converted from React)
# -----------------------------

def is_algorithm_compatible(algo: AlgoProfile, dataset: DatasetMeta) -> bool:
    if algo.requiresSingleCell and not dataset.isSingleCell:
        return False
    if algo.requiresBulk and not dataset.isBulk:
        return False
    if algo.requiresTFList and not dataset.hasTFList:
        return False
    if algo.requiresTimeSeries and not dataset.isTimeSeries:
        return False
    if algo.minGenes and dataset.nGenes < algo.minGenes:
        return False
    if algo.maxGenes and dataset.nGenes > algo.maxGenes:
        return False
    if algo.minCells and dataset.nCells < algo.minCells:
        return False
    if algo.maxCells and dataset.nCells > algo.maxCells:
        return False

    return True


# -----------------------------
# ROUTES
# -----------------------------

@router.get("/datasets", response_model=List[Dataset])
def list_datasets():
    return DATASETS


@router.get("/datasets/{dataset_id}", response_model=Dataset)
def get_dataset(dataset_id: str):
    dataset = next((d for d in DATASETS if d["id"] == dataset_id), None)
    if not dataset:
        raise HTTPException(status_code=404, detail="Dataset not found")
    return dataset


@router.get("/algorithms", response_model=List[AlgoProfile])
def list_algorithms():
    return ALGORITHMS


@router.get("/algorithms/compatible/{dataset_id}", response_model=List[AlgoProfile])
def compatible_algorithms(dataset_id: str):
    dataset = next((d for d in DATASETS if d["id"] == dataset_id), None)
    if not dataset:
        raise HTTPException(status_code=404, detail="Dataset not found")

    meta = DatasetMeta(**dataset["meta"])

    return [
        algo for algo in ALGORITHMS
        if is_algorithm_compatible(algo, meta)
    ]


@router.post("/compatibility/check")
def check_compatibility(dataset: DatasetMeta):
    return {
        algo.name: is_algorithm_compatible(algo, dataset)
        for algo in ALGORITHMS
    }