Skip to content

Commit

Permalink
Include comments here #511 (review)
Browse files Browse the repository at this point in the history
Use includeFASTA instead of withFasta and --include-fasta instead of
--with-fasta in cli
  • Loading branch information
dariober committed Feb 11, 2025
1 parent 0c1cdac commit 43b5785
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions packages/apollo-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <value>] [--config-file <value>] [--with-fasta]
$ apollo export gff3 ASSEMBLY [--profile <value>] [--config-file <value>] [--include-fasta]
ARGUMENTS
ASSEMBLY Export features for this assembly name or id
ASSEMBLY Export annotations for this assembly name or id
FLAGS
--config-file=<value> Use this config file (mostly for testing)
--include-fasta Include fasta sequence in output
--profile=<value> 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
```
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
15 changes: 9 additions & 6 deletions packages/apollo-cli/src/commands/export/gff3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ import {
import { Readable } from 'node:stream'

export default class Get extends BaseCommand<typeof Get> {
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,
}),
}
Expand Down Expand Up @@ -77,7 +78,7 @@ export default class Get extends BaseCommand<typeof Get> {
const params: Record<string, string> = {
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()
Expand All @@ -95,6 +96,8 @@ export default class Get extends BaseCommand<typeof Get> {
if (body) {
const readable = Readable.from(body)
readable.pipe(process.stdout)
} else {
this.error('Failed to export gff3')
}
}
}
12 changes: 6 additions & 6 deletions packages/apollo-cli/src/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -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'))
Expand All @@ -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`)
Expand All @@ -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`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import {
Controller,
DefaultValuePipe,
Get,
Logger,
ParseBoolPipe,
ParseIntPipe,
Query,
Response,
StreamableFile,
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function DownloadGFF3({ handleClose, session }: DownloadGFF3Props) {
const exportURL = new URL('export', internetAccount.baseURL)
const params: Record<string, string> = {
exportID,
withFasta: 'True',
includeFASTA: 'true',
}
const exportSearchParams = new URLSearchParams(params)
exportURL.search = exportSearchParams.toString()
Expand Down
12 changes: 6 additions & 6 deletions packages/website/docs/admin/cli/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <value>] [--config-file <value>] [--with-fasta]
$ apollo export gff3 ASSEMBLY [--profile <value>] [--config-file <value>] [--include-fasta]
ARGUMENTS
ASSEMBLY Export features for this assembly name or id
ASSEMBLY Export annotations for this assembly name or id
FLAGS
--config-file=<value> Use this config file (mostly for testing)
--include-fasta Include fasta sequence in output
--profile=<value> 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
```
Expand Down

0 comments on commit 43b5785

Please sign in to comment.