Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial airr-js package #687

Merged
merged 55 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
59743fc
initial airr-js package
schristley Apr 15, 2023
6776a52
new function
schristley Apr 19, 2023
d41f751
restructure to support browser
schristley Jun 1, 2023
6145eff
restructure node edition
schristley Jun 2, 2023
b031cff
cleanup package dependencies, deref spec for browser
schristley Jun 8, 2023
c1f1246
fix bug for array of objects
schristley Jun 22, 2023
4d4ade3
update docs
schristley Jul 10, 2023
de06af2
Created default spec to reduce load time (#683)
jday1 Apr 17, 2023
e544ef2
Update nullable fields, add additional fields to AlleleDescription (#…
williamdlees May 15, 2023
4c7cde1
Various schema updates (#674)
javh Jun 12, 2023
bd93f36
Copy of PR #685 (#695)
javh Jun 12, 2023
1729129
Remove RTD C compile dependency hack (#694)
javh Jun 12, 2023
ec5a9ab
Update datarep_cmd_example.rst
bussec Jul 10, 2023
9dd3727
Update study_keywords documentation
bcorrie Jul 10, 2023
ffb5b29
Replace adc-query_support with adc-query-support
bcorrie Jul 10, 2023
5efa9cc
Changed adc-api-optional to adc-query-support.
bcorrie Jul 10, 2023
1201971
Added adc-api-optional to AIRR extensions docs.
bcorrie Jul 10, 2023
3ca4a8b
newer version of sphinx required
schristley Jul 10, 2023
d6aca53
Add paragraph linking to ADC
bcorrie Jul 11, 2023
e8fe17e
Added links to ADC registry github
bcorrie Jul 11, 2023
ff6c23f
Added a clairification about server names
bcorrie Jul 11, 2023
c926196
Point to ADC registry github
bcorrie Jul 11, 2023
5886d7d
Change link to ADC page.
bcorrie Jul 11, 2023
5fa6f89
Synchronize schema copies
bussec Jul 24, 2023
82a16ae
Sync schema v3 with v2
bussec Jul 24, 2023
a49d072
Merge branch 'issue-697' into airr-js
schristley Jul 25, 2023
2f9bf56
remove duplicates
schristley Jul 25, 2023
1f3d4a7
proper return value
schristley Jul 25, 2023
609a759
remove discriminator
schristley Jul 25, 2023
275e2c0
allow custom schema
schristley Aug 29, 2023
7a5a574
Merge branch 'airr-js' of https://github.com/airr-community/airr-stan…
schristley Aug 29, 2023
251aa6f
return all errors
schristley Sep 25, 2023
25898e9
Merge branch 'airr-js' of https://github.com/airr-community/airr-stan…
schristley Sep 25, 2023
7658f59
functions for CURIE
schristley Dec 5, 2023
5d46e80
handle allOf at top level of object
schristley Jan 10, 2024
d4a41e2
ignore discriminator for older schemas
schristley Feb 13, 2024
b8d5490
merge allOfs as dereference does not
schristley Feb 13, 2024
785f628
Merge branch 'master' into airr-js
schristley Mar 15, 2024
2028d47
spec to lang dir
schristley Mar 15, 2024
1d252a8
enable enum default
schristley Apr 25, 2024
0c00c30
exclude deprecated
schristley Jun 13, 2024
4f1529d
curie resolve, handle undefined, fix deprecate bug, additional vocabu…
schristley Jun 13, 2024
fe0d36e
Merge branch 'master' into airr-js
schristley Oct 16, 2024
2458a37
implement write_airr and test case
schristley Oct 16, 2024
48b6ce6
add nano, fix ENV syntax
schristley Oct 16, 2024
a494e51
implement rearrangement write functions and tests
schristley Oct 17, 2024
fe10577
additional doc
schristley Oct 17, 2024
a8bb911
update version
schristley Oct 17, 2024
a3c00cb
Merge branch 'master' into airr-js
schristley Oct 17, 2024
ae333a0
sync with v1.5
schristley Oct 17, 2024
2a5446f
add lock file
schristley Oct 17, 2024
659c81e
specify working directory
schristley Oct 17, 2024
ad5519e
is it the cache?
schristley Oct 17, 2024
094d9cf
cleanup
schristley Oct 17, 2024
a87eac9
try again
schristley Oct 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ on:
pull_request:
branches: [ "master" ]

defaults:
run:
working-directory: lang/js

jobs:
build:

runs-on: ubuntu-latest

defaults:
run:
working-directory: lang/js

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
Expand All @@ -29,7 +29,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
# cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
17 changes: 16 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -
libfontconfig1-dev \
libssl-dev \
libharfbuzz-dev libfribidi-dev \
libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev
libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev \
nano

RUN pip3 install \
pandas \
Expand All @@ -33,13 +34,27 @@ RUN pip3 install \
# Install R devtools
RUN R -e 'install.packages(c("devtools","knitr","rmarkdown","testthat","readr"),dependencies=T)'

# node
ENV NODE_VER=v14.21.3
RUN wget https://nodejs.org/dist/$NODE_VER/node-$NODE_VER-linux-x64.tar.xz
RUN tar xf node-$NODE_VER-linux-x64.tar.xz
RUN cp -rf /node-$NODE_VER-linux-x64/bin/* /usr/bin
RUN cp -rf /node-$NODE_VER-linux-x64/lib/* /usr/lib
RUN cp -rf /node-$NODE_VER-linux-x64/include/* /usr/include
RUN cp -rf /node-$NODE_VER-linux-x64/share/* /usr/share

# Copy source
RUN mkdir /airr-standards
COPY . /airr-standards

# Install python package
RUN cd /airr-standards/lang/python && pip3 install .

# nodejs package
RUN cd /airr-standards/lang/js && npm install
RUN cd /airr-standards/lang/js && npm run eslint
RUN cd /airr-standards/lang/js && npm run test

# Generate the documentation
RUN cd /airr-standards && pip3 install -r docs/requirements.txt
RUN cd /airr-standards && sphinx-build -a -E -b html docs docs/_build/html
6 changes: 6 additions & 0 deletions docs/packages/airr-js/news.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _JavaScriptNews:

JavaScript Library Release Notes
=================================

.. include:: ../../../lang/js/NEWS.rst
17 changes: 17 additions & 0 deletions docs/packages/airr-js/overview.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. _JavaScriptOverview:

AIRR JavaScript Reference Library
===============================================================================

The ``airr-js`` reference library provides basic functions and classes for
interacting with AIRR Community Data Representation Standards, including tools
for read, write and validation. The library can be used in the browser or nodejs.

.. toctree::
:maxdepth: 1
:caption: Table of Contents

Release Notes <news>

.. include:: ../../../lang/js/README.rst

1 change: 1 addition & 0 deletions docs/software.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ AIRR Standards Reference Implementations

Python Library <packages/airr-python/overview>
R Library <packages/airr-R/overview>
JavaScript Library <packages/airr-js/overview>
ADC API Reference Implementation <api/reference>

Resources and Tools Supporting AIRR Standards
Expand Down
1 change: 0 additions & 1 deletion lang/R/inst/extdata/airr-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,6 @@ DeletedGene:
Chromosomal phasing indicator. Alleles with the same value are inferred to be located on the
same chromosome.


# List of MHCGenotypes describing a subject's genotype
MHCGenotypeSet:
type: object
Expand Down
16 changes: 16 additions & 0 deletions lang/js/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"no-unused-vars": 0,
"no-redeclare": 0,
"no-prototype-builtins": 1
}
}
4 changes: 4 additions & 0 deletions lang/js/NEWS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Version 2.0.0: DATE
--------------------------------------------------------------------------------

Initial release.
162 changes: 162 additions & 0 deletions lang/js/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
Installation
------------------------------------------------------------------------------

Install in the usual manner from npm::

> npm install airr-js

Or from the `downloaded <https://github.com/airr-community/airr-standards>`__
source code directory::

> npm install file:lang/js


Quick Start
------------------------------------------------------------------------------

The ``airr-js`` package supports use in the browser or in nodejs. In the browser, the
file system is not available, so the read/write functions are not implemented but template
objects can be created, objects can be validated, and the OpenAPI V3 specification can be
accessed. For nodejs, the full functionality is available including the read/write functions.

For nodejs, need to await the loading of the schema before using any functions::

var airr = require('airr-js');

// await schema to be loaded and dereferenced
var spec = await airr.load_schema();

For the browser, the schema also needs to be loaded but the package cannot do it itself,
instead you must provide the Open API V3 specification file as part of your packaging
of the website. When using webpack, a resolve alias in ``webpack.config.js`` can be used
to point to the dereferenced yaml file::

resolve: {
alias: {
'airr-schema': path.resolve(__dirname,'node_modules') + '/airr-js/airr-schema-openapi3-deref.yaml'
}
}

The ``package.json`` utilizes the ``browser`` setting supported by website packaging tools
like webpack to provide an alternative entry point, and browser code can import like so::

import { airr } from 'airr-js';

The read and write functions for AIRR Rearrangement TSV files support gzip compressed
data. File names that end with ``.gz`` extension will automatically be uncompressed
when reading or automatically compressed when writing.

Create Blank Template Schema Objects (browser, nodejs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Import the ``airr-js`` package correctly depending upon browser or nodejs usage as
described above, and then blank template objects can be created::

// Get the schema definition for an AIRR Object
var repertoire_schema = new airr.SchemaDefinition('Repertoire');
// Create a template object
var blank_repertoire = repertoire_schema.template();

Validate Objects (browser, nodejs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Import the ``airr-js`` package correctly depending upon browser or nodejs usage as
described above, and then an object can be validated to its schema::

// Get the schema definition for an AIRR Object
var repertoire_schema = new airr.SchemaDefinition('Repertoire');
// Validate a repertoire object
var is_valid = repertoire_schema.validate_object(obj);

Reading AIRR Data Files (nodejs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The ``airr-js`` package contains functions to read and write AIRR Data
Model files. The file format is either YAML or JSON, and the package provides a
light wrapper over the standard parsers. The file needs a ``json``, ``yaml``, or ``yml``
file extension so that the proper parser is utilized. All of the AIRR objects
are loaded into memory at once and no streaming interface is provided::

var airr = require('airr-js');
await airr.load_schema();

// read AIRR DataFile
var data = await airr.read_airr('input.airr.json');

Writing AIRR Data Files (nodejs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Writing an AIRR Data File is also a light wrapper over standard YAML or JSON
parsers. Multiple AIRR objects, such as Repertoire, GermlineSet, and etc., can be
written together into the same file. In this example, we create some blank
Repertoire objects, and write them to a file.
As with the read function, the complete list of repertoires are written at once,
there is no streaming interface::

var airr = require('airr-js');
await airr.load_schema();

// Create some blank repertoire objects in a list
var repertoire_schema = new airr.SchemaDefinition('Repertoire');
var data = { 'Repertoire': [] };
for (let i = 0; i < 5; ++i)
data['Repertoire'].push(repertoire_schema.template());

// Write the AIRR Data
await airr.write_airr('output.airr.json', data);

Reading AIRR Rearrangement TSV files (nodejs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The ``airr-js`` package contains functions to read AIRR Rearrangement
TSV files as either a stream or the complete file. The streaming interface requires
two callback functions to be provided; one for the header and another for each
row as it is read. The callback functions can be synchronous or they can
return a Promise::

var airr = require('airr-js');
await airr.load_schema();

// read file completely
var data = await airr.load_rearrangement('input.airr.tsv');

// for streaming, need two callback functions
var header_callback = function(headers) { console.log('got headers:', headers); }
var row_callback = function(row) { console.log('got row:', row); }
// read the file
await airr.read_rearrangement('input.airr.tsv', header_callback, row_callback);

Writing AIRR Rearrangement TSV files (nodejs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The ``airr-js`` package contains functions to write AIRR Rearrangement
TSV files as either a stream or the complete file. The streaming interface requires
a callback function which provides the data for each row or returns ``null`` to indicate
no more data. The callback function can be synchronous or it can return a Promise::

var airr = require('airr-js');
await airr.load_schema();

// read some data
var data = await airr.load_rearrangement('input.airr.tsv');

// write file completely
var data = await airr.load_rearrangement(data, 'output.airr.tsv');

// for streaming, need a callback function to provide the row data
var idx = 0;
var row_callback = function(fields) {
if (idx >= data.length) return null;
else return data[idx++];
};
// write the file
await airr.create_rearrangement('output.airr.tsv', row_callback)

// callback function which returns a promise
var row_callback = function(fields) {
return new Promise(function(resolve, reject) {
// acquire some data asynchronously, e.g. from a database
row = await read_from_database();
return resolve(row);
});
};
23 changes: 23 additions & 0 deletions lang/js/airr-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

//
// airr-browser.js
// AIRR Standards reference library for antibody and TCR sequencing data
// browser edition
//
// Copyright (C) 2023 The AIRR Community
//
// Author: Scott Christley <[email protected]>
//

// The I/O file routines are not provided with the browser edition.

// For webpack, we are utilizing the browser entry in package.json
// Are we assuming Webpack?

export var airr = {};

// the specification, resolved by webpack
import AIRRSchema from 'airr-schema';
// schema functions
var schema = require('./schema')(airr, AIRRSchema);
Loading
Loading