Library (API Documentation)

This code is intended to be primarily used as a library, and works best when used in an interactive python session (e.g. with jupyter) alongside pandas. Many of the query functions in this library returns pandas dataframes.

Below is a complete documentation of the API for this library. The functions in grasp.query will be the most interesting for most users wanting to do common db queries.

Tables are defined in grasp.tables, functions for connecting to and building the database are in grasp.db. grasp.info contains simple documentation for all of the tables and phenotypes (used to build this documentation).

grasp.config handles the static database configuration at ~/.grasp, and grasp.ref is used to define module wide static objects, like dictionaries and the PopFlags class.

grasp.query

A mix of functions to make querying the database and analyzing the results faster.

Primary query functions:
get_studies():
Allows querying the Study table by a combination of population and phenotype variables.
get_snps():
Take a study list (possibly from get_studies) and return a SNP list or dataframe.
Helpful additional functions:
intersecting_phenos():
Return a list of phenotypes or phenotype categories present in all queried populations.
write_study_dict():
Write the dictionary returned from get_studies(dictionary=True) to a tab delimited file with extra data from the database.
Lookup functions:
lookup_rsid(), lookup_location() and lookup_studies() allow the querying of the database for specific SNPs and can return customized information on them.
MyVariant:
get_variant_info():
Use myvariant to get variant info for a list of SNPs.
DataFrame Manipulation:
collapse_dataframe():
Collapse a dataframe (such as that returned by get_snps()) to include only a single entry per SNP (collapsing multiple studies into one).
intersect_overlapping_series():
Merge two sets of pvalues (such as those from collapse_dataframe()) into a single merged dataframe with the original index and one column for each pvalue. Good for plotting.

get_studies

grasp.query.get_studies(primary_phenotype=None, pheno_cats=None, pheno_cats_alias=None, primary_pop=None, has_pop=None, only_pop=None, has_disc_pop=None, has_rep_pop=None, only_disc_pop=None, only_rep_pop=None, query=False, count=False, dictionary=False, pandas=False)[source]

Return a list of studies filtered by phenotype and population.

There are two ways to query both phenotype and population.

Phenotype:

GRASP provides a ‘primary phenotype’ for each study, which are fairly poorly curated. They also provide a list of phenotype categories, which are well curated. The problem with the categories is that there are multiple per study and some are to general to be useful. If using categories be sure to post filter the study list.

Note: I have made a list of aliases for the phenotype categories to make them easier to type. Use pheno_cats_alias for that.

Population:

Each study has a primary population (list available with ‘get_populations’) but some studies also have other populations in the cohort. GRASP indexes all population counts, so those can be used to query also. To query these use has_ or only_ (exclusive) parameters, you can query either discovery populations or replication populations. Note that you cannot provide both has_ and only_ parameters for the same population type.

For doing population specific analyses most of the time you will want the excl_disc_pop query.

Argument Description:

Phenotype Arguments are ‘primary_phenotype’, ‘pheno_cats’, and ‘pheno_cats_alias’.

Only provide one of pheno_cats or pheno_cats_alias

Population Arguments are primary_pop, has_pop, only_pop, has_disc_pop, has_rep_pop, only_disc_pop, only_rep_pop.

primary_pop is a simple argument, the others use bitwise flags for lookup.

has_pop and only_pop simpply combine both the discovery and replication population lookups.

The easiest way to use the has_ and only_ parameters is with the PopFlag object. It uses py-flags. For example:

pops = PopFlag.eur | PopFlag.afr

In addition you can provide a list of strings corresponding to PopFlag attributes.

Note: the only_ parameters work as ANDs, not ORs. So only_disc_pop=’eur|afr’ will return those studies that have BOTH european and african discovery populations, but no other discovery populations. On the other hand, has_ works as an OR, and will return any study with any of the specified populations.

Parameters:
  • primary_phenotype – Phenotype of interest, string or list of strings.
  • pheno_cats – Phenotype category of interest.
  • pheno_cats_alias – Phenotype category of interest.
  • primary_pop – Query the primary population, string or list of strings.
  • has_pop – Return all studies with these populations
  • only_pop – Return all studies with these populations
  • has_disc_pop – Return all studies with these discovery populations
  • has_rep_pop – Return all studies with these replication populations
  • only_disc_pop – Return all studies with ONLY these discovery populations
  • only_rep_pop – Return all studies with ONLY these replication populations
  • query – Return the query instead of the list of study objects.
  • count – Return a count of the number of studies.
  • dictionary – Return a dictionary of title->id for filtering.
  • pandas – Return a dataframe of study information instead of the list.
