Skip to content

Commit

Permalink
Standardize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Apr 11, 2023
1 parent 549bd9f commit 226a50a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
11 changes: 6 additions & 5 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Parser, { ParseCallbacks } from './parse'
import { GFF3Parser, ParseCallbacks } from './parse'
import {
formatItem,
formatSequence,
Expand Down Expand Up @@ -48,7 +48,7 @@ function _processParseOptions(options: ParseOptions): ParseOptionsProcessed {
*/
export class GFFTransformer implements Transformer<Uint8Array, GFF3Item> {
private decoder: TextDecoder
private parser: Parser
private parser: GFF3Parser
private lastString = ''
private parseFeatures: boolean
private parseDirectives: boolean
Expand All @@ -63,7 +63,7 @@ export class GFFTransformer implements Transformer<Uint8Array, GFF3Item> {
this.decoder = new TextDecoder()
const processedOptions = _processParseOptions(options)
const { bufferSize, disableDerivesFromReferences } = processedOptions
this.parser = new Parser({ bufferSize, disableDerivesFromReferences })
this.parser = new GFF3Parser({ bufferSize, disableDerivesFromReferences })
this.parseFeatures = processedOptions.parseFeatures
this.parseDirectives = processedOptions.parseDirectives
this.parseComments = processedOptions.parseComments
Expand Down Expand Up @@ -462,7 +462,7 @@ export function parseStringSync(
callbacks.sequenceCallback = push
}

const parser = new Parser({
const parser = new GFF3Parser({
disableDerivesFromReferences: options.disableDerivesFromReferences || false,
bufferSize: Infinity,
})
Expand Down Expand Up @@ -532,7 +532,8 @@ export class GFFFormattingTransformer implements Transformer<GFF3Item, string> {
*/
constructor(options: FormatOptions = {}) {
this.minLinesBetweenSyncMarks = options.minSyncLines || 100
this.insertVersionDirective = options.insertVersionDirective || true
this.insertVersionDirective =
options.insertVersionDirective === false ? false : true
}

transform(
Expand Down
47 changes: 27 additions & 20 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import * as GFF3 from './util'
import {
parseDirective,
parseFeature,
GFF3Feature,
GFF3FeatureLineWithRefs,
GFF3Comment,
GFF3Directive,
GFF3Sequence,
} from './util'

const containerAttributes = {
Parent: 'child_features' as const,
Derives_from: 'derived_features' as const,
}

export interface ParseCallbacks {
featureCallback?(feature: GFF3.GFF3Feature): void
commentCallback?(comment: GFF3.GFF3Comment): void
featureCallback?(feature: GFF3Feature): void
commentCallback?(comment: GFF3Comment): void
errorCallback?(error: string): void
directiveCallback?(directive: GFF3.GFF3Directive): void
sequenceCallback?(sequence: GFF3.GFF3Sequence): void
directiveCallback?(directive: GFF3Directive): void
sequenceCallback?(sequence: GFF3Sequence): void
}

export class FASTAParser {
Expand All @@ -20,7 +28,7 @@ export class FASTAParser {

constructor(
// eslint-disable-next-line @typescript-eslint/no-empty-function
private seqCallback: (sequence: GFF3.GFF3Sequence) => void = () => {},
private seqCallback: (sequence: GFF3Sequence) => void = () => {},
) {
this.currentSequence = undefined
}
Expand Down Expand Up @@ -52,11 +60,11 @@ interface ParserArgs {
}

interface References {
Parent: GFF3.GFF3Feature[]
Derives_from: GFF3.GFF3Feature[]
Parent: GFF3Feature[]
Derives_from: GFF3Feature[]
}

export default class Parser {
export class GFF3Parser {
endCallback: () => void
disableDerivesFromReferences: boolean
bufferSize: number
Expand All @@ -67,10 +75,9 @@ export default class Parser {
lineNumber = 0
// features that we have to keep on hand for now because they might be
// referenced by something else
private underConstructionTopLevel: GFF3.GFF3Feature[] = []
private underConstructionTopLevel: GFF3Feature[] = []
// index of the above by ID
private underConstructionById: Record<string, GFF3.GFF3Feature | undefined> =
{}
private underConstructionById: Record<string, GFF3Feature | undefined> = {}
private completedReferences: Record<
string,
Record<string, boolean | undefined> | undefined
Expand Down Expand Up @@ -125,7 +132,7 @@ export default class Parser {
// sync directive, all forward-references are resolved.
this.emitAllUnderConstructionFeatures(callbacks)
} else if (hashsigns.length === 2) {
const directive = GFF3.parseDirective(line)
const directive = parseDirective(line)
if (directive) {
if (directive.directive === 'FASTA') {
this.emitAllUnderConstructionFeatures(callbacks)
Expand Down Expand Up @@ -161,7 +168,7 @@ export default class Parser {
}

private emitItem(
i: GFF3.GFF3Feature | GFF3.GFF3Directive | GFF3.GFF3Comment,
i: GFF3Feature | GFF3Directive | GFF3Comment,
callbacks: ParseCallbacks,
) {
if (Array.isArray(i) && callbacks.featureCallback)
Expand All @@ -176,7 +183,7 @@ export default class Parser {
additionalItemCount = 0,
callbacks: ParseCallbacks,
) {
const _unbufferItem = (item?: GFF3.GFF3Feature) => {
const _unbufferItem = (item?: GFF3Feature) => {
if (
item &&
Array.isArray(item) &&
Expand Down Expand Up @@ -236,8 +243,8 @@ export default class Parser {

// do the right thing with a newly-parsed feature line
private bufferLine(line: string, callbacks: ParseCallbacks) {
const rawFeatureLine = GFF3.parseFeature(line)
const featureLine: GFF3.GFF3FeatureLineWithRefs = {
const rawFeatureLine = parseFeature(line)
const featureLine: GFF3FeatureLineWithRefs = {
...rawFeatureLine,
child_features: [],
derived_features: [],
Expand All @@ -257,7 +264,7 @@ export default class Parser {
return
}

let feature: GFF3.GFF3Feature | undefined = undefined
let feature: GFF3Feature | undefined = undefined
ids.forEach((id) => {
const existing = this.underConstructionById[id]
if (existing) {
Expand Down Expand Up @@ -296,7 +303,7 @@ export default class Parser {
)
}

private resolveReferencesTo(feature: GFF3.GFF3Feature, id: string) {
private resolveReferencesTo(feature: GFF3Feature, id: string) {
const references = this.underConstructionOrphans.get(id)
// references is of the form
// {
Expand Down Expand Up @@ -335,7 +342,7 @@ export default class Parser {
}

private resolveReferencesFrom(
feature: GFF3.GFF3Feature,
feature: GFF3Feature,
references: { Parent: string[]; Derives_from: string[] },
ids: string[],
) {
Expand Down

0 comments on commit 226a50a

Please sign in to comment.