← Files Biological Sequence & Alignment ViewerARCHIVED FILE
src/sequence/feature-resolution.ts
1.14 KB · Sep 30, 2026 · 23:01 UTC
import type { SequenceFeature } from "./types";
export function resolveSequenceFeatureSelector(
features: SequenceFeature[],
selector: string,
): SequenceFeature[] {
const query = normalize(selector);
if (query.length === 0) {
return [];
}
const exactIdMatches = features.filter(
(feature) => normalize(feature.id) === query,
);
if (exactIdMatches.length > 0) {
return exactIdMatches;
}
const exactBiologicalMatches = features.filter((feature) =>
featureSearchTerms(feature).some((term) => term === query),
);
if (exactBiologicalMatches.length > 0) {
return exactBiologicalMatches;
}
return features.filter((feature) =>
featureSearchTerms(feature).some((term) => term.includes(query)),
);
}
function featureSearchTerms(feature: SequenceFeature): string[] {
return [
feature.type,
feature.label,
...Object.values(feature.qualifiers).flatMap((value) =>
Array.isArray(value) ? value : [value],
),
]
.filter((value): value is string => value != null)
.map(normalize)
.filter(Boolean);
}
function normalize(value: string): string {
return value.trim().toLocaleLowerCase();
}
SHA-256: b9d1f1c54f0b2bc7123b693af66725e7aa171dd068c066c89de7c24cbed14eae