### Install pandasGWAS Package Source: https://github.com/caotianze/pandasgwas/blob/main/README.md Installs the pandasGWAS package using pip. This is the primary method for setting up the library for use. ```bash pip install pandasgwas ``` -------------------------------- ### Search, Download, and Parse GWAS Summary Statistics Source: https://context7.com/caotianze/pandasgwas/llms.txt Provides examples for interacting with GWAS summary statistics data. This includes searching for statistics using various IDs, opening the FTP directory in a browser, downloading the data, and parsing it into a pandas DataFrame for analysis, including filtering for significant variants. ```python from pandasgwas.summary_statistics import search, browser, download, parse # Search for summary statistics by PubMed ID and study accession search_results = search(PubMed_id='27918534', study_accession_id='GCST003966') print(search_results[['PubMed_id', 'study_accession_id', 'EFO_trait_id', 'file_name']]) # Search by EFO trait ID trait_results = search(EFO_trait_id='EFO_0004340') print(f"Found {len(trait_results)} summary statistics files") # Open FTP directory in web browser browser(search_results, interactive=True) # Download summary statistics to ~/pandasgwas_home download(search_results) # Parse downloaded data into DataFrame df = parse(search_results) print(df.columns.tolist()) # ['variant_id', 'p_value', 'chromosome', 'base_pair_location', 'odds_ratio', # 'ci_lower', 'ci_upper', 'beta', 'standard_error', 'effect_allele', # 'other_allele', 'effect_allele_frequency', 'hm_variant_id', 'hm_odds_ratio', # 'hm_ci_lower', 'hm_ci_upper', 'hm_beta', 'hm_effect_allele', 'hm_other_allele', # 'hm_effect_allele_frequency', 'hm_code', 'PubMed_id', 'study_accession_id', 'EFO_trait_id'] # Filter significant variants significant = df[df['p_value'] < 5e-8] print(f"Found {len(significant)} genome-wide significant variants") ``` -------------------------------- ### Get Variants by Cytogenetic Band, Gene Name, or Reported Trait Source: https://context7.com/caotianze/pandasgwas/llms.txt Demonstrates how to retrieve genetic variants based on cytogenetic band, gene name, or reported trait using pandasGWAS. These functions return objects containing variant information, which can then be accessed and printed. ```python from pandasgwas import get_variants_by_gene_name, get_variants_by_reported_trait # Get variants by cytogenetic band band_variants = get_variants_by_cytogenetic_band('1p36.32') print(band_variants.locations) # Get variants by gene name gene_variants = get_variants_by_gene_name('KIAA0319') print(gene_variants.variants[['rsId', 'merged', 'lastUpdateDate']]) # Get variants by reported trait trait_variants = get_variants_by_reported_trait("Dupuytren's disease") print(trait_variants.ensembl_gene_ids[['rsId', 'ensemblGeneId']]) ``` -------------------------------- ### Retrieve Variants for a Specific Study Source: https://github.com/caotianze/pandasgwas/blob/main/README.md Retrieves genetic variants associated with a given GWAS study ID using the `get_variants` function. It takes a `study_id` and returns a DataFrame of variants, with an example showing the 'rsId' and 'functionalClass' columns for study GCST002305. ```python from pandasgwas import get_variants variants = get_variants(study_id='GCST002305') variants.variants[['rsId', 'functionalClass']] ``` -------------------------------- ### Retrieve GWAS Studies by Trait Source: https://github.com/caotianze/pandasgwas/blob/main/README.md Fetches studies related to a specific trait from the GWAS Catalog using the `get_studies` function. It takes an `efo_trait` as input and returns a DataFrame containing study details. The example shows retrieving studies for 'triple-negative breast cancer'. ```python from pandasgwas import get_studies studies = get_studies(efo_trait = 'triple-negative breast cancer') studies.studies[0:4] ``` -------------------------------- ### Open GWAS Catalog Entities in Browser (Python) Source: https://context7.com/caotianze/pandasgwas/llms.txt Helper functions to open GWAS Catalog entities, PubMed citations, dbSNP entries, and GTEx portal pages in a web browser. These functions take specific identifiers as input and launch the corresponding web pages. ```python from pandasgwas import ( open_in_pubmed, open_in_dbsnp, open_in_gtex, open_study_in_gwas_catalog, open_variant_in_gwas_catalog, open_trait_in_gwas_catalog, open_gene_in_gwas_catalog, open_region_in_gwas_catalog, open_publication_in_gwas_catalog ) # Open PubMed citation open_in_pubmed('26301688') # Open variant in dbSNP open_in_dbsnp('rs56261590') # Open variant in GTEx portal (eQTL browser) open_in_gtex('rs56261590') # Open study in GWAS Catalog open_study_in_gwas_catalog('GCST000016') # Open variant in GWAS Catalog open_variant_in_gwas_catalog('rs146992477') # Open trait in GWAS Catalog open_trait_in_gwas_catalog('EFO_0004884') # Open gene in GWAS Catalog open_gene_in_gwas_catalog('DPP6') # Open genomic region by cytogenetic band or coordinates open_region_in_gwas_catalog('2q37.1') open_region_in_gwas_catalog('chr2:230100001-234700000') # Open publication in GWAS Catalog open_publication_in_gwas_catalog('25533513') ``` -------------------------------- ### Perform Set Operations on pandasGWAS Objects Source: https://context7.com/caotianze/pandasgwas/llms.txt Illustrates how to perform set operations (union, intersection, difference, symmetric difference, equality check) on pandasGWAS objects using both explicit functions and overloaded operators (+, |, &, -, ^, ==). This allows for combining and comparing genetic data sets. ```python from pandasgwas import get_studies, bind, intersect, set_diff, set_xor, union, set_equal # Combine studies from multiple queries using bind (+) study1 = get_studies(reported_trait='Suicide risk') study2 = get_studies(reported_trait="Dupuytren's disease") study3 = get_studies(reported_trait="Triglycerides") all_studies = study1 + study2 + study3 # or: bind(study1, bind(study2, study3)) print(f"Combined {len(all_studies)} studies") # Union: combine without duplicates (|) from pandasgwas import get_traits traits1 = get_traits(study_id='GCST000854', efo_id='EFO_0001065') traits2 = get_traits(study_id='GCST000854', efo_uri='http://www.ebi.ac.uk/efo/EFO_0005133') unique_traits = traits1 | traits2 # or: union(traits1, traits2) # Intersection: find common elements (&) common_traits = traits1 & traits2 # or: intersect(traits1, traits2) # Set difference: elements in first but not second (-) diff_traits = traits1 - traits2 # or: set_diff(traits1, traits2) # Symmetric difference: elements in either but not both (^) xor_traits = traits1 ^ traits2 # or: set_xor(traits1, traits2) # Check equality traits_a = get_traits(study_id='GCST000854') traits_b = get_traits(study_id='GCST000854') are_equal = set_equal(traits_a, traits_b) # or: traits_a == traits_b print(f"Traits are equal: {are_equal}") ``` -------------------------------- ### Utility Functions for API and Ontology (Python) Source: https://context7.com/caotianze/pandasgwas/llms.txt Provides helper functions for checking GWAS Catalog API availability, clearing the request cache, and retrieving child EFO terms. These functions are essential for managing API interactions and exploring ontology relationships. ```python from pandasgwas import is_API_available, clear_cache, get_child_efo # Check if GWAS Catalog API is available if is_API_available(): print("API is available, proceeding with queries...") else: print("API is unavailable, try again later") # Clear cached API requests (cache is stored in memory) clear_cache() # Get child terms of an EFO trait in the ontology hierarchy child_terms = get_child_efo('EFO_0004884') print(child_terms) # ['EFO_0009393'] child_terms = get_child_efo('EFO_0009640') print(child_terms) # ['EFO_0600083', 'EFO_0005606', 'EFO_0008346', 'EFO_0006953'] # No children returns empty list child_terms = get_child_efo('EFO_0005299') print(child_terms) # [] ``` -------------------------------- ### Query Summary Statistics Data with PandasGWAS (Python) Source: https://github.com/caotianze/pandasgwas/blob/main/README.md This snippet demonstrates how to use the pandasGWAS library to interact with summary statistics data. It covers searching for data based on identifiers, browsing results, downloading the data, and parsing it into a DataFrame. The library relies on FTP data due to ongoing redevelopment of the REST API. ```python from pandasgwas.summary_statistics import search, browser, download, parse #Search the index based on PubMed_id, study_accession_id, and EFO_trait_id. The indexed results will be returned as a DataFrame. search_DF = search(PubMed_id='27918534', study_accession_id='GCST003966') #Based on the index results, view the data directory on the browser. browser(search_DF) #Based on index results, download summary statistics data in $Home/pandasgwas_home. download(search_DF) #Based on the index results, load the data from $Home/pandasgwas_home and convert it into a DataFrame. df = parse(search_DF) ``` -------------------------------- ### Accessing GWAS Data Objects (Python) Source: https://context7.com/caotianze/pandasgwas/llms.txt Demonstrates how to retrieve and interact with custom data objects (Study, Variant, Association) returned by pandasGWAS queries. These objects contain hierarchically organized pandas DataFrames and support indexing and slicing. ```python from pandasgwas import get_studies, get_variants, get_associations # Study object contains 7 DataFrames studies = get_studies(study_id='GCST000854') print(studies) # Study has 7 DataFrames with hierarchical dependencies. # studies # | # -platforms # | # -ancestries # | # -ancestral_groups # | # -countries_of_origin # | # -countries_recruitment # | # -geontyping_tcchnologies # Access individual DataFrames print(studies.studies.columns.tolist()) print(studies.ancestries[['type', 'numberOfIndividuals']]) print(studies.platforms[['manufacturer', 'accessionId']]) # Variant object contains 5 DataFrames variants = get_variants(study_id='GCST000854') print(variants.variants[['rsId', 'functionalClass']]) print(variants.locations[['chromosomeName', 'chromosomePosition']]) print(variants.genomic_contexts[['gene.geneName', 'isIntergenic']]) # Association object contains 6 DataFrames associations = get_associations(study_id='GCST000854') print(associations.associations[['associationId', 'pvalue']]) print(associations.loci[['description', 'haplotypeSnpCount']]) print(associations.strongest_risk_alleles[['riskAlleleName', 'riskFrequency']]) # Indexing and slicing first_study = studies[0] subset = studies[0:3] by_id = studies['GCST000854'] ``` -------------------------------- ### Retrieve Experimental Factor Ontology (EFO) Traits Source: https://context7.com/caotianze/pandasgwas/llms.txt Shows how to fetch EFO traits from the GWAS Catalog using various identifiers like study ID, association ID, EFO ID, PubMed ID, EFO URI, or trait description. The function returns a Trait object with a DataFrame of trait information. ```python from pandasgwas import get_traits # Get traits associated with a study traits = get_traits(study_id='GCST000854') print(traits.efo_traits[['trait', 'shortForm', 'uri']]) # trait shortForm uri # 0 LDL cholesterol levels EFO_0004611 http://www.ebi.ac.uk/efo/EFO_0004611 # Get trait by EFO ID trait = get_traits(efo_id='EFO_0001065') print(trait.efo_traits) # Get traits by EFO URI uri_traits = get_traits(efo_uri='http://www.ebi.ac.uk/efo/EFO_0005133') print(uri_traits.efo_traits[['trait', 'shortForm']]) # Get traits matching a description matched_traits = get_traits(efo_trait='MHPG measurement') print(matched_traits.efo_traits) # Get traits from a publication pub_traits = get_traits(pubmed_id='21041247') print(f"Found {len(pub_traits)} traits in publication 21041247") ``` -------------------------------- ### Aggregate GWAS Study Results with Set Operations Source: https://github.com/caotianze/pandasgwas/blob/main/README.md Demonstrates how to aggregate GWAS study results using set operations. The `get_studies` function is used to fetch studies for different traits, and then standard mathematical symbols like '+' can be used to combine these results into a single dataset. ```python from pandasgwas.get_studies import get_studies study1=get_studies(reported_trait='Suicide risk') study2=get_studies(reported_trait="Dupuytren's disease") study3=get_studies(reported_trait="Triglycerides") study4=get_studies(reported_trait="Retinal vascular caliber") study5=get_studies(reported_trait="Non-small cell lung cancer (survival)") all_studies=study1+study2+study3+study4+study5 ``` -------------------------------- ### Retrieve GWAS Catalog Studies using pandasGWAS Source: https://context7.com/caotianze/pandasgwas/llms.txt Fetches GWAS Catalog studies based on various identifiers such as study ID, EFO trait, reported trait, or PubMed ID. It returns a Study object containing DataFrames for studies, platforms, ancestries, and more. This function is useful for exploring study-level information and filtering studies by specific criteria. ```python from pandasgwas import get_studies # Get studies by study accession ID studies = get_studies(study_id='GCST000854') print(studies.studies[['accessionId', 'initialSampleSize', 'diseaseTrait.trait']]) # Get studies by EFO trait description cancer_studies = get_studies(efo_trait='triple-negative breast cancer') print(f"Found {len(cancer_studies)} studies") print(cancer_studies.studies[['accessionId', 'publicationInfo.pubmedId', 'publicationInfo.title']]) # Get studies by reported trait (as reported by original authors) vitamin_studies = get_studies(reported_trait='Vitamin D levels') print(vitamin_studies.studies[['accessionId', 'replicationSampleSize']]) # Get studies by PubMed ID pubmed_studies = get_studies(pubmed_id='21041247') print(pubmed_studies.ancestries[['type', 'numberOfIndividuals']]) # Combine multiple query criteria with intersection studies = get_studies(study_id='GCST000854', efo_id='EFO_0001065', set_operation='intersection') ``` -------------------------------- ### Retrieve GWAS Catalog Associations using pandasGWAS Source: https://context7.com/caotianze/pandasgwas/llms.txt Retrieves genetic associations from the GWAS Catalog based on study ID, association ID, variant ID, EFO trait ID, PubMed ID, or trait description. It returns an Association object with DataFrames for associations, loci, risk alleles, and author-reported genes. This function is key for detailed analysis of genetic associations. ```python from pandasgwas import get_associations # Get associations by study ID associations = get_associations(study_id='GCST000854') print(associations.associations[['associationId', 'pvalue', 'orPerCopyNum', 'betaNum']]) # Get associations by association ID assoc = get_associations(association_id='16603') print(assoc.loci[['description', 'haplotypeSnpCount']]) print(assoc.strongest_risk_alleles[['riskAlleleName', 'riskFrequency']]) # Get associations by variant rsID variant_assocs = get_associations(variant_id='rs6538678') print(variant_assocs.associations[['associationId', 'pvalueMantissa', 'pvalueExponent']]) # Get associations by EFO trait description trait_assocs = get_associations(efo_trait='MHPG measurement') print(trait_assocs.author_reported_genes[['geneName', 'associationId']]) # Get associations by EFO ID efo_assocs = get_associations(efo_id='EFO_0001065') print(f"Found {len(efo_assocs)} associations for EFO_0001065") ``` -------------------------------- ### Retrieve GWAS Catalog Variants using pandasGWAS Source: https://context7.com/caotianze/pandasgwas/llms.txt Fetches Single Nucleotide Polymorphisms (SNPs) from the GWAS Catalog using various identifiers like study ID, variant ID, EFO ID, genomic range, or gene name. It returns a Variant object containing DataFrames for variants, locations, genomic contexts, and gene IDs. This function is useful for detailed SNP analysis and genomic region queries. ```python from pandasgwas import get_variants # Get variants associated with a study variants = get_variants(study_id='GCST002305') print(variants.variants[['rsId', 'functionalClass']]) # Get a specific variant by rsID snp = get_variants(variant_id='rs7744020') print(snp.locations[['chromosomeName', 'chromosomePosition', 'region.name']]) print(snp.genomic_contexts[['gene.geneName', 'isIntergenic', 'distance']]) # Get variants in a genomic range (chromosome, start, end) range_variants = get_variants(genomic_range=['1', 2300001, 5300000]) print(f"Found {len(range_variants)} variants in chr1:2300001-5300000") print(range_variants.variants[['rsId', 'functionalClass']]) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.