UNPKG

@gmod/gff

Version:

read and write GFF3 data as streams

217 lines (215 loc) 11.8 kB
/// <reference types="node" /> import { Transform, TransformCallback, Readable, Writable } from 'stream'; import { StringDecoder as Decoder } from 'string_decoder'; import Parser from './parse'; import { GFF3Comment, GFF3Directive, GFF3Feature, GFF3FeatureLine, GFF3FeatureLineWithRefs, GFF3Sequence, GFF3Item } from './util'; export type { GFF3Comment, GFF3Directive, GFF3Feature, GFF3FeatureLine, GFF3FeatureLineWithRefs, GFF3Sequence, GFF3Item, }; /** Parser options */ export interface ParseOptions { /** Whether to resolve references to derives from features */ disableDerivesFromReferences?: boolean; /** Text encoding of the input GFF3. default 'utf8' */ encoding?: BufferEncoding; /** Whether to parse features, default true */ parseFeatures?: boolean; /** Whether to parse directives, default false */ parseDirectives?: boolean; /** Whether to parse comments, default false */ parseComments?: boolean; /** Whether to parse sequences, default true */ parseSequences?: boolean; /** * Parse all features, directives, comments, and sequences. Overrides other * parsing options. Default false. */ parseAll?: boolean; /** Maximum number of GFF3 lines to buffer, default 1000 */ bufferSize?: number; } declare class GFFTransform extends Transform { encoding: BufferEncoding; decoder: Decoder; textBuffer: string; parser: Parser; constructor(inputOptions?: ParseOptions); private _addLine; private _nextText; _transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback): void; _flush(callback: TransformCallback): void; } /** * Parse a stream of text data into a stream of feature, directive, comment, * an sequence objects. * * @param options - Parsing options * @returns stream (in objectMode) of parsed items */ export declare function parseStream(options?: ParseOptions): GFFTransform; /** * Synchronously parse a string containing GFF3 and return an array of the * parsed items. * * @param str - GFF3 string * @param inputOptions - Parsing options * @returns array of parsed features, directives, comments and/or sequences */ export declare function parseStringSync(str: string, inputOptions?: { disableDerivesFromReferences?: boolean; encoding?: BufferEncoding; bufferSize?: number; } | undefined): (GFF3Feature | GFF3Sequence)[]; export declare function parseStringSync<T extends boolean>(str: string, inputOptions: { parseAll?: T; disableDerivesFromReferences?: boolean; encoding?: BufferEncoding; bufferSize?: number; }): T extends true ? GFF3Item[] : never; export declare function parseStringSync<F extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseFeatures: F; encoding?: BufferEncoding; bufferSize?: number; }): F extends true ? (GFF3Feature | GFF3Sequence)[] : GFF3Sequence[]; export declare function parseStringSync<D extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseDirectives: D; encoding?: BufferEncoding; bufferSize?: number; }): D extends true ? (GFF3Feature | GFF3Directive | GFF3Sequence)[] : (GFF3Feature | GFF3Sequence)[]; export declare function parseStringSync<C extends boolean>(str: string, inputOptions: { parseComments: C; encoding?: BufferEncoding; bufferSize?: number; }): C extends true ? (GFF3Feature | GFF3Comment | GFF3Sequence)[] : (GFF3Feature | GFF3Sequence)[]; export declare function parseStringSync<S extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseSequences: S; encoding?: BufferEncoding; bufferSize?: number; }): S extends true ? (GFF3Feature | GFF3Sequence)[] : GFF3Feature[]; export declare function parseStringSync<F extends boolean, D extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseFeatures: F; parseDirectives: D; encoding?: BufferEncoding; bufferSize?: number; }): F extends true ? D extends true ? (GFF3Feature | GFF3Directive | GFF3Sequence)[] : (GFF3Feature | GFF3Sequence)[] : D extends true ? (GFF3Directive | GFF3Sequence)[] : GFF3Sequence[]; export declare function parseStringSync<F extends boolean, C extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseFeatures: F; parseComments: C; encoding?: BufferEncoding; bufferSize?: number; }): F extends true ? C extends true ? (GFF3Feature | GFF3Comment | GFF3Sequence)[] : (GFF3Feature | GFF3Sequence)[] : C extends true ? (GFF3Comment | GFF3Sequence)[] : GFF3Sequence[]; export declare function parseStringSync<F extends boolean, S extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseFeatures: F; parseSequences: S; encoding?: BufferEncoding; bufferSize?: number; }): F extends true ? S extends true ? (GFF3Feature | GFF3Sequence)[] : GFF3Feature[] : S extends true ? GFF3Sequence[] : []; export declare function parseStringSync<D extends boolean, C extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseDirectives: D; parseComments: C; encoding?: BufferEncoding; bufferSize?: number; }): D extends true ? C extends true ? (GFF3Feature | GFF3Directive | GFF3Comment | GFF3Sequence)[] : (GFF3Feature | GFF3Directive | GFF3Sequence)[] : C extends true ? (GFF3Feature | GFF3Comment | GFF3Sequence)[] : (GFF3Feature | GFF3Sequence)[]; export declare function parseStringSync<D extends boolean, S extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseDirectives: D; parseSequences: S; encoding?: BufferEncoding; bufferSize?: number; }): D extends true ? S extends true ? (GFF3Feature | GFF3Directive | GFF3Sequence)[] : (GFF3Feature | GFF3Directive)[] : S extends true ? (GFF3Feature | GFF3Sequence)[] : GFF3Feature[]; export declare function parseStringSync<C extends boolean, S extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseComments: C; parseSequences: S; encoding?: BufferEncoding; bufferSize?: number; }): C extends true ? S extends true ? (GFF3Feature | GFF3Comment | GFF3Sequence)[] : (GFF3Feature | GFF3Comment)[] : S extends true ? (GFF3Feature | GFF3Sequence)[] : GFF3Feature[]; export declare function parseStringSync<F extends boolean, D extends boolean, C extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseFeatures: F; parseDirectives: D; parseComments: C; encoding?: BufferEncoding; bufferSize?: number; }): F extends true ? D extends true ? C extends true ? GFF3Item[] : (GFF3Feature | GFF3Directive | GFF3Sequence)[] : C extends true ? (GFF3Feature | GFF3Comment | GFF3Sequence)[] : (GFF3Feature | GFF3Sequence)[] : D extends true ? C extends true ? (GFF3Directive | GFF3Comment | GFF3Sequence)[] : (GFF3Directive | GFF3Sequence)[] : C extends true ? (GFF3Comment | GFF3Sequence)[] : GFF3Sequence[]; export declare function parseStringSync<F extends boolean, D extends boolean, S extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseFeatures: F; parseDirectives: D; parseSequences: S; encoding?: BufferEncoding; bufferSize?: number; }): F extends true ? D extends true ? S extends true ? (GFF3Feature | GFF3Directive | GFF3Sequence)[] : (GFF3Feature | GFF3Directive)[] : S extends true ? (GFF3Feature | GFF3Sequence)[] : GFF3Feature[] : D extends true ? S extends true ? (GFF3Directive | GFF3Sequence)[] : GFF3Directive[] : S extends true ? GFF3Sequence[] : []; export declare function parseStringSync<F extends boolean, C extends boolean, S extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseFeatures: F; parseComments: C; parseSequences: S; encoding?: BufferEncoding; bufferSize?: number; }): F extends true ? C extends true ? S extends true ? (GFF3Feature | GFF3Comment | GFF3Sequence)[] : (GFF3Feature | GFF3Comment)[] : S extends true ? (GFF3Feature | GFF3Sequence)[] : GFF3Feature[] : C extends true ? S extends true ? (GFF3Comment | GFF3Sequence)[] : GFF3Comment[] : S extends true ? GFF3Sequence[] : []; export declare function parseStringSync<D extends boolean, C extends boolean, S extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseFeatures: D; parseComments: C; parseSequences: S; encoding?: BufferEncoding; bufferSize?: number; }): D extends true ? C extends true ? S extends true ? GFF3Item[] : (GFF3Feature | GFF3Directive | GFF3Comment)[] : S extends true ? (GFF3Feature | GFF3Directive | GFF3Sequence)[] : (GFF3Feature | GFF3Directive)[] : C extends true ? S extends true ? (GFF3Feature | GFF3Comment | GFF3Sequence)[] : (GFF3Feature | GFF3Comment)[] : S extends true ? (GFF3Feature | GFF3Sequence)[] : GFF3Feature[]; export declare function parseStringSync<F extends boolean, D extends boolean, C extends boolean, S extends boolean>(str: string, inputOptions: { disableDerivesFromReferences?: boolean; parseFeatures: F; parseDirectives: D; parseComments: C; parseSequences: S; encoding?: BufferEncoding; bufferSize?: number; }): F extends true ? D extends true ? C extends true ? S extends true ? GFF3Item[] : (GFF3Feature | GFF3Directive | GFF3Comment)[] : S extends true ? (GFF3Feature | GFF3Directive | GFF3Sequence)[] : (GFF3Feature | GFF3Directive)[] : C extends true ? S extends true ? (GFF3Feature | GFF3Comment | GFF3Sequence)[] : (GFF3Feature | GFF3Comment)[] : S extends true ? (GFF3Feature | GFF3Sequence)[] : GFF3Feature[] : D extends true ? C extends true ? S extends true ? (GFF3Directive | GFF3Comment | GFF3Sequence)[] : (GFF3Directive | GFF3Comment)[] : S extends true ? (GFF3Directive | GFF3Sequence)[] : GFF3Directive[] : C extends true ? S extends true ? (GFF3Comment | GFF3Sequence)[] : GFF3Comment[] : S extends true ? GFF3Sequence[] : []; /** * Format an array of GFF3 items (features,directives,comments) into string of * GFF3. Does not insert synchronization (###) marks. * * @param items - Array of features, directives, comments and/or sequences * @returns the formatted GFF3 */ export declare function formatSync(items: GFF3Item[]): string; interface FormatOptions { minSyncLines?: number; insertVersionDirective?: boolean; encoding?: BufferEncoding; } declare class FormattingTransform extends Transform { linesSinceLastSyncMark: number; haveWeEmittedData: boolean; fastaMode: boolean; minLinesBetweenSyncMarks: number; insertVersionDirective: boolean; constructor(options?: FormatOptions); _transform(chunk: GFF3Item[], _encoding: BufferEncoding, callback: TransformCallback): void; } /** * Format a stream of features, directives, comments and/or sequences into a * stream of GFF3 text. * * Inserts synchronization (###) marks automatically. * * @param options - parser options */ export declare function formatStream(options?: FormatOptions): FormattingTransform; /** * Format a stream of features, directives, comments and/or sequences into a * GFF3 file and write it to the filesystem. * Inserts synchronization (###) marks and a ##gff-version * directive automatically (if one is not already present). * * @param stream - the stream to write to the file * @param filename - the file path to write to * @param options - parser options * @returns promise for null that resolves when the stream has been written */ export declare function formatFile(stream: Readable, writeStream: Writable, options?: FormatOptions): Promise<null>;