fix(model-export): make model TSV download work (#221) - #228
Open
VibhavSetlur wants to merge 1 commit into
Open
Conversation
The model Download menu offered a "TSV" option that called GET /api/models/export?format=tsv, but the ModelSEED API only supports json | sbml | cobrapy (verified against https://modelseed.org/PMS/openapi.json). The option therefore never produced a file. Derive the tabular exports in the browser from the supported `format=json` export instead, and split the single dead entry into two working ones: "Reactions (TSV)" and "Compounds (TSV)". This gives users the cpdtbl/rxntbl style tables requested in the issue. - add lib/utils/modelTsv.ts with pure buildReactionsTsv/buildCompoundsTsv builders reusing the existing RFC-4180 escaper in lib/utils/exportCsv.ts - rewire components/ui/DownloadModelMenu.tsx onto a discriminated 'api' | 'derived-tsv' option union and export EXPORT_OPTIONS - correct the stale exportModelFromApi doc comment that listed 'tsv' - update the model page helper text - add unit tests for the TSV builders plus a contract test asserting no menu entry requests a format outside the backend's supported set Note: the issue also reported that the SBML download is not valid XML. The reporter's own attachment parses as complete, well-formed SBML L3V1-FBCv2 (1100 species, 1127 reactions, fbc objective); the key/value text they saw is the content of legal <notes> blocks. No SBML change was needed.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the actionable half of #221.
What was actually wrong
TSV download (real bug). The model Download menu offered a
TSVentry that issuedGET /api/models/export?ref=…&format=tsv. The ModelSEED API only supportsjson,sbmlandcobrapy— verified live against https://modelseed.org/PMS/openapi.json:So that menu entry could never produce a file. Nothing in the repo tested it
(
scripts/api-test.mjsandscripts/comprehensive-api-test.mjsonly cover SBML and JSON).SBML download (not a bug). The reporter's attached
DC1RawModel.xmlwas downloaded andchecked: it is complete, well-formed SBML L3V1 + FBC v2 — 1100
<species>, 1127<reaction>,unit definitions, compartments,
fbc:objective fbc:type="maximize",fbc:listOfGeneProducts,properly closed
</model></sbml>. Thekbase_compartment_data/modelseed_template_id: cpdXXXX_clines they saw are the text of legal
<notes><html><p>…</p></html></notes>blocks, which is what abrowser shows if it renders the file as HTML. No SBML change was made or needed — that file
should load in COBRA Toolbox / cobrapy as-is.
The fix
Build the tabular exports client-side from the supported
format=jsonexport, and split the onedead entry into two working ones:
format=sbml<model>.xml(unchanged)format=json<model>.json(unchanged)format=json<model>.reactions.tsvformat=json<model>.compounds.tsvColumns follow the legacy
rxntbl/cpdtblshape the issue asks for:id,direction,compartment,gpr,name,equation,pathwaysid,name,formula,charge,compartmentcompartmentis derived from the id suffix (cpd00443_c0→c0).Changes
lib/utils/modelTsv.ts— purebuildReactionsTsv/buildCompoundsTsv/compartmentFromId, reusing the existing RFC-4180 escaper inlib/utils/exportCsv.ts(no new escaping code, no new dependency).
components/ui/DownloadModelMenu.tsx— options moved to an exported, typed'api' | 'derived-tsv'discriminated union;downloadingFormat→downloadingKey.Props interface unchanged, so both call sites (model viewer and My Models) are unaffected.
lib/api/modelseed.ts— doc comment corrected; it still advertised a'tsv'format. Nobehaviour change.
app/model/[...path]/page.tsx— helper text updated (one line).Tests
tests/unit/utils/modelTsv.test.ts— header rows, compartment derivation,charge: 0renderingas
0, commas in reaction names staying unquoted under a tab delimiter, missing optional fieldskeeping the full column count, pathway joining, and the empty-model error paths.
tests/unit/components/downloadModelMenuOptions.test.ts— the regression test that would havecaught this: asserts every API-backed menu entry requests a format inside the backend's
documented set
['json','sbml','cobrapy'], and that nothing requeststsvfrom the API.Fixture shapes were taken from the reporter's own
DC1RawModel.json, i.e. real productionformat=jsonoutput.Verification
All green locally, mirroring
.github/workflows/ci.yml:npm run lint— 0 errors (16 pre-existing warnings, none in changed files)npx tsc --noEmit— cleannpm run test:run— 18 files, 145 tests passed (+18 new)npm run build— compiled successfully, 31/31 static pagesnpm audit --omit=dev --audit-level=high— 0 vulnerabilitiesNotes for review
stagingis promoted tomaster.format=cobrapyis documented by the API but was not added to the menu, because it could notbe verified end-to-end without an auth token, and shipping an unverified format is exactly the
bug this PR fixes. Easy follow-up once someone confirms it works.
TSV/cpdtbl export) is a backend concern for
modelseed-api, not this repo.staging; kept separate from the still-open feat(feedback): add homepage GitHub Issues link #227 so the two can be reviewedindependently.