From 52f0494d282880c8f78199a435c6eee1c4c8f7c6 Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Mon, 17 Jun 2024 14:42:08 +0200 Subject: [PATCH 1/7] require node 22 to use fetch --- .nvmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..2bd5a0a9 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22 From 02c2af5e94c6ede3e48be7cb8c045606d96cb3ad Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Mon, 17 Jun 2024 14:44:32 +0200 Subject: [PATCH 2/7] yarn init --- package.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 00000000..5e12f37a --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "name": "unipept-cli", + "version": "4.0.0", + "description": "Command line interface to the Unipept web services", + "main": "index.js", + "repository": "git@github.com:unipept/unipept-cli.git", + "author": "Bart Mesuere ", + "license": "MIT", + "private": false +} From 49b56815cd848f4b558fa2f7601c3d93c04ddb9e Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Mon, 17 Jun 2024 16:07:08 +0200 Subject: [PATCH 3/7] get basic version working --- .gitignore | 2 ++ index.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 6 +++++- yarn.lock | 8 ++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 index.js create mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore index bd5f33a8..fb549fa7 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ pkg # For rubinius: #*.rbc + +node_modules/** diff --git a/index.js b/index.js new file mode 100644 index 00000000..293bd307 --- /dev/null +++ b/index.js @@ -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 ", `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 ""; + } + } +} diff --git a/package.json b/package.json index 5e12f37a..e07702f5 100644 --- a/package.json +++ b/package.json @@ -6,5 +6,9 @@ "repository": "git@github.com:unipept/unipept-cli.git", "author": "Bart Mesuere ", "license": "MIT", - "private": false + "private": false, + "type": "module", + "dependencies": { + "commander": "^12.1.0" + } } diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 00000000..d082ea04 --- /dev/null +++ b/yarn.lock @@ -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== From f1222746086b964b6749bdc0f6c0cf585e04268a Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Mon, 17 Jun 2024 16:18:10 +0200 Subject: [PATCH 4/7] move to bin folder --- index.js => bin/uniprot.js | 2 ++ package.json | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) rename index.js => bin/uniprot.js (98%) mode change 100644 => 100755 diff --git a/index.js b/bin/uniprot.js old mode 100644 new mode 100755 similarity index 98% rename from index.js rename to bin/uniprot.js index 293bd307..6918d6ad --- a/index.js +++ b/bin/uniprot.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + import { Option, program } from 'commander'; import { createInterface } from 'node:readline'; diff --git a/package.json b/package.json index e07702f5..fec1e02a 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,14 @@ "name": "unipept-cli", "version": "4.0.0", "description": "Command line interface to the Unipept web services", - "main": "index.js", "repository": "git@github.com:unipept/unipept-cli.git", "author": "Bart Mesuere ", "license": "MIT", "private": false, "type": "module", + "bin": { + "uniprot": "./bin/uniprot.js" + }, "dependencies": { "commander": "^12.1.0" } From 691bda3f84a2b0fe80c65c1179e453103f7634f8 Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Mon, 17 Jun 2024 17:06:15 +0200 Subject: [PATCH 5/7] move to typescript --- .gitignore | 1 + bin/{uniprot.js => uniprot.ts} | 4 +- package.json | 8 ++ tsconfig.json | 10 ++ yarn.lock | 188 +++++++++++++++++++++++++++++++++ 5 files changed, 209 insertions(+), 2 deletions(-) rename bin/{uniprot.js => uniprot.ts} (92%) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index fb549fa7..bc79950e 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ pkg #*.rbc node_modules/** +dist/** diff --git a/bin/uniprot.js b/bin/uniprot.ts similarity index 92% rename from bin/uniprot.js rename to bin/uniprot.ts index 6918d6ad..8b1abfce 100755 --- a/bin/uniprot.js +++ b/bin/uniprot.ts @@ -33,11 +33,11 @@ if (accessions.length !== 0) { }; } -async function processUniprotEntry(accession) { +async function processUniprotEntry(accession: string) { process.stdout.write(await getUniprotEntry(accession, format) + "\n"); } -async function getUniprotEntry(accession, format) { +async function getUniprotEntry(accession: string, format: string): Promise { if (format === "sequence") { return (await getUniprotEntry(accession, "fasta")) .split("\n") diff --git a/package.json b/package.json index fec1e02a..94cac332 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,15 @@ "bin": { "uniprot": "./bin/uniprot.js" }, + "scripts": { + "build": "yarn run tsc" + }, "dependencies": { "commander": "^12.1.0" + }, + "devDependencies": { + "@types/node": "^20.14.2", + "tsx": "^4.15.6", + "typescript": "^5.4.5" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..b5f214f7 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "include": [ + "bin/**/*" + ], + "compilerOptions": { + "outDir": "./dist", + "module": "NodeNext", + "strict": true + } +} diff --git a/yarn.lock b/yarn.lock index d082ea04..f6423ed5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,7 +2,195 @@ # yarn lockfile v1 +"@esbuild/aix-ppc64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz#c7184a326533fcdf1b8ee0733e21c713b975575f" + integrity sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ== + +"@esbuild/android-arm64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/android-arm64/-/android-arm64-0.21.5.tgz#09d9b4357780da9ea3a7dfb833a1f1ff439b4052" + integrity sha512-c0uX9VAUBQ7dTDCjq+wdyGLowMdtR/GoC2U5IYk/7D1H1JYC0qseD7+11iMP2mRLN9RcCMRcjC4YMclCzGwS/A== + +"@esbuild/android-arm@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.21.5.tgz#9b04384fb771926dfa6d7ad04324ecb2ab9b2e28" + integrity sha512-vCPvzSjpPHEi1siZdlvAlsPxXl7WbOVUBBAowWug4rJHb68Ox8KualB+1ocNvT5fjv6wpkX6o/iEpbDrf68zcg== + +"@esbuild/android-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/android-x64/-/android-x64-0.21.5.tgz#29918ec2db754cedcb6c1b04de8cd6547af6461e" + integrity sha512-D7aPRUUNHRBwHxzxRvp856rjUHRFW1SdQATKXH2hqA0kAZb1hKmi02OpYRacl0TxIGz/ZmXWlbZgjwWYaCakTA== + +"@esbuild/darwin-arm64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz#e495b539660e51690f3928af50a76fb0a6ccff2a" + integrity sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ== + +"@esbuild/darwin-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/darwin-x64/-/darwin-x64-0.21.5.tgz#c13838fa57372839abdddc91d71542ceea2e1e22" + integrity sha512-se/JjF8NlmKVG4kNIuyWMV/22ZaerB+qaSi5MdrXtd6R08kvs2qCN4C09miupktDitvh8jRFflwGFBQcxZRjbw== + +"@esbuild/freebsd-arm64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/freebsd-arm64/-/freebsd-arm64-0.21.5.tgz#646b989aa20bf89fd071dd5dbfad69a3542e550e" + integrity sha512-5JcRxxRDUJLX8JXp/wcBCy3pENnCgBR9bN6JsY4OmhfUtIHe3ZW0mawA7+RDAcMLrMIZaf03NlQiX9DGyB8h4g== + +"@esbuild/freebsd-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/freebsd-x64/-/freebsd-x64-0.21.5.tgz#aa615cfc80af954d3458906e38ca22c18cf5c261" + integrity sha512-J95kNBj1zkbMXtHVH29bBriQygMXqoVQOQYA+ISs0/2l3T9/kj42ow2mpqerRBxDJnmkUDCaQT/dfNXWX/ZZCQ== + +"@esbuild/linux-arm64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-arm64/-/linux-arm64-0.21.5.tgz#70ac6fa14f5cb7e1f7f887bcffb680ad09922b5b" + integrity sha512-ibKvmyYzKsBeX8d8I7MH/TMfWDXBF3db4qM6sy+7re0YXya+K1cem3on9XgdT2EQGMu4hQyZhan7TeQ8XkGp4Q== + +"@esbuild/linux-arm@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-arm/-/linux-arm-0.21.5.tgz#fc6fd11a8aca56c1f6f3894f2bea0479f8f626b9" + integrity sha512-bPb5AHZtbeNGjCKVZ9UGqGwo8EUu4cLq68E95A53KlxAPRmUyYv2D6F0uUI65XisGOL1hBP5mTronbgo+0bFcA== + +"@esbuild/linux-ia32@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-ia32/-/linux-ia32-0.21.5.tgz#3271f53b3f93e3d093d518d1649d6d68d346ede2" + integrity sha512-YvjXDqLRqPDl2dvRODYmmhz4rPeVKYvppfGYKSNGdyZkA01046pLWyRKKI3ax8fbJoK5QbxblURkwK/MWY18Tg== + +"@esbuild/linux-loong64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.21.5.tgz#ed62e04238c57026aea831c5a130b73c0f9f26df" + integrity sha512-uHf1BmMG8qEvzdrzAqg2SIG/02+4/DHB6a9Kbya0XDvwDEKCoC8ZRWI5JJvNdUjtciBGFQ5PuBlpEOXQj+JQSg== + +"@esbuild/linux-mips64el@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-mips64el/-/linux-mips64el-0.21.5.tgz#e79b8eb48bf3b106fadec1ac8240fb97b4e64cbe" + integrity sha512-IajOmO+KJK23bj52dFSNCMsz1QP1DqM6cwLUv3W1QwyxkyIWecfafnI555fvSGqEKwjMXVLokcV5ygHW5b3Jbg== + +"@esbuild/linux-ppc64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-ppc64/-/linux-ppc64-0.21.5.tgz#5f2203860a143b9919d383ef7573521fb154c3e4" + integrity sha512-1hHV/Z4OEfMwpLO8rp7CvlhBDnjsC3CttJXIhBi+5Aj5r+MBvy4egg7wCbe//hSsT+RvDAG7s81tAvpL2XAE4w== + +"@esbuild/linux-riscv64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-riscv64/-/linux-riscv64-0.21.5.tgz#07bcafd99322d5af62f618cb9e6a9b7f4bb825dc" + integrity sha512-2HdXDMd9GMgTGrPWnJzP2ALSokE/0O5HhTUvWIbD3YdjME8JwvSCnNGBnTThKGEB91OZhzrJ4qIIxk/SBmyDDA== + +"@esbuild/linux-s390x@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-s390x/-/linux-s390x-0.21.5.tgz#b7ccf686751d6a3e44b8627ababc8be3ef62d8de" + integrity sha512-zus5sxzqBJD3eXxwvjN1yQkRepANgxE9lgOW2qLnmr8ikMTphkjgXu1HR01K4FJg8h1kEEDAqDcZQtbrRnB41A== + +"@esbuild/linux-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz#6d8f0c768e070e64309af8004bb94e68ab2bb3b0" + integrity sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ== + +"@esbuild/netbsd-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/netbsd-x64/-/netbsd-x64-0.21.5.tgz#bbe430f60d378ecb88decb219c602667387a6047" + integrity sha512-Woi2MXzXjMULccIwMnLciyZH4nCIMpWQAs049KEeMvOcNADVxo0UBIQPfSmxB3CWKedngg7sWZdLvLczpe0tLg== + +"@esbuild/openbsd-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/openbsd-x64/-/openbsd-x64-0.21.5.tgz#99d1cf2937279560d2104821f5ccce220cb2af70" + integrity sha512-HLNNw99xsvx12lFBUwoT8EVCsSvRNDVxNpjZ7bPn947b8gJPzeHWyNVhFsaerc0n3TsbOINvRP2byTZ5LKezow== + +"@esbuild/sunos-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/sunos-x64/-/sunos-x64-0.21.5.tgz#08741512c10d529566baba837b4fe052c8f3487b" + integrity sha512-6+gjmFpfy0BHU5Tpptkuh8+uw3mnrvgs+dSPQXQOv3ekbordwnzTVEb4qnIvQcYXq6gzkyTnoZ9dZG+D4garKg== + +"@esbuild/win32-arm64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/win32-arm64/-/win32-arm64-0.21.5.tgz#675b7385398411240735016144ab2e99a60fc75d" + integrity sha512-Z0gOTd75VvXqyq7nsl93zwahcTROgqvuAcYDUr+vOv8uHhNSKROyU961kgtCD1e95IqPKSQKH7tBTslnS3tA8A== + +"@esbuild/win32-ia32@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/win32-ia32/-/win32-ia32-0.21.5.tgz#1bfc3ce98aa6ca9a0969e4d2af72144c59c1193b" + integrity sha512-SWXFF1CL2RVNMaVs+BBClwtfZSvDgtL//G/smwAc5oVK/UPu2Gu9tIaRgFmYFFKrmg3SyAjSrElf0TiJ1v8fYA== + +"@esbuild/win32-x64@0.21.5": + version "0.21.5" + resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.21.5.tgz#acad351d582d157bb145535db2a6ff53dd514b5c" + integrity sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw== + +"@types/node@^20.14.2": + version "20.14.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.2.tgz#a5f4d2bcb4b6a87bffcaa717718c5a0f208f4a18" + integrity sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q== + dependencies: + undici-types "~5.26.4" + 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== + +esbuild@~0.21.4: + version "0.21.5" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.21.5.tgz#9ca301b120922959b766360d8ac830da0d02997d" + integrity sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw== + optionalDependencies: + "@esbuild/aix-ppc64" "0.21.5" + "@esbuild/android-arm" "0.21.5" + "@esbuild/android-arm64" "0.21.5" + "@esbuild/android-x64" "0.21.5" + "@esbuild/darwin-arm64" "0.21.5" + "@esbuild/darwin-x64" "0.21.5" + "@esbuild/freebsd-arm64" "0.21.5" + "@esbuild/freebsd-x64" "0.21.5" + "@esbuild/linux-arm" "0.21.5" + "@esbuild/linux-arm64" "0.21.5" + "@esbuild/linux-ia32" "0.21.5" + "@esbuild/linux-loong64" "0.21.5" + "@esbuild/linux-mips64el" "0.21.5" + "@esbuild/linux-ppc64" "0.21.5" + "@esbuild/linux-riscv64" "0.21.5" + "@esbuild/linux-s390x" "0.21.5" + "@esbuild/linux-x64" "0.21.5" + "@esbuild/netbsd-x64" "0.21.5" + "@esbuild/openbsd-x64" "0.21.5" + "@esbuild/sunos-x64" "0.21.5" + "@esbuild/win32-arm64" "0.21.5" + "@esbuild/win32-ia32" "0.21.5" + "@esbuild/win32-x64" "0.21.5" + +fsevents@~2.3.3: + version "2.3.3" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" + integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== + +get-tsconfig@^4.7.5: + version "4.7.5" + resolved "https://registry.yarnpkg.com/get-tsconfig/-/get-tsconfig-4.7.5.tgz#5e012498579e9a6947511ed0cd403272c7acbbaf" + integrity sha512-ZCuZCnlqNzjb4QprAzXKdpp/gh6KTxSJuw3IBsPnV/7fV4NxC9ckB+vPTt8w7fJA0TaSD7c55BR47JD6MEDyDw== + dependencies: + resolve-pkg-maps "^1.0.0" + +resolve-pkg-maps@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f" + integrity sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw== + +tsx@^4.15.6: + version "4.15.6" + resolved "https://registry.yarnpkg.com/tsx/-/tsx-4.15.6.tgz#4522ed093f7fa54f031a7a999274e8b35dbf3165" + integrity sha512-is0VQQlfNZRHEuSSTKA6m4xw74IU4AizmuB6lAYLRt9XtuyeQnyJYexhNZOPCB59SqC4JzmSzPnHGBXxf3k0hA== + dependencies: + esbuild "~0.21.4" + get-tsconfig "^4.7.5" + optionalDependencies: + fsevents "~2.3.3" + +typescript@^5.4.5: + version "5.4.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" + integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ== + +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== From bff18e997208985c272e4705145ee8d4b69f6360 Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Mon, 17 Jun 2024 17:15:21 +0200 Subject: [PATCH 6/7] cleanup --- VERSION | 1 - bin/uniprot.ts | 30 +++++++++++++++++++++++------- tsconfig.json | 3 ++- 3 files changed, 25 insertions(+), 9 deletions(-) delete mode 100644 VERSION diff --git a/VERSION b/VERSION deleted file mode 100644 index fd2a0186..00000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -3.1.0 diff --git a/bin/uniprot.ts b/bin/uniprot.ts index 8b1abfce..bbe9aab0 100755 --- a/bin/uniprot.ts +++ b/bin/uniprot.ts @@ -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 @@ -17,7 +15,12 @@ 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 ", `output format`).choices(VALID_FORMATS).default("sequence")); @@ -25,19 +28,32 @@ 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 { + // 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") diff --git a/tsconfig.json b/tsconfig.json index b5f214f7..e101d71c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "compilerOptions": { "outDir": "./dist", "module": "NodeNext", - "strict": true + "strict": true, + "resolveJsonModule": true } } From dcaee59b520974c0927ae821972040c9b803b747 Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Mon, 17 Jun 2024 17:18:48 +0200 Subject: [PATCH 7/7] add uniprot run command --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 94cac332..74077291 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "uniprot": "./bin/uniprot.js" }, "scripts": { - "build": "yarn run tsc" + "build": "yarn run tsc", + "uniprot": "yarn run tsx bin/uniprot.ts" }, "dependencies": { "commander": "^12.1.0"