Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bmesuere committed Jun 17, 2024
1 parent 691bda3 commit bff18e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

30 changes: 23 additions & 7 deletions bin/uniprot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import { Option, program } from 'commander';
import { createInterface } from 'node:readline';
import { version } from '../package.json';

const VALID_FORMATS = ["fasta", "gff", "json", "rdf", "sequence", "xml"];

program
.version("1.0.0")
.summary("Command line interface to UniProt web services.")
.description(`Command line interface to UniProt web services.
const description = `Command line interface to UniProt web services.
The uniprot command fetches UniProt entries from the UniProt web services. The command expects a list of UniProt Accession Numbers that are passed
Expand All @@ -17,27 +15,45 @@ The uniprot command fetches UniProt entries from the UniProt web services. The c
The command will give priority to the first way UniProt Accession Numbers are passed, in the order as listed above. The standard input should have one UniProt Accession Number per line.
The uniprot command yields just the protein sequences as a default, but can return several formats.`)
The uniprot command yields just the protein sequences as a default, but can return several formats.`;

program
.version(version)
.summary("Command line interface to UniProt web services.")
.description(description)
.argument("[accessions...]", "UniProt Accession Numbers")
.addOption(new Option("-f, --format <format>", `output format`).choices(VALID_FORMATS).default("sequence"));

program.parse(process.argv);
const format = program.opts().format;
const accessions = program.args;

if (accessions.length !== 0) {
if (accessions.length !== 0) { // input from command line arguments
accessions.forEach(processUniprotEntry);
} else {
} else { // input from standard input
for await (const line of createInterface({ input: process.stdin })) {
processUniprotEntry(line.trim());
};
}

/**
* Fetches a UniProt entry and writes it to standard output.
*
* @param accession UniProt Accession Number
*/
async function processUniprotEntry(accession: string) {
process.stdout.write(await getUniprotEntry(accession, format) + "\n");
}

/**
* Fetches a UniProt entry in the requested format.
*
* @param accession UniProt Accession Number
* @param format output format
* @returns UniProt entry in the requested format
*/
async function getUniprotEntry(accession: string, format: string): Promise<string> {
// The UniProt REST API does not support the "sequence" format, so fetch fasta and remove the header
if (format === "sequence") {
return (await getUniprotEntry(accession, "fasta"))
.split("\n")
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"outDir": "./dist",
"module": "NodeNext",
"strict": true
"strict": true,
"resolveJsonModule": true
}
}

0 comments on commit bff18e9

Please sign in to comment.