Skip to content

Commit

Permalink
Create the jbrowse pif command
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 11, 2023
1 parent 1f3ca2d commit 87209ca
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 37 deletions.
48 changes: 24 additions & 24 deletions products/jbrowse-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ It is likely preferable in most cases to install the tools globally with
- [`jbrowse add-track-json TRACK`](#jbrowse-add-track-json-track)
- [`jbrowse admin-server`](#jbrowse-admin-server)
- [`jbrowse create LOCALPATH`](#jbrowse-create-localpath)
- [`jbrowse create-pif FILE`](#jbrowse-create-pif-file)
- [`jbrowse help [COMMANDS]`](#jbrowse-help-commands)
- [`jbrowse make-pif FILE`](#jbrowse-make-pif-file)
- [`jbrowse remove-track TRACK`](#jbrowse-remove-track-track)
- [`jbrowse set-default-session`](#jbrowse-set-default-session)
- [`jbrowse sort-gff FILE`](#jbrowse-sort-gff-file)
Expand Down Expand Up @@ -458,56 +458,56 @@ EXAMPLES
_See code:
[src/commands/create.ts](https://github.com/GMOD/jbrowse-components/blob/v2.9.0/products/jbrowse-cli/src/commands/create.ts)_

## `jbrowse create-pif FILE`
## `jbrowse help [COMMANDS]`

creates pairwise indexed PAF (PIF), with bgzip and tabix
Display help for jbrowse.

```
USAGE
$ jbrowse create-pif FILE [--out <value>] [--csi <value>] [-h]
$ jbrowse help [COMMANDS] [-n]
ARGUMENTS
FILE PAF file as input
COMMANDS Command to show help for.
FLAGS
-h, --help Show CLI help.
--csi=<value> Create a CSI index for the PIF file instead of TBI
--out=<value> Where to write the output file. If unspecified, will be ${file}.pif.gz
-n, --nested-commands Include all nested commands in the output.
DESCRIPTION
creates pairwise indexed PAF (PIF), with bgzip and tabix
EXAMPLES
$ jbrowse create-pif input.paf # creates input.pif.gz in same directory
$ jbrowse create-pif input.paf --out output.pif.gz # specify output file, creates output.pif.gz.tbi also
Display help for jbrowse.
```

_See code:
[src/commands/create-pif.ts](https://github.com/GMOD/jbrowse-components/blob/v2.9.0/products/jbrowse-cli/src/commands/create-pif.ts)_
[@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.20/src/commands/help.ts)_

## `jbrowse help [COMMANDS]`
## `jbrowse make-pif FILE`

Display help for jbrowse.
creates pairwise indexed PAF (PIF), with bgzip and tabix

```
USAGE
$ jbrowse help [COMMANDS] [-n]
$ jbrowse make-pif FILE [--out <value>] [--csi] [-h]
ARGUMENTS
COMMANDS Command to show help for.
FILE PAF file as input
FLAGS
-n, --nested-commands Include all nested commands in the output.
-h, --help Show CLI help.
--csi Create a CSI index for the PIF file instead of TBI
--out=<value> Where to write the output file. will write ${file}.pif.gz and ${file}.pif.gz.tbi
DESCRIPTION
Display help for jbrowse.
creates pairwise indexed PAF (PIF), with bgzip and tabix
EXAMPLES
$ jbrowse pif input.paf # creates input.pif.gz in same directory
$ jbrowse pif input.paf --out output.pif.gz # specify output file, creates output.pif.gz.tbi also
```

_See code:
[@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.20/src/commands/help.ts)_
[src/commands/make-pif.ts](https://github.com/GMOD/jbrowse-components/blob/v2.9.0/products/jbrowse-cli/src/commands/make-pif.ts)_

## `jbrowse remove-track TRACK`

Expand Down
7 changes: 7 additions & 0 deletions products/jbrowse-cli/out.paf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ctgA 45141 1 45141 + ctgA 50001 1 50001 45135 50000 60 tp:A:P cm:i:8494 s1:i:44546 s2:i:0 dv:f:0 rl:i:0
ctgB 6079 2 6079 + ctgB 6079 2 6079 6077 6077 2 tp:A:P cm:i:1213 s1:i:6077 s2:i:6027 dv:f:0 rl:i:0
ctgB 6079 52 6079 + ctgB 6079 2 6029 6027 6027 0 tp:A:S cm:i:1203 s1:i:6027 dv:f:0.0001 rl:i:0
ctgB 6079 2 6029 + ctgB 6079 52 6079 6027 6027 0 tp:A:S cm:i:1203 s1:i:6027 dv:f:0 rl:i:0
ctgB 6079 102 6079 + ctgB 6079 2 5979 5977 5977 0 tp:A:S cm:i:1193 s1:i:5977 dv:f:0.0001 rl:i:0
ctgB 6079 2 5979 + ctgB 6079 102 6079 5977 5977 0 tp:A:S cm:i:1193 s1:i:5977 dv:f:0 rl:i:0
ctgB 6079 2 5929 + ctgB 6079 152 6079 5927 5927 0 tp:A:S cm:i:1183 s1:i:5927 dv:f:0 rl:i:0
Binary file added products/jbrowse-cli/out.pif.gz
Binary file not shown.
Binary file added products/jbrowse-cli/out.pif.gz.tbi
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ const simplePaf = path.join(base, 'volvox_inv_indels.paf')

const exists = (p: string) => fs.existsSync(p)

describe('create-pif', () => {
describe('make-pif', () => {
const fn = path.basename(simplePaf, '.paf') + '.pif.gz'
setup
.command(['create-pif', simplePaf, '--out', fn])
.command(['make-pif', simplePaf, '--out', fn])
.it('processes volvox paf', () => {
expect(exists(fn)).toBeTruthy()
expect(gunzipSync(fs.readFileSync(fn)).toString()).toMatchSnapshot()
})
setup.command(['make-pif', simplePaf, '--out', fn, '--csi']).it('csi', () => {
expect(exists(fn)).toBeTruthy()
expect(exists(fn + '.csi')).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function swapIndelCigar(cigar: string) {

export async function createPIF(
filename: string | undefined,
stream: { write: any },
stream: { write: (arg: string) => void },
) {
const rl1 = filename ? getReadline(filename) : getStdReadline()
for await (const line of rl1) {
Expand All @@ -76,22 +76,22 @@ export async function createPIF(
rl1.close()
}

export default class CreatePIF extends JBrowseCommand {
export default class MakePIF extends JBrowseCommand {
static description =
'creates pairwise indexed PAF (PIF), with bgzip and tabix'

static examples = [
'$ jbrowse create-pif input.paf # creates input.pif.gz in same directory',
'$ jbrowse pif input.paf # creates input.pif.gz in same directory',
'',
'$ jbrowse create-pif input.paf --out output.pif.gz # specify output file, creates output.pif.gz.tbi also',
'$ jbrowse pif input.paf --out output.pif.gz # specify output file, creates output.pif.gz.tbi also',
]

static flags = {
out: Flags.string({
description:
'Where to write the output file. If unspecified, will be ${file}.pif.gz',
'Where to write the output file. will write ${file}.pif.gz and ${file}.pif.gz.tbi',
}),
csi: Flags.string({
csi: Flags.boolean({
description: 'Create a CSI index for the PIF file instead of TBI',
}),
help: Flags.help({ char: 'h' }),
Expand All @@ -107,8 +107,7 @@ export default class CreatePIF extends JBrowseCommand {
const {
args: { file },
flags: { out, csi },
} = await this.parse(CreatePIF)
console.error('wtf')
} = await this.parse(MakePIF)

if (
commandExistsSync('sh') &&
Expand All @@ -117,13 +116,14 @@ export default class CreatePIF extends JBrowseCommand {
commandExistsSync('tabix') &&
commandExistsSync('bgzip')
) {
console.error('wtf')
const fn = out || `${path.basename(file, '.paf')}.pif.gz`
const fn = out || `${path.basename(file || 'output', '.paf')}.pif.gz`
const child = spawn(
'sh',
[
'-c',
`sort -t"\`printf '\t'\`" -k1,1 -k3,3n | bgzip > ${fn}; tabix -s1 -b3 -e4 ${fn}`,
`sort -t"\`printf '\t'\`" -k1,1 -k3,3n | bgzip > ${fn}; tabix ${
csi ? '-C ' : ''
}-s1 -b3 -e4 ${fn}`,
],
{
env: { ...process.env, LC_ALL: 'C' },
Expand Down

0 comments on commit 87209ca

Please sign in to comment.