forked from GMOD/Apollo3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60b512e
commit 3da532b
Showing
4 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { BaseCommand } from '../../baseCommand.js' | ||
import { wrapLines, queryApollo } from '../../utils.js' | ||
|
||
export default class GetConfig extends BaseCommand<typeof GetConfig> { | ||
static summary = 'Get Jbrowse configuration from Apollo' | ||
static description = wrapLines( | ||
'Print to stdout the Jbrowse configuration from Apollo in json format', | ||
) | ||
|
||
public async run(): Promise<void> { | ||
const { flags } = await this.parse(GetConfig) | ||
|
||
const access: { address: string; accessToken: string } = | ||
await this.getAccess(flags['config-file'], flags.profile) | ||
|
||
const response = await queryApollo( | ||
access.address, | ||
access.accessToken, | ||
'jbrowse/config.json', | ||
) | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to fetch jbrowse configuration') | ||
} | ||
|
||
const json = (await response.json()) as object | ||
this.log(JSON.stringify(json, null, 2)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import * as fs from 'node:fs' | ||
import { | ||
ImportJBrowseConfigChange, | ||
JBrowseConfig, | ||
} from '@apollo-annotation/shared' | ||
import { Flags } from '@oclif/core' | ||
import { Agent, RequestInit, fetch } from 'undici' | ||
import { ConfigError } from '../../ApolloConf.js' | ||
import { BaseCommand } from '../../baseCommand.js' | ||
import { | ||
wrapLines, | ||
localhostToAddress, | ||
createFetchErrorMessage, | ||
} from '../../utils.js' | ||
|
||
export default class SetConfig extends BaseCommand<typeof SetConfig> { | ||
static summary = 'Add jbrowse configuration' | ||
static description = wrapLines( | ||
'Add jbrowse configuration into apollo database', | ||
) | ||
|
||
static examples = [ | ||
{ | ||
description: 'Add jbrowse configuration:', | ||
command: '<%= config.bin %> <%= command.id %> -i config.json', | ||
}, | ||
] | ||
|
||
static flags = { | ||
'input-file': Flags.string({ | ||
char: 'i', | ||
description: 'Input jbrowse configuration file', | ||
required: true, | ||
}), | ||
} | ||
|
||
async run(): Promise<void> { | ||
const { flags } = await this.parse(SetConfig) | ||
|
||
if (!fs.existsSync(flags['input-file'])) { | ||
this.error(`File ${flags['input-file']} does not exist`) | ||
} | ||
|
||
const access: { address: string; accessToken: string } = | ||
await this.getAccess(flags['config-file'], flags.profile) | ||
const filehandle = await fs.promises.open(flags['input-file']) | ||
const fileContent = await filehandle.readFile({ encoding: 'utf8' }) | ||
await filehandle.close() | ||
|
||
const change = new ImportJBrowseConfigChange({ | ||
typeName: 'ImportJBrowseConfigChange', | ||
newJBrowseConfig: JSON.parse(fileContent) as JBrowseConfig, | ||
}) | ||
|
||
const auth: RequestInit = { | ||
method: 'POST', | ||
body: JSON.stringify(change), | ||
headers: { | ||
Authorization: `Bearer ${access.accessToken}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
dispatcher: new Agent({ headersTimeout: 60 * 60 * 1000 }), | ||
} | ||
const url = new URL(localhostToAddress(`${access.address}/changes`)) | ||
const response = await fetch(url, auth) | ||
if (!response.ok) { | ||
const errorMessage = await createFetchErrorMessage( | ||
response, | ||
'Failed to add jbrowse configuration', | ||
) | ||
throw new ConfigError(errorMessage) | ||
} | ||
this.log('Jbrowse configuartion added successfully to apollo') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# `apollo jbrowse` | ||
|
||
Get Jbrowse configuration from Apollo | ||
|
||
- [`apollo jbrowse get-config`](#apollo-jbrowse-get-config) | ||
- [`apollo jbrowse set-config`](#apollo-jbrowse-set-config) | ||
|
||
## `apollo jbrowse get-config` | ||
|
||
Get Jbrowse configuration from Apollo | ||
|
||
``` | ||
USAGE | ||
$ apollo jbrowse get-config [--profile <value>] [--config-file <value>] | ||
FLAGS | ||
--config-file=<value> Use this config file (mostly for testing) | ||
--profile=<value> Use credentials from this profile | ||
DESCRIPTION | ||
Get Jbrowse configuration from Apollo | ||
Print to stdout the Jbrowse configuration from Apollo in json format | ||
``` | ||
|
||
_See code: | ||
[src/commands/jbrowse/get-config.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/jbrowse/get-config.ts)_ | ||
|
||
## `apollo jbrowse set-config` | ||
|
||
Add jbrowse configuration | ||
|
||
``` | ||
USAGE | ||
$ apollo jbrowse set-config -i <value> [--profile <value>] [--config-file <value>] | ||
FLAGS | ||
-i, --input-file=<value> (required) Input jbrowse configuration file | ||
--config-file=<value> Use this config file (mostly for testing) | ||
--profile=<value> Use credentials from this profile | ||
DESCRIPTION | ||
Add jbrowse configuration | ||
Add jbrowse configuration into apollo database | ||
EXAMPLES | ||
Add jbrowse configuration: | ||
$ apollo jbrowse set-config -i config.json | ||
``` | ||
|
||
_See code: | ||
[src/commands/jbrowse/set-config.ts](https://github.com/GMOD/Apollo3/blob/v0.1.19/packages/apollo-cli/src/commands/jbrowse/set-config.ts)_ |