Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 12, 2024
1 parent 33423bf commit dc491e8
Show file tree
Hide file tree
Showing 13 changed files with 1,385 additions and 2,179 deletions.
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Read legacy JBrowse 1 nested containment list JSON.

[![Build Status](https://img.shields.io/github/actions/workflow/status/GMOD/nclist-js/push.yml?branch=master)](https://github.com/GMOD/nclist-js/actions)
[![Coverage Status](https://img.shields.io/codecov/c/github/GMOD/nclist-js/master.svg?style=flat-square)](https://codecov.io/gh/GMOD/nclist-js/branch/master)
[![NPM version](https://img.shields.io/npm/v/@gmod/nclist.svg?logo=npm\&style=flat-square)](https://npmjs.org/package/@gmod/nclist)
[![NPM version](https://img.shields.io/npm/v/@gmod/nclist.svg?logo=npm&style=flat-square)](https://npmjs.org/package/@gmod/nclist)

## Usage

```javascript
import { RemoteFile } from 'generic-filehandle'
import { RemoteFile } from 'generic-filehandle2'
import NCList from '@gmod/nclist'
;(async () => {
const store = new NCList({
Expand Down Expand Up @@ -40,12 +40,12 @@ import NCList from '@gmod/nclist'

#### Table of Contents

* [NCListStore](#ncliststore)
* [Parameters](#parameters)
* [getRegionFeatureDensities](#getregionfeaturedensities)
* [Parameters](#parameters-1)
* [getFeatures](#getfeatures)
* [Parameters](#parameters-2)
- [NCListStore](#ncliststore)
- [Parameters](#parameters)
- [getRegionFeatureDensities](#getregionfeaturedensities)
- [Parameters](#parameters-1)
- [getFeatures](#getfeatures)
- [Parameters](#parameters-2)

### NCListStore

Expand All @@ -54,28 +54,28 @@ lists held in JSON files that are lazily read.

#### Parameters

* `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** constructor args
- `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** constructor args

* `args.baseUrl` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** base URL for resolving relative URLs
* `args.urlTemplate` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Template string for
the root file of each reference sequence. The reference sequence
name will be interpolated into this string where `{refseq}` appears.
* `args.readFile` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** function to use for reading remote from URLs.
* `args.cacheSize` (optional, default `10`)
- `args.baseUrl` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** base URL for resolving relative URLs
- `args.urlTemplate` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Template string for
the root file of each reference sequence. The reference sequence
name will be interpolated into this string where `{refseq}` appears.
- `args.readFile` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** function to use for reading remote from URLs.
- `args.cacheSize` (optional, default `10`)

#### getRegionFeatureDensities

fetch binned counts of feature coverage in the given region.

##### Parameters

* `query` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
- `query` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

* `query.refName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** reference sequence name
* `query.start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** region start
* `query.end` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** region end
* `query.numBins` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** number of bins desired in the feature counts
* `query.basesPerBin` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** number of bp desired in each feature counting bin
- `query.refName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** reference sequence name
- `query.start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** region start
- `query.end` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** region end
- `query.numBins` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** number of bins desired in the feature counts
- `query.basesPerBin` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** number of bp desired in each feature counting bin

Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** as:
`{ bins: hist, stats: statEntry }`
Expand All @@ -87,8 +87,8 @@ yielding feature objects.

##### Parameters

* `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
- `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

* `args.refName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** reference sequence name
* `args.start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** start of region. 0-based half-open.
* `args.end` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** end of region. 0-based half-open.
- `args.refName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** reference sequence name
- `args.start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** start of region. 0-based half-open.
- `args.end` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** end of region. 0-based half-open.
112 changes: 84 additions & 28 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,42 +1,98 @@
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:prettier/recommended',
),
export default tseslint.config(
{
ignores: [
'webpack.config.js',
'dist/*',
'esm/*',
'example/*',
'eslint.config.mjs',
],
},
{
plugins: {
prettier,
'@typescript-eslint': typescriptEslint,
},

languageOptions: {
parser: tsParser,
parserOptions: {
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',
{
argsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],

'no-underscore-dangle': 0,
curly: 'error',
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-empty-function': 0,
semi: ['error', 'never'],
'unicorn/no-new-array': 'off',
'unicorn/no-empty-file': 'off',
'unicorn/prefer-type-error': 'off',
'unicorn/prefer-modern-math-apis': 'off',
'unicorn/prefer-node-protocol': 'off',
'unicorn/no-unreadable-array-destructuring': 'off',
'unicorn/no-abusive-eslint-disable': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/number-literal-case': 'off',
'unicorn/prefer-add-event-listener': 'off',
'unicorn/prefer-top-level-await': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/no-await-expression-member': 'off',
'unicorn/no-lonely-if': 'off',
'unicorn/consistent-destructuring': 'off',
'unicorn/prefer-module': 'off',
'unicorn/prefer-optional-catch-binding': 'off',
'unicorn/no-useless-undefined': 'off',
'unicorn/no-null': 'off',
'unicorn/no-nested-ternary': 'off',
'unicorn/filename-case': 'off',
'unicorn/catch-error-name': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/prefer-code-point': 'off',
'unicorn/numeric-separators-style': 'off',
'unicorn/no-array-for-each': 'off',
'unicorn/prefer-spread': 'off',
'unicorn/explicit-length-check': 'off',
'unicorn/prefer-regexp-test': 'off',
'unicorn/relative-url-style': 'off',
'unicorn/prefer-math-trunc': 'off',
'unicorn/prefer-query-selector': 'off',
'unicorn/no-negated-condition': 'off',
'unicorn/switch-case-braces': 'off',
'unicorn/prefer-switch': 'off',
'unicorn/better-regex': 'off',
'unicorn/no-for-loop': 'off',
'unicorn/escape-case': 'off',
'unicorn/prefer-number-properties': 'off',
'unicorn/no-process-exit': 'off',
'unicorn/prefer-at': '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/require-await': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'no-empty': 'off',
},
},
]
)
5 changes: 0 additions & 5 deletions jest.config.js

This file was deleted.

30 changes: 14 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,33 @@
"node": ">=8"
},
"scripts": {
"test": "jest",
"coverage": "npm test -- --coverage",
"lint": "eslint --report-unused-disable-directives --max-warnings 0 src test",
"test": "vitest",
"coverage": "yarn test --coverage",
"lint": "eslint --report-unused-disable-directives --max-warnings 0",
"docs": "documentation readme --shallow src/feature_store.ts --section API",
"clean": "rimraf dist esm",
"prebuild": "npm run docs && npm run clean && npm run lint",
"prebuild": "yarn docs && yarn clean && yarn lint",
"build:esm": "tsc --target es2018 --outDir esm",
"build:es5": "tsc --target es2015 --module commonjs --outDir dist",
"build": "npm run build:esm && npm run build:es5",
"prepublishOnly": "npm test && npm run build",
"build": "yarn build:esm && yarn build:es5",
"prepublishOnly": "yarn test --run && yarn build",
"postversion": "git push --follow-tags"
},
"devDependencies": {
"@types/jest": "^29.2.5",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"cross-fetch": "^3.0.2",
"documentation": "^14.0.1",
"eslint": "^9.5.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^56.0.1",
"express": "^4.18.2",
"generic-filehandle": "^3.2.0",
"generic-filehandle2": "^0.0.2",
"get-port": "^5.0.0",
"jest": "^29.3.1",
"prettier": "^3.3.2",
"rimraf": "^5.0.0",
"ts-jest": "^29.0.3",
"typescript": "^5.0.4"
"rimraf": "^6.0.1",
"typescript": "^5.0.4",
"typescript-eslint": "^8.18.0",
"vitest": "^2.1.8"
},
"dependencies": {
"@gmod/abortable-promise-cache": "^2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions src/feature_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class NCListStore {

fetchDataRoot(refName) {
const url = newURL(
this.urlTemplates.root.replace(/{\s*refseq\s*}/g, refName),
this.urlTemplates.root.replaceAll(/{\s*refseq\s*}/g, refName),
this.baseUrl,
)

Expand All @@ -89,7 +89,7 @@ export default class NCListStore {
}

const { histograms } = trackInfo
if (histograms && histograms.meta) {
if (histograms?.meta) {
for (let i = 0; i < histograms.meta.length; i += 1) {
histograms.meta[i].lazyArray = new LazyArray(
{ ...histograms.meta[i].arrayParams, readFile: this.readFile },
Expand Down Expand Up @@ -218,7 +218,7 @@ export default class NCListStore {
*/
async *getFeatures({ refName, start, end }) {
const data = await this.getDataRoot(refName)
const accessors = data.attrs && data.attrs.accessors()
const accessors = data.attrs?.accessors()
for await (const [feature, path] of data.nclist.iterate(start, end)) {
// the unique ID is a stringification of the path in the
// NCList where the feature lives; it's unique across the
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ts-nocheck
import NCListStore from './feature_store'

export default NCListStore
export { default } from './feature_store'
2 changes: 1 addition & 1 deletion src/lazy_array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class LazyArray {
}

async getChunk(chunkNumber) {
let url = this.urlTemplate.replace(/\{Chunk\}/gi, chunkNumber)
let url = this.urlTemplate.replaceAll(/\{Chunk\}/gi, chunkNumber)
if (this.baseUrl) {
url = newURL(url, this.baseUrl)
}
Expand Down
2 changes: 1 addition & 1 deletion src/nclist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class NCList {

readChunkItems(chunkNum) {
const url = newURL(
this.lazyUrlTemplate.replace(/\{Chunk\}/gi, chunkNum),
this.lazyUrlTemplate.replaceAll(/\{Chunk\}/gi, chunkNum),
this.baseURL,
)
return readJSON(url, this.readFile, { defaultContent: [] })
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export async function readJSON(url, readFile, options = {}) {

export function foo() {}

export function newURL(arg: string, base?: string = '.') {
export function newURL(arg: string, base = '.') {
return resolve(arg, base)
}
4 changes: 2 additions & 2 deletions test/ensembl_genes.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ts-nocheck
import { RemoteFile } from 'generic-filehandle'
import { RemoteFile } from 'generic-filehandle2'
import fetch from 'cross-fetch'
import NCListStore from '../src/feature_store'
import makeTestServer from './static_server'
Expand All @@ -13,7 +13,7 @@ afterAll(() => testServer.close())
describe('ensembl genes', () => {
const testCases = [
[
'read with generic-filehandle RemoteFile with http urls',
'read with generic-filehandle2 RemoteFile with http urls',
() => ({
baseUrl: `${testServer.url}/`,
urlTemplate: 'ensembl_genes/{refseq}/trackData.json',
Expand Down
4 changes: 2 additions & 2 deletions test/simple.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ts-nocheck
import { RemoteFile } from 'generic-filehandle'
import { RemoteFile } from 'generic-filehandle2'
import fetch from 'cross-fetch'

import NCListStore from '../src'
Expand All @@ -14,7 +14,7 @@ afterAll(() => testServer.close())
describe('simple data', () => {
const testCases = [
[
'read with generic-filehandle RemoteFile with http urls',
'read with generic-filehandle2 RemoteFile with http urls',
() => ({
baseUrl: `${testServer.url}/`,
urlTemplate: 'volvox_genes/{refseq}/trackData.json',
Expand Down
7 changes: 4 additions & 3 deletions test/static_server.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//eslint-disable-next-line @typescript-eslint/no-var-requires
const getPort = require('get-port')
//eslint-disable-next-line @typescript-eslint/no-var-requires

const express = require('express')

module.exports = async () => {
const app = express()
const port = await getPort()
app.use(express.static('test/data'))
const server = await new Promise(resolve => {
const s = app.listen(port, () => resolve(s))
const s = app.listen(port, () => {
resolve(s)
})
})

return {
Expand Down
Loading

0 comments on commit dc491e8

Please sign in to comment.