### Install weasyprint for PDF Generation Source: https://cloufield.github.io/gwaslab/QC_Report Provides instructions for installing the `weasyprint` library, which is a dependency for generating PDF reports. It includes both pip installation and system-level package installation for Ubuntu/Debian. ```bash pip install weasyprint # Ubuntu/Debian: sudo apt-get install python3-weasyprint ``` -------------------------------- ### Install bcftools Source: https://cloufield.github.io/gwaslab/AssignCHRPOS Instructions for installing the `bcftools` utility, which is a prerequisite for both `.rsid_to_chrpos2()` and `gl.process_vcf_to_hfd5()` functions in GWASLab for processing VCF files. ```bash # Using conda: conda install -c bioconda bcftools # Or download from the official website: # https://www.htslib.org/download/ # Verify installation: bcftools --version ``` -------------------------------- ### Get GWASLab Help and Version Source: https://cloufield.github.io/gwaslab/CLI Displays the help message for GWASLab, providing information on available commands and options. Also shows the installed version of the GWASLab tool. ```bash # Show help message gwaslab --help # Show version gwaslab version ``` -------------------------------- ### Install GWASLab Package Source: https://cloufield.github.io/gwaslab/tutorial_v4 Installs the GWASLab package version 4.0.0 using pip. This command ensures that the library is available for use in the current environment. ```shell # !pip install gwaslab==4.0.0 ``` -------------------------------- ### Show GWASLab CLI Version Source: https://cloufield.github.io/gwaslab/CLI Displays the installed version of the GWASLab CLI. This is a simple command to verify the installation and check for updates. ```bash gwaslab version ``` -------------------------------- ### Install GWASLab using uv Source: https://cloufield.github.io/gwaslab/index Installs the latest version of GWASLab using uv, a fast Python package installer written in Rust. This method also requires a compatible Python version. ```bash uv pip install -U gwaslab ``` -------------------------------- ### Install and Import GWASLab from GitHub Source: https://cloufield.github.io/gwaslab/tutorial_v4 Clones the GWASLab repository from GitHub and adds its source directory to the Python system path. This allows using the latest development version of the library. ```python #!git clone https://github.com/Cloufield/gwaslab.git import sys sys.path.insert(0,"/home/yunye/work/gwaslab/src") import gwaslab as gl ``` -------------------------------- ### Comprehensive QC Report Generation Example Source: https://cloufield.github.io/gwaslab/QC_Report A complete example demonstrating the generation of a comprehensive QC report in PDF format with customized options for basic QC, lead variant extraction, MQQ plots, and regional plots. It also includes setting a custom report title. ```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}") ``` -------------------------------- ### Complete Pipeline with All Options in GWASLab CLI Source: https://cloufield.github.io/gwaslab/CLIWorkflowExamples Executes a comprehensive pipeline including QC, harmonization, and format conversion with numerous options using the GWASLab CLI. This example showcases advanced filtering, reference file usage, and output formatting for LDSC. Requires input sumstats and various reference files. ```bash # Complete pipeline: QC + Harmonization + Format conversion gwaslab --input raw_sumstats.tsv \ --fmt auto \ --qc \ --remove \ --remove-dup \ --normalize \ --harmonize \ --ref-seq /data/reference/hg19.fasta.gz \ --ref-rsid-vcf /data/reference/dbsnp.vcf.gz \ --ref-infer /data/reference/1kg.vcf.gz \ --ref-alt-freq AF \ --maf-threshold 0.40 \ --ref-maf-threshold 0.4 \ --sweep-mode \ --threads 8 \ --out final_sumstats \ --to-fmt ldsc \ --tab-fmt tsv \ --exclude-hla \ --hapmap3 \ --n 100000 \ --chr-prefix chr \ --xymt-number ``` -------------------------------- ### Import GWASLab and Pandas Libraries Source: https://cloufield.github.io/gwaslab/visualization_brisbane Initializes the environment by importing the GWASLab library as 'gl' and the pandas library as 'pd'. These are essential for subsequent operations in the script. ```python import gwaslab as gl import pandas as pd ``` -------------------------------- ### Download Sample Data using wget Source: https://cloufield.github.io/gwaslab/visualization_brisbane Downloads an Excel file containing genetic association data from a specified URL using the 'wget' command. This data is required for the subsequent plotting and analysis steps. ```shell !wget https://static-content.springer.com/esm/art%3A10.1038%2Fs41586-022-05275-y/MediaObjects/41586_2022_5275_MOESM3_ESM.xlsx ``` -------------------------------- ### BED File Format Example Source: https://cloufield.github.io/gwaslab/QC%26Filtering Illustrates the standard format for a BED (Browser Extensible Data) file used for defining genomic regions. Each line specifies a chromosome, start position, and end position. ```text chr1 1000000 2000000 chr2 5000000 6000000 chr3 10000000 11000000 ``` -------------------------------- ### Example Verbose Output for Ancestry Inference Source: https://cloufield.github.io/gwaslab/InferAncestry This example illustrates the detailed logging output produced by `mysumstats.infer_ancestry` when `verbose=True`. It shows the Fst values calculated for different populations, the variant count used, and the final inferred closest ancestry. This output is crucial for understanding the inference process and potential data quality issues. ```text Start to infer ancestry based on Fst ...(version) -Estimating Fst using 12345 variants... -FST_GBR : 0.001234 -FST_FIN : 0.001456 -FST_CHS : 0.002345 ... -FST_EUR : 0.001234 -Closest Ancestry: EUR Finished inferring ancestry. ``` -------------------------------- ### SSF Validation Output Examples Source: https://cloufield.github.io/gwaslab/Format Provides examples of the output messages from the SSF validation process in GWASLab. It shows both successful validation and specific error messages when validation fails, such as missing required columns. ```text ✓ SSF validation successful: File passes all validation checks ``` ```text ✗ SSF validation failed: Missing required columns: ['standard_error'] - Missing required columns: ['standard_error'] ``` -------------------------------- ### Download Sample Data using wget Source: https://cloufield.github.io/gwaslab/visualization_regional Downloads a sample summary statistics file (t2d_bbj.txt.gz) using the wget command-line utility. This file is used in subsequent examples. ```bash #!wget -O t2d_bbj.txt.gz http://jenger.riken.jp/14/ ``` -------------------------------- ### Load Summary Statistics with GWASLab Source: https://cloufield.github.io/gwaslab/harmonization_workflow This example demonstrates how to load summary statistics from a TSV file using the `gl.Sumstats` class. It specifies the file path, the format ('gwaslab'), and additional columns to include ('NOTE'). The output shows the loading process and initial data verification. ```python mysumstats = gl.Sumstats("/home/yunye/work/gwaslab/examples/toy_data/to_harmonize.tsv",fmt="gwaslab",other=["NOTE"]) ``` -------------------------------- ### Multi-step Processing with GWASLab CLI Source: https://cloufield.github.io/gwaslab/CLIWorkflowExamples Demonstrates a multi-step processing workflow using the GWASLab CLI, including QC, harmonization, and final format conversion. Each step takes the output of the previous step as input, allowing for modular data processing. ```bash # Step 1: QC gwaslab --input raw.tsv --fmt auto --qc --remove-dup --out step1_qc --to-fmt gwaslab # Step 2: Harmonize gwaslab --input step1_qc.gwaslab.tsv.gz --fmt gwaslab --harmonize \ --ref-seq ref.fasta --out step2_harmonized --to-fmt gwaslab # Step 3: Format for specific tool gwaslab --input step2_harmonized.gwaslab.tsv.gz --fmt gwaslab \ --out final --to-fmt plink --tab-fmt tsv ``` -------------------------------- ### Download and Load GWAS Data Source: https://cloufield.github.io/gwaslab/EffectSize Downloads example GWAS summary statistics files for male and female BMI from a remote URL and loads them into Sumstats objects. This sets up the data for subsequent analysis. ```python !wget -O bbj_bmi_male.txt.gz http://jenger.riken.jp/2analysisresult_qtl_download/ !wget -O bbj_bmi_female.txt.gz http://jenger.riken.jp/4analysisresult_qtl_download/ # Load sumstats as Sumstats objects gl1 = gl.Sumstats("bbj_bmi_female.txt.gz",fmt="gwaslab",snpid="SNP",ea="REF",nea="ALT",sep="\t") gl2 = gl.Sumstats("bbj_bmi_male.txt.gz",fmt="gwaslab",snpid="SNP",ea="REF",nea="ALT",sep="\t") ``` -------------------------------- ### Output with bgzip and tabix Indexing using GWASLab CLI Source: https://cloufield.github.io/gwaslab/CLIWorkflowExamples Creates a bgzip-compressed file with a tabix index for the output sumstats using the GWASLab CLI. This is useful for creating indexed files that can be efficiently queried. Requires input sumstats. ```bash # Create bgzip-compressed file with tabix index gwaslab --input sumstats.tsv \ --fmt gwaslab \ --out indexed_sumstats \ --to-fmt gwaslab \ --bgzip \ --tabix ``` -------------------------------- ### GWASLab CLI with Filtering Options Source: https://cloufield.github.io/gwaslab/Format Demonstrates advanced CLI usage of GWASLab, including options for filtering data. This example shows how to apply HapMap3 filtering, exclude HLA variants, and limit the number of variants to 10,000. ```bash gwaslab --input sumstats.tsv --fmt gwaslab --out output --to-fmt gwaslab \ --hapmap3 --exclude-hla --n 10000 ``` -------------------------------- ### Example Usage of Regional Plot with LD Link Source: https://cloufield.github.io/gwaslab/RegionalPlot Provides a Python code example demonstrating how to use the `plot_mqq` function for regional plotting with LD link visualization enabled. It shows how to specify the plot mode, region, VCF path for LD reference, and parameters for LD link, including alpha scaling, line width, and significance level. ```python mysumstats.plot_mqq( mode="r", region=(7, 156938803, 157038803), vcf_path="path/to/reference.vcf.gz", ld_link=True, ld_link_alpha_scale=0.2, ld_link_linewidth=1.0, ld_link_sig_level=5e-8 # Only show lines for significant variants ) ``` -------------------------------- ### Display GWASLab Version and Environment Information Source: https://cloufield.github.io/gwaslab/harmonization_liftover Calls the 'show_version' function from the GWASLab library to display the installed version, license information, and the Python environment details. This is useful for debugging and ensuring compatibility. ```python gl.show_version() ``` -------------------------------- ### Download Sample Data Source: https://cloufield.github.io/gwaslab/visualization_miami2 These commands use wget to download sample GWAS summary statistics files. The files are saved with specific names and paths, intended for use in subsequent analysis or examples. ```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/ ``` -------------------------------- ### Gene Annotation Workflow Example Source: https://cloufield.github.io/gwaslab/GTF Illustrates a common gene annotation workflow: reading GTF with essential columns, filtering for protein-coding genes, and then extracting gene coordinates for display. ```python from gwaslab.io.io_gtf import read_gtf # Read genes with essential information gt = read_gtf( "annotation.gtf.gz", features={"gene"}, usecols=["seqname", "start", "end", "strand", "gene_id", "gene_name", "gene_biotype"] ) # Filter for protein-coding genes protein_coding = gt[gt["gene_biotype"] == "protein_coding"] # Get gene coordinates for _, gene in protein_coding.iterrows(): print(f"{gene['gene_name']}: {gene['seqname']}:{gene['start']}-{gene['end']}") ``` -------------------------------- ### Generate HTML and PDF QC Reports Source: https://cloufield.github.io/gwaslab/QC_Report Demonstrates how to generate QC reports in both HTML and PDF formats by changing the file extension in the `output_path`. PDF generation requires the `weasyprint` library to be installed. ```python # Generate HTML report mysumstats.report("report.html") # Generate PDF report (requires weasyprint) mysumstats.report("report.pdf") ``` -------------------------------- ### Format Conversion for LDSC with GWASLab CLI Source: https://cloufield.github.io/gwaslab/CLIWorkflowExamples Converts sumstats to LDSC format for heritability analysis using the GWASLab CLI. It takes an input sumstats file and specifies the output format as 'ldsc', with an option to disable gzip compression. ```bash # Convert to LDSC format for heritability analysis gwaslab --input sumstats.tsv \ --fmt gwaslab \ --out sumstats_ldsc \ --to-fmt ldsc \ --no-gzip ``` -------------------------------- ### List Files in Sample Data Directory Source: https://cloufield.github.io/gwaslab/tutorial_v4 Lists the files present in the cloned gwaslab-sample-data directory. This helps verify that the sample data has been downloaded correctly. ```shell !ls gwaslab-sample-data ``` -------------------------------- ### Get Number to NCBI Conversion Table - gwaslab Python Source: https://cloufield.github.io/gwaslab/harmonization_workflow Retrieves a dictionary mapping chromosome numbers to NCBI Sequence Identifiers for a specified build. This is useful for standardizing chromosome names in VCF files. ```python gl.get_number_to_NC(build="19") ``` -------------------------------- ### Clone GWASLab Sample Data Repository Source: https://cloufield.github.io/gwaslab/tutorial_v4 Clones the gwaslab-sample-data repository from GitHub to download necessary sample files for the tutorial. This is a prerequisite for loading and processing data. ```shell #!git clone https://github.com/Cloufield/gwaslab-sample-data.git ``` -------------------------------- ### Assign RSIDs with VCF to BCF Conversion Source: https://cloufield.github.io/gwaslab/AssignrsID This example demonstrates assigning RSIDs from a VCF file after converting it to BCF format for improved performance. It also includes options to `strip_info` fields to reduce file size. Requires `bcftools` to be installed. ```python # Convert VCF to BCF first for better performance mysumstats.basic_check() mysumstats.assign_rsid2( vcf_path="/path/to/dbsnp/GCF_000001405.25.vcf.gz", convert_to_bcf=True, # Convert to BCF format strip_info=True, # Strip INFO fields to reduce size threads=8 ) ``` -------------------------------- ### Basic Format Conversion Examples Source: https://cloufield.github.io/gwaslab/Format Demonstrates basic usage of the .to_format() function for converting summary statistics to different formats like LDSC and PLINK. It shows how to specify the output path, format, tabular format, and whether to gzip the output. ```python # Convert to LDSC format mysumstats.to_format(path="./output", fmt="ldsc") # Output: output.ldsc.tsv.gz # Convert to PLINK format with CSV mysumstats.to_format(path="./output", fmt="plink", tab_fmt="csv", gzip=False) # Output: output.plink.csv # 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 ``` -------------------------------- ### Verify bcftools Installation Source: https://cloufield.github.io/gwaslab/AssignrsID This command verifies the installation and version of bcftools, which is a prerequisite for the sweep mode (.assign_rsid2()) in GWASLab. Successful execution shows the bcftools version and its associated htslib version. ```bash bcftools --version ``` -------------------------------- ### Install GWASLab in a conda environment Source: https://cloufield.github.io/gwaslab/index Sets up a conda environment with Python 3.12 and installs GWASLab using pip. Alternatively, it shows how to create an environment from a yml file. ```bash conda create -n gwaslab -c conda-forge python=3.12 conda activate gwaslab pip install -U gwaslab ``` ```bash conda env create -n gwaslab -f environment.yml -c conda-forge ``` -------------------------------- ### Install GWASLab using pip Source: https://cloufield.github.io/gwaslab/index Installs the latest version of GWASLab using pip. This method requires Python 3.9 or later, with Python 3.12 recommended for optimal performance and compatibility. ```bash pip install -U gwaslab ``` -------------------------------- ### Prepare Data for Meta-analysis with GWASLab CLI Source: https://cloufield.github.io/gwaslab/CLIWorkflowExamples Prepares data for meta-analysis by performing QC, harmonization, and formatting using the GWASLab CLI. It includes options for removing duplicates, excluding the HLA region, and specifying sample size (N). Requires input sumstats and reference files. ```bash # QC, harmonize, and format for meta-analysis gwaslab --input study1.tsv \ --fmt auto \ --qc \ --remove-dup \ --harmonize \ --ref-seq /data/reference/hg19.fasta.gz \ --ref-rsid-vcf /data/reference/dbsnp.vcf.gz \ --out study1_ready \ --to-fmt gwaslab \ --exclude-hla \ --n 50000 ``` -------------------------------- ### Example Usage of GWASLab Clumping Function Source: https://cloufield.github.io/gwaslab/Clumping This example demonstrates how to use the `clump` function from the `mysumstats` module in GWASLab. It shows a basic call to the function, specifying a VCF file as input for the clumping process. ```python clumps = mysumstats.clump(vcf= "/home/yunye/.gwaslab/EAS.ALL.split_norm_af.1kgp3v5.hg19.vcf.gz") ``` -------------------------------- ### Initialize and Display Sumstats Data Source: https://cloufield.github.io/gwaslab/utility_data_conversion This example shows how to initialize a `Sumstats` object with data from a gzipped text file, specifying column mappings for SNP ID, chromosome, position, beta, and standard error. It also demonstrates how to display the first few rows of the loaded data and then modifies the 'SE' column to simulate extreme P-values. ```python mysumstats = gl.Sumstats("../0_sample_data/t2d_bbj.txt.gz", snpid="SNP", chrom="CHR", pos="POS", beta="BETA", se="SE",nrows=5, verbose=False) # simulate some extreme P values by shrinking the SE mysumstats.data["SE"] = mysumstats.data["SE"]/100 print(mysumstats.data) ``` -------------------------------- ### Customize MQQ Plot Appearance Source: https://cloufield.github.io/gwaslab/visualization_brisbane Customizes the appearance of the MQQ plot. This example enables annotation, sets the significance line color to red, increases the window size for density calculation, and suppresses verbose output. It utilizes the 'b' mode for the Brisbane plot. ```python sumstats.plot_mqq(mode="b",anno=True,sig_line_color="red", windowsizekb=100000, verbose=False) ``` -------------------------------- ### Download Reference Data with gl.download_ref Source: https://cloufield.github.io/gwaslab/tutorial_v4 This function downloads reference genome data, such as GTF files for specific builds. It requires the name of the reference dataset to be downloaded. No specific input validation or output is shown, but it's essential for downstream analyses requiring genomic annotations. ```python gl.download_ref("ensembl_hg19_gtf") ``` -------------------------------- ### Download Reference Data for GWASLab Source: https://cloufield.github.io/gwaslab/AssignrsID Downloads necessary reference data for rsID assignment. This is a one-time setup. Supported references include '1kg_dbsnp151_hg19_auto' and '1kg_dbsnp151_hg38_auto'. ```python # 1. Download reference data (one-time setup) gl.download_ref("1kg_dbsnp151_hg19_auto") ``` -------------------------------- ### Download Reference Files using GWASLab Source: https://cloufield.github.io/gwaslab/tutorial_v4 This function allows users to download preprocessed reference datasets for use in GWAS analysis. The downloaded files are stored in the ~/.gwaslab directory by default. Ensure sufficient disk space for downloads, such as the ~2.8GB for '1kg_eas_hg19'. ```python # gl.download_ref("1kg_eas_hg19") ``` -------------------------------- ### Method Chaining for Report Generation (Python) Source: https://cloufield.github.io/gwaslab/QC_Report Demonstrates how to use the `report()` method with method chaining to generate a GWAS report. This example shows initializing a `Sumstats` object, performing basic checks, identifying lead variants, and then generating an HTML report. ```python mysumstats = gl.Sumstats("data.txt.gz", ...) result = (mysumstats .basic_check(remove=False, normalize=True) .get_lead(sig_level=5e-8) .report("report.html") ) ``` -------------------------------- ### Get Reference GTF Data Source: https://cloufield.github.io/gwaslab/GTF Retrieves reference GTF data for a specified build and source, such as Ensembl hg38. It demonstrates filtering the retrieved data for protein-coding genes. ```python from gwaslab.io.io_gtf import get_gtf # Get Ensembl hg38 GTF for chromosome 1 gt = get_gtf(chrom="1", build="38", source="ensembl") # Filter for protein-coding genes protein_coding = gt[gt["gene_biotype"] == "protein_coding"] print(f"Protein-coding genes on chr1: {len(protein_coding)}") ``` -------------------------------- ### Create QQ Plot with GWASLab Source: https://cloufield.github.io/gwaslab/tutorial_v4 Generates a Quantile-Quantile (QQ) plot from GWAS summary statistics. It processes variants, calculates lambda GC, and annotates the plot with gene names. The plot can be saved to a file. ```python mysumstats.plot_mqq(output="my_first_mqq_plot.png", GENENAME="GENENAME", repel_force=0.03) ``` -------------------------------- ### Basic QC Pipeline with GWASLab CLI Source: https://cloufield.github.io/gwaslab/CLIWorkflowExamples Loads, performs quality control, and saves sumstats using the GWASLab CLI. It handles input file loading, auto-detection of format, QC steps (ID, chromosome, position, allele fixing), removal of low-quality variants and duplicates, indel normalization, and output saving. Requires input sumstats file. ```bash # Load, QC, and save sumstats gwaslab --input raw_sumstats.tsv \ --fmt auto \ --qc \ --remove \ --remove-dup \ --normalize \ --threads 4 \ --out cleaned_sumstats \ --to-fmt gwaslab \ --quiet ``` -------------------------------- ### Testing with Small Sample using GWASLab CLI Source: https://cloufield.github.io/gwaslab/CLIWorkflowExamples Tests the GWASLab CLI command on the first 1000 rows of a large sumstats file. This is useful for quick checks and debugging before running on the full dataset. Includes QC and duplicate removal options. ```bash # Test command on first 1000 rows gwaslab --input large_sumstats.tsv \ --fmt auto \ --nrows 1000 \ --qc \ --remove-dup \ --out test_output \ --to-fmt gwaslab ``` -------------------------------- ### Get Chromosome List - GWASLab Source: https://cloufield.github.io/gwaslab/CommonData Retrieves a list of chromosomes for a specified species, with options to include numeric representations or only numeric autosomes. Supports species-specific chromosome naming conventions. ```python gl.get_chr_list() # ['1','2','3',...,'22','X','Y','MT'] gl.get_chr_list(species="mouse") # ['1','2','3',...,'19','X','Y','MT'] gl.get_chr_list(species="chicken") # ['1','2','3',...,'28','Z','W','MT'] gl.get_chr_list(add_number=True) # ['1','2',...,'22','X','Y','MT',1,2,...,22] gl.get_chr_list(only_number=True) # [1, 2, 3, ..., 22] ``` -------------------------------- ### Display GWASLab Version Source: https://cloufield.github.io/gwaslab/visualization_miami2 This command displays the installed version of the gwaslab library and its associated license and contact information. It's a simple utility function to verify the library's version. ```python import gwaslab as gl gl.show_version() ``` -------------------------------- ### Load Sumstats by Specifying Columns Source: https://cloufield.github.io/gwaslab/SumstatsObject Demonstrates how to load summary statistics by manually specifying the column names for each required and optional field. ```APIDOC ## Load sumstats by specifying columns ### Description This example shows how to load GWAS summary statistics from a file by manually mapping the column names to the expected fields in the Sumstats Object. ### Method `gl.Sumstats(file_path, snpid='column_name', chrom='column_name', pos='column_name', ea='column_name', nea='column_name', eaf='column_name', beta='column_name', se='column_name', p='column_name', n='column_name', ...)` ### Parameters (See `gl.Sumstats()` constructor for a full list of parameters and their descriptions.) ### Request Example ```python mysumstats = gl.Sumstats("t2d_bbj.txt.gz", snpid="SNPID", chrom="CHR", pos="POS", ea="Allele2", nea="Allele1", eaf="AF_Allele2", beta="BETA", se="SE", p="p.value", n="N") ``` ### Response #### Success Response (200) - **Sumstats Object**: A GWASLab Sumstats Object populated with data from the specified file and column mappings. ``` -------------------------------- ### Load Summary Statistics into GWASLab Sumstats Object Source: https://cloufield.github.io/gwaslab/tutorial_v4 Loads summary statistics from a gzipped text file into a GWASLab Sumstats object. It requires specifying column names for various genetic association parameters and the file's separator. ```python mysumstats = gl.Sumstats("gwaslab-sample-data/bbj_t2d_hm3_chr7_variants.txt.gz", snpid="SNPID", chrom="CHR", pos="POS", ea="EA", nea="NEA", neaf="EAF", beta="BETA", se="SE", p="P", n="N", sep="\t") ``` -------------------------------- ### Testing with Small Samples (GWASLab CLI) Source: https://cloufield.github.io/gwaslab/CLI Demonstrates how to test commands on a subset of data using the `--nrows` option. This is helpful for debugging and verifying command functionality before running on the entire dataset. ```bash gwaslab --input large_sumstats.tsv --fmt auto --nrows 1000 --qc --out test_output --to-fmt gwaslab ``` -------------------------------- ### Input Format Detection (GWASLab CLI) Source: https://cloufield.github.io/gwaslab/CLI Demonstrates the use of `--fmt auto` to automatically detect the input file format. This simplifies the process by removing the need to manually specify the input format, making it easier to process various sumstats files. ```bash gwaslab --input sumstats.tsv --fmt auto --qc --out output --to-fmt gwaslab ``` -------------------------------- ### Performance Tips for GTF Handling Source: https://cloufield.github.io/gwaslab/GTF Provides recommendations for optimizing GTF file processing performance within GWASLab. ```APIDOC ## Performance Tips 1. **Filter early** : Use `chrom` and `features` parameters to filter data during reading, not after loading. 2. **Select columns** : Use `usecols` to load only the columns you need, reducing memory usage. 3. **Use built-in references** : For common reference genomes, use `get_gtf()` which automatically handles downloading and caching. 4. **Compressed files** : GWASLab automatically handles gzip-compressed GTF files, so you can work directly with `.gtf.gz` files. 5. **Polars backend** : The GTF reader uses Polars internally for fast file reading, then converts to pandas for compatibility. ``` -------------------------------- ### Get Default Download Directory with GWASLab Source: https://cloufield.github.io/gwaslab/Download Retrieves the currently set default directory for downloaded files. This function returns the path as a string, allowing users to confirm their download location settings. ```python gl.get_default_directory() ``` -------------------------------- ### Infer Genome Build - Output Logs - Python Source: https://cloufield.github.io/gwaslab/InferBuild Example logging output from the .infer_build() function, showing the process of matching variants and inferring the genome build. It also includes a warning for unreliable inference due to a limited number of matching variants. ```python -Loading Hapmap3 variants data... -CHR and POS will be used for matching... -Matching variants for hg19: num_hg19 = 12345 -Matching variants for hg38: 5678 -Since num_hg19 >> num_hg38, set the genome build to hg19 for the STATUS code.... ⚠️ Please be cautious due to the limited number of variants. ``` -------------------------------- ### Common Filtering Workflow Example Source: https://cloufield.github.io/gwaslab/QC%26Filtering Demonstrates a typical sequence of filtering steps for genetic association data, including removing palindromic variants, indels, excluding the HLA region, and retaining HapMap3 variants for LDSC analysis. ```python # Remove palindromic variants mysumstats.filter_palindromic(mode="out") # Remove indels mysumstats.filter_indel(mode="out") # Exclude HLA region mysumstats.exclude_hla() # Filter to HapMap3 variants (for LDSC) mysumstats.filter_hapmap3() ``` -------------------------------- ### Run Basic QC Workflow in gwaslab Source: https://cloufield.github.io/gwaslab/Standardization Demonstrates how to load GWAS summary statistics and run the basic quality control workflow using the `basic_check()` method in the gwaslab library. It shows default usage, removal of bad variants, and customization of individual steps. ```python import gwaslab as gl # Load sumstats mysumstats = gl.Sumstats("sumstats.txt.gz", fmt="plink2") # Run comprehensive QC (doesn't remove variants by default) mysumstats.basic_check() # Run QC and remove bad variants mysumstats.basic_check(remove=True, remove_dup=True) # Customize individual steps mysumstats.basic_check( remove=True, remove_dup=True, normalize=True, threads=4, fix_chr_kwargs={"remove": True}, fix_pos_kwargs={"limit": 300000000}, sanity_check_stats_kwargs={"p": (1e-300, 1)} ) ``` -------------------------------- ### Save Annotated Effect Size Comparison Plot Source: https://cloufield.github.io/gwaslab/EffectSize Performs an annotated comparison of effect sizes between two GWAS datasets and saves the resulting plot to a file. This example includes options for plot customization and saving. ```python # GWASLab will automatically extract significant variants from both sumstats. a = gl.compare_effect(path1=gl1, path2=gl2, label=["Female","Male","Both","None"], xylabel_prefix="Per-allele effect size for ", anno=True, anno_het=True, anno_diff=0.015, sig_level=5e-8, legend_title=r'$mathregular{ P < 5 x 10^{-8}}$ in:', verbose=True, save="myplot.png", save_kwargs={"dpi":300,"facecolor":"white"} ) ```