credibleset
Credible Set functions.
CredibleSet
¶
Class representing credible sets from one fine-mapping tool.
Parameters¶
tool : str The name of the fine-mapping tool. parameters : Dict[str, Any] Additional parameters used by the fine-mapping tool. coverage : float The coverage of the credible sets. n_cs : int The number of credible sets. cs_sizes : List[int] Sizes of each credible set. lead_snps : List[str] List of lead SNPs. snps : List[List[str]] List of SNPs for each credible set. pips : pd.Series Posterior inclusion probabilities.
Attributes¶
tool : str The name of the fine-mapping tool. n_cs : int The number of credible sets. coverage : float The coverage of the credible sets. lead_snps : List[str] List of lead SNPs. snps : List[List[str]] List of SNPs for each credible set. cs_sizes : List[int] Sizes of each credible set. pips : pd.Series Posterior inclusion probabilities. parameters : Dict[str, Any] Additional parameters used by the fine-mapping tool.
Source code in credtools/credibleset.py
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
coverage
property
¶
Get the coverage.
cs_sizes
property
¶
Get the sizes of each credible set.
lead_snps
property
¶
Get the lead SNPs.
n_cs
property
¶
Get the number of credible sets.
parameters
property
¶
Get the parameters.
pips
property
¶
Get the PIPs.
snps
property
¶
Get the SNPs.
tool
property
¶
Get the tool name.
__init__(tool, parameters, coverage, n_cs, cs_sizes, lead_snps, snps, pips)
¶
Initialize CredibleSet object.
Parameters¶
tool : str The name of the fine-mapping tool. parameters : Dict[str, Any] Additional parameters used by the fine-mapping tool. coverage : float The coverage of the credible sets. n_cs : int The number of credible sets. cs_sizes : List[int] Sizes of each credible set. lead_snps : List[str] List of lead SNPs. snps : List[List[str]] List of SNPs for each credible set. pips : pd.Series Posterior inclusion probabilities.
Source code in credtools/credibleset.py
__repr__()
¶
Return a string representation of the CredibleSet object.
Returns¶
str String representation of the CredibleSet object.
Source code in credtools/credibleset.py
copy()
¶
Copy the CredibleSet object.
Returns¶
CredibleSet A copy of the CredibleSet object.
Source code in credtools/credibleset.py
create_enhanced_pips_df(locus_set)
¶
Create DataFrame with PIPs and full sumstats information.
Parameters¶
locus_set : LocusSet The locus set containing locus data.
Returns¶
pd.DataFrame DataFrame containing full sumstats, PIPs, R2, and credible set assignments.
Source code in credtools/credibleset.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
from_dict(data, pips)
classmethod
¶
Create CredibleSet from dictionary and pips.
Parameters¶
data : Dict[str, Any] A dictionary containing the data to initialize the CredibleSet. pips : pd.Series Posterior inclusion probabilities.
Returns¶
CredibleSet An instance of CredibleSet initialized with the provided data and pips.
Source code in credtools/credibleset.py
to_dict()
¶
Convert to dictionary for TOML storage (excluding pips).
Returns¶
Dict[str, Any] A dictionary representation of the CredibleSet excluding pips.
Source code in credtools/credibleset.py
cluster_cs(dict_sets, threshold=0.9)
¶
Cluster dictionaries from different sets based on continuous Jaccard similarity.
Parameters¶
dict_sets : List[List[Dict[str, float]]] List of m sets, where each set contains dictionaries with PIP values. threshold : float, optional Clustering threshold, by default 0.9.
Returns¶
List[List[str]] List of merged clusters, where each cluster contains a list of unique SNP IDs from the dictionaries in that cluster.
Raises¶
ValueError If less than two sets of dictionaries are provided or if any set is empty.
Examples¶
sets = [ ... [{'a': 0.8, 'b': 0.5}], ... [{'b': 0.6, 'c': 0.3}] ... ] clusters = cluster_cs(sets)
Source code in credtools/credibleset.py
combine_creds(creds, combine_cred='union', combine_pip='max', jaccard_threshold=0.1)
¶
Combine credible sets from multiple tools.
Parameters¶
creds : List[CredibleSet] List of credible sets from multiple tools. combine_cred : str, optional Method to combine credible sets, by default "union". Options: "union", "intersection", "cluster".
- "union": Union of all credible sets to form a merged credible set.
- "intersection": First merge the credible sets from the same tool,
then take the intersection of all merged credible sets.
No credible set will be returned if no common SNPs found.
- "cluster": Merge credible sets with Jaccard index > jaccard_threshold.
combine_pip : str, optional Method to combine PIPs, by default "max". Options: "max", "min", "mean", "meta".
- "meta": PIP_meta = 1 - prod(1 - PIP_i), where i is the index of tools,
PIP_i = 0 when the SNP is not in the credible set of the tool.
- "max": Maximum PIP value for each SNP across all tools.
- "min": Minimum PIP value for each SNP across all tools.
- "mean": Mean PIP value for each SNP across all tools.
jaccard_threshold : float, optional Jaccard index threshold for the "cluster" method, by default 0.1.
Returns¶
CredibleSet Combined credible set.
Raises¶
ValueError If the method is not supported.
Notes¶
'union' and 'intersection' methods will merge all credible sets into one.
Source code in credtools/credibleset.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
|
combine_pips(pips, method='max')
¶
Combine PIPs from multiple tools.
Parameters¶
pips : List[pd.Series] List of PIPs from multiple tools. method : str, optional Method to combine PIPs, by default "max". Options: "max", "min", "mean", "meta". When "meta" is selected, the method will use the formula: PIP_meta = 1 - prod(1 - PIP_i), where i is the index of tools, PIP_i = 0 when the SNP is not in the credible set of the tool. When "max", "min", "mean" is selected, the SNP not in the credible set will be excluded from the calculation.
Returns¶
pd.Series Combined PIPs.
Raises¶
ValueError If the method is not supported.
Source code in credtools/credibleset.py
continuous_jaccard(dict1, dict2)
¶
Calculate modified Jaccard similarity for continuous values (PIP values).
Formula: ∑min(xi,yi)/∑max(xi,yi) where xi, yi are PIP values or 0 if missing
Parameters¶
dict1 : Dict[str, float] First dictionary with keys and PIP values (0-1). dict2 : Dict[str, float] Second dictionary with keys and PIP values (0-1).
Returns¶
float Modified Jaccard similarity index between 0 and 1.
Raises¶
ValueError If any values are not between 0 and 1.
Examples¶
d1 = {'a': 0.8, 'b': 0.5} d2 = {'b': 0.6, 'c': 0.3} continuous_jaccard(d1, d2) 0.5
Source code in credtools/credibleset.py
create_similarity_matrix(dict_sets)
¶
Create a similarity matrix for all pairs of dictionaries across different sets.
Parameters¶
dict_sets : List[List[Dict[str, float]]] List of m sets, where each set contains dictionaries with PIP values.
Returns¶
Tuple[np.ndarray, List[Dict[str, float]]] A tuple containing: - Similarity matrix (n_dicts x n_dicts) - Flattened list of dictionaries
Examples¶
sets = [[{'a': 0.8, 'b': 0.5}], [{'b': 0.6, 'c': 0.3}]] matrix, dicts = create_similarity_matrix(sets)