@apollo-annotation/cli 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +899 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +9 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +8 -0
- package/dist/Config.d.ts +43 -0
- package/dist/Config.js +233 -0
- package/dist/baseCommand.d.ts +21 -0
- package/dist/baseCommand.js +62 -0
- package/dist/commands/assembly/add-fasta.d.ts +15 -0
- package/dist/commands/assembly/add-fasta.js +98 -0
- package/dist/commands/assembly/add-gff.d.ts +16 -0
- package/dist/commands/assembly/add-gff.js +76 -0
- package/dist/commands/assembly/check.d.ts +15 -0
- package/dist/commands/assembly/check.js +148 -0
- package/dist/commands/assembly/delete.d.ts +14 -0
- package/dist/commands/assembly/delete.js +43 -0
- package/dist/commands/assembly/get.d.ts +9 -0
- package/dist/commands/assembly/get.js +33 -0
- package/dist/commands/assembly/get.test.d.ts +1 -0
- package/dist/commands/assembly/get.test.js +50 -0
- package/dist/commands/assembly/sequence.d.ts +16 -0
- package/dist/commands/assembly/sequence.js +117 -0
- package/dist/commands/change/get.d.ts +9 -0
- package/dist/commands/change/get.js +35 -0
- package/dist/commands/change/get.test.d.ts +1 -0
- package/dist/commands/change/get.test.js +22 -0
- package/dist/commands/config.d.ts +25 -0
- package/dist/commands/config.js +217 -0
- package/dist/commands/config.test.d.ts +1 -0
- package/dist/commands/config.test.js +188 -0
- package/dist/commands/feature/add-child.d.ts +17 -0
- package/dist/commands/feature/add-child.js +120 -0
- package/dist/commands/feature/check.d.ts +14 -0
- package/dist/commands/feature/check.js +97 -0
- package/dist/commands/feature/copy.d.ts +17 -0
- package/dist/commands/feature/copy.js +110 -0
- package/dist/commands/feature/delete.d.ts +11 -0
- package/dist/commands/feature/delete.js +99 -0
- package/dist/commands/feature/edit-attribute.d.ts +16 -0
- package/dist/commands/feature/edit-attribute.js +100 -0
- package/dist/commands/feature/edit-coords.d.ts +15 -0
- package/dist/commands/feature/edit-coords.js +109 -0
- package/dist/commands/feature/edit-type.d.ts +10 -0
- package/dist/commands/feature/edit-type.js +70 -0
- package/dist/commands/feature/edit.d.ts +13 -0
- package/dist/commands/feature/edit.js +81 -0
- package/dist/commands/feature/get-id.d.ts +14 -0
- package/dist/commands/feature/get-id.js +56 -0
- package/dist/commands/feature/get.d.ts +16 -0
- package/dist/commands/feature/get.js +87 -0
- package/dist/commands/feature/import.d.ts +15 -0
- package/dist/commands/feature/import.js +83 -0
- package/dist/commands/feature/search.d.ts +14 -0
- package/dist/commands/feature/search.js +91 -0
- package/dist/commands/login.d.ts +21 -0
- package/dist/commands/login.js +206 -0
- package/dist/commands/login.test.d.ts +1 -0
- package/dist/commands/login.test.js +52 -0
- package/dist/commands/logout.d.ts +10 -0
- package/dist/commands/logout.js +41 -0
- package/dist/commands/logout.test.d.ts +1 -0
- package/dist/commands/logout.test.js +67 -0
- package/dist/commands/refseq/get.d.ts +13 -0
- package/dist/commands/refseq/get.js +44 -0
- package/dist/commands/status.d.ts +6 -0
- package/dist/commands/status.js +38 -0
- package/dist/commands/status.test.d.ts +1 -0
- package/dist/commands/status.test.js +54 -0
- package/dist/commands/user/get.d.ts +14 -0
- package/dist/commands/user/get.js +46 -0
- package/dist/commands/user/get.test.d.ts +1 -0
- package/dist/commands/user/get.test.js +23 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/test/fixtures.d.ts +7 -0
- package/dist/test/fixtures.js +40 -0
- package/dist/utils.d.ts +54 -0
- package/dist/utils.js +373 -0
- package/oclif.manifest.json +1632 -0
- package/package.json +100 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { fetch } from 'undici';
|
|
3
|
+
import { BaseCommand } from '../../baseCommand.js';
|
|
4
|
+
import { CheckError, convertCheckNameToId, createFetchErrorMessage, getAssembly, idReader, localhostToAddress, wrapLines, } from '../../utils.js';
|
|
5
|
+
async function setChecks(address, accessToken, assembly, checkId) {
|
|
6
|
+
const check = {
|
|
7
|
+
_id: assembly,
|
|
8
|
+
checks: checkId,
|
|
9
|
+
name: '',
|
|
10
|
+
};
|
|
11
|
+
const auth = {
|
|
12
|
+
method: 'POST',
|
|
13
|
+
body: JSON.stringify(check),
|
|
14
|
+
headers: {
|
|
15
|
+
Authorization: `Bearer ${accessToken}`,
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const url = new URL(localhostToAddress(`${address}/assemblies/checks`));
|
|
20
|
+
const response = await fetch(url, auth);
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
const errorMessage = await createFetchErrorMessage(response, 'setChecks failed');
|
|
23
|
+
throw new Error(errorMessage);
|
|
24
|
+
}
|
|
25
|
+
return response;
|
|
26
|
+
}
|
|
27
|
+
async function getCheckTypes(address, accessToken) {
|
|
28
|
+
const auth = {
|
|
29
|
+
method: 'GET',
|
|
30
|
+
headers: {
|
|
31
|
+
Authorization: `Bearer ${accessToken}`,
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const url = new URL(localhostToAddress(`${address}/checks/types`));
|
|
36
|
+
const response = await fetch(url, auth);
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const errorMessage = await createFetchErrorMessage(response, 'getCheckTypes failed');
|
|
39
|
+
throw new Error(errorMessage);
|
|
40
|
+
}
|
|
41
|
+
const chk = (await response.json());
|
|
42
|
+
return chk;
|
|
43
|
+
}
|
|
44
|
+
function getCheckTypesForAssembly(checkTypes, assembly) {
|
|
45
|
+
const checks = [];
|
|
46
|
+
for (const chkType of checkTypes) {
|
|
47
|
+
for (const chk of assembly['checks']) {
|
|
48
|
+
if (chkType['_id'] === chk) {
|
|
49
|
+
checks.push(chkType);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return checks;
|
|
54
|
+
}
|
|
55
|
+
export default class Check extends BaseCommand {
|
|
56
|
+
static summary = 'Add, view, or delete checks to assembly';
|
|
57
|
+
static description = wrapLines('Manage checks, i.e. the rules ensuring features in an assembly are plausible. \
|
|
58
|
+
This command only sets the check to apply, to retrieve features flagged by these checks use `apollo feature check`.');
|
|
59
|
+
static examples = [
|
|
60
|
+
{
|
|
61
|
+
description: 'View available check types:',
|
|
62
|
+
command: '<%= config.bin %> <%= command.id %>',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
description: 'View checks set for assembly hg19:',
|
|
66
|
+
command: '<%= config.bin %> <%= command.id %> -a hg19',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
description: 'Add checks to assembly:',
|
|
70
|
+
command: '<%= config.bin %> <%= command.id %> -a hg19 -c CDSCheck',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
description: 'Delete checks from assembly:',
|
|
74
|
+
command: '<%= config.bin %> <%= command.id %> -a hg19 -c CDSCheck --delete',
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
static flags = {
|
|
78
|
+
assembly: Flags.string({
|
|
79
|
+
char: 'a',
|
|
80
|
+
description: 'Manage checks in this assembly',
|
|
81
|
+
}),
|
|
82
|
+
check: Flags.string({
|
|
83
|
+
char: 'c',
|
|
84
|
+
description: 'Add these check names or IDs. If unset, print the checks set for assembly',
|
|
85
|
+
multiple: true,
|
|
86
|
+
}),
|
|
87
|
+
delete: Flags.boolean({
|
|
88
|
+
char: 'd',
|
|
89
|
+
description: 'Delete (instead of adding) checks',
|
|
90
|
+
}),
|
|
91
|
+
};
|
|
92
|
+
async run() {
|
|
93
|
+
const { flags } = await this.parse(Check);
|
|
94
|
+
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
95
|
+
const checkTypes = await getCheckTypes(access.address, access.accessToken);
|
|
96
|
+
if (flags.check === undefined && flags.assembly === undefined) {
|
|
97
|
+
this.log(JSON.stringify(checkTypes, null, 2));
|
|
98
|
+
this.exit(0);
|
|
99
|
+
}
|
|
100
|
+
if (flags.assembly === undefined) {
|
|
101
|
+
this.logToStderr('Please specify the assembly to manage for checks');
|
|
102
|
+
this.exit(1);
|
|
103
|
+
}
|
|
104
|
+
const asm = idReader([flags.assembly]);
|
|
105
|
+
const assembly = await getAssembly(access.address, access.accessToken, asm[0]);
|
|
106
|
+
if (Object.keys(assembly).length === 0) {
|
|
107
|
+
this.logToStderr(`Assembly ${flags.assembly} not found`);
|
|
108
|
+
this.exit(1);
|
|
109
|
+
}
|
|
110
|
+
const currentChecks = getCheckTypesForAssembly(checkTypes, assembly);
|
|
111
|
+
if (flags.check === undefined) {
|
|
112
|
+
this.log(JSON.stringify(currentChecks, null, 2));
|
|
113
|
+
this.exit(0);
|
|
114
|
+
}
|
|
115
|
+
let inputCheckIds = [];
|
|
116
|
+
try {
|
|
117
|
+
inputCheckIds = await convertCheckNameToId(access.address, access.accessToken, flags.check);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error instanceof CheckError) {
|
|
121
|
+
this.logToStderr(error.message);
|
|
122
|
+
this.exit(1);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const newChecks = new Set();
|
|
126
|
+
if (flags.delete) {
|
|
127
|
+
const currentCheckIds = new Set();
|
|
128
|
+
for (const chk of currentChecks) {
|
|
129
|
+
currentCheckIds.add(chk['_id']);
|
|
130
|
+
}
|
|
131
|
+
for (const id of inputCheckIds) {
|
|
132
|
+
if (!currentCheckIds.has(id)) {
|
|
133
|
+
newChecks.add(id);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
for (const chk of inputCheckIds) {
|
|
139
|
+
newChecks.add(chk);
|
|
140
|
+
}
|
|
141
|
+
for (const chk of currentChecks) {
|
|
142
|
+
newChecks.add(chk['_id']);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
await setChecks(access.address, access.accessToken, assembly['_id'], [...newChecks.values()]);
|
|
146
|
+
this.exit(0);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../baseCommand.js';
|
|
2
|
+
export default class Delete extends BaseCommand<typeof Delete> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: {
|
|
6
|
+
description: string;
|
|
7
|
+
command: string;
|
|
8
|
+
}[];
|
|
9
|
+
static flags: {
|
|
10
|
+
assembly: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string[], import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
+
verbose: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../baseCommand.js';
|
|
3
|
+
import { convertAssemblyNameToId, deleteAssembly, getAssembly, idReader, wrapLines, } from '../../utils.js';
|
|
4
|
+
export default class Delete extends BaseCommand {
|
|
5
|
+
static summary = 'Delete assemblies';
|
|
6
|
+
static description = wrapLines('Assemblies to delete may be names or IDs');
|
|
7
|
+
static examples = [
|
|
8
|
+
{
|
|
9
|
+
description: 'Delete multiple assemblies using name or ID:',
|
|
10
|
+
command: '<%= config.bin %> <%= command.id %> -a mouse 6605826fbd0eee691f83e73f',
|
|
11
|
+
},
|
|
12
|
+
];
|
|
13
|
+
static flags = {
|
|
14
|
+
assembly: Flags.string({
|
|
15
|
+
char: 'a',
|
|
16
|
+
description: 'Assembly names or IDs to delete',
|
|
17
|
+
multiple: true,
|
|
18
|
+
required: true,
|
|
19
|
+
}),
|
|
20
|
+
verbose: Flags.boolean({
|
|
21
|
+
char: 'v',
|
|
22
|
+
description: 'Print to stdout the array of assemblies deleted',
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
async run() {
|
|
26
|
+
const { flags } = await this.parse(Delete);
|
|
27
|
+
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
28
|
+
const assembly = idReader(flags.assembly);
|
|
29
|
+
const deleteIds = await convertAssemblyNameToId(access.address, access.accessToken, assembly);
|
|
30
|
+
let i = 0;
|
|
31
|
+
const deleted = [];
|
|
32
|
+
for (const x of deleteIds) {
|
|
33
|
+
const asm = await getAssembly(access.address, access.accessToken, x);
|
|
34
|
+
await deleteAssembly(access.address, access.accessToken, x);
|
|
35
|
+
deleted.push(asm);
|
|
36
|
+
i += 1;
|
|
37
|
+
}
|
|
38
|
+
if (flags.verbose) {
|
|
39
|
+
this.log(JSON.stringify(deleted, null, 2));
|
|
40
|
+
}
|
|
41
|
+
this.logToStderr(`${i} assemblies deleted`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseCommand } from '../../baseCommand.js';
|
|
2
|
+
export default class Get extends BaseCommand<typeof Get> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static flags: {
|
|
6
|
+
assembly: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../baseCommand.js';
|
|
3
|
+
import { convertAssemblyNameToId, idReader, queryApollo, wrapLines, } from '../../utils.js';
|
|
4
|
+
export default class Get extends BaseCommand {
|
|
5
|
+
static summary = 'Get available assemblies';
|
|
6
|
+
static description = wrapLines('Print to stdout the list of assemblies in json format');
|
|
7
|
+
static flags = {
|
|
8
|
+
assembly: Flags.string({
|
|
9
|
+
char: 'a',
|
|
10
|
+
description: 'Get assemblies in this list of names or IDs',
|
|
11
|
+
multiple: true,
|
|
12
|
+
}),
|
|
13
|
+
};
|
|
14
|
+
async run() {
|
|
15
|
+
const { flags } = await this.parse(Get);
|
|
16
|
+
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
17
|
+
const assemblies = await queryApollo(access.address, access.accessToken, 'assemblies');
|
|
18
|
+
let assemblyIds = [];
|
|
19
|
+
if (flags.assembly !== undefined) {
|
|
20
|
+
const assembly = idReader(flags.assembly);
|
|
21
|
+
assemblyIds = await convertAssemblyNameToId(access.address, access.accessToken, assembly);
|
|
22
|
+
}
|
|
23
|
+
const json = (await assemblies.json());
|
|
24
|
+
const keep = [];
|
|
25
|
+
for (const x of json) {
|
|
26
|
+
if (flags.assembly === undefined ||
|
|
27
|
+
assemblyIds.includes(x['_id'])) {
|
|
28
|
+
keep.push(x);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
this.log(JSON.stringify(keep, null, 2));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { expect, test } from '@oclif/test';
|
|
5
|
+
import { CONFIG_FILE, TEST_DATA_DIR, VERBOSE, copyFile, } from '../../test/fixtures.js';
|
|
6
|
+
// import nock from 'nock'
|
|
7
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
8
|
+
describe.skip('apollo assembly get: Fail without token', () => {
|
|
9
|
+
before(() => {
|
|
10
|
+
copyFile(`${TEST_DATA_DIR}/guest.yaml`, CONFIG_FILE, VERBOSE);
|
|
11
|
+
});
|
|
12
|
+
after(() => {
|
|
13
|
+
fs.rmSync(CONFIG_FILE);
|
|
14
|
+
});
|
|
15
|
+
const cmd = ['assembly:get'];
|
|
16
|
+
test
|
|
17
|
+
.stderr()
|
|
18
|
+
.command(cmd, { root: dirname(dirname(__dirname)) })
|
|
19
|
+
.exit(1)
|
|
20
|
+
.do((output) => expect(output.stderr).to.contain('Profile "default" has no access token'))
|
|
21
|
+
.do((output) => expect(output.stderr).to.not.contain(' at async ')) // Don't print error stack
|
|
22
|
+
.it(cmd.join(' '));
|
|
23
|
+
});
|
|
24
|
+
// TODO: Need valid token
|
|
25
|
+
describe.skip('apollo assembly get: Get assemblies as YAML string', () => {
|
|
26
|
+
before(() => {
|
|
27
|
+
copyFile(`${TEST_DATA_DIR}/complete_config.yaml`, CONFIG_FILE, VERBOSE);
|
|
28
|
+
});
|
|
29
|
+
after(() => {
|
|
30
|
+
fs.rmSync(CONFIG_FILE);
|
|
31
|
+
});
|
|
32
|
+
const cmd = ['assembly:get'];
|
|
33
|
+
test
|
|
34
|
+
.stdout()
|
|
35
|
+
.command(cmd, { root: dirname(dirname(__dirname)) })
|
|
36
|
+
.it(cmd.join(' '), (output) => {
|
|
37
|
+
JSON.parse(output.stdout);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe.skip('apollo assembly get: Test nock', () => {
|
|
41
|
+
const cmd = ['assembly:get', '--config-file', 'tmp.yaml'];
|
|
42
|
+
test
|
|
43
|
+
.stdout()
|
|
44
|
+
.nock('http://127.0.0.1:3999', (api) => api.persist().get('/assemblies').reply(200, { stuff: 'foo' }))
|
|
45
|
+
.command(cmd, { root: dirname(dirname(__dirname)) })
|
|
46
|
+
.it(cmd.join(' '), (output) => {
|
|
47
|
+
console.error(output.stdout);
|
|
48
|
+
// const out = JSON.parse(output.stdout)
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseCommand } from '../../baseCommand.js';
|
|
2
|
+
export default class ApolloCmd extends BaseCommand<typeof ApolloCmd> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: {
|
|
6
|
+
description: string;
|
|
7
|
+
command: string;
|
|
8
|
+
}[];
|
|
9
|
+
static flags: {
|
|
10
|
+
assembly: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
+
refseq: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
|
+
start: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
13
|
+
end: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
14
|
+
};
|
|
15
|
+
run(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
3
|
+
import { Flags } from '@oclif/core';
|
|
4
|
+
import { fetch } from 'undici';
|
|
5
|
+
import { BaseCommand } from '../../baseCommand.js';
|
|
6
|
+
import { createFetchErrorMessage, getRefseqId, idReader, localhostToAddress, queryApollo, wrapLines, } from '../../utils.js';
|
|
7
|
+
async function getSequence(address, accessToken, refSeq, start, end) {
|
|
8
|
+
const url = new URL(localhostToAddress(`${address}/sequence`));
|
|
9
|
+
const searchParams = new URLSearchParams({
|
|
10
|
+
refSeq,
|
|
11
|
+
start: start.toString(),
|
|
12
|
+
end: end.toString(),
|
|
13
|
+
});
|
|
14
|
+
url.search = searchParams.toString();
|
|
15
|
+
const uri = url.toString();
|
|
16
|
+
const controller = new AbortController();
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
controller.abort();
|
|
19
|
+
}, 24 * 60 * 60 * 1000);
|
|
20
|
+
const auth = {
|
|
21
|
+
headers: {
|
|
22
|
+
authorization: `Bearer ${accessToken}`,
|
|
23
|
+
},
|
|
24
|
+
signal: controller.signal,
|
|
25
|
+
};
|
|
26
|
+
const response = await fetch(uri, auth);
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
const errorMessage = await createFetchErrorMessage(response, 'getSequence failed');
|
|
29
|
+
throw new Error(errorMessage);
|
|
30
|
+
}
|
|
31
|
+
return response;
|
|
32
|
+
}
|
|
33
|
+
export default class ApolloCmd extends BaseCommand {
|
|
34
|
+
static summary = 'Get reference sequence in fasta format';
|
|
35
|
+
static description = wrapLines('Return the reference sequence for a given assembly and coordinates');
|
|
36
|
+
static examples = [
|
|
37
|
+
{
|
|
38
|
+
description: 'Get all sequences in myAssembly:',
|
|
39
|
+
command: '<%= config.bin %> <%= command.id %> -a myAssembly',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
description: 'Get sequence in coordinates chr1:1..1000:',
|
|
43
|
+
command: '<%= config.bin %> <%= command.id %> -a myAssembly -r chr1 -s 1 -e 1000',
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
static flags = {
|
|
47
|
+
assembly: Flags.string({
|
|
48
|
+
char: 'a',
|
|
49
|
+
description: 'Find input reference sequence in this assembly',
|
|
50
|
+
}),
|
|
51
|
+
refseq: Flags.string({
|
|
52
|
+
char: 'r',
|
|
53
|
+
description: 'Reference sequence. If unset, get all sequences',
|
|
54
|
+
}),
|
|
55
|
+
start: Flags.integer({
|
|
56
|
+
char: 's',
|
|
57
|
+
description: 'Start coordinate (1-based)',
|
|
58
|
+
default: 1,
|
|
59
|
+
}),
|
|
60
|
+
end: Flags.integer({
|
|
61
|
+
char: 'e',
|
|
62
|
+
description: 'End coordinate',
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
async run() {
|
|
66
|
+
const { flags } = await this.parse(ApolloCmd);
|
|
67
|
+
const endCoord = flags.end ?? Number.MAX_SAFE_INTEGER;
|
|
68
|
+
if (flags.start <= 0 || endCoord <= 0) {
|
|
69
|
+
this.logToStderr('Start and end coordinates must be greater than 0.');
|
|
70
|
+
this.exit(1);
|
|
71
|
+
}
|
|
72
|
+
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
73
|
+
let assembly = undefined;
|
|
74
|
+
if (flags.assembly !== undefined) {
|
|
75
|
+
;
|
|
76
|
+
[assembly] = idReader([flags.assembly]);
|
|
77
|
+
}
|
|
78
|
+
let refseqIds = [];
|
|
79
|
+
try {
|
|
80
|
+
refseqIds = await getRefseqId(access.address, access.accessToken, flags.refseq, assembly);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
this.logToStderr(error.message);
|
|
84
|
+
this.exit(1);
|
|
85
|
+
}
|
|
86
|
+
if (refseqIds.length === 0) {
|
|
87
|
+
this.logToStderr('No reference sequence found');
|
|
88
|
+
this.exit(1);
|
|
89
|
+
}
|
|
90
|
+
const refs = await queryApollo(access.address, access.accessToken, 'refSeqs');
|
|
91
|
+
const refSeqs = (await refs.json());
|
|
92
|
+
for (const rid of refseqIds) {
|
|
93
|
+
const res = await getSequence(access.address, access.accessToken, rid, flags.start - 1, endCoord);
|
|
94
|
+
const seqObj = await res.body?.getReader().read();
|
|
95
|
+
const seq = new TextDecoder().decode(seqObj?.value);
|
|
96
|
+
let header = '';
|
|
97
|
+
for (const x of refSeqs) {
|
|
98
|
+
if (x['_id'] === rid) {
|
|
99
|
+
const rname = x['name'];
|
|
100
|
+
header = `>${rname}:${flags.start}..${flags.start + seq.length - 1}`;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
this.log(header);
|
|
105
|
+
this.log(splitStringIntoChunks(seq, 80).join('\n'));
|
|
106
|
+
}
|
|
107
|
+
this.exit(0);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function splitStringIntoChunks(input, chunkSize) {
|
|
111
|
+
const chunks = [];
|
|
112
|
+
for (let i = 0; i < input.length; i += chunkSize) {
|
|
113
|
+
const chunk = input.slice(i, i + chunkSize);
|
|
114
|
+
chunks.push(chunk);
|
|
115
|
+
}
|
|
116
|
+
return chunks;
|
|
117
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseCommand } from '../../baseCommand.js';
|
|
2
|
+
export default class Get extends BaseCommand<typeof Get> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static flags: {
|
|
6
|
+
assembly: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
7
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../baseCommand.js';
|
|
3
|
+
import { convertAssemblyNameToId, idReader, queryApollo, wrapLines, } from '../../utils.js';
|
|
4
|
+
export default class Get extends BaseCommand {
|
|
5
|
+
static summary = 'Get list of changes';
|
|
6
|
+
static description = wrapLines('Return the change log in json format. Note \
|
|
7
|
+
that when an assembly is deleted the link between common name and ID is lost \
|
|
8
|
+
(it can still be recovered by inspecting the change log but at present this task is left to the user). \
|
|
9
|
+
In such cases you need to use the assembly ID.');
|
|
10
|
+
static flags = {
|
|
11
|
+
assembly: Flags.string({
|
|
12
|
+
char: 'a',
|
|
13
|
+
multiple: true,
|
|
14
|
+
description: 'Get changes only for these assembly names or IDs (but see description)',
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
async run() {
|
|
18
|
+
const { flags } = await this.parse(Get);
|
|
19
|
+
const access = await this.getAccess(flags['config-file'], flags.profile);
|
|
20
|
+
const changes = await queryApollo(access.address, access.accessToken, 'changes');
|
|
21
|
+
const json = (await changes.json());
|
|
22
|
+
let keep = json;
|
|
23
|
+
if (flags.assembly !== undefined) {
|
|
24
|
+
keep = [];
|
|
25
|
+
const assembly = idReader(flags.assembly);
|
|
26
|
+
const assemblyIds = await convertAssemblyNameToId(access.address, access.accessToken, assembly);
|
|
27
|
+
for (const x of json) {
|
|
28
|
+
if (assemblyIds.includes(x['assembly'])) {
|
|
29
|
+
keep.push(x);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
this.log(JSON.stringify(keep, null, 2));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { test } from '@oclif/test';
|
|
5
|
+
import { CONFIG_FILE, TEST_DATA_DIR, VERBOSE, copyFile, } from '../../test/fixtures.js';
|
|
6
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
7
|
+
// TODO: Need valid token
|
|
8
|
+
describe.skip('apollo change get: Get changes as YAML string', () => {
|
|
9
|
+
before(() => {
|
|
10
|
+
copyFile(`${TEST_DATA_DIR}/complete_config.yaml`, CONFIG_FILE, VERBOSE);
|
|
11
|
+
});
|
|
12
|
+
after(() => {
|
|
13
|
+
fs.rmSync(CONFIG_FILE);
|
|
14
|
+
});
|
|
15
|
+
const cmd = ['change:get'];
|
|
16
|
+
test
|
|
17
|
+
.stdout()
|
|
18
|
+
.command(cmd, { root: dirname(dirname(__dirname)) })
|
|
19
|
+
.it(cmd.join(' '), (output) => {
|
|
20
|
+
JSON.parse(output.stdout);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseCommand } from '../baseCommand.js';
|
|
2
|
+
export default class ApolloConfig extends BaseCommand<typeof ApolloConfig> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static args: {
|
|
6
|
+
key: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
|
|
7
|
+
value: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
|
|
8
|
+
};
|
|
9
|
+
static flags: {
|
|
10
|
+
profile: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
+
'get-config-file': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
12
|
+
};
|
|
13
|
+
static examples: {
|
|
14
|
+
description: string;
|
|
15
|
+
command: string;
|
|
16
|
+
}[];
|
|
17
|
+
run(): Promise<void>;
|
|
18
|
+
private interactiveSetup;
|
|
19
|
+
private askProfileName;
|
|
20
|
+
private askPassword;
|
|
21
|
+
private askUsername;
|
|
22
|
+
private askAddress;
|
|
23
|
+
private selectAccessType;
|
|
24
|
+
private getLoginTypes;
|
|
25
|
+
}
|