Skip to content

Parsing GenBank files with multiline qualifiers ignores newlines #272

Description

@nicolazilio

Hello,

I would like to report an issue related to parsing GenBank files that contain multiline qualifiers, for example, see plannot_description

rep_origin      12..467
                    /label="f1 ori"
                    /plannot_database="snapgene"
                    /plannot_description="f1 bacteriophage origin of
                    replication; arrow indicates direction of (+) strand
                    synthesis "
                    /plannot_sseqid="f1_ori_(3)"

in the resulting json file produced by anyToJson, this is the output

{
  "notes": {
    "plannot_database": [
      "snapgene"
    ],
    "plannot_description": [
      "f1 bacteriophage origin ofreplication; arrow indicates direction of (+) strandsynthesis "
    ],
    "plannot_sseqid": [
      "f1_ori_(3)"
    ]
  },
  "type": "rep_origin",
  "strand": 1,
  "forward": true,
  "name": "f1 ori",
  "start": 11,
  "end": 466
}

As you can see, newline characters in the original GenBank qualifier are ignored and lines are simply merged together.

I would expect the parser to either preserve a newline character or, probably better, use a whitespace character.

This is the snippet of code that I use for the conversion

import fs from "fs/promises";
import path from "path";
import { anyToJson, snapgeneToJson } from "@teselagen/bio-parsers";

const SUPPORTED_GENBANK = new Set([".gbk", ".gb"]);
const SUPPORTED_SNAPGENE = new Set([".dna"]);

async function parseMapFile(filePath) {
  const ext = path.extname(filePath).toLowerCase();
  const raw = await fs.readFile(filePath);

  const input =
    SUPPORTED_GENBANK.has(ext)
      ? raw.toString("utf8")
      : SUPPORTED_SNAPGENE.has(ext)
        ? new Blob([raw], { type: "application/octet-stream" })
        : raw;

  return anyToJson(input, { fileName: path.basename(filePath) });
}

async function main() {
  const filePath = process.argv[2];
  if (!filePath) {
    console.error("Usage: node parseMapFile.mjs <map-file>");
    process.exit(1);
  }

  const parsed = await parseMapFile(filePath);
  console.log(JSON.stringify(parsed, null, 2));
}

main().catch((err) => {
  console.error("Failed to parse file:", err);
  process.exit(1);
});

Example input and output are attached.

Thank you in advance.

{
  "dependencies": {
    "@teselagen/bio-parsers": "^0.4.38"
  }
}

test_plasmid.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions