From 43b57859a6430670db0c7ecebd582c1db751f054 Mon Sep 17 00:00:00 2001 From: dariober Date: Tue, 11 Feb 2025 15:14:38 +0000 Subject: [PATCH] Include comments here https://github.com/GMOD/Apollo3/pull/511#pullrequestreview-2607168267 Use includeFASTA instead of withFasta and --include-fasta instead of --with-fasta in cli --- .github/workflows/pull_request.yml | 2 +- packages/apollo-cli/README.md | 12 +++++----- packages/apollo-cli/package.json | 1 + .../apollo-cli/src/commands/export/gff3.ts | 15 +++++++----- packages/apollo-cli/src/test/test.ts | 12 +++++----- .../src/export/export.controller.ts | 23 +++++++++---------- .../src/export/export.service.ts | 8 +++---- .../src/components/DownloadGFF3.tsx | 2 +- packages/website/docs/admin/cli/export.md | 12 +++++----- 9 files changed, 45 insertions(+), 42 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 6130f2f7..9bccdea2 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -42,7 +42,7 @@ jobs: yarn --cwd packages/apollo-shared start & ALLOW_ROOT_USER=true ROOT_USER_PASSWORD=pass yarn --cwd packages/apollo-collaboration-server start & - name: Run CLI tests - run: yarn tsx src/test/test.ts + run: yarn test:cli working-directory: packages/apollo-cli # - name: Run docker tests # working-directory: packages/apollo-cli diff --git a/packages/apollo-cli/README.md b/packages/apollo-cli/README.md index b3d51c60..126b2acb 100644 --- a/packages/apollo-cli/README.md +++ b/packages/apollo-cli/README.md @@ -352,25 +352,25 @@ _See code: ## `apollo export gff3 ASSEMBLY` -Export the annotation of an assembly to stdout as gff3 +Export the annotations for an assembly to stdout as gff3 ``` USAGE - $ apollo export gff3 ASSEMBLY [--profile ] [--config-file ] [--with-fasta] + $ apollo export gff3 ASSEMBLY [--profile ] [--config-file ] [--include-fasta] ARGUMENTS - ASSEMBLY Export features for this assembly name or id + ASSEMBLY Export annotations for this assembly name or id FLAGS --config-file= Use this config file (mostly for testing) + --include-fasta Include fasta sequence in output --profile= Use credentials from this profile - --with-fasta Append fasta sequence to output DESCRIPTION - Export the annotation of an assembly to stdout as gff3 + Export the annotations for an assembly to stdout as gff3 EXAMPLES - Export annotation for myAssembly: + Export annotations for myAssembly: $ apollo export gff3 myAssembly > out.gff3 ``` diff --git a/packages/apollo-cli/package.json b/packages/apollo-cli/package.json index 45489f2a..e1c70bbc 100644 --- a/packages/apollo-cli/package.json +++ b/packages/apollo-cli/package.json @@ -29,6 +29,7 @@ "test": "mocha --require src/test/fixtures.ts 'src/**/*.test.ts'", "posttest": "yarn lint", "test:ci": "nyc mocha 'src/**/*.test.ts'", + "test:cli": "yarn tsx src/test/test.ts", "version": "oclif readme --multi --dir ../website/docs/admin/cli/ && oclif readme && git add README.md" }, "oclif": { diff --git a/packages/apollo-cli/src/commands/export/gff3.ts b/packages/apollo-cli/src/commands/export/gff3.ts index a40925fa..83d64b66 100644 --- a/packages/apollo-cli/src/commands/export/gff3.ts +++ b/packages/apollo-cli/src/commands/export/gff3.ts @@ -12,25 +12,26 @@ import { import { Readable } from 'node:stream' export default class Get extends BaseCommand { - static description = 'Export the annotation of an assembly to stdout as gff3' + static description = + 'Export the annotations for an assembly to stdout as gff3' static examples = [ { - description: 'Export annotation for myAssembly:', + description: 'Export annotations for myAssembly:', command: '<%= config.bin %> <%= command.id %> myAssembly > out.gff3', }, ] static args = { assembly: Args.string({ - description: 'Export features for this assembly name or id', + description: 'Export annotations for this assembly name or id', required: true, }), } static flags = { - 'with-fasta': Flags.boolean({ - description: 'Append fasta sequence to output', + 'include-fasta': Flags.boolean({ + description: 'Include fasta sequence in output', default: false, }), } @@ -77,7 +78,7 @@ export default class Get extends BaseCommand { const params: Record = { exportID, assemblyId, - withFasta: this.flags['with-fasta'] ? 'True' : 'False', + includeFASTA: this.flags['include-fasta'] ? 'true' : 'false', } const exportSearchParams = new URLSearchParams(params) exportURL.search = exportSearchParams.toString() @@ -95,6 +96,8 @@ export default class Get extends BaseCommand { if (body) { const readable = Readable.from(body) readable.pipe(process.stdout) + } else { + this.error('Failed to export gff3') } } } diff --git a/packages/apollo-cli/src/test/test.ts b/packages/apollo-cli/src/test/test.ts index 859d5504..e8f990fe 100644 --- a/packages/apollo-cli/src/test/test.ts +++ b/packages/apollo-cli/src/test/test.ts @@ -9,7 +9,7 @@ * USAGE * From package root directory (`packages/apollo-cli`). Run all tests: * - * yarn tsx src/test/test.ts + * yarn test:cli * * Run only matching pattern: * @@ -1371,7 +1371,7 @@ void describe('Test CLI', () => { `${apollo} assembly add-from-fasta ${P} test_data/tiny.fasta.gz -a vv1 -f --editable`, ) new Shell(`${apollo} feature import ${P} test_data/tiny.fasta.gff3 -a vv1`) - let p = new Shell(`${apollo} export gff3 ${P} vv1 --with-fasta`) + let p = new Shell(`${apollo} export gff3 ${P} vv1 --include-fasta`) let gff = p.stdout assert.ok(gff.startsWith('##gff-version 3')) assert.ok(gff.includes('multivalue=val1,val2,val3')) @@ -1395,12 +1395,12 @@ void describe('Test CLI', () => { `${apollo} assembly add-from-fasta ${P} test_data/tiny.fasta.gz -a vv1 -f`, ) new Shell(`${apollo} feature import ${P} test_data/tiny.fasta.gff3 -a vv1`) - let p = new Shell(`${apollo} export gff3 ${P} vv1 --with-fasta`) + let p = new Shell(`${apollo} export gff3 ${P} vv1 --include-fasta`) let gff = p.stdout assert.ok(gff.startsWith('##gff-version 3')) assert.ok(gff.includes('multivalue=val1,val2,val3')) assert.ok(gff.includes('##FASTA\n')) - // We have end with two newlines because the test data does have an extra newline at the end. + // We end with two newlines because the test data does have an extra newline at the end. assert.deepStrictEqual(gff.slice(-7, gff.length), 'taccc\n\n') p = new Shell(`${apollo} export gff3 ${P} vv1`) @@ -1415,12 +1415,12 @@ void describe('Test CLI', () => { `${apollo} assembly add-from-fasta ${P} https://raw.githubusercontent.com/GMOD/Apollo3/refs/heads/main/packages/apollo-cli/test_data/tiny.fasta.gz -a vv1 -f`, ) new Shell(`${apollo} feature import ${P} test_data/tiny.fasta.gff3 -a vv1`) - let p = new Shell(`${apollo} export gff3 ${P} vv1 --with-fasta`) + let p = new Shell(`${apollo} export gff3 ${P} vv1 --include-fasta`) let gff = p.stdout assert.ok(gff.startsWith('##gff-version 3')) assert.ok(gff.includes('multivalue=val1,val2,val3')) assert.ok(gff.includes('##FASTA\n')) - // We have end with two newlines because the test data does have an extra newline at the end. + // We end with two newlines because the test data does have an extra newline at the end. assert.deepStrictEqual(gff.slice(-7, gff.length), 'taccc\n\n') p = new Shell(`${apollo} export gff3 ${P} vv1`) diff --git a/packages/apollo-collaboration-server/src/export/export.controller.ts b/packages/apollo-collaboration-server/src/export/export.controller.ts index ffabbb50..dfc524e8 100644 --- a/packages/apollo-collaboration-server/src/export/export.controller.ts +++ b/packages/apollo-collaboration-server/src/export/export.controller.ts @@ -1,8 +1,11 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { Controller, + DefaultValuePipe, Get, Logger, + ParseBoolPipe, + ParseIntPipe, Query, Response, StreamableFile, @@ -41,21 +44,17 @@ export class ExportController { @Validations(Role.None) @Get() async exportGFF3( - @Query() - request: { - exportID: string - withFasta: 'True' | 'False' - fastaWidth?: number - }, + // @Query() + @Query('exportID') exportID: string, + @Query('includeFASTA', new DefaultValuePipe(false), ParseBoolPipe) + includeFASTA: boolean, + @Query('fastaWidth', new DefaultValuePipe(80), ParseIntPipe) + fastaWidth: number, @Response({ passthrough: true }) res: ExpressResponse, ) { - const { exportID, withFasta, ...rest } = request - if (!['True', 'False'].includes(withFasta)) { - throw new Error(`withFasta must be "True" or "False", got: ${withFasta}`) - } const [stream, assembly] = await this.exportService.exportGFF3(exportID, { - withFasta: withFasta === 'True', - ...rest, + includeFASTA, + fastaWidth, }) const assemblyName = await this.exportService.getAssemblyName(assembly) res.set({ diff --git a/packages/apollo-collaboration-server/src/export/export.service.ts b/packages/apollo-collaboration-server/src/export/export.service.ts index f21ad3bc..a60283bb 100644 --- a/packages/apollo-collaboration-server/src/export/export.service.ts +++ b/packages/apollo-collaboration-server/src/export/export.service.ts @@ -153,13 +153,13 @@ export class ExportService { async exportGFF3( exportID: string, - opts: { withFasta?: boolean; fastaWidth?: number }, + opts: { includeFASTA?: boolean; fastaWidth?: number }, ): Promise<[Readable, string]> { const exportDoc = await this.exportModel.findById(exportID) if (!exportDoc) { throw new NotFoundException() } - const { fastaWidth, withFasta } = opts + const { fastaWidth, includeFASTA } = opts const { assembly } = exportDoc const refSeqs = await this.refSeqModel.find({ assembly }).exec() const refSeqIds = refSeqs.map((refSeq) => refSeq._id) @@ -212,14 +212,14 @@ export class ExportService { gff.formatStream({ insertVersionDirective: true }), (error) => { if (error) { - this.logger.error('GFF3 export failed here') + this.logger.error('GFF3 export failed') this.logger.error(error) } }, ) let sequenceStream: Readable[] = [] - if (withFasta) { + if (includeFASTA) { const assemblyDoc = await this.assemblyModel.findById(assembly.toString()) if (!assemblyDoc) { throw new Error( diff --git a/packages/jbrowse-plugin-apollo/src/components/DownloadGFF3.tsx b/packages/jbrowse-plugin-apollo/src/components/DownloadGFF3.tsx index 269d3993..55e4fc01 100644 --- a/packages/jbrowse-plugin-apollo/src/components/DownloadGFF3.tsx +++ b/packages/jbrowse-plugin-apollo/src/components/DownloadGFF3.tsx @@ -113,7 +113,7 @@ export function DownloadGFF3({ handleClose, session }: DownloadGFF3Props) { const exportURL = new URL('export', internetAccount.baseURL) const params: Record = { exportID, - withFasta: 'True', + includeFASTA: 'true', } const exportSearchParams = new URLSearchParams(params) exportURL.search = exportSearchParams.toString() diff --git a/packages/website/docs/admin/cli/export.md b/packages/website/docs/admin/cli/export.md index 6a4ba679..7877f3c0 100644 --- a/packages/website/docs/admin/cli/export.md +++ b/packages/website/docs/admin/cli/export.md @@ -6,25 +6,25 @@ Commands to export data ## `apollo export gff3 ASSEMBLY` -Export the annotation of an assembly to stdout as gff3 +Export the annotations for an assembly to stdout as gff3 ``` USAGE - $ apollo export gff3 ASSEMBLY [--profile ] [--config-file ] [--with-fasta] + $ apollo export gff3 ASSEMBLY [--profile ] [--config-file ] [--include-fasta] ARGUMENTS - ASSEMBLY Export features for this assembly name or id + ASSEMBLY Export annotations for this assembly name or id FLAGS --config-file= Use this config file (mostly for testing) + --include-fasta Include fasta sequence in output --profile= Use credentials from this profile - --with-fasta Append fasta sequence to output DESCRIPTION - Export the annotation of an assembly to stdout as gff3 + Export the annotations for an assembly to stdout as gff3 EXAMPLES - Export annotation for myAssembly: + Export annotations for myAssembly: $ apollo export gff3 myAssembly > out.gff3 ```