Class: BaseAdapter

LocusZoom_Adapters~BaseAdapter(config)

Base class for LocusZoom data sources (any). See also: BaseApiAdapter for requests from a remote URL.

Constructor

new BaseAdapter(config)

Parameters:
Name Type Description
config object

Configuration options

Source:

Methods

(protected) annotateData(records, chain) → {Array.<Object>|Promise}

Hook to post-process the data returned by this source with new, additional behavior. (eg cleaning up API values or performing complex calculations on the returned data)

Parameters:
Name Type Description
records Array.<Object>

The parsed data from the source (eg standardized api response)

chain Object

The data chain object. For example, chain.headers may provide useful annotation metadata

Source:
Returns:

The modified set of records

Type
Array.<Object> | Promise

(protected) combineChainBody(data, chain, fields, outnames, trans) → {Promise|Array.<Object>}

Combine records from this source with others in the chain to yield final chain body. Handles merging this data with other sources (if applicable).

Parameters:
Name Type Description
data Array.<Object>

The data That would be returned from this source alone

chain Object

The data chain built up during previous requests

fields Array.<String>
outnames Array.<String>
trans Array.<String>
Source:
Returns:

The new chain body

Type
Promise | Array.<Object>

(protected) extractFields(data, fields, outnames, trans)

Clean up the server records for use by datalayers: extract only certain fields, with the specified names. Apply per-field transformations as appropriate.

This hook can be overridden, eg to create a source that always returns all records and ignores the "fields" array. This is particularly common for sources at the end of a chain- many "dependent" sources do not allow cherry-picking individual fields, in which case by convention the fields array specifies "last_source_name:all"

Parameters:
Name Type Description
data Array.<Object>

One record object per element

fields Array.<String>

The names of fields to extract (as named in the source data). Eg "afield"

outnames Array.<String>

How to represent the source fields in the output. Eg "namespace:afield|atransform"

trans Array.<function()>

An array of transformation functions (if any). One function per data element, or null.

Source:

(protected) fetchRequest(state, chain, fields) → {Promise}

Perform a network request to fetch data for this source. This is usually the method that is used to override when defining how to retrieve data.

Parameters:
Name Type Description
state Object

The state of the parent plot

chain
fields
Source:
Returns:
Type
Promise

(protected) getCacheKey(state, chain, fields) → {String}

A unique identifier that indicates whether cached data is valid for this request. For most sources using GET requests to a REST API, this is usually the region requested. Some sources will append additional params to define the request.

This means that to change caching behavior, both the URL and the cache key may need to be updated. However, it allows most datasources to skip an extra network request when zooming in.

Parameters:
Name Type Description
state Object

Information available in plot.state (chr, start, end). Sometimes used to inject globally available information that influences the request being made.

chain Object

The data chain from previous requests made in a sequence.

fields
Source:
Returns:
Type
String

(protected) getRequest() → {Promise}

Gets the data for just this source, typically via a network request (but using cache where possible)

For most use cases, it is better to override fetchRequest instead, to avoid bypassing the cache mechanism by accident.

Source:
Returns:
Type
Promise

(protected) getURL()

Stub: build the URL for any requests made by this source.

Source:

(protected) normalizeResponse(data)

Ensure the server response is in a canonical form, an array of one object per record. [ {field: oneval} ]. If the server response contains columns, reformats the response from {column1: [], column2: []} to the above.

Does not apply namespacing, transformations, or field extraction.

May be overridden by data adapters that inherently return more complex payloads, or that exist to annotate other sources (eg, if the payload provides extra data rather than a series of records).

Parameters:
Name Type Description
data Array.<Object> | Object

The original parsed server response

Source:

(protected) parseInit(config)

Parse configuration used to create the instance. Many custom sources will override this method to suit their needs (eg specific config options, or for sources that do not retrieve data from a URL)

Parameters:
Name Type Description
config String | Object

Basic configuration- either a url, or a config object

Properties
Name Type Attributes Description
url String <optional>

The datasource URL

params String <optional>

Initial config params for the datasource

Source:

(protected) parseResponse(resp, chain, fields, outnames, trans) → {Promise}

Coordinates the work of parsing a response and returning records. This is broken into 4 steps, which may be overridden separately for fine-grained control. Each step can return either raw data or a promise.

Parameters:
Name Type Description
resp String | Object

The raw data associated with the response

chain Object

The combined parsed response data from this and all other requests made in the chain

fields Array.<String>

Array of requested field names (as they would appear in the response payload)

outnames Array.<String>

Array of field names as they will be represented in the data returned by this source, including the namespace. This must be an array with the same length as fields

trans Array.<function()>

The collection of transformation functions to be run on selected fields. This must be an array with the same length as fields

Source:
See:
Returns:

A promise that resolves to an object containing request metadata (headers: {}), the consolidated data for plotting (body: []), and the individual responses that would be returned by each source in the chain in isolation (discrete: {})

Type
Promise