-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
4 changed files
with
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,5 @@ pkg | |
|
||
# For rubinius: | ||
#*.rbc | ||
|
||
node_modules/** |
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,53 @@ | ||
import { Option, program } from 'commander'; | ||
import { createInterface } from 'node:readline'; | ||
|
||
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. | ||
The uniprot command fetches UniProt entries from the UniProt web services. The command expects a list of UniProt Accession Numbers that are passed | ||
- as separate command line arguments | ||
- to standard input | ||
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.`) | ||
.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) { | ||
accessions.forEach(processUniprotEntry); | ||
} else { | ||
for await (const line of createInterface({ input: process.stdin })) { | ||
processUniprotEntry(line.trim()); | ||
}; | ||
} | ||
|
||
async function processUniprotEntry(accession) { | ||
process.stdout.write(await getUniprotEntry(accession, format) + "\n"); | ||
} | ||
|
||
async function getUniprotEntry(accession, format) { | ||
if (format === "sequence") { | ||
return (await getUniprotEntry(accession, "fasta")) | ||
.split("\n") | ||
.slice(1) | ||
.join(""); | ||
} else { | ||
const r = await fetch(`https://rest.uniprot.org/uniprotkb/${accession}.${format}`); | ||
if (r.ok) { | ||
return r.text(); | ||
} else { | ||
process.stderr.write(`Error fetching ${accession}: ${r.status} ${r.statusText}\n`); | ||
return ""; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6,5 +6,9 @@ | |
"repository": "[email protected]:unipept/unipept-cli.git", | ||
"author": "Bart Mesuere <[email protected]>", | ||
"license": "MIT", | ||
"private": false | ||
"private": false, | ||
"type": "module", | ||
"dependencies": { | ||
"commander": "^12.1.0" | ||
} | ||
} |
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,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
commander@^12.1.0: | ||
version "12.1.0" | ||
resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3" | ||
integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA== |