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

Add support for single file hubs #34

Merged
merged 11 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ on: push

jobs:
test:
name: Lint, build, and test on node 14.x and ubuntu-latest
name: Lint, build, and test on node 20.x and ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v1
- uses: actions/checkout@v3
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 20.x
- name: Install deps (with cache)
uses: bahmutov/npm-install@v1
- name: Lint codebase
Expand Down
63 changes: 57 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ read and write UCSC track and assembly hub files in node or the browser

Read about hub.txt, genomes.txt, and trackDb.txt files here: <https://genome.ucsc.edu/goldenpath/help/hgTrackHubHelp.html>

Files are essentially JavaScript `Map`s. A hub.txt file is a map with th keys as the first word in each line and the value as the rest of the line, like this:
Files are essentially JavaScript `Map`s. A hub.txt file is a map with keys as the first word in each line and the value as the rest of the line, like this:

Map {
"hub" => "UCSCHub",
Expand Down Expand Up @@ -66,7 +66,7 @@ values of the first line of each section and the value is a `Map` of the lines i
},
}

Example usage:
Example usage for a "standard" multi-file hub:

```javascript
const fs = require('fs')
Expand All @@ -85,6 +85,24 @@ console.log(trackDbFile.get('dnaseSignal').get('shortLabel'))
// ↳ DNAse Signal
```

Example usage for a single-file hub:

```javascript
const fs = require('fs')
const { SingleFileHub } = require('@gmod/ucsc-hub')

const hubFile = new HubFile(fs.readFileSync('hub.txt', 'utf8'))
console.log(hubFile.get('genomesFile'))
// ↳ genomes.txt

const genomesFile = new GenomesFile(fs.readFileSync('genomes.txt', 'utf8'))
console.log(genomesFile.get('hg19').get('trackDb'))
// ↳ hg19/trackDb.txt

const trackDbFile = new TrackDbFile(fs.readFileSync('hg19/trackDb.txt', 'utf8'))
console.log(trackDbFile.get('dnaseSignal').get('shortLabel'))
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
Expand Down Expand Up @@ -117,10 +135,14 @@ console.log(trackDbFile.get('dnaseSignal').get('shortLabel'))
* [Parameters](#parameters-9)
* [clear](#clear-1)
* [toString](#tostring-1)
* [TrackDbFile](#trackdbfile)
* [SingleFileHub](#singlefilehub)
* [Parameters](#parameters-10)
* [genome](#genome)
* [trackDbs](#trackdbs)
* [TrackDbFile](#trackdbfile)
* [Parameters](#parameters-11)
* [settings](#settings)
* [Parameters](#parameters-11)
* [Parameters](#parameters-12)

### GenomesFile

Expand Down Expand Up @@ -170,7 +192,7 @@ as it performs more validity checks than using `set()`.
* `raFile` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** An ra file, either as a single
string or an array of strings with one stanza per entry. Supports both LF
and CRLF line terminators. (optional, default `[]`)
* `options` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{checkIndent:true}`)
* `options` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;

* `options.checkIndent` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** \[true] - Check if a the stanzas within
the file are indented consistently and keep track of the indentation
Expand Down Expand Up @@ -246,7 +268,7 @@ than using `set()`.
* `stanza` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** An ra file stanza, either as a
string or a array of strings with one line per entry. Supports both LF and
CRLF line terminators. (optional, default `[]`)
* `options` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{checkIndent:true}`)
* `options` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;

* `options.checkIndent` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** \[true] - Check if a stanza is indented
consistently and keep track of the indentation
Expand Down Expand Up @@ -314,6 +336,34 @@ as a single line and all comments will have the same indentations as the
rest of the stanza. Comments between joined lines will move before that
line.

### SingleFileHub

**Extends RaFile**

Class representing a "single-file" hub.txt file that contains all the sections
of a hub in a single file.

#### Parameters

* `hubText` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** A hub.txt file as a string (optional, default `[]`)

<!---->

* Throws **[Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)** Throws if the first line of the hub.txt file doesn't start
with "genome \<genome\_name>" or if it has invalid entries

#### genome

a GenomesFile object for the hub's genome section

Type: [GenomesFile](#genomesfile)

#### trackDbs

an array of TrackDbFile objects for the hub's trackDb sections

Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[TrackDbFile](#trackdbfile)>

### TrackDbFile

**Extends RaFile**
Expand All @@ -323,6 +373,7 @@ Class representing a genomes.txt file.
#### Parameters

* `trackDbFile` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** A trackDb.txt file as a string (optional, default `[]`)
* `options` **any?**&#x20;

<!---->

Expand Down
24 changes: 11 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gmod/ucsc-hub",
"version": "0.1.7",
"version": "0.2.0",
"description": "Read and write UCSC track and assembly hub files in node or the browser",
"license": "MIT",
"repository": "github:GMOD/ucsc-hub-js",
Expand All @@ -18,15 +18,13 @@
],
"scripts": {
"test": "jest --rootDir=./src",
"coverage": "npm test -- --coverage",
"postcoverage": "opn coverage/lcov-report/index.html",
"lint": "eslint --report-unused-disable-directives --max-warnings 0 --ext .js,.ts src",
"docs": "documentation readme src --section=API",
"postdocs": "git add README.md",
"clean": "rimraf dist esm",
"prebuild": "npm run docs && npm run clean",
"build:esm": "tsc --target es2018 --outDir esm",
"build:es5": "tsc --target es2015 --module commonjs --outDir dist",
"build:es5": "tsc --target es2018 --module commonjs --outDir dist",
"build": "npm run build:esm && npm run build:es5",
"preversion": "npm run lint && npm test && npm run build",
"postversion": "git push --follow-tags",
Expand All @@ -40,22 +38,22 @@
],
"devDependencies": {
"@types/jest": "^29.2.4",
"@types/node": "^18.11.16",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.46.1",
"@types/node": "^20.7.2",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"documentation": "^14.0.1",
"eslint": "^8.30.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-unicorn": "^49.0.0",
"husky": "^8.0.2",
"jest": "^29.3.1",
"opn-cli": "^5.0.0",
"prettier": "^2.8.1",
"rimraf": "^3.0.2",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"ts-jest": "^29.0.1",
"typescript": "^4.9.4"
"typescript": "^5.2.2"
},
"publishConfig": {
"access": "public"
Expand Down
5 changes: 5 additions & 0 deletions src/__snapshots__/raFile.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ Map {
"key2" => "valH",
"key3" => "valI",
},
"Foot" => Map {
"key1" => "Foot",
"key2" => "Ankle",
"key3" => "Knee",
},
}
`;

Expand Down
Loading