# Module: ext/lz-parsers

Optional LocusZoom extension: must be included separately, and after LocusZoom has been loaded

This plugin exports helper function, as well as a few optional extra helpers for rendering the plot. The GWAS parsers can be used without registering the plugin.

To use in an environment without special JS build tooling, simply load the extension file as JS from a CDN (after any dependencies):

    <script src="https://cdn.jsdelivr.net/npm/locuszoom@INSERT_VERSION_HERE/dist/ext/lz-parsers.min.js" type="application/javascript"></script>

To use with ES6 modules, import the helper functions and use them with your layout:

    import { install, makeGWASParser, makeBed12Parser, makePlinkLDParser } from 'locuszoom/esm/ext/lz-parsers';
    LocusZoom.use(install);

### Features provided

- module:LocusZoom_Adapters~UserTabixLD (if the module:ext/lz-tabix-source extension is loaded first)

Source:
  - ext/lz-parsers/index.js, line 1

### Methods

#### (inner) makeBed12Parser(options)

Parse a BED file, according to the widely used UCSC (quasi-)specification

NOTE: This original version is aimed at tabix region queries, and carries an implicit assumption that data is the only thing that will be parsed. It makes no attempt to identify or handle header rows / metadata fields.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | object | ###### Properties
Name | Type | Description
--- | --- | ---
`normalize` | Boolean | Whether to normalize the output to the format expected by LocusZoom (eg type coercion for numbers, removing chr chromosome prefixes, and using 1-based and inclusive coordinates instead of 0-based disjoint intervals)

Source:
  - ext/lz-parsers/bed.js, line 41

##### Returns:

function A configured parser function that runs on one line of text from an input file

#### (inner) makeGWASParser(options) → {function}

Specify how to parse a GWAS file, given certain column information. Outputs an object with fields in portal API format.

All column options must be provided as 1-indexed column IDs (human-friendly argument values)

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` |  | ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`marker_col` |  | <optional> |  | A single identifier that specifies all of chrom, pos, ref, and alt as a single string field. Eg 1:23_A/C
`chrom_col` |  | <optional> |  | Chromosome
`pos_col` |  | <optional> |  | Position
`ref_col` |  | <optional> |  | Reference allele (relative to human reference genome, eg GRCh37 or 38).
`alt_col` |  | <optional> |  | Alt allele. Some programs specify generic A1/A2 instead; it is the job of the user to identify which columns of this GWAS are ref and alt.
`rsid_col` |  | <optional> |  | rsID
`pvalue_col` |  |  |  | p-value (or -log10p)
`beta_col` |  | <optional> |  |
`stderr_beta_col` |  | <optional> |  |
`allele_freq_col` |  | <optional> |  | Specify allele frequencies directly
`allele_count_col` |  | <optional> |  | Specify allele frequencies in terms of count and n_samples
`n_samples_col` |  | <optional> |  |
`is_alt_effect` |  | <optional> | true | Some programs specify beta and frequency information in terms of ref, others alt. Identify effect allele to orient values to the correct allele.
`is_neg_log_pvalue` |  | <optional> | false |
`delimiter` |  | <optional> | '\t' | Since this parser is usually used with tabix data, this is rarely changed (tabix does not accept other delimiters)

Source:
  - ext/lz-parsers/gwas/parsers.js, line 36

##### Returns:

A parser function that can be called on each line of text with the provided options

Type
  function

#### (inner) makePlinkLdParser(options) → {function}

Parse the output of plink v1.9 R2 calculations relative to one (or a few) target SNPs. See: https://www.cog-genomics.org/plink/1.9/ld and reformatting commands at https://www.cog-genomics.org/plink/1.9/other

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | object | ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`normalize` | boolean | <optional> | true | Normalize fields to expected datatypes and format; if false, returns raw strings as given in the file

Source:
  - ext/lz-parsers/ld.js, line 18

##### Returns:

A configured parser function that runs on one line of text from an input file

Type
  function