Skip to content

Commit

Permalink
Single file minified tabix bundle (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin authored Aug 30, 2024
1 parent d864fe8 commit d30bb70
Show file tree
Hide file tree
Showing 26 changed files with 1,656 additions and 2,224 deletions.
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid",
"proseWrap": "always"
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ const { TabixIndexedFile } = require('@gmod/tabix')
import { TabixIndexedFile } from '@gmod/tabix'
```

### Single file bundle

You can use tabix-js without NPM also with the tabix-bundle.js. See the example
directory for usage with script tag [example/index.html](example/index.html)

```
<script src="https://unpkg.com/@gmod/tabix/dist/tabix-bundle.js"></script>
```

### TabixIndexedFile constructor

Basic usage of TabixIndexedFile under node.js supplies a path and optionally a
Expand Down
61 changes: 27 additions & 34 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,43 +1,32 @@
import prettier from 'eslint-plugin-prettier'
import typescriptEslint from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'
import eslint from '@eslint/js'
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
import tseslint from 'typescript-eslint'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [
...compat.extends(
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:prettier/recommended',
'plugin:unicorn/recommended',
),
export default tseslint.config(
{
ignores: [
'webpack.config.js',
'dist/*',
'esm/*',
'example/*',
'eslint.config.mjs',
],
},
{
plugins: {
prettier,
'@typescript-eslint': typescriptEslint,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: 'script',

parserOptions: {
project: './tsconfig.lint.json',
project: ['./tsconfig.lint.json'],
tsconfigRootDir: import.meta.dirname,
},
},
},
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylisticTypeChecked,
...tseslint.configs.strictTypeChecked,

eslintPluginUnicorn.configs['flat/recommended'],
{
rules: {
'@typescript-eslint/no-unused-vars': [
'warn',
Expand Down Expand Up @@ -93,12 +82,16 @@ export default [
'unicorn/escape-case': 'off',
'unicorn/prefer-number-properties': 'off',
'unicorn/no-process-exit': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/no-deprecated': 'off',
'no-empty': 'off',
},
},
]
)
2 changes: 2 additions & 0 deletions example/cram-bundle.js

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions example/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { IndexedCramFile, CramFile, CraiIndex } = window.gmodCRAM

// open local files
const indexedFile = new IndexedCramFile({
cramUrl: 'volvox-sorted.cram',
index: new CraiIndex({
url: 'volvox-sorted.cram.crai',
}),
seqFetch: async (seqId, start, end) => {
return ''
},
checkSequenceMD5: false,
})

// example of fetching records from an indexed CRAM file.
// NOTE: only numeric IDs for the reference sequence are accepted.
// For indexedfasta the numeric ID is the order in which the sequence names appear in the header

// Wrap in an async and then run
run = async () => {
const records = await indexedFile.getRecordsForRange(0, 10000, 20000)
records.forEach(record => {
console.log(`got a record named ${record.readName}`)
if (record.readFeatures != undefined) {
record.readFeatures.forEach(({ code, pos, refPos, ref, sub }) => {
if (code === 'X') {
console.log(
`${record.readName} shows a base substitution of ${ref}->${sub} at ${refPos}`,
)
}
})
}
})
}

run()
25 changes: 25 additions & 0 deletions example/index-debug.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>
<head>
<script src="tabix-bundle.js"></script>
<script type="text/javascript">
;(async () => {
const { TabixIndexedFile } = window.gmodTABIX

const tbiIndexed = new TabixIndexedFile({
url: 'volvox.filtered.vcf.gz',
tbiUrl: 'volvox.filtered.vcf.gz.tbi',
})
const lines = []
const res = await tbiIndexed.getLines('ctgA', 0, 10000, line =>
lines.push(line),
)
console.log({ lines })
document.getElementById('output').innerHTML = lines.join('\n')
})()
</script>
</head>
<body>
<h1>Hello world</h1>
<pre id="output" />
</body>
</html>
25 changes: 25 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>
<head>
<script src="https://unpkg.com/@gmod/tabix/dist/tabix-bundle.js"></script>
<script type="text/javascript">
;(async () => {
const { TabixIndexedFile } = window.gmodTABIX

const tbiIndexed = new TabixIndexedFile({
url: 'volvox.filtered.vcf.gz',
tbiUrl: 'volvox.filtered.vcf.gz.tbi',
})
const lines = []
const res = await tbiIndexed.getLines('ctgA', 0, 10000, line =>
lines.push(line),
)
console.log({ lines })
document.getElementById('output').innerHTML = lines.join('\n')
})()
</script>
</head>
<body>
<h1>Hello world</h1>
<pre id="output" />
</body>
</html>
73 changes: 73 additions & 0 deletions example/volvox.filtered.lowercase.vcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
##fileformat=VCFv4.1
##samtoolsVersion=0.1.18 (r982:295)
##INFO=<ID=DP,Number=1,Type=Integer,Description="Raw read depth">
##INFO=<ID=DP4,Number=4,Type=Integer,Description="# high-quality ref-forward bases, ref-reverse, alt-forward and alt-reverse bases">
##INFO=<ID=MQ,Number=1,Type=Integer,Description="Root-mean-square mapping quality of covering reads">
##INFO=<ID=FQ,Number=1,Type=Float,Description="Phred probability of all samples being the same">
##INFO=<ID=AF1,Number=1,Type=Float,Description="Max-likelihood estimate of the first ALT allele frequency (assuming HWE)">
##INFO=<ID=AC1,Number=1,Type=Float,Description="Max-likelihood estimate of the first ALT allele count (no HWE assumption)">
##INFO=<ID=G3,Number=3,Type=Float,Description="ML estimate of genotype frequencies">
##INFO=<ID=HWE,Number=1,Type=Float,Description="Chi^2 based HWE test P-value based on G3">
##INFO=<ID=CLR,Number=1,Type=Integer,Description="Log ratio of genotype likelihoods with and without the constraint">
##INFO=<ID=UGT,Number=1,Type=String,Description="The most probable unconstrained genotype configuration in the trio">
##INFO=<ID=CGT,Number=1,Type=String,Description="The most probable constrained genotype configuration in the trio">
##INFO=<ID=PV4,Number=4,Type=Float,Description="P-values for strand bias, baseQ bias, mapQ bias and tail distance bias">
##INFO=<ID=INDEL,Number=0,Type=Flag,Description="Indicates that the variant is an INDEL.">
##INFO=<ID=PC2,Number=2,Type=Integer,Description="Phred probability of the nonRef allele frequency in group1 samples being larger (,smaller) than in group2.">
##INFO=<ID=PCHI2,Number=1,Type=Float,Description="Posterior weighted chi^2 P-value for testing the association between group1 and group2 samples.">
##INFO=<ID=QCHI2,Number=1,Type=Integer,Description="Phred scaled PCHI2.">
##INFO=<ID=PR,Number=1,Type=Integer,Description="# permutations yielding a smaller PCHI2.">
##INFO=<ID=VDB,Number=1,Type=Float,Description="Variant Distance Bias">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##FORMAT=<ID=GQ,Number=1,Type=Integer,Description="Genotype Quality">
##FORMAT=<ID=GL,Number=3,Type=Float,Description="Likelihoods for RR,RA,AA genotypes (R=ref,A=alt)">
##FORMAT=<ID=DP,Number=1,Type=Integer,Description="# high-quality bases">
##FORMAT=<ID=SP,Number=1,Type=Integer,Description="Phred-scaled strand bias P-value">
##FORMAT=<ID=PL,Number=G,Type=Integer,Description="List of Phred-scaled genotype likelihoods">
##contig=<ID=ctga,length=248956422,assembly=GRCh38.d1.vd1>
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT sample_data/raw/volvox/volvox-sorted.bam
ctga 277 . T C 10.4 . DP=3;VDB=0.0186;AF1=1;AC1=2;DP4=0,0,3,0;MQ=37;FQ=-36 GT:PL:GQ 1/1:42,9,0:13
ctga 1694 . T C 107 . DP=23;VDB=0.0308;AF1=1;AC1=2;DP4=0,1,8,14;MQ=37;FQ=-73;PV4=1,1,0.42,1 GT:PL:GQ 1/1:140,46,0:89
ctga 2644 . T G 44 . DP=22;VDB=0.0253;AF1=0.5;AC1=1;DP4=6,5,3,8;MQ=37;FQ=45.3;PV4=0.39,1,1,1 GT:PL:GQ 0/1:74,0,77:75
ctga 3213 . T A 124 . DP=19;VDB=0.0384;AF1=1;AC1=2;DP4=0,0,8,11;MQ=36;FQ=-84 GT:PL:GQ 1/1:157,57,0:99
ctga 3858 . ctt ct 160 . INDEL;DP=15;VDB=0.0384;AF1=1;AC1=2;DP4=0,0,5,6;MQ=37;FQ=-67.5 GT:PL:GQ 1/1:201,33,0:63
ctga 5496 . C G 6.98 . DP=18;VDB=0.0011;AF1=0.4999;AC1=1;DP4=5,7,4,2;MQ=37;FQ=9.53;PV4=0.62,1,1,1 GT:PL:GQ 0/1:36,0,92:37
ctga 8471 . G T 124 . DP=21;VDB=0.0355;AF1=1;AC1=2;DP4=0,0,11,10;MQ=37;FQ=-90 GT:PL:GQ 1/1:157,63,0:99
ctga 9603 . A T 126 . DP=21;VDB=0.0356;AF1=1;AC1=2;DP4=0,0,10,11;MQ=36;FQ=-90 GT:PL:GQ 1/1:159,63,0:99
ctga 10423 . T A 25 . DP=19;VDB=0.0404;AF1=0.5;AC1=1;DP4=3,7,3,6;MQ=37;FQ=28;PV4=1,1,1,0.27 GT:PL:GQ 0/1:55,0,73:58
ctga 13202 . G T 40 . DP=22;VDB=0.0399;AF1=0.5;AC1=1;DP4=4,8,5,5;MQ=37;FQ=42.8;PV4=0.67,1,1,1 GT:PL:GQ 0/1:70,0,84:73
ctga 14247 . ac aCc 61.5 . INDEL;DP=22;VDB=0.0404;AF1=0.5;AC1=1;DP4=3,4,6,0;MQ=37;FQ=62.4;PV4=0.07,1,1,1 GT:PL:GQ 0/1:99,0,101:99
ctga 14481 . G A 42 . DP=21;VDB=0.0394;AF1=0.5;AC1=1;DP4=4,6,5,6;MQ=37;FQ=42;PV4=1,1,1,0.12 GT:PL:GQ 0/1:72,0,72:72
ctga 15078 . T A 96 . DP=12;VDB=0.0404;AF1=1;AC1=2;DP4=0,0,4,8;MQ=37;FQ=-63 GT:PL:GQ 1/1:129,36,0:69
ctga 15163 . gcc gCcc 213 . INDEL;DP=20;VDB=0.0404;AF1=1;AC1=2;DP4=0,0,10,7;MQ=37;FQ=-85.5 GT:PL:GQ 1/1:254,51,0:99
ctga 15418 . A G 64 . DP=19;VDB=0.0253;AF1=0.5003;AC1=1;DP4=5,1,5,8;MQ=35;FQ=4.13;PV4=0.14,0.26,0.11,1 GT:PL:GQ 0/1:94,0,29:32
ctga 17042 . C T 119 . DP=22;VDB=0.0394;AF1=1;AC1=2;DP4=0,0,13,9;MQ=37;FQ=-93 GT:PL:GQ 1/1:152,66,0:99
ctga 18948 . A G 57 . DP=23;VDB=0.0308;AF1=0.5;AC1=1;DP4=6,4,4,9;MQ=37;FQ=39;PV4=0.22,1,0.2,1 GT:PL:GQ 0/1:87,0,66:69
ctga 19882 . acg a 98.5 . INDEL;DP=22;VDB=0.0374;AF1=0.5;AC1=1;DP4=4,6,3,5;MQ=37;FQ=101;PV4=1,0.049,1,1 GT:PL:GQ 0/1:136,0,202:99
ctga 20675 . T C 40 . DP=18;VDB=0.0401;AF1=0.5;AC1=1;DP4=5,3,4,6;MQ=36;FQ=31.7;PV4=0.64,1,0.19,0.15 GT:PL:GQ 0/1:70,0,59:62
ctga 21485 . C T,A 118 . DP=20;VDB=0.0388;AF1=1;AC1=2;DP4=0,0,8,12;MQ=36;FQ=-84 GT:PL:GQ 1/1:151,57,0,150,42,147:99
ctga 22326 . C T 107 . DP=14;VDB=0.0399;AF1=1;AC1=2;DP4=0,0,6,8;MQ=36;FQ=-69 GT:PL:GQ 1/1:140,42,0:81
ctga 23636 . A C 58 . DP=19;VDB=0.0320;AF1=0.5;AC1=1;DP4=2,5,5,7;MQ=37;FQ=18.1;PV4=0.66,0.23,1,0.037 GT:PL:GQ 0/1:88,0,45:48
ctga 23959 . A G 118 . DP=19;VDB=0.0374;AF1=1;AC1=2;DP4=0,0,7,11;MQ=36;FQ=-81 GT:PL:GQ 1/1:151,54,0:99
ctga 24978 . C G 127 . DP=22;VDB=0.0355;AF1=1;AC1=2;DP4=0,0,11,11;MQ=35;FQ=-93 GT:PL:GQ 1/1:160,66,0:99
ctga 25558 . A C 104 . DP=27;VDB=0.0371;AF1=1;AC1=2;DP4=0,0,18,7;MQ=36;FQ=-102 GT:PL:GQ 1/1:137,75,0:99
ctga 26079 . C A 29 . DP=18;VDB=0.0339;AF1=0.5;AC1=1;DP4=6,4,4,4;MQ=36;FQ=31.9;PV4=1,0.14,0.44,0.13 GT:PL:GQ 0/1:59,0,76:62
ctga 28463 . T A 27 . DP=20;VDB=0.0399;AF1=0.5;AC1=1;DP4=5,6,4,5;MQ=36;FQ=30;PV4=1,1,1,1 GT:PL:GQ 0/1:57,0,82:60
ctga 28719 . T G 39 . DP=18;VDB=0.0333;AF1=0.5;AC1=1;DP4=6,3,5,4;MQ=37;FQ=36.6;PV4=1,1,1,1 GT:PL:GQ 0/1:69,0,65:67
ctga 29032 . G T 103 . DP=19;VDB=0.0399;AF1=1;AC1=2;DP4=0,0,13,6;MQ=37;FQ=-84 GT:PL:GQ 1/1:136,57,0:99
ctga 29848 . C T 91 . DP=11;VDB=0.0333;AF1=1;AC1=2;DP4=0,0,5,6;MQ=36;FQ=-60 GT:PL:GQ 1/1:124,33,0:63
ctga 34015 . T A 85 . DP=10;VDB=0.0339;AF1=1;AC1=2;DP4=0,0,4,6;MQ=37;FQ=-57 GT:PL:GQ 1/1:118,30,0:57
ctga 35771 . T A 99 . DP=16;VDB=0.0399;AF1=1;AC1=2;DP4=0,0,3,13;MQ=36;FQ=-75 GT:PL:GQ 1/1:132,48,0:93
ctga 38156 . C G 16.1 . DP=12;VDB=0.0168;AF1=0.5;AC1=1;DP4=3,2,3,2;MQ=37;FQ=16.1;PV4=1,1,1,0.43 GT:PL:GQ 0/1:46,0,46:46
ctga 39952 . C T 124 . DP=21;VDB=0.0404;AF1=1;AC1=2;DP4=0,0,11,10;MQ=33;FQ=-90 GT:PL:GQ 1/1:157,63,0:99
ctga 39966 . T C 11.3 . DP=27;VDB=0.0299;AF1=0.5;AC1=1;DP4=11,5,2,7;MQ=34;FQ=14.2;PV4=0.041,1,0.01,1 GT:PL:GQ 0/1:41,0,88:43
ctga 39983 . A T 127 . DP=24;VDB=0.0355;AF1=1;AC1=2;DP4=0,0,13,11;MQ=34;FQ=-99 GT:PL:GQ 1/1:160,72,0:99
ctga 41826 . T C 110 . DP=18;VDB=0.0388;AF1=1;AC1=2;DP4=0,0,11,7;MQ=36;FQ=-81 GT:PL:GQ 1/1:143,54,0:99
ctga 42608 . G T 31 . DP=24;VDB=0.0404;AF1=0.5;AC1=1;DP4=10,4,3,7;MQ=36;FQ=34;PV4=0.095,0.12,0.044,1 GT:PL:GQ 0/1:61,0,82:64
ctga 43007 . T A 36 . DP=19;VDB=0.0355;AF1=0.5;AC1=1;DP4=3,5,9,2;MQ=36;FQ=30.4;PV4=0.074,1,0.11,1 GT:PL:GQ 0/1:66,0,58:60
ctga 43354 . A C 35 . DP=20;VDB=0.0147;AF1=0.5;AC1=1;DP4=5,6,5,4;MQ=37;FQ=37.9;PV4=1,1,1,0.39 GT:PL:GQ 0/1:65,0,82:68
ctga 45666 . G T,A 91 . DP=16;VDB=0.0388;AF1=1;AC1=2;DP4=0,0,10,6;MQ=36;FQ=-72 GT:PL:GQ 1/1:124,45,0,122,31,119:87
ctga 46994 . T A 40 . DP=24;VDB=0.0308;AF1=0.5;AC1=1;DP4=6,7,7,4;MQ=37;FQ=43;PV4=0.44,1,1,0.49 GT:PL:GQ 0/1:70,0,89:73
ctga 47847 . C A,T 126 . DP=23;VDB=0.0388;AF1=1;AC1=2;DP4=0,0,9,14;MQ=36;FQ=-93 GT:PL:GQ 1/1:159,66,0,158,51,155:99
ctga 48199 . A T 22 . DP=17;VDB=0.0320;AF1=0.5;AC1=1;DP4=2,8,4,3;MQ=36;FQ=25;PV4=0.16,1,0.12,0.0062 GT:PL:GQ 0/1:52,0,71:55
ctga 49288 . G A 106 . DP=23;VDB=0.0399;AF1=1;AC1=2;DP4=0,0,16,7;MQ=35;FQ=-96 GT:PL:GQ 1/1:139,69,0:99
Loading

0 comments on commit d30bb70

Please sign in to comment.