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 jbrowse sort-gff subcommand #4032

Merged
merged 2 commits into from
Nov 3, 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@types/base64-js": "^1.2.5",
"@types/buffer-crc32": "^0.2.2",
"@types/cli-progress": "^3.9.2",
"@types/command-exists": "^1.2.2",
"@types/cors": "^2.8.13",
"@types/cross-spawn": "^6.0.2",
"@types/crypto-js": "^4.0.1",
Expand Down
29 changes: 29 additions & 0 deletions products/jbrowse-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ It is likely preferable in most cases to install the tools globally with
- [`jbrowse help [COMMANDS]`](#jbrowse-help-commands)
- [`jbrowse remove-track TRACK`](#jbrowse-remove-track-track)
- [`jbrowse set-default-session`](#jbrowse-set-default-session)
- [`jbrowse sort-gff FILE`](#jbrowse-sort-gff-file)
- [`jbrowse text-index`](#jbrowse-text-index)
- [`jbrowse upgrade [LOCALPATH]`](#jbrowse-upgrade-localpath)

Expand Down Expand Up @@ -543,6 +544,34 @@ EXAMPLES
_See code:
[src/commands/set-default-session.ts](https://github.com/GMOD/jbrowse-components/blob/v2.7.2/products/jbrowse-cli/src/commands/set-default-session.ts)_

## `jbrowse sort-gff FILE`

Helper utility to sort GFF files for tabix. Moves all lines starting with # to
the top of the file, and sort by refname and start position using unix utilities
sort and grep

```
USAGE
$ jbrowse sort-gff FILE

ARGUMENTS
FILE GFF file

DESCRIPTION
Helper utility to sort GFF files for tabix. Moves all lines starting with # to the top of the file, and sort by
refname and start position using unix utilities sort and grep

EXAMPLES
# sort gff and pipe to bgzip

$ jbrowse sort-gff input.gff | bgzip > sorted.gff.gz

$ tabix sorted.gff.gz
```

_See code:
[src/commands/sort-gff.ts](https://github.com/GMOD/jbrowse-components/blob/v2.7.2/products/jbrowse-cli/src/commands/sort-gff.ts)_

## `jbrowse text-index`

Make a text-indexing file for any given track(s).
Expand Down
1 change: 1 addition & 0 deletions products/jbrowse-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"boxen": "^4.2.0",
"chalk": "^4.1.0",
"cli-progress": "^3.9.0",
"command-exists": "^1.2.9",
"cors": "^2.8.5",
"decompress": "^4.0.0",
"express": "^4.17.1",
Expand Down
52 changes: 52 additions & 0 deletions products/jbrowse-cli/src/commands/sort-gff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Args } from '@oclif/core'
import { sync as commandExistsSync } from 'command-exists'

import { spawn } from 'child_process'
import JBrowseCommand from '../base'

export default class SortGff extends JBrowseCommand {
static description =
'Helper utility to sort GFF files for tabix. Moves all lines starting with # to the top of the file, and sort by refname and start position using unix utilities sort and grep'

static examples = [
'# sort gff and pipe to bgzip',
'$ jbrowse sort-gff input.gff | bgzip > sorted.gff.gz',
'$ tabix sorted.gff.gz',
]

static args = {
file: Args.string({
required: true,
description: `GFF file`,
}),
}

async run() {
const {
args: { file },
} = await this.parse(SortGff)

if (
commandExistsSync('sh') &&
commandExistsSync('sort') &&
commandExistsSync('grep')
) {
// this command comes from the tabix docs http://www.htslib.org/doc/tabix.html
spawn(
'sh',
[
'-c',
`(grep "^#" "${file}"; grep -v "^#" "${file}" | sort -t"\`printf '\t'\`" -k1,1 -k4,4n)`,
],
{
env: { ...process.env, LC_ALL: 'C' },
stdio: 'inherit',
},
)
} else {
throw new Error(
'Unable to sort, requires unix type environment with sort, grep',
)
}
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4364,6 +4364,11 @@
resolved "https://registry.yarnpkg.com/@types/clone/-/clone-2.1.3.tgz#91d16af4006a24fd3d683f5454d48b29a695b0e9"
integrity sha512-DxFaNYaIUXW1OSRCVCC1UHoLcvk6bVJ0v9VvUaZ6kR5zK8/QazXlOThgdvnK0Xpa4sBq+b/Yoq/mnNn383hVRw==

"@types/command-exists@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@types/command-exists/-/command-exists-1.2.2.tgz#b386d1deb4b423122467dfb536b7262589216827"
integrity sha512-1qKPTkjLmghE5C7UUHXGcLaG8MNftchOcLAIryUXNKahRO5beS+iJ9rIL8XD4+B8K2phjYUsPQDox1FRX4KMTQ==

"@types/connect-history-api-fallback@^1.3.5":
version "1.5.2"
resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.5.2.tgz#acf51e088b3bb6507f7b093bd2b0de20940179cc"
Expand Down