qc
Quality control functions for CREDTOOLS data.
cochran_q(locus_set)
¶
Compute Cochran-Q statistic for heterogeneity testing across cohorts.
Parameters¶
locus_set : LocusSet LocusSet object containing multiple loci/cohorts.
Returns¶
pd.DataFrame DataFrame with SNPID as index and columns: - Q: Cochran-Q test statistic - Q_pvalue: p-value from chi-squared test - I_squared: I² heterogeneity statistic (percentage)
Notes¶
The Cochran-Q test assesses heterogeneity in effect sizes across studies:
Q = Σ w_i(β_i - β_pooled)²
where: - w_i = 1/SE_i² (inverse variance weights) - β_i = effect size in study i - β_pooled = weighted average effect size
The I² statistic quantifies the proportion of total variation due to heterogeneity rather than chance:
I² = max(0, (Q - df)/Q × 100%)
Interpretation: - Q p-value < 0.05: significant heterogeneity - I² > 50%: substantial heterogeneity - I² > 75%: considerable heterogeneity
High heterogeneity may indicate: - Population differences - Different LD patterns - Batch effects - Population stratification
Source code in credtools/qc.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 | |
compare_maf(locus)
¶
Compare allele frequencies between summary statistics and LD reference.
Parameters¶
locus : Locus Locus object containing summary statistics and LD matrix.
Returns¶
pd.DataFrame DataFrame containing the comparison results with columns: - SNPID: SNP identifier - MAF_sumstats: MAF from summary statistics - MAF_ld: MAF from LD reference
Returns empty DataFrame if AF2 column is not available in LD matrix.
Warnings¶
If AF2 column is not present in the LD matrix, a warning is logged.
Notes¶
This function compares minor allele frequencies (MAF) between:
- Summary statistics (derived from EAF)
- LD reference panel (from AF2 column)
Large discrepancies may indicate: - Population stratification - Allele frequency differences between studies - Potential data quality issues
MAF is calculated as min(AF, 1-AF) for both sources.
Source code in credtools/qc.py
compute_dentist_s(locus)
¶
Compute Dentist-S statistic and p-value for outlier detection.
Parameters¶
locus : Locus Locus object containing summary statistics and LD matrix.
Returns¶
pd.DataFrame DataFrame containing the results of the Dentist-S test with columns: - SNPID: SNP identifier - t_dentist_s: Dentist-S test statistic - -log10p_dentist_s: -log10 p-value
Notes¶
Reference: https://github.com/mkanai/slalom/blob/854976f8e19e6fad2db3123eb9249e07ba0e1c1b/slalom.py#L254
The Dentist-S statistic tests for outliers by comparing each variant's z-score to what would be expected based on its LD with the lead variant:
t_dentist_s = (z_j - r_jk * z_k)^2 / (1 - r_jk^2)
where: - z_j: z-score for variant j - z_k: z-score for lead variant k - r_jk: LD correlation between variants j and k
TODO: Use ABF to select lead variant, although in most cases the lead variant is the one with the smallest p-value.
Source code in credtools/qc.py
estimate_s_rss(locus, r_tol=1e-08, method='null-mle', eigvens=None, dtype=None)
¶
Estimate s parameter in the susie_rss Model Using Regularized LD.
Parameters¶
locus : Locus Locus object containing summary statistics and LD matrix. r_tol : float, optional Tolerance level for eigenvalue check of positive semidefinite matrix, by default 1e-8. method : str, optional Method to estimate s, by default "null-mle". Options: "null-mle", "null-partialmle", or "null-pseudomle". eigvens : Optional[Dict[str, np.ndarray]], optional Pre-computed eigenvalues and eigenvectors, by default None. dtype : Optional[np.dtype], optional Data type for computation. If None, uses float64. Use np.float32 for reduced memory usage with minimal precision loss.
Returns¶
float Estimated s value between 0 and 1 (or potentially > 1 for "null-partialmle").
Raises¶
ValueError If n <= 1 or if the method is not implemented.
Notes¶
This function estimates the parameter s, which provides information about the consistency between z-scores and the LD matrix. A larger s indicates a strong inconsistency between z-scores and the LD matrix.
The function implements three estimation methods:
- "null-mle": Maximum likelihood estimation under the null model
- "null-partialmle": Partial MLE using null space projection
- "null-pseudomle": Pseudo-likelihood estimation
The z-scores are transformed using the formula: z_transformed = sqrt(sigma2) * z where sigma2 = (n-1) / (z^2 + n-2)
Source code in credtools/qc.py
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 | |
get_eigen(ldmatrix, dtype=None)
¶
Compute eigenvalues and eigenvectors of LD matrix.
Parameters¶
ldmatrix : np.ndarray A p by p symmetric, positive semidefinite correlation matrix. dtype : Optional[np.dtype], optional Data type for computation. If None, uses the input matrix dtype. Use np.float32 for reduced memory usage with minimal precision loss.
Returns¶
Dict[str, np.ndarray] Dictionary containing eigenvalues and eigenvectors with keys: - 'eigvals': eigenvalues array - 'eigvecs': eigenvectors matrix
Notes¶
TODO: accelerate with joblib for large matrices.
This function uses numpy.linalg.eigh which is optimized for symmetric matrices and returns eigenvalues in ascending order.
Source code in credtools/qc.py
identify_outliers(qc_metrics, cohort, logLR_threshold=2, z_threshold=2, z_std_diff_threshold=3, r_threshold=0.8, dentist_s_pvalue_threshold=4, dentist_s_r2_threshold=0.6)
¶
Identify outlier SNPs based on QC metrics.
Parameters¶
qc_metrics : Dict[str, pd.DataFrame] Dictionary of QC results from locus_qc function. cohort : str Cohort identifier (format: "popu_cohort"). logLR_threshold : float, optional LogLR threshold for LD mismatch detection, by default 2. z_threshold : float, optional Z-score threshold for both LD mismatch and marginal SNP detection, by default 2. z_std_diff_threshold : float, optional Z_std_diff threshold for marginal SNP outlier detection, by default 3. r_threshold : float, optional Correlation threshold with lead SNP for marginal SNP detection, by default 0.8. dentist_s_pvalue_threshold : float, optional -log10 p-value threshold for Dentist-S outlier detection, by default 4. dentist_s_r2_threshold : float, optional R² threshold for Dentist-S outlier detection, by default 0.6.
Returns¶
pd.DataFrame DataFrame of outlier SNPs with columns: SNPID, C1_ld_mismatch, C2_marginal, C3_dentist_s. Each row represents a SNP that triggered at least one outlier criterion.
Source code in credtools/qc.py
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 | |
kriging_rss(locus, r_tol=1e-08, s=None, eigvens=None, dtype=None)
¶
Compute distribution of z-scores of variant j given other z-scores, and detect possible allele switch issues.
Parameters¶
locus : Locus Locus object containing summary statistics and LD matrix. r_tol : float, optional Tolerance level for eigenvalue check of positive semidefinite matrix, by default 1e-8. s : Optional[float], optional An estimated s parameter from estimate_s_rss function, by default None. If None, s will be estimated automatically. eigvens : Optional[Dict[str, np.ndarray]], optional Pre-computed eigenvalues and eigenvectors, by default None. dtype : Optional[np.dtype], optional Data type for computation. If None, uses float64. Use np.float32 for reduced memory usage with minimal precision loss.
Returns¶
pd.DataFrame DataFrame containing the results of the kriging RSS test with columns: - SNPID: SNP identifier - z: transformed z-score - condmean: conditional mean - condvar: conditional variance - z_std_diff: standardized difference - logLR: log likelihood ratio
Raises¶
ValueError If n <= 1.
Notes¶
Under the null hypothesis, the RSS model with regularized LD matrix assumes: z|R,s ~ N(0, (1-s)R + sI)
This function uses a mixture of normals to model the conditional distribution of z_j given other z-scores. The method can help detect:
- Allele switch issues
- Outlier variants
- LD inconsistencies
The algorithm: 1. Computes conditional means and variances for each variant 2. Fits a Gaussian mixture model to capture heterogeneity 3. Calculates likelihood ratios for allele switch detection
Source code in credtools/qc.py
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 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
ld_4th_moment(locus_set)
¶
Compute the 4th moment of the LD matrix as a measure of LD structure.
Parameters¶
locus_set : LocusSet LocusSet object containing multiple loci/cohorts.
Returns¶
pd.DataFrame DataFrame with variants as rows and cohorts as columns, containing the 4th moment values (sum of r^4 - 1 for each variant).
Notes¶
The 4th moment is calculated as: Σ(r_ij^4) - 1 for each variant i
This metric provides information about: - LD structure complexity - Potential issues with LD matrix quality - Differences in LD patterns between populations
Higher values may indicate: - Strong local LD structure - Potential genotyping errors - Population stratification effects
The function intersects variants across all cohorts to ensure fair comparison.
Source code in credtools/qc.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | |
ld_decay(locus_set)
¶
Compute LD decay patterns across cohorts.
Parameters¶
locus_set : LocusSet LocusSet object containing multiple loci/cohorts.
Returns¶
pd.DataFrame DataFrame containing LD decay information with columns: - distance_kb: distance in kilobases - r2_avg: average r² value at that distance - decay_rate: fitted exponential decay rate parameter - cohort: cohort identifier
Notes¶
This function analyzes LD decay by:
- Computing pairwise distances between all variants
- Binning distances into 1kb windows
- Calculating average r² within each distance bin
- Fitting an exponential decay model: r² = a * exp(-b * distance)
LD decay patterns can reveal: - Population-specific recombination patterns - Effective population size differences - Demographic history effects
Different populations typically show different decay rates due to: - Historical effective population sizes - Admixture patterns - Founder effects
Source code in credtools/qc.py
loci_qc(inputs, out_dir, threads=1, remove_outlier=False, logLR_threshold=2, z_threshold=2, z_std_diff_threshold=3, r_threshold=0.8, dentist_s_pvalue_threshold=4, dentist_s_r2_threshold=0.6)
¶
Perform quality control analysis on multiple loci in parallel.
Parameters¶
inputs : str Path to input file containing locus information. Must be tab-separated with columns including 'locus_id'. out_dir : str Output directory path where results will be saved. threads : int, optional Number of parallel threads to use, by default 1. remove_outlier : bool, optional Whether to remove outliers and re-run QC on cleaned data, by default False. logLR_threshold : float, optional LogLR threshold for LD mismatch detection, by default 2. z_threshold : float, optional Z-score threshold for both LD mismatch and marginal SNP detection, by default 2. z_std_diff_threshold : float, optional Z_std_diff threshold for marginal SNP outlier detection, by default 3. r_threshold : float, optional Correlation threshold with lead SNP for marginal SNP detection, by default 0.8. dentist_s_pvalue_threshold : float, optional -log10 p-value threshold for Dentist-S outlier detection, by default 4. dentist_s_r2_threshold : float, optional R² threshold for Dentist-S outlier detection, by default 0.6.
Returns¶
Dict[str, Any]
Run summary containing counts of successful and failed loci and error
details. QC result files are written under out_dir.
Raises¶
ValueError
Raised when threads is less than 1.
Notes¶
This function processes multiple loci in parallel with the following workflow:
- Reads locus information from input file
- Groups loci by locus_id
- Processes each locus group using multiprocessing
- Displays progress bar for user feedback
- Saves results organized by locus_id
The input file should contain columns: locus_id, prefix, popu, cohort, sample_size.
Output structure: {out_dir}/{locus_id}/{qc_metric}.txt.gz {out_dir}/{locus_id}/qc.txt.gz {out_dir}/qc.txt.gz
Each locus gets its own subdirectory with compressed QC result files. A global QC summary file is also generated at the output directory root.
Source code in credtools/qc.py
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 | |
locus_qc(locus_set, r_tol=0.001, method='null-mle', out_dir=None, dtype=None, logLR_threshold=2, z_threshold=2, z_std_diff_threshold=3, r_threshold=0.8, dentist_s_pvalue_threshold=4, dentist_s_r2_threshold=0.6)
¶
Perform comprehensive quality control analysis for a locus.
Parameters¶
locus_set : LocusSet LocusSet object containing loci to analyze. r_tol : float, optional Tolerance level for eigenvalue check of positive semidefinite matrix, by default 1e-3. method : str, optional Method to estimate s parameter, by default "null-mle". Options: "null-mle", "null-partialmle", or "null-pseudomle". out_dir : Optional[str], optional Output directory to save results, by default None. dtype : Optional[np.dtype], optional Data type for computation. If None, uses float64. Use np.float32 for reduced memory usage with minimal precision loss. logLR_threshold : float, optional LogLR threshold for LD mismatch detection, by default 2. z_threshold : float, optional Z-score threshold for both LD mismatch and marginal SNP detection, by default 2. z_std_diff_threshold : float, optional Z_std_diff threshold for marginal SNP outlier detection, by default 3. r_threshold : float, optional Correlation threshold with lead SNP for marginal SNP detection, by default 0.8. dentist_s_pvalue_threshold : float, optional -log10 p-value threshold for Dentist-S outlier detection, by default 4. dentist_s_r2_threshold : float, optional R² threshold for Dentist-S outlier detection, by default 0.6.
Returns¶
Dict[str, pd.DataFrame] Dictionary of quality control results with keys: - 'expected_z': kriging RSS results - 'dentist_s': Dentist-S test results - 'compare_maf': MAF comparison results
Note: heterogeneity metrics (ld_4th_moment, ld_decay, cochran_q,
snp_missingness) are now computed before meta-analysis via
``credtools.meta.compute_heterogeneity()``.
Notes¶
This function performs comprehensive QC including:
Single-locus analyses: - Kriging RSS for outlier detection with combined lambda-s outlier criteria: * LD Mismatch Indicators (SuSiE guidelines): logLR > threshold AND |z| > threshold * Marginally Non-significant SNPs: |z| < threshold AND |z_std_diff| > threshold AND |r| > threshold with lead SNP - Dentist-S for outlier detection - MAF comparison between sumstats and LD reference - LD matrix 4th moment analysis - LD decay pattern analysis
Multi-locus analyses (when applicable): - Cochran-Q heterogeneity testing - SNP missingness across cohorts
TODO: Add LAVA (Local Analysis of Variant Associations) analysis.
If out_dir is provided, results are saved as tab-separated files.
Source code in credtools/qc.py
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 | |
locus_qc_summary(qc_metrics, logLR_threshold=2, z_threshold=2, z_std_diff_threshold=3, r_threshold=0.8, dentist_s_pvalue_threshold=4, dentist_s_r2_threshold=0.6)
¶
Generate summary QC statistics for a locus across all cohorts.
Parameters¶
qc_metrics : Dict[str, pd.DataFrame] Dictionary of QC results from locus_qc function. logLR_threshold : float, optional LogLR threshold for LD mismatch detection, by default 2. z_threshold : float, optional Z-score threshold for both LD mismatch and marginal SNP detection, by default 2. z_std_diff_threshold : float, optional Z_std_diff threshold for marginal SNP outlier detection, by default 3. r_threshold : float, optional Correlation threshold with lead SNP for marginal SNP detection, by default 0.8. dentist_s_pvalue_threshold : float, optional -log10 p-value threshold for Dentist-S outlier detection, by default 4. dentist_s_r2_threshold : float, optional R² threshold for Dentist-S outlier detection, by default 0.6.
Returns¶
pd.DataFrame Summary QC statistics with columns: popu, cohort, n_snps, n_1e-5, n_5e-8, maf_corr, lambda_s, n_lambda_s_outlier, n_dentist_s_outlier.
Source code in credtools/qc.py
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 | |
qc_locus_cli(args)
¶
Quality control for a single locus (command-line interface wrapper).
Parameters¶
args : Tuple[str, pd.DataFrame, str, bool, float, float, float, float, float, float] Tuple containing: - locus_id : str Locus identifier - locus_info : pd.DataFrame DataFrame with locus information - base_out_dir : str Base output directory - remove_outlier : bool Whether to remove outliers and re-run QC - logLR_threshold : float LogLR threshold for LD mismatch detection - z_threshold : float Z-score threshold for both LD mismatch and marginal SNP detection - z_std_diff_threshold : float Z_std_diff threshold for marginal SNP outlier detection - r_threshold : float Correlation threshold with lead SNP for marginal SNP detection - dentist_s_pvalue_threshold : float -log10 p-value threshold for Dentist-S outlier detection - dentist_s_r2_threshold : float R² threshold for Dentist-S outlier detection
Returns¶
Tuple[str, pd.DataFrame, Optional[pd.DataFrame], Optional[pd.DataFrame], Optional[pd.DataFrame]] Tuple containing the locus_id that was processed, its summary QC stats, outlier removal summary, cleaned QC summary, and outlier detail DataFrame if applicable.
Notes¶
This function is designed for multiprocessing and:
- Loads the locus set from the provided information
- Performs comprehensive QC analysis
- Creates locus-specific output directory
- Saves all QC results as compressed files
- Generates and saves locus-level summary QC statistics
- Returns the processed locus_id and summary for global aggregation
Output files are saved as: {base_out_dir}/{locus_id}/{qc_metric}.txt.gz {base_out_dir}/{locus_id}/qc.txt.gz
Source code in credtools/qc.py
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 | |
remove_outliers_and_rerun_qc(locus_set, qc_metrics, base_out_dir, locus_id, r_tol=0.001, method='null-mle', dtype=None, logLR_threshold=2, z_threshold=2, z_std_diff_threshold=3, r_threshold=0.8, dentist_s_pvalue_threshold=4, dentist_s_r2_threshold=0.6)
¶
Remove outliers from locus set and re-run QC.
Parameters¶
locus_set : LocusSet Original LocusSet object. qc_metrics : Dict[str, pd.DataFrame] QC metrics from initial QC run. base_out_dir : str Base output directory. locus_id : str Locus identifier. r_tol : float, optional Tolerance level for eigenvalue check, by default 1e-3. method : str, optional Method to estimate s parameter, by default "null-mle". dtype : Optional[np.dtype], optional Data type for computation, by default None.
Returns¶
Tuple[LocusSet, Dict[str, pd.DataFrame], pd.DataFrame, pd.DataFrame] Cleaned LocusSet, new QC metrics, summary of outlier removal, and detailed outlier SNP DataFrame with columns: SNPID, C1_ld_mismatch, C2_marginal, C3_dentist_s, locus_id, popu, cohort.
Source code in credtools/qc.py
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
remove_snps_from_locus(locus, outlier_snps)
¶
Remove outlier SNPs from a Locus object.
Parameters¶
locus : Locus Input Locus object. outlier_snps : List[str] List of SNP IDs to remove.
Returns¶
Locus New Locus object with outliers removed.
Source code in credtools/qc.py
safe_qc_locus_cli(args)
¶
Wrapper for qc_locus_cli that captures exceptions.
Source code in credtools/qc.py
save_cleaned_locus(locus, output_dir, prefix)
¶
Save cleaned locus data to files.
Parameters¶
locus : Locus Cleaned Locus object to save. output_dir : str Output directory path. prefix : str Prefix for output files.
Source code in credtools/qc.py
snp_missingness(locus_set)
¶
Compute the missingness rate of each cohort across variants.
Parameters¶
locus_set : LocusSet LocusSet object containing multiple loci/cohorts.
Returns¶
pd.DataFrame DataFrame with variants as rows and cohorts as columns, where 1 indicates presence and 0 indicates absence of the variant in that cohort.
Warnings¶
If any cohort has a missing rate > 0.1, a warning is logged.
Notes¶
This function:
- Identifies all unique variants across cohorts
- Creates a binary matrix indicating variant presence/absence
- Calculates and logs missing rates for each cohort
- Issues warnings for cohorts with high missing rates (>10%)
High missing rates may indicate: - Different genotyping platforms - Different quality control criteria - Population-specific variants