### Quick Start Example Source: https://github.com/cloufield/gwaslab/blob/main/docs/api/index.md A basic example demonstrating how to load summary statistics and perform a basic check using the GWASLab library. ```APIDOC ## Quick start ```python import gwaslab as gl mysumstats = gl.Sumstats("sumstats.txt.gz", fmt="plink2") mysumstats.basic_check() mysumstats.plot_mqq() ``` ``` -------------------------------- ### bcftools Example Output Source: https://github.com/cloufield/gwaslab/blob/main/docs/AssignCHRPOS.md Example output from the `bcftools --version` command, indicating the installed version and associated htslib version. ```text bcftools 1.19 Using htslib 1.19 Copyright (C) 2023 Genome Research Ltd. License Expat: The MIT/Expat license This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. ``` -------------------------------- ### Install and Serve Documentation Locally Source: https://github.com/cloufield/gwaslab/blob/main/docs/api/index.md Install the package with documentation dependencies and serve the documentation locally for live preview. Alternatively, build the documentation statically. ```bash pip install -e ".[docs]" pip install zensical zensical serve # live preview # or: zensical build --clean ``` -------------------------------- ### Test Installation from TestPyPI Source: https://github.com/cloufield/gwaslab/blob/main/test/Upload_checklist.md Install the package from TestPyPI to verify that it was uploaded correctly. Replace X.Y.Z with the actual version number. ```bash pip install --index-url https://test.pypi.org/simple/ gwaslab==X.Y.Z ``` -------------------------------- ### Test Installation from PyPI Source: https://github.com/cloufield/gwaslab/blob/main/test/Upload_checklist.md Install the package from the main PyPI repository to confirm a successful public release. Replace X.Y.Z with the actual version number. ```bash pip install gwaslab==X.Y.Z ``` -------------------------------- ### Complete QC Report Example Source: https://github.com/cloufield/gwaslab/blob/main/docs/QC_Report.md A comprehensive example demonstrating loading sumstats and generating a PDF QC report with customized options for basic checks, lead variants, MQQ plots, and regional plots. ```python import gwaslab as gl # Load sumstats mysumstats = gl.Sumstats( "examples/0_sample_data/t2d_bbj.txt.gz", snpid="SNP", chrom="CHR", pos="POS", ea="ALT", nea="REF", neaf="Frq", beta="BETA", se="SE", p="P", build="19", n="N" ) # Generate comprehensive QC report with regional plots report_path = mysumstats.report( output_path="t2d_qc_report.pdf", report_title="T2D GWAS QC Report", basic_check_kwargs={ "remove": False, "remove_dup": False, "normalize": True, "verbose": False }, get_lead_kwargs={ "sig_level": 5e-8, "windowsizekb": 500, "anno": False, "verbose": False }, mqq_plot_kwargs={ "save": True, "dpi": 300, "verbose": False }, regional_plot_kwargs={ "vcf_path": "/path/to/reference.vcf.gz", "region_size": 500, "save": True, "dpi": 300, "verbose": False } ) print(f"Report generated: {report_path}") ``` -------------------------------- ### Test Install from Local Wheel Source: https://github.com/cloufield/gwaslab/blob/main/test/Upload_checklist.md Install the package locally from the generated wheel file to verify the build artifacts. Replace X.Y.Z with the actual version number. ```bash pip install dist/gwaslab-X.Y.Z-py3-none-any.whl --force-reinstall ``` -------------------------------- ### Complete GSF Workflow Example Source: https://github.com/cloufield/gwaslab/blob/main/docs/GSF_Format.md A comprehensive example showing the typical workflow: loading data, performing basic processing and QC, saving to GSF format, and later loading with filters and specific columns. This covers essential operations for managing summary statistics. ```python import gwaslab as gl # Load data mysumstats = gl.Sumstats("input.txt.gz", ...) # Process and QC mysumstats.basic_check() mysumstats.harmonize(...) # Save to GSF mysumstats.to_gsf("processed_sumstats.gsf", compression="zstd") # Later: Load with filtering significant_variants = gl.load_gsf( "processed_sumstats.gsf", filters="P < 5e-8 & CHR in [1, 2, 3, 7, 22]", columns=["CHR", "POS", "EA", "NEA", "BETA", "SE", "P"] ) # Work with filtered data print(f"Found {len(significant_variants.data)} significant variants") ``` -------------------------------- ### Example Workflow: Harmonize, Infer EAF, and Check AF Source: https://github.com/cloufield/gwaslab/blob/main/docs/InferAF.md This example demonstrates a typical workflow: harmonizing sumstats, inferring EAF using the faster `infer_af2` method, and then checking the inferred AF values. ```python import gwaslab as gl mysumstats = gl.Sumstats("sumstats.txt.gz") mysumstats.harmonize(basic_check=True) mysumstats.infer_af2(vcf_path="reference.vcf.gz", ref_alt_freq="AF") mysumstats.check_af2(vcf_path="reference.vcf.gz", ref_alt_freq="AF") ``` -------------------------------- ### Example: Save and Load Sumstats using dump_pickle() Source: https://github.com/cloufield/gwaslab/blob/main/docs/Pickle.md This example shows how to process sumstats, save the object using the `gl.dump_pickle()` function, and then load it back using `gl.load_pickle()`. ```python import gwaslab as gl # Process sumstats mysumstats = gl.Sumstats("sumstats.txt.gz", fmt="plink2") mysumstats.basic_check() # Save using function gl.dump_pickle(mysumstats, "./first.pickle", overwrite=True) # Load it back mysumstats2 = gl.load_pickle("./first.pickle") ``` -------------------------------- ### Example: Save and Load Sumstats using to_pickle() Source: https://github.com/cloufield/gwaslab/blob/main/docs/Pickle.md This example demonstrates loading sumstats, performing basic checks and fixes, saving the processed object using `to_pickle()` with overwrite enabled, and then loading it back. ```python import gwaslab as gl # Load and process sumstats mysumstats = gl.Sumstats("sumstats.txt.gz", fmt="plink2") mysumstats.basic_check() mysumstats.fix_chr() mysumstats.fix_pos() # Save the processed object mysumstats.to_pickle("./processed_sumstats.pickle", overwrite=True) # Later, load it back mysumstats2 = gl.load_pickle("./processed_sumstats.pickle") ``` -------------------------------- ### Verify bcftools Installation Source: https://github.com/cloufield/gwaslab/blob/main/docs/AssignCHRPOS.md Verify that bcftools is installed and accessible in your PATH. This is a prerequisite for processing VCF files. ```bash bcftools --version ``` -------------------------------- ### Install Weasyprint for PDF Generation Source: https://github.com/cloufield/gwaslab/blob/main/docs/QC_Report.md Install the 'weasyprint' library using pip for PDF report generation. System dependencies may also be required on some platforms. ```bash pip install weasyprint ``` ```bash # Ubuntu/Debian: sudo apt-get install python3-weasyprint ``` -------------------------------- ### Install GWASLab via uv Source: https://github.com/cloufield/gwaslab/blob/main/docs/index.md Installs the latest version of GWASLab using the uv package installer. uv is known for its speed. ```bash uv pip install -U gwaslab ``` -------------------------------- ### Log Operation Start Source: https://github.com/cloufield/gwaslab/blob/main/docs/Logging.md Logs the beginning of an operation, including its name and an optional version. ```python log_operation_start(operation_name, version=None, indent=0) ``` -------------------------------- ### Install GWASLab in Conda Environment Source: https://github.com/cloufield/gwaslab/blob/main/README.md Create and activate a Conda environment with a compatible Python version, then install GWASLab. This ensures dependency management. ```bash conda env create -n gwaslab -c conda-forge python=3.12 conda activate gwaslab pip install gwaslab ``` ```bash conda env create -n gwaslab -f environment.yml ``` -------------------------------- ### Build Wheel Package Source: https://github.com/cloufield/gwaslab/blob/main/test/Upload_checklist.md Create a wheel (binary distribution) of the Python package. This is a pre-compiled format that speeds up installation. ```bash python -m build --wheel ``` -------------------------------- ### GWASLab CLI - Show Version Source: https://github.com/cloufield/gwaslab/blob/main/docs/index.md Display the installed GWASLab version using the CLI. ```bash gwaslab version ``` -------------------------------- ### Import GWASLab and Check Version Source: https://github.com/cloufield/gwaslab/blob/main/docs/Extract_LD_proxy.md Import the GWASLab library and display its version information. This is the initial setup step for using the library. ```python import gwaslab as gl gl.show_version() ``` -------------------------------- ### Generate PDF QC Report Source: https://github.com/cloufield/gwaslab/blob/main/docs/QC_Report.md Generate a PDF QC report by specifying a .pdf file extension. This requires the 'weasyprint' library to be installed. ```python # Generate HTML report mysumstats.report("report.html") # Generate PDF report (requires weasyprint) mysumstats.report("report.pdf") ``` -------------------------------- ### Get Associations for a Specific Variant (get_all=True) Source: https://github.com/cloufield/gwaslab/blob/main/docs/GWASCatalogAPI.md Retrieve all associations for a given variant rsID using `gl.get_associations()` with `get_all=True`. This example also demonstrates printing the head of the resulting DataFrame. ```python import gwaslab as gl # Get all associations for rs1050316 associations = gl.get_associations(rs_id="rs1050316", get_all=True) print(associations.head()) ``` -------------------------------- ### Get Reference GTF Data and Filter Source: https://github.com/cloufield/gwaslab/blob/main/docs/GTF.md Retrieves reference GTF data (e.g., Ensembl hg38) for a specific chromosome and build. The retrieved data can then be filtered, for example, to isolate protein-coding genes. ```python from gwaslab.io.io_gtf import get_gtf # Get Ensembl hg38 GTF for chromosome 1 gtf = get_gtf(chrom="1", build="38", source="ensembl") # Filter for protein-coding genes protein_coding = gtf[gtf["gene_biotype"] == "protein_coding"] print(f"Protein-coding genes on chr1: {len(protein_coding)}") ``` -------------------------------- ### Load and Plot GWAS Summary Statistics Source: https://github.com/cloufield/gwaslab/blob/main/README.md Quick start example demonstrating how to load GWAS summary statistics from a file using different format detection methods (plink2, auto, or manual column specification) and then generate Manhattan and QQ plots. ```python import gwaslab as gl # load plink2 output mysumstats = gl.Sumstats("sumstats.txt.gz", fmt="plink2") # or load sumstats with auto mode (auto-detecting commonly used headers) # assuming ALT/A1 is EA, and frq is EAF mysumstats = gl.Sumstats("sumstats.txt.gz", fmt="auto") # or you can specify the columns: mysumstats = gl.Sumstats("sumstats.txt.gz", snpid="SNP", chrom="CHR", pos="POS", ea="ALT", nea="REF", eaf="Frq", beta="BETA", se="SE", p="P", direction="Dir", n="N", build="19") # manhattan and qq plot mysumstats.plot_mqq() ... ``` -------------------------------- ### Rename Gene Start and End Columns Source: https://github.com/cloufield/gwaslab/blob/main/examples/7_visualization/gwplot.ipynb Rename the 'Gene start' and 'Gene end' columns in the Sumstats object's data to 'START' and 'END' respectively for convenience. ```python mapping_gls.data = mapping_gls.data.rename(columns={"Gene start":"START","Gene end":"END"}) ``` -------------------------------- ### Partitioned GSF Workflow Example Source: https://github.com/cloufield/gwaslab/blob/main/docs/GSF_Format.md Demonstrates a workflow for handling partitioned GSF files, including saving data partitioned by a column and loading specific partitions (e.g., a single chromosome) for processing. This is useful for very large datasets. ```python # Save partitioned by chromosome mysumstats.to_gsf( "sumstats_partitioned", partition_cols=["CHR"], compression="zstd" ) # Load specific chromosome chr7_data = gl.load_gsf("sumstats_partitioned", filters="CHR == 7") # Process chromosome by chromosome for chr_num in range(1, 23): chr_data = gl.load_gsf("sumstats_partitioned", filters=f"CHR == {chr_num}") # Process chromosome data ... ``` -------------------------------- ### Install GWASLab Package Source: https://github.com/cloufield/gwaslab/blob/main/examples/1_main_tutorial/tutorial_v4.ipynb Installs the GWASLab package from pip. This is a prerequisite for using the library. ```python # !pip install gwaslab==4.0.0 ``` -------------------------------- ### Example SSF validation success output Source: https://github.com/cloufield/gwaslab/blob/main/docs/Format.md This is an example of the output when an SSF file passes all validation checks. ```text ✓ SSF validation successful: File passes all validation checks ``` -------------------------------- ### List Downloaded Sample Data Source: https://github.com/cloufield/gwaslab/blob/main/docs/tutorial_v4.md After cloning, use this command to list the contents of the sample data directory. ```python !ls gwaslab-sample-data ``` -------------------------------- ### Install GWASLab via pip Source: https://github.com/cloufield/gwaslab/blob/main/README.md Install the latest version of GWASLab using pip. This command is suitable for most users and environments. ```bash pip install gwaslab ``` -------------------------------- ### Example SSF validation failure output Source: https://github.com/cloufield/gwaslab/blob/main/docs/Format.md This is an example of the output when an SSF file fails validation, indicating missing required columns. ```text ✗ SSF validation failed: Missing required columns: ['standard_error'] - Missing required columns: ['standard_error'] ``` -------------------------------- ### Download Liftover Chain File Source: https://github.com/cloufield/gwaslab/blob/main/docs/harmonization_liftover.md Use wget to download the necessary chain file for liftover. Ensure the URL is correct for the desired genome builds. ```bash ! wget https://s3-us-west-2.amazonaws.com/human-pangenomics/T2T/CHM13/assemblies/chain/v1_nflo/grch38-chm13v2.chain ``` -------------------------------- ### Limit Variants for Example Source: https://github.com/cloufield/gwaslab/blob/main/examples/3_standardization/quality_control_and_filtering.ipynb Use this command to limit the number of variants processed for examples or testing purposes. This helps in managing computational resources. ```bash # use only 100000 variants for example ``` -------------------------------- ### Load Partitioned GSF Files Source: https://github.com/cloufield/gwaslab/blob/main/docs/GSF_Format.md Demonstrates loading partitioned GSF files using the same API as non-partitioned files. Filtering on partition columns during loading is particularly efficient. ```python # Load partitioned file (same API) mysumstats = gl.load_gsf("sumstats_partitioned") # Filtering on partition columns is especially efficient mysumstats = gl.load_gsf("sumstats_partitioned", filters="CHR == 7") ``` -------------------------------- ### Basic Format Conversion Examples Source: https://github.com/cloufield/gwaslab/blob/main/docs/Format.md Demonstrates converting summary statistics to different formats like LDSC, PLINK (with CSV), and VCF (with bgzip and tabix indexing). ```python # Convert to LDSC format mysumstats.to_format(path="./output", fmt="ldsc") # Output: output.ldsc.tsv.gz ``` ```python # Convert to PLINK format with CSV mysumstats.to_format(path="./output", fmt="plink", tab_fmt="csv", gzip=False) # Output: output.plink.csv ``` ```python # Convert to VCF with bgzip and tabix index mysumstats.to_format(path="./output", fmt="vcf", bgzip=True, tabix=True) # Output: output.vcf.bcf.gz and output.vcf.bcf.gz.tbi ``` -------------------------------- ### Run Test Suite Source: https://github.com/cloufield/gwaslab/blob/main/test/Upload_checklist.md Execute the project's test suite from the root directory. Ensure all tests pass before proceeding with a release. ```bash python test/run_all_tests.py ``` -------------------------------- ### Initialize GWASLab Registry Source: https://github.com/cloufield/gwaslab/blob/main/docs/CLI.md Prepares the local reference registry by creating the necessary directory structure and optionally setting a data directory. Use `--recursive` to scan subdirectories and `--quiet` to reduce logging. ```bash gwaslab init ``` ```bash gwaslab init --directory /data/refs ``` ```bash gwaslab init -d /data/refs --recursive --quiet ``` -------------------------------- ### Set Default Directory and Get Path Source: https://github.com/cloufield/gwaslab/blob/main/docs/Download_reference.md Configure the default directory for downloaded data and retrieve paths for registered references. Use `gl.set_default_directory()` to change the download location. `gl.options.paths["config"]` shows the current configuration file path. `gl.get_path()` resolves a reference keyword to its local path without downloading. ```python gl.set_default_directory("/data/refs/") gl.options.paths["config"] # ~/.gwaslab/config.json by default gl.get_path("1kg_eas_hg19") # resolves from registry; does not download ``` -------------------------------- ### Quick Start: Multiple Studies Meta-Analysis Source: https://github.com/cloufield/gwaslab/blob/main/docs/MetaAnalysis.md Shows how to load multiple summary statistics files and perform meta-analysis using `SumstatsMulti` with the pandas engine. ```python import gwaslab as gl # Load multiple sumstats sumstats_list = [ gl.Sumstats("study1.txt.gz", verbose=False), gl.Sumstats("study2.txt.gz", verbose=False), gl.Sumstats("study3.txt.gz", verbose=False) ] # Create SumstatsMulti object multi = gl.SumstatsMulti(sumstats_list, engine="pandas", verbose=False) # Run meta-analysis result = multi.run_meta_analysis(random_effects=False) ``` -------------------------------- ### BED Format Conversion Example Source: https://github.com/cloufield/gwaslab/blob/main/docs/Format.md Example of converting summary statistics to BED format, which uses 0-based, half-open coordinates, and enabling bgzip compression and tabix indexing. ```python mysumstats.to_format(path="./output", fmt="bed", bgzip=True, tabix=True) # Output: output.bed.gz (bgzipped and tabix-indexed) ``` -------------------------------- ### Example of Clumping with a VCF File Source: https://github.com/cloufield/gwaslab/blob/main/docs/Clumping.md This example demonstrates how to initiate clumping using a VCF file as input via the GWASLab `clump` function. The output file will be named 'clumping_plink2' by default. ```python clumps = mysumstats.clump(vcf= "/home/yunye/.gwaslab/EAS.ALL.split_norm_af.1kgp3v5.hg19.vcf.gz") ``` -------------------------------- ### Example: Saving Sumstats to Custom Paths Source: https://github.com/cloufield/gwaslab/blob/main/docs/Pickle.md Demonstrates saving a Sumstats object to different locations including the home directory using `~`, the current directory, and an absolute path. ```python # Save to home directory mysumstats.to_pickle("~/my_analysis/sumstats.pickle") # Save to current directory mysumstats.to_pickle("./sumstats.pickle", overwrite=True) # Save with absolute path mysumstats.to_pickle("/data/analysis/sumstats.pickle") ``` -------------------------------- ### Download Sample Data Source: https://github.com/cloufield/gwaslab/blob/main/docs/visualization_miami2.md Use wget to download sample GWAS summary statistics files for demonstration purposes. ```bash #!wget -O ../0_sample_data/bmi_male_bbj.txt.gz http://jenger.riken.jp/2analysisresult_qtl_download/ #!wget -O ../0_sample_data/bmi_female_bbj.txt.gz http://jenger.riken.jp/4analysisresult_qtl_download/ ``` -------------------------------- ### Enable bgzip Compression and Create Tabix Index Source: https://github.com/cloufield/gwaslab/blob/main/docs/CLI.md Use `--bgzip` for block-gzipped compression and `--tabix` to create a tabix index for the output file, which is useful for large files. ```bash gwaslab --input sumstats.tsv --fmt gwaslab --out output --to-fmt gwaslab --bgzip --tabix ``` -------------------------------- ### Create Partitioned GSF Files Source: https://github.com/cloufield/gwaslab/blob/main/docs/GSF_Format.md Shows how to save summary statistics data into a partitioned GSF directory structure, using a specified column (e.g., 'CHR') for partitioning. This optimizes queries on partition columns. ```python # Partition by chromosome mysumstats.to_gsf("sumstats_partitioned", partition_cols=["CHR"]) # This creates a directory structure: # sumstats_partitioned/ # CHR=1/ # part-0.parquet # CHR=2/ # part-0.parquet # ... ``` -------------------------------- ### Plot Regional (legacy chromosome) Source: https://github.com/cloufield/gwaslab/blob/main/docs/CLI.md Generate a regional association plot using the legacy `--chr` option for the chromosome and `--start`/`--end` for the interval. Note that `--chr` with `--start`/`--end` is treated as the plot region, not a variant filter. ```bash gwaslab --input sumstats.tsv --fmt auto --plot regional --chr 6 --start 26000000 --end 34000000 --out region.png ``` -------------------------------- ### Download Liftover Chain File Source: https://github.com/cloufield/gwaslab/blob/main/examples/4_harmonization/harmonization_liftover.ipynb Download the necessary chain file for liftover. Ensure the URL is correct for the desired genome builds. ```python #https://github.com/marbl/CHM13 ``` ```bash ! wget https://s3-us-west-2.amazonaws.com/human-pangenomics/T2T/CHM13/assemblies/chain/v1_nflo/grch38-chm13v2.chain ``` -------------------------------- ### List Sample Data Files Source: https://github.com/cloufield/gwaslab/blob/main/examples/1_main_tutorial/tutorial_v4.ipynb Lists the files available in the cloned gwaslab-sample-data directory to verify the download. ```bash !ls gwaslab-sample-data ``` -------------------------------- ### Get Panel Type Source: https://github.com/cloufield/gwaslab/blob/main/docs/PanelSystem.md Retrieve the type of the panel using the `get_type()` method. ```python # Get panel type panel_type = panel.get_type() ``` -------------------------------- ### Get Genomic Control (GC) Source: https://github.com/cloufield/gwaslab/blob/main/docs/api/sumstats/downstream.md Calculates the genomic control inflation factor. ```APIDOC ## get_gc ### Description Calculates the genomic control (GC) inflation factor. ### Method `get_gc()` ### Parameters None ### Response - **gc_value** (float) - The genomic control value. ``` -------------------------------- ### Initialize gwaslab Environment (CLI) Source: https://github.com/cloufield/gwaslab/blob/main/docs/Download_reference.md Initialize the gwaslab environment using the command-line interface. `gwaslab init` creates necessary directories and migrates configuration files. Use `--directory DIR` to specify a custom data directory, which will be persisted. ```bash gwaslab init # create dirs, migrate config, scan default data_directory gwaslab init --directory /data/refs # set data_directory (persisted) and scan gwaslab config set data_directory /data/refs gwaslab path config # show registry JSON path ``` -------------------------------- ### Default .get_lead() parameters Source: https://github.com/cloufield/gwaslab/blob/main/docs/ExtractLead.md This snippet shows the default parameters for the `.get_lead()` method. It uses MLOG10P by default and a 500kb window size. ```python mysumstats.get_lead( scaled=False, use_p=False, windowsizekb=500, sig_level=5e-8, anno=False, build="19", source="ensembl", gtf_path=None, wc_correction=False, verbose=True, gls=False ) ``` -------------------------------- ### Get All Panel Parameters Source: https://github.com/cloufield/gwaslab/blob/main/docs/PanelSystem.md Retrieve all parameters associated with the panel using the `get_kwargs()` method. ```python # Get all parameters kwargs = panel.get_kwargs() ``` -------------------------------- ### Test Command on Small Sample Source: https://github.com/cloufield/gwaslab/blob/main/docs/CLIWorkflowExamples.md Tests the command on the first 1000 rows of a large sumstats file. This is useful for quick checks and debugging. ```python gwaslab --input large_sumstats.tsv \ --fmt auto \ --nrows 1000 \ --qc \ --remove-dup \ --out test_output \ --to-fmt gwaslab ``` -------------------------------- ### Get LD Matrix from VCF Source: https://github.com/cloufield/gwaslab/blob/main/docs/api/sumstats/downstream.md Retrieves the LD matrix directly from a VCF file. ```APIDOC ## get_ld_matrix_from_vcf ### Description Retrieves the LD matrix from a VCF file. ### Method `get_ld_matrix_from_vcf()` ### Parameters None ### Response - **ld_matrix_from_vcf** (numpy.ndarray) - The LD matrix derived from the VCF file. ``` -------------------------------- ### Get CS Lead Source: https://github.com/cloufield/gwaslab/blob/main/docs/api/sumstats/downstream.md Identifies the lead SNP within each credible set (CS). ```APIDOC ## get_cs_lead ### Description Identifies the lead SNP within each credible set. ### Method `get_cs_lead()` ### Parameters None ### Response - **cs_lead_snps** (dict) - Lead SNPs for each credible set. ``` -------------------------------- ### List Available Reference Data Source: https://github.com/cloufield/gwaslab/blob/main/docs/CLI.md Lists available reference datasets for download. ```bash gwaslab list ref --available ``` -------------------------------- ### Get Association Density Source: https://github.com/cloufield/gwaslab/blob/main/docs/api/sumstats/downstream.md Calculates the density of associations across the genome or specific regions. ```APIDOC ## get_density ### Description Calculates the density of associations. ### Method `get_density()` ### Parameters None ### Response - **association_density** (dict) - A dictionary representing association density. ``` -------------------------------- ### Multi-step Processing Pipeline Source: https://github.com/cloufield/gwaslab/blob/main/docs/CLIWorkflowExamples.md Demonstrates a multi-step processing pipeline involving QC, harmonization, and final formatting for a specific tool. Each step builds upon the output of the previous one. ```python gwaslab --input raw.tsv --fmt auto --qc --remove-dup --out step1_qc --to-fmt gwaslab gwaslab --input step1_qc.gwaslab.tsv.gz --fmt gwaslab --harmonize \ --ref-seq ref.fasta --out step2_harmonized --to-fmt gwaslab gwaslab --input step2_harmonized.gwaslab.tsv.gz --fmt gwaslab \ --out final --to-fmt plink --tab-fmt tsv ``` -------------------------------- ### get_region_start_and_end Source: https://github.com/cloufield/gwaslab/blob/main/docs/api/sumstats/filter.md Determines the start and end positions of the genomic region covered by the current sumstats data. ```APIDOC ## get_region_start_and_end ### Description Determines the start and end positions of the genomic region covered by the current sumstats data. ### Method `get_region_start_and_end()` ### Request Example ```python start, end = sumstats.get_region_start_and_end() ``` ### Response #### Success Response (200) - **Tuple[int, int]** - A tuple containing the start and end positions of the genomic region. ``` -------------------------------- ### Quick Start: Two Studies Meta-Analysis Source: https://github.com/cloufield/gwaslab/blob/main/docs/MetaAnalysis.md Demonstrates loading two summary statistics files and performing both fixed-effects and random-effects meta-analysis using `SumstatsPair`. ```python import gwaslab as gl # Load two sumstats sumstats1 = gl.Sumstats("study1.txt.gz", verbose=False) sumstats2 = gl.Sumstats("study2.txt.gz", verbose=False) # Create SumstatsPair object pair = gl.SumstatsPair(sumstats1, sumstats2, keep_all_variants=False) # Run fixed-effects meta-analysis result = pair.run_meta_analysis(random_effects=False) # Run random-effects meta-analysis result = pair.run_meta_analysis(random_effects=True) ``` -------------------------------- ### Get Effective Sample Size (ESS) Source: https://github.com/cloufield/gwaslab/blob/main/docs/api/sumstats/downstream.md Calculates the effective sample size for association signals. ```APIDOC ## get_ess ### Description Calculates the effective sample size (ESS). ### Method `get_ess()` ### Parameters None ### Response - **ess_values** (dict) - Effective sample sizes. ``` -------------------------------- ### Example of Nested Function Calls with Logging Source: https://github.com/cloufield/gwaslab/blob/main/docs/Logging.md Illustrates how logging methods can be used within nested function calls to track complex processes, with `indent` parameter managing the hierarchical output. ```python def process_data(log, verbose=True): log.log_operation_start("process data", verbose=verbose) log.log_dataframe_shape(sumstats, verbose=verbose) # Call inner function filter_variants(sumstats, log, verbose=verbose, indent=1) log.log_operation_finish("processing data", verbose=verbose) def filter_variants(sumstats, log, verbose=True, indent=0): log.log_operation_start("filter variants", indent=indent, verbose=verbose) # Nested operations log.log_variants_filtered(150, reason="with P > 0.05", indent=indent+1, verbose=verbose) log.log_variants_removed(25, reason="duplicates", indent=indent+1, verbose=verbose) log.log_operation_finish("filtering variants", indent=indent, verbose=verbose) ``` ```python Start to process data ... -Current Dataframe shape : 1000 x 20 ; Memory usage: 19.95 MB Start to filter variants ... -Filtered out 150 variants with P > 0.05 -Removed 25 variants duplicates Finished filtering variants. Finished processing data. ```