@ncbijs/fasta
v0.0.0
Published
Parse FASTA format sequences into typed records
Maintainers
Readme
@ncbijs/fasta
Parse FASTA format sequences into typed records. Zero dependencies.
Installation
npm install @ncbijs/fastaUsage
import { parseFasta } from '@ncbijs/fasta';
const text = `
>NP_000537.3 cellular tumor antigen p53 isoform a [Homo sapiens]
MEEPQSDPSVEPPLSQETFSDLWKLLPENNVLSPLPSQAMDDLMLSPDDIEQWFTEDPGP
DEAPRMPEAAPPVAPAPAAPTPAAPAPAPSWPLSSSVPSQKTYPQGLNGTVNLPGRNSFEV
`;
const records = parseFasta(text);
console.log(records[0].id); // 'NP_000537.3'
console.log(records[0].description); // 'cellular tumor antigen p53 isoform a [Homo sapiens]'
console.log(records[0].sequence); // 'MEEPQSDPSVEPPLSQETFSDLWKLL...'API
parseFasta(text: string): Array<FastaRecord>
Parses a FASTA-formatted string into an array of records.
- Header lines (
>) split intoid(first word) anddescription(rest) - Multi-line sequences are concatenated
- Comment lines (
;) and blank lines are skipped - Handles GenBank, UniProt/SwissProt, and NCBI identifier formats
Error handling
parseFasta is a pure synchronous parser. It does not throw on malformed input — records without a header line (>) are silently skipped, and empty sequences produce records with an empty sequence string.
FastaRecord
interface FastaRecord {
readonly id: string;
readonly description: string;
readonly sequence: string;
}