Returns:

A list of study objects, a query, or a dataframe.

get_snps

grasp.query.get_snps(studies, pandas=True)[source]

Return a list of SNPs in a single population in a single phenotype.

Studies:A list of studies.
Pandas:Return a dataframe instead of a list of SNP objects.
Returns:Either a DataFrame or list of SNP objects.

lookup_rsid

grasp.query.lookup_rsid(rsid, study=False, columns=None, pandas=False)[source]

Query database by rsID.

Parameters:
  • rsID (str) – An rsID or list of rsIDs
  • study (bool) – Include study info in the output.
  • columns (list) – A list of columns to include in the query. Default is all. List must be made up of column objects, e.g. [t.SNP.snpid, t.Study.id]
  • pandas (bool) – Return a dataframe instead of a list of SNPs
Returns:

List of SNP objects

Return type:

list

lookup_location

grasp.query.lookup_location(chrom, position, study=False, columns=None, pandas=False)[source]

Query database by location.

Parameters:
  • chrom (str) – The chromosome as an int or string (e.g. 1 or chr1)
  • position (int) – Either one location, a list of locations, or a range of locations, range can be expressed as a tuple of two ints, a range object, or a string of ‘int-int’
  • study (bool) – Include study info in the output.
  • columns (list) – A list of columns to include in the query. Default is all. List must be made up of column objects, e.g. [t.SNP.snpid, t.Study.id]
  • pandas (bool) – Return a dataframe instead of a list of SNPs
Returns:

List of SNP objects

Return type:

list

lookup_studies

grasp.query.lookup_studies(title=None, study_id=None, columns=None, pandas=False)[source]

Find all studies matching either title or id.

Parameters:
  • title (str) – The study title, string or list of strings.
  • study_id (int) – The row ID, usually the PMID, int or list of ints.
  • columns (list) – A list of columns to include in the query. Default is all. List must be made up of column objects, e.g. [t.SNP.snpid, t.Study.id]
  • pandas (bool) – Return a dataframe instead of a list of SNPs
Returns:

All matching studies as either a dataframe or a list

Return type:

DataFrame or list

get_variant_info

grasp.query.get_variant_info(snp_list, fields='dbsnp', pandas=True)[source]

Get variant info for a list of SNPs.

Parameters:
  • snp_list – A list of SNP objects or SNP rsIDs
  • fields – Choose fields to display from: docs.myvariant.info/en/latest/doc/data.html#available-fields Good choices are ‘dbsnp’, ‘clinvar’, or ‘gwassnps’ Can also use ‘grasp’ to get a different version of this info.
  • pandas – Return a dataframe instead of dictionary.
Returns:

A dictionary or a dataframe.

get_collapse_dataframe

grasp.query.collapse_dataframe(df, mechanism='median', pvalue_filter=None, protected_columns=None)[source]

Collapse a dataframe by chrom:location from get_snps.

Will use the mechanism defined by ‘mechanism’ to collapse a dataframe to one indexed by ‘chrom:location’ with pvalue and count only.

This function is agnostic to all dataframe columns other than:

['chrom', 'pos', 'snpid', 'pval']

All other columns are collapsed into a comma separated list, a string. ‘chrom’ and ‘pos’ are merged to become the new colon-separated index, snpid is maintained, and pval is merged using the function in ‘mechanism’.

Parameters:
  • df – A pandas dataframe, must have ‘chrom’, ‘pos’, ‘snpid’, and ‘pval’ columns.
  • mechanism – A numpy statistical function to use to collapse the pvalue, median or mean are the common ones.
  • pvalue_filter – After collapsing the dataframe, filter to only include pvalues less than this cutoff.
  • protected_columns – A list of column names that will be maintained as is, although all duplicates will be dropped (randomly). Only makes sense for columns that are identical for all studies of the same SNP.
Returns:

Indexed by chr:pos, contains flattened pvalue column, and all original columns as a comma-separated list. Additionally contains a count and stddev (of pvalues) column. stddev is nan if count is 1.

Return type:

DataFrame

intersect_overlapping_series

grasp.query.intersect_overlapping_series(series1, series2, names=None, stats=True, plot=None, name=None)[source]

Plot all SNPs that overlap between two pvalue series.

Parameters:
  • series{1,2} (Series) – A pandas series object
  • names (list) – A list of two names to use for the resultant dataframes
  • stats (bool) – Print some stats on the intersection
  • plot (str) – Plot the resulting intersection, path to save figure to (must end in .pdf/.png). Numpy and Matplotlib are required.
  • name (str) – A name for the plot, optional.
Returns:

with the two series as columns

Return type:

DataFrame

write_study_dict

grasp.query.write_study_dict(study_dict, outfile)[source]

Write a study dictionary from get_studies(dictionary=True) to file.

Looks up studies in the Study table first.

Parameters:
  • study_dict (dict) – A dictionary of title=>id from the Study table.
  • outfile – A valid path to a file with write permission.
Outputs:
A tab delimited file of ID, Title, Author, Journal, Discovery Population, Replication Population, SNP_Count
Returns:None

grasp.tables

GRASP table descriptions in SQLAlchemy ORM.

These tables do not exist in the GRASP data, which is a single flat file. By separating the data into these tables querying is much more efficient.

This submodule should only be used for querying.

SNP

class grasp.tables.SNP(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

An SQLAlchemy Talble for GRASP SNPs.

Study and phenotype information are pushed to other tables to minimize table size and make querying easier.

Table Name:
snps
Columns:
Described in the columns attribute
int

The ID number of the SNP, usually the NHLBIkey

str

SNP loction expressed as ‘chr:pos’

hvgs_ids

A list of HGVS IDs for this SNP

columns

A dictionary of all columns ‘column_name’=>(‘type’, ‘desc’)

__int__()[source]

Return ID number.

__repr__()[source]

Display information about the table.

__str__()[source]

Return coordinates.

columns = OrderedDict([('id', ('BigInteger', 'NHLBIkey')), ('snpid', ('String', 'SNPid')), ('chrom', ('String', 'chr')), ('pos', ('Integer', 'pos')), ('pval', ('Float', 'Pvalue')), ('NHLBIkey', ('String', 'NHLBIkey')), ('HUPfield', ('String', 'HUPfield')), ('LastCurationDate', ('Date', 'LastCurationDate')), ('CreationDate', ('Date', 'CreationDate')), ('population_id', ('Integer', 'Primary')), ('population', ('relationship', 'Link')), ('study_id', ('Integer', 'Primary')), ('study', ('relationship', 'Link')), ('study_snpid', ('String', 'SNPid')), ('paper_loc', ('String', 'LocationWithinPaper')), ('phenotype_desc', ('String', 'Phenotype')), ('phenotype_cats', ('relationship', 'Link')), ('InGene', ('String', 'InGene')), ('NearestGene', ('String', 'NearestGene')), ('InLincRNA', ('String', 'InLincRNA')), ('InMiRNA', ('String', 'InMiRNA')), ('InMiRNABS', ('String', 'InMiRNABS')), ('dbSNPfxn', ('String', 'dbSNPfxn')), ('dbSNPMAF', ('String', 'dbSNPMAF')), ('dbSNPinfo', ('String', 'dbSNPalleles')), ('dbSNPvalidation', ('String', 'dbSNPvalidation')), ('dbSNPClinStatus', ('String', 'dbSNPClinStatus')), ('ORegAnno', ('String', 'ORegAnno')), ('ConservPredTFBS', ('String', 'ConservPredTFBS')), ('HumanEnhancer', ('String', 'HumanEnhancer')), ('RNAedit', ('String', 'RNAedit')), ('PolyPhen2', ('String', 'PolyPhen2')), ('SIFT', ('String', 'SIFT')), ('LSSNP', ('String', 'LS')), ('UniProt', ('String', 'UniProt')), ('EqtlMethMetabStudy', ('String', 'EqtlMethMetabStudy'))])

A description of all columns in this table.

display_columns(display_as='table', write=False)[source]

Return all columns in the table nicely formatted.

Display choices:
table: A formatted grid-like table tab: A tab delimited non-formatted version of table list: A string list of column names
Parameters:
  • display_as – {table,tab,list}
  • write – If true, print output to console, otherwise return string.
Returns:

A formatted string or None

get_columns(return_as='list')[source]

Return all columns in the table nicely formatted.

Display choices:
list: A python list of column names dictionary: A python dictionary of name=>desc long_dict: A python dictionary of name=>(type, desc)
Parameters:return_as – {table,tab,list,dictionary,long_dict,id_dict}
Returns:A list or dictionary
get_variant_info(fields='dbsnp', pandas=True)[source]

Use the myvariant API to get info about this SNP.

Note that this service can be very slow. It will be faster to query multiple SNPs.

Parameters:
Returns:

A dictionary or a dataframe.

hvgs_ids

The HVGS ID from myvariant.

snp_loc

Return a simple string containing the SNP location.

Study

class grasp.tables.Study(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

An SQLAlchemy table to store study information.

This table provides easy ways to query for SNPs by study information, including population and phenotype.

Note: disc_pop_flag and rep_pop_flag are integer representations of a bitwise flag describing population, defined in ref.PopFlag. To see the string representation of this property, lookup disc_pops or rep_pops.

Table Name:
studies
Columns:
Described in the columns attribute.
int

The integer ID number, usually the PMID, unless not indexed.

str

Summary data on this study.

len

The number of individuals in this study.

disc_pops

A string displaying the number of discovery poplations.

rep_pops

A string displaying the number of replication poplations.

columns

A dictionary of all columns ‘column_name’=>(‘type’, ‘desc’)

population_information

A multi-line string describing the populations in this study.

__int__()[source]

Return ID number.

__len__()[source]

Return total individual count.

__repr__()[source]

Display informaertn about this study.

__str__()[source]

Display refertnce.

columns = OrderedDict([('id', ('Integer', 'id')), ('pmid', ('String', 'PubmedID')), ('title', ('String', 'Study')), ('journal', ('String', 'Journal')), ('author', ('String', '1st_author')), ('grasp_ver', ('Integer', 'GRASPversion?')), ('noresults', ('Boolean', 'No results flag')), ('results', ('Integer', '#results')), ('qtl', ('Boolean', 'IsEqtl/meQTL/pQTL/gQTL/Metabolmics?')), ('snps', ('relationship', 'Link to all SNPs in this study')), ('phenotype_id', ('Integer', 'ID of primary phenotype in Phenotype table')), ('phenotype', ('relationship', 'A link to the primary phenotype in the Phenotype table')), ('phenotype_cats', ('relationship', 'A link to all phenotype categories assigned in the PhenoCats table')), ('datepub', ('Date', 'DatePub')), ('in_nhgri', ('Boolean', 'In NHGRI GWAS catalog (8/26/14)?')), ('locations', ('String', 'Specific place(s) mentioned for samples')), ('mf', ('Boolean', 'Includes male/female only analyses in discovery and/or replication?')), ('mf_only', ('Boolean', 'Exclusively male or female study?')), ('platforms', ('relationship', 'Link to platforms in the Platform table. Platform [SNPs passing QC]')), ('snp_count', ('String', 'From "Platform [SNPs passing QC]"')), ('imputed', ('Boolean', 'From "Platform [SNPs passing QC]"')), ('population_id', ('Integer', 'Primary key of population table')), ('population', ('relationship', 'GWAS description, link to table')), ('total', ('Integer', 'Total Discovery + Replication sample size')), ('total_disc', ('Integer', 'Total discovery samples')), ('pop_flag', ('Integer', 'A bitwise flag that shows presence/absence of all populations (discovery and replication)')), ('disc_pop_flag', ('Integer', 'A bitwise flag that shows presence/absence of discovery populations')), ('european', ('Integer', 'European')), ('african', ('Integer', 'African ancestry')), ('east_asian', ('Integer', 'East Asian')), ('south_asian', ('Integer', 'Indian/South Asian')), ('hispanic', ('Integer', 'Hispanic')), ('native', ('Integer', 'Native')), ('micronesian', ('Integer', 'Micronesian')), ('arab', ('Integer', 'Arab/ME')), ('mixed', ('Integer', 'Mixed')), ('unpecified', ('Integer', 'Unspec')), ('filipino', ('Integer', 'Filipino')), ('indonesian', ('Integer', 'Indonesian')), ('total_rep', ('Integer', 'Total replication samples')), ('rep_pop_flag', ('Integer', 'A bitwise flag that shows presence/absence of replication populations')), ('rep_european', ('Integer', 'European.1')), ('rep_african', ('Integer', 'African ancestry.1')), ('rep_east_asian', ('Integer', 'East Asian.1')), ('rep_south_asian', ('Integer', 'Indian/South Asian.1')), ('rep_hispanic', ('Integer', 'Hispanic.1')), ('rep_native', ('Integer', 'Native.1')), ('rep_micronesian', ('Integer', 'Micronesian.1')), ('rep_arab', ('Integer', 'Arab/ME.1')), ('rep_mixed', ('Integer', 'Mixed.1')), ('rep_unpecified', ('Integer', 'Unspec.1')), ('rep_filipino', ('Integer', 'Filipino.1')), ('rep_indonesian', ('Integer', 'Indonesian.1')), ('sample_size', ('String', 'Initial Sample Size, string description of integer population counts above.')), ('replication_size', ('String', 'Replication Sample Size, string description of integer population counts above.'))])

A description of all columns in this table.

disc_pops

Convert disc_pop_flag to PopFlag.

display_columns(display_as='table', write=False)[source]

Return all columns in the table nicely formatted.

Display choices:
table: A formatted grid-like table tab: A tab delimited non-formatted version of table list: A string list of column names
Parameters:
  • display_as – {table,tab,list}
  • write – If true, print output to console, otherwise return string.
Returns:

A formatted string or None

get_columns(return_as='list')[source]

Return all columns in the table nicely formatted.

Display choices:
list: A python list of column names dictionary: A python dictionary of name=>desc long_dict: A python dictionary of name=>(type, desc)
Parameters:return_as – {table,tab,list,dictionary,long_dict,id_dict}
Returns:A list or dictionary
pops

Convert rep_pop_flag to PopFlag.

population_information

Display a summary of population data.

rep_pops

Convert rep_pop_flag to PopFlag.

Phenotype

class grasp.tables.Phenotype(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

An SQLAlchemy table to store the primary phenotype.

Table Name:
phenos
Columns:
phenotype: The string phenotype from the GRASP DB, unique. alias: A short representation of the phenotype, not unique. studies: A link to the studies table.
int

The ID number.

str

The name of the phenotype.

__int__()[source]

Return ID number.

__repr__()[source]

Display information.

__str__()[source]

Display phenotype name.

PhenoCats

class grasp.tables.Phenotype(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

An SQLAlchemy table to store the primary phenotype.

Table Name:
phenos
Columns:
phenotype: The string phenotype from the GRASP DB, unique. alias: A short representation of the phenotype, not unique. studies: A link to the studies table.
int

The ID number.

str

The name of the phenotype.

__int__()[source]

Return ID number.

__repr__()[source]

Display information.

__str__()[source]

Display phenotype name.

Population

class grasp.tables.Population(population)[source]

Bases: sqlalchemy.ext.declarative.api.Base

An SQLAlchemy table to store the platform information.

Table Name:
populations
Columns:
population: The name of the population. studies: A link to all studies in this population. snps: A link to all SNPs in this populations.
int

Population ID number

str

The name of the population

__int__()[source]

Return ID number.

__repr__()[source]

Display information.

__str__()[source]

Display platform name.

Platform

class grasp.tables.Platform(platform)[source]

Bases: sqlalchemy.ext.declarative.api.Base

An SQLAlchemy table to store the platform information.

Table Name:
platforms
Columns:
platform: The name of the platform from GRASP. studies: A link to all studies using this platform.
int

The ID number of this platform

str

The name of the platform

__int__()[source]

Return ID number.

__repr__()[source]

Display information.

__str__()[source]

Display platform name.

grasp.db

Functions for managing the GRASP database.

get_session() is used everywhere in the module to create a connection to the database. initialize_database() is used to build the database from the GRASP file. It takes about an hour 90 minutes to run and will overwrite any existing database.

grasp.db.get_session(echo=False)[source]

Return a session and engine, uses config file.

Parameters:echo – Echo all SQL to the console.
Returns:A SQLAlchemy session and engine object corresponding to the grasp database for use in querying.
Return type:session, engine
grasp.db.initialize_database(study_file, grasp_file, commit_every=250000, progress=False)[source]

Create the database quickly.

Study_file:Tab delimited GRASP study file, available here: github.com/MikeDacre/grasp/blob/master/grasp_studies.txt
Grasp_file:Tab delimited GRASP file.
Commit_every:How many rows to go through before commiting to disk.
Progress:Display a progress bar (db length hard coded).

grasp.config

Manage a persistent configuration for the database.

grasp.config.config = <configparser.ConfigParser object>

A globally accessible ConfigParger object, initialized with CONFIG_FILE.

grasp.config.CONFIG_FILE = '/home/docs/.grasp'

The PATH to the config file.

grasp.config.init_config(db_type, db_file='', db_host='', db_user='', db_pass='')[source]

Create an initial config file.

Parameters:
  • db_type – ‘sqlite/mysql/postgresql’
  • db_file – PATH to sqlite database file
  • db_host – Hostname for mysql or postgresql server
  • db_user – Username for mysql or postgresql server
  • db_pass – Password for mysql or postgresql server (not secure)
Returns:

NoneType

Return type:

None

grasp.config.init_config_interactive()[source]

Interact with the user to create a new config.

Uses readline autocompletion to make setup easier.

grasp.config.write_config()[source]

Write the current config to CONFIG_FILE.

grasp.info

Little functions to pretty print column lists and category info.

get_{phenotypes,phenotype_categories,popululations} all display a dump of the whole database.

get_population_flags displays available flags from PopFlag.

display_{study,snp}_columns displays a list of available columns in those two tables as a formatted string.

get_{study,snp}_columns return a list of available columns in those two tables as python objects.

grasp.info.display_snp_columns(display_as='table', write=False)[source]

Return all columns in the SNP table as a string.

Display choices:
table: A formatted grid-like table tab: A tab delimited non-formatted version of table list: A string list of column names
Parameters:
  • display_as – {table,tab,list}
  • write – If true, print output to console, otherwise return string.
Returns:

A formatted string or None

grasp.info.display_study_columns(display_as='table', write=False)[source]

Return all columns in the Study table as a string.

Display choices:
table: A formatted grid-like table tab: A tab delimited non-formatted version of table list: A string list of column names
Parameters:
  • display_as – {table,tab,list}
  • write – If true, print output to console, otherwise return string.
Returns:

A formatted string or None

grasp.info.get_phenotype_categories(list_only=False, dictionary=False, table=False)[source]

Return all phenotype categories from the PhenoCats table.

List_only:Return a simple text list instead of a list of Phenotype objects.
Dictionary:Return a dictionary of phenotype=>ID
Table:Return a pretty table for printing.
grasp.info.get_phenotypes(list_only=False, dictionary=False, table=False)[source]

Return all phenotypes from the Phenotype table.

List_only:Return a simple text list instead of a list of Phenotype objects.
Dictionary:Return a dictionary of phenotype=>ID
Table:Return a pretty table for printing.
grasp.info.get_population_flags(list_only=False, dictionary=False, table=False)[source]

Return all population flags available in the PopFlags class.

List_only:Return a simple text list instead of a list of Phenotype objects.
Dictionary:Return a dictionary of population=>ID
Table:Return a pretty table for printing.
grasp.info.get_populations(list_only=False, dictionary=False, table=False)[source]

Return all populatons from the Population table.

List_only:Return a simple text list instead of a list of Phenotype objects.
Dictionary:Return a dictionary of population=>ID
Table:Return a pretty table for printing.
grasp.info.get_snp_columns(return_as='list')[source]

Return all columns in the SNP table.

Display choices:
list: A python list of column names dictionary: A python dictionary of name=>desc long_dict: A python dictionary of name=>(type, desc)
Parameters:return_as – {table,tab,list,dictionary,long_dict,id_dict}
Returns:A list or dictionary
grasp.info.get_study_columns(return_as='list')[source]

Return all columns in the SNP table.

Display choices:
list: A python list of column names dictionary: A python dictionary of name=>desc long_dict: A python dictionary of name=>(type, desc)
Parameters:return_as – {table,tab,list,dictionary,long_dict,id_dict}
Returns:A list or dictionary

grasp.ref

ref.py holds some simple lookups and the PopFlags classes that don’t really go anywhere else.

Holds reference objects for use elsewhere in the module.

class grasp.ref.PopFlag[source]

Bases: flags.Flags

A simplified bitwise flag system for tracking populations.

Based on py-flags

eur

1 # European

afr

2 # African ancestry

east_asian

4 # East Asian

south_asian

8 # Indian/South Asian

his

16 # Hispanic

native

32 # Native

micro

64 # Micronesian

arab

128 # Arab/ME

mix

256 # Mixed

uns

512 # Unspec

filipino

1024 # Filipino

indonesian

2048 # Indonesian

Example::
eur = PopFlag.eur afr = PopFlag(2) his_micro = PopFlag.from_simple_string(‘his|micro’) four_pops = eur | afr four_pops |= his_micro assert four_pops == PopFlag.from_simple_string(‘his|micro|afr|eur’) PopFlag.eur & four_pops > 0 # Returns True PopFlag.eur i== four_pops # Returns False PopFlag.arab & four_pops > 0 # Returns False