Sign in

    moonbit-vcfkit

    Native MoonBit toolkit for parsing, filtering, transforming, and inspecting VCF text data.

    vcf
    genomics
    bioinformatics
    variant
    cli
    Download zip
    Author
    Version
    0.2.2
    License
    Apache-2.0
    Last updated
    last month
    Downloads
    24

    #MoonBit VCF Kit

    This package provides typed VCF text parsing, validation, filtering, transformation, indexing, querying, merge/diff, genotype analysis, and deterministic writing for MoonBit applications.

    The executable demo is available through cmd/vcfkit; the testable command API is cli.run_cli_text. See README.md for installation, CLI examples, benchmark methodology, supported targets, and limitations.

    All repository fixtures are synthetic and deterministic. The project is licensed under Apache-2.0.

    ParseError

    pub(all) suberror ParseError {
    InvalidHeader(line~ : Int, column~ : Int, message~ : String)
    InvalidRecord(line~ : Int, column~ : Int, field~ : String, message~ : String)
    InvalidValue(line~ : Int, column~ : Int, field~ : String, value~ : String, message~ : String)
    } derive(Eq,
    Debug
    )

    Cardinality

    pub(all) enum Cardinality {
    Fixed(Int)
    PerAlt
    PerAllele
    PerGenotype
    Variable
    Unknown(String)
    } derive(Eq,
    Debug
    )

    ContigDef

    pub(all) struct ContigDef {
    id : String
    length : Int?
    attributes : Array[(String, String)]
    } derive(Eq,
    Debug
    )

    Diagnostic

    pub(all) struct Diagnostic {
    severity : DiagnosticSeverity
    code : String
    line : Int
    column : Int
    field : String
    message : String
    } derive(Eq,
    Debug
    )

    DiagnosticSeverity

    pub(all) enum DiagnosticSeverity {
    Error
    Warning
    } derive(Eq,
    Debug
    )

    FilterDef

    pub(all) struct FilterDef {
    id : String
    description : String
    attributes : Array[(String, String)]
    } derive(Eq,
    Debug
    )

    FormatDef

    pub(all) struct FormatDef {
    id : String
    number : Cardinality
    value_type : ValueType
    description : String
    attributes : Array[(String, String)]
    } derive(Eq,
    Debug
    )

    GenomicInterval

    pub(all) struct GenomicInterval {
    start : Int
    end : Int
    } derive(Eq,
    Debug
    )

    GenotypeCall

    pub(all) struct GenotypeCall {
    alleles : Array[Int?]
    phased : Bool
    invalid : Bool
    } derive(Eq,
    Debug
    )

    GenotypeClass

    pub(all) enum GenotypeClass {
    Missing
    Reference
    Heterozygous
    HomozygousAlternate
    MultiAlternate
    Invalid
    } derive(Eq,
    Debug
    )

    InfoDef

    pub(all) struct InfoDef {
    id : String
    number : Cardinality
    value_type : ValueType
    description : String
    attributes : Array[(String, String)]
    } derive(Eq,
    Debug
    )

    MetaLine

    pub(all) enum MetaLine {
    FileFormat(String)
    Info(InfoDef)
    Format(FormatDef)
    Filter(FilterDef)
    Contig(ContigDef)
    Generic(key~ : String, value~ : String)
    } derive(Eq,
    Debug
    )

    NormalizationOutcome

    pub(all) enum NormalizationOutcome {
    Changed(VcfRecord)
    Unchanged(VcfRecord)
    Invalid(String)
    } derive(Eq,
    Debug
    )

    QualitySummary

    pub(all) struct QualitySummary {
    count : Int
    missing : Int
    minimum : Double?
    maximum : Double?
    mean : Double?
    } derive(Eq,
    Debug
    )

    RecordDiff

    pub(all) struct RecordDiff {
    kind : RecordDiffKind
    key : String
    left : VcfRecord?
    right : VcfRecord?
    } derive(Eq,
    Debug
    )

    RecordDiffKind

    pub(all) enum RecordDiffKind {
    Added
    Removed
    Changed
    } derive(Eq,
    Debug
    )

    SampleCall

    pub(all) struct SampleCall {
    name : String
    values : Array[(String, VcfValue)]
    } derive(Eq,
    Debug
    )

    SampleStats

    pub(all) struct SampleStats {
    sample_count : Int
    called_count : Int
    missing_count : Int
    invalid_count : Int
    alt_allele_count : Int
    total_dosage : Int?
    heterozygous_count : Int
    homozygous_reference_count : Int
    homozygous_alternate_count : Int
    } derive(Eq,
    Debug
    )

    ValidationOptions

    pub(all) struct ValidationOptions {
    strict : Bool
    } derive(Eq,
    Debug
    )

    ValidationReport

    pub(all) struct ValidationReport {
    issues : Array[Diagnostic]
    } derive(Eq,
    Debug
    )

    ValueType

    pub(all) enum ValueType {
    Integer
    Float
    Flag
    Character
    String
    Unknown(String)
    } derive(Eq,
    Debug
    )

    VariantClass

    pub(all) enum VariantClass {
    Empty
    SNV
    MNV
    Insertion
    Deletion
    Mixed
    Symbolic
    } derive(Eq,
    Debug
    )

    VcfDocument

    pub(all) struct VcfDocument {
    header : VcfHeader
    records : Array[VcfRecord]
    } derive(Eq,
    Debug
    )

    VcfHeader

    pub(all) struct VcfHeader {
    fileformat : String
    meta : Array[MetaLine]
    columns : Array[String]
    samples : Array[String]
    } derive(Eq,
    Debug
    )

    VcfIndex

    pub(all) struct VcfIndex {
    entries : Array[(String, Int, VcfRecord)]
    } derive(Eq,
    Debug
    )

    VcfRecord

    pub(all) struct VcfRecord {
    chrom : String
    pos : Int
    ids : Array[String]
    ref_allele : String
    alt_alleles : Array[String]
    qual : Double?
    filters : Array[String]
    info : Array[(String, VcfValue)]
    format_keys : Array[String]
    samples : Array[SampleCall]
    } derive(Eq,
    Debug
    )

    VcfStats

    pub(all) struct VcfStats {
    record_count : Int
    contig_counts : Array[(String, Int)]
    filter_counts : Array[(String, Int)]
    info_counts : Array[(String, Int)]
    variant_type_counts : Array[(String, Int)]
    sample_count : Int
    multiallelic_count : Int
    } derive(Eq,
    Debug
    )

    VcfValue

    pub(all) enum VcfValue {
    Missing
    Flag
    Integer(Int)
    Float(Double)
    String(String)
    List(Array[VcfValue])
    } derive(Eq,
    Debug
    )

    WindowSummary

    pub(all) struct WindowSummary {
    chrom : String
    interval : GenomicInterval?
    record_count : Int
    snv_count : Int
    indel_count : Int
    filtered_count : Int
    mean_qual : Double?
    } derive(Eq,
    Debug
    )

    analyze_alt_count

    fn analyze_alt_count(records : Array[VcfRecord]) -> Int

    analyze_class_counts

    fn analyze_class_counts(records : Array[VcfRecord]) -> Array[(VariantClass, Int)]

    analyze_contig_span

    fn analyze_contig_span(records : Array[VcfRecord], chrom : String) -> GenomicInterval?

    analyze_duplicate_keys

    fn analyze_duplicate_keys(records : Array[VcfRecord]) -> Int

    analyze_filter_rate

    fn analyze_filter_rate(records : Array[VcfRecord]) -> Double

    analyze_id_count

    fn analyze_id_count(records : Array[VcfRecord]) -> Int

    analyze_info_presence

    fn analyze_info_presence(records : Array[VcfRecord], key : String) -> Int

    analyze_quality

    fn analyze_quality(records : Array[VcfRecord]) -> QualitySummary

    analyze_record_length

    fn analyze_record_length(record : VcfRecord) -> Int

    analyze_sample_count

    fn analyze_sample_count(records : Array[VcfRecord]) -> Int

    analyze_total_bases

    fn analyze_total_bases(records : Array[VcfRecord]) -> Int

    analyze_transitions

    fn analyze_transitions(records : Array[VcfRecord]) -> Int

    analyze_transversions

    fn analyze_transversions(records : Array[VcfRecord]) -> Int

    build_index

    fn build_index(document : VcfDocument) -> VcfIndex

    codec_escape_description

    fn codec_escape_description(value : String) -> String

    codec_format_bool

    fn codec_format_bool(value : Bool) -> String

    codec_format_float_list

    fn codec_format_float_list(values : Array[Double?]) -> String

    codec_format_int_list

    fn codec_format_int_list(values : Array[Int?]) -> String

    codec_is_missing

    fn codec_is_missing(value : String) -> Bool

    codec_join_escaped

    fn codec_join_escaped(values : Array[String], sep : Char) -> String

    codec_join_nonempty

    fn codec_join_nonempty(values : Array[String], sep : String) -> String

    codec_normalize_missing

    fn codec_normalize_missing(value : String) -> String

    codec_pad

    fn codec_pad(values : Array[String], width : Int, filler : String) -> Array[String]

    codec_parse_bool

    fn codec_parse_bool(value : String) -> Bool?

    codec_parse_float_list

    fn codec_parse_float_list(value : String) -> Array[Double?]

    codec_parse_int_list

    fn codec_parse_int_list(value : String) -> Array[Int?]

    codec_quote

    fn codec_quote(value : String) -> String

    codec_split_escaped

    fn codec_split_escaped(value : String, sep : Char) -> Array[String]

    codec_truncate

    fn codec_truncate(values : Array[String], width : Int) -> Array[String]

    codec_unescape_description

    fn codec_unescape_description(value : String) -> String

    codec_unquote

    fn codec_unquote(value : String) -> String

    collect_alternate_bases

    fn collect_alternate_bases(records : Array[VcfRecord]) -> Array[(String, Int)]

    collect_reference_bases

    fn collect_reference_bases(records : Array[VcfRecord]) -> Array[(String, Int)]

    decode_genotype

    fn decode_genotype(raw : String) -> GenotypeCall

    diff_documents

    fn diff_documents(left : VcfDocument, right : VcfDocument) -> Array[RecordDiff]

    format_document

    fn format_document(document : VcfDocument) -> String

    format_genotype

    fn format_genotype(call : GenotypeCall) -> String

    format_header

    fn format_header(header : VcfHeader) -> String

    format_interval

    fn format_interval(interval : GenomicInterval?) -> String

    format_record

    fn format_record(record : VcfRecord) -> String

    format_stats

    fn format_stats(stats : VcfStats) -> String

    format_window_summary

    fn format_window_summary(summary : WindowSummary) -> String

    genotype_alt_count

    fn genotype_alt_count(call : GenotypeCall) -> Int

    genotype_alt_indexes

    fn genotype_alt_indexes(call : GenotypeCall) -> Array[Int]

    genotype_class

    fn genotype_class(call : GenotypeCall) -> GenotypeClass

    genotype_dosage

    fn genotype_dosage(call : GenotypeCall) -> Int?

    genotype_has_allele

    fn genotype_has_allele(call : GenotypeCall, wanted : Int) -> Bool

    genotype_is_called

    fn genotype_is_called(call : GenotypeCall) -> Bool

    genotype_is_het

    fn genotype_is_het(call : GenotypeCall) -> Bool

    genotype_is_hom_alt

    fn genotype_is_hom_alt(call : GenotypeCall) -> Bool

    genotype_is_hom_ref

    fn genotype_is_hom_ref(call : GenotypeCall) -> Bool

    genotype_is_missing

    fn genotype_is_missing(call : GenotypeCall) -> Bool

    group_record_counts

    fn group_record_counts(records : Array[VcfRecord]) -> Array[(String, Int)]

    interval_clip

    fn interval_clip(interval : GenomicInterval?, lower : Int, upper : Int) -> GenomicInterval?

    interval_contains

    fn interval_contains(interval : GenomicInterval?, position : Int) -> Bool

    interval_distance

    fn interval_distance(left : GenomicInterval?, right : GenomicInterval?) -> Int

    interval_expand

    fn interval_expand(interval : GenomicInterval?, padding : Int) -> GenomicInterval?

    interval_intersection

    fn interval_intersection(left : GenomicInterval?, right : GenomicInterval?) -> GenomicInterval?

    interval_merge

    fn interval_merge(intervals : Array[GenomicInterval?]) -> Array[GenomicInterval?]

    interval_overlaps

    fn interval_overlaps(left : GenomicInterval?, right : GenomicInterval?) -> Bool

    interval_shift

    fn interval_shift(interval : GenomicInterval?, offset : Int) -> GenomicInterval?

    interval_subtract

    fn interval_subtract(source : GenomicInterval?, removed : GenomicInterval?) -> Array[GenomicInterval?]

    interval_width

    fn interval_width(interval : GenomicInterval?) -> Int

    make_interval

    fn make_interval(start : Int, end : Int) -> GenomicInterval?

    merge_documents

    fn merge_documents(left : VcfDocument, right : VcfDocument) -> VcfDocument raise ParseError

    merge_sample_stats

    fn merge_sample_stats(left : SampleStats, right : SampleStats) -> SampleStats

    normalize_basic

    fn normalize_basic(record : VcfRecord) -> VcfRecord

    normalize_record

    fn normalize_record(record : VcfRecord) -> NormalizationOutcome

    parse_document

    fn parse_document(text : String) -> VcfDocument raise ParseError

    parse_header

    fn parse_header(text : String) -> VcfHeader raise ParseError

    parse_meta_line

    fn parse_meta_line(line : String, line_number~ : Int) -> MetaLine raise ParseError

    parse_record

    fn parse_record(line : String, header~ : VcfHeader) -> VcfRecord raise ParseError

    patch_alt

    fn patch_alt(record : VcfRecord, alts : Array[String]) -> VcfRecord

    patch_clear_info

    fn patch_clear_info(record : VcfRecord) -> VcfRecord

    patch_filters

    fn patch_filters(record : VcfRecord, filters : Array[String]) -> VcfRecord

    patch_ids

    fn patch_ids(record : VcfRecord, ids : Array[String]) -> VcfRecord

    patch_info

    fn patch_info(record : VcfRecord, key : String, value : VcfValue) -> VcfRecord

    patch_position

    fn patch_position(record : VcfRecord, chrom : String, pos : Int) -> VcfRecord

    patch_qual

    fn patch_qual(record : VcfRecord, qual : Double?) -> VcfRecord

    patch_remove_info

    fn patch_remove_info(record : VcfRecord, key : String) -> VcfRecord

    patch_sample

    fn patch_sample(record : VcfRecord, sample : SampleCall) -> VcfRecord

    patch_sample_value

    fn patch_sample_value(sample : SampleCall, key : String, value : VcfValue) -> SampleCall

    pipeline_apply_normalization

    fn pipeline_apply_normalization(document : VcfDocument) -> VcfDocument

    pipeline_concat

    fn pipeline_concat(documents : Array[VcfDocument]) -> VcfDocument?

    pipeline_contigs

    fn pipeline_contigs(document : VcfDocument) -> Array[String]

    pipeline_count

    fn pipeline_count(document : VcfDocument) -> Int

    pipeline_dedupe

    fn pipeline_dedupe(document : VcfDocument) -> VcfDocument

    pipeline_drop

    fn pipeline_drop(document : VcfDocument, count : Int) -> VcfDocument

    pipeline_filter

    fn pipeline_filter(document : VcfDocument, keep : (VcfRecord) -> Bool) -> VcfDocument

    pipeline_filters

    fn pipeline_filters(document : VcfDocument) -> Array[String]

    pipeline_first

    fn pipeline_first(document : VcfDocument) -> VcfRecord?

    pipeline_format

    fn pipeline_format(document : VcfDocument) -> String

    pipeline_info_keys

    fn pipeline_info_keys(document : VcfDocument) -> Array[String]

    pipeline_is_empty

    fn pipeline_is_empty(document : VcfDocument) -> Bool

    pipeline_last

    fn pipeline_last(document : VcfDocument) -> VcfRecord?

    pipeline_limit_by_contig

    fn pipeline_limit_by_contig(document : VcfDocument, chrom : String) -> VcfDocument

    pipeline_limit_by_interval

    fn pipeline_limit_by_interval(document : VcfDocument, chrom : String, interval : GenomicInterval?) -> VcfDocument

    pipeline_map

    fn pipeline_map(document : VcfDocument, transform : (VcfRecord) -> VcfRecord) -> VcfDocument

    pipeline_merge

    fn pipeline_merge(left : VcfDocument, right : VcfDocument) -> VcfDocument raise ParseError

    pipeline_pairwise

    fn pipeline_pairwise(left : VcfDocument, right : VcfDocument) -> Array[RecordDiff]

    pipeline_project_info

    fn pipeline_project_info(document : VcfDocument, keys : Array[String]) -> VcfDocument

    pipeline_project_samples

    fn pipeline_project_samples(document : VcfDocument, names : Array[String]) -> VcfDocument raise ParseError

    pipeline_query

    fn pipeline_query(document : VcfDocument, chrom : String, start : Int, end : Int) -> Array[VcfRecord]

    pipeline_record_counts_by_class

    fn pipeline_record_counts_by_class(document : VcfDocument) -> Array[(VariantClass, Int)]

    pipeline_round_trip

    fn pipeline_round_trip(document : VcfDocument) -> VcfDocument raise ParseError

    pipeline_sort

    fn pipeline_sort(document : VcfDocument) -> VcfDocument

    pipeline_split_by_filter

    fn pipeline_split_by_filter(document : VcfDocument, filter : String) -> (VcfDocument, VcfDocument)

    pipeline_split_by_qualification

    fn pipeline_split_by_qualification(document : VcfDocument, threshold : Double) -> (VcfDocument, VcfDocument)

    pipeline_split_multiallelic

    fn pipeline_split_multiallelic(document : VcfDocument) -> VcfDocument

    pipeline_stats

    fn pipeline_stats(document : VcfDocument) -> VcfStats

    pipeline_take

    fn pipeline_take(document : VcfDocument, count : Int) -> VcfDocument

    pipeline_validate

    fn pipeline_validate(document : VcfDocument, strict : Bool) -> ValidationReport

    quality_missing_rate

    fn quality_missing_rate(summary : QualitySummary) -> Double

    quality_passes

    fn quality_passes(summary : QualitySummary, threshold : Double) -> Bool

    quality_range

    fn quality_range(summary : QualitySummary) -> Double?

    query_index

    fn query_index(index : VcfIndex, chrom : String, start : Int, end : Int) -> Array[VcfRecord]

    record_alt_count

    fn record_alt_count(record : VcfRecord) -> Int

    record_has_info

    fn record_has_info(record : VcfRecord, key : String) -> Bool

    record_info_float

    fn record_info_float(record : VcfRecord, key : String) -> Double?

    record_info_int

    fn record_info_int(record : VcfRecord, key : String) -> Int?

    record_info_value

    fn record_info_value(record : VcfRecord, key : String) -> VcfValue?

    record_is_indel

    fn record_is_indel(record : VcfRecord) -> Bool

    record_is_snv

    fn record_is_snv(record : VcfRecord) -> Bool

    record_key

    fn record_key(record : VcfRecord) -> String

    record_sample

    fn record_sample(record : VcfRecord, name : String) -> SampleCall?

    record_sort_key

    fn record_sort_key(record : VcfRecord) -> String

    record_variant_class

    fn record_variant_class(record : VcfRecord) -> VariantClass

    sample_alt_frequency

    fn sample_alt_frequency(stats : SampleStats) -> Double?

    sample_call_rate

    fn sample_call_rate(stats : SampleStats) -> Double

    sample_is_high_quality

    fn sample_is_high_quality(stats : SampleStats, minimum_call_rate : Double) -> Bool

    sample_missing_rate

    fn sample_missing_rate(stats : SampleStats) -> Double

    sample_value

    fn sample_value(sample : SampleCall, key : String) -> VcfValue?

    schema_contig

    fn schema_contig(header : VcfHeader, key : String) -> ContigDef?

    schema_contig_length

    fn schema_contig_length(header : VcfHeader, key : String) -> Int?

    schema_expected_cardinality

    fn schema_expected_cardinality(number : Cardinality, alt_count : Int) -> Int?

    schema_filter

    fn schema_filter(header : VcfHeader, key : String) -> FilterDef?

    schema_format

    fn schema_format(header : VcfHeader, key : String) -> FormatDef?

    schema_has_sample

    fn schema_has_sample(header : VcfHeader, name : String) -> Bool

    schema_has_samples

    fn schema_has_samples(header : VcfHeader) -> Bool

    schema_header_width

    fn schema_header_width(header : VcfHeader) -> Int

    schema_ids

    fn schema_ids(header : VcfHeader, kind : String) -> Array[String]

    schema_info

    fn schema_info(header : VcfHeader, key : String) -> InfoDef?

    schema_is_genotype_format

    fn schema_is_genotype_format(header : VcfHeader, key : String) -> Bool

    schema_is_structured

    fn schema_is_structured(header : VcfHeader) -> Bool

    schema_sample_index

    fn schema_sample_index(header : VcfHeader, name : String) -> Int?

    schema_value_type

    fn schema_value_type(header : VcfHeader, key : String) -> ValueType?

    select_document_samples

    fn select_document_samples(document : VcfDocument, names : Array[String]) -> VcfDocument raise ParseError

    select_info_fields

    fn select_info_fields(record : VcfRecord, keys : Array[String]) -> VcfRecord

    sort_records

    fn sort_records(records : Array[VcfRecord]) -> Array[VcfRecord]

    split_multi_allelic

    fn split_multi_allelic(record : VcfRecord, header~ : VcfHeader) -> Array[VcfRecord]

    stream_document

    fn stream_document(text : String) -> VcfDocument raise ParseError

    stream_records

    fn stream_records(text : String, consume~ : (VcfRecord) -> Unit) -> VcfHeader raise ParseError

    summarize

    fn summarize(document : VcfDocument) -> VcfStats

    summarize_document_samples

    fn summarize_document_samples(document : VcfDocument, key : String) -> Array[(String, SampleStats)]

    summarize_fixed_windows

    fn summarize_fixed_windows(document : VcfDocument, chrom : String, start : Int, end : Int, width : Int) -> Array[WindowSummary]

    summarize_sample_calls

    fn summarize_sample_calls(calls : Array[SampleCall], key : String) -> SampleStats

    summarize_window

    fn summarize_window(document : VcfDocument, chrom : String, interval : GenomicInterval?) -> WindowSummary

    transition_transversion_ratio

    fn transition_transversion_ratio(records : Array[VcfRecord]) -> Double?

    validate_document

    fn validate_document(document : VcfDocument, options~ : ValidationOptions) -> ValidationReport

    window_density

    fn window_density(summary : WindowSummary) -> Double

    window_filter_fraction

    fn window_filter_fraction(summary : WindowSummary) -> Double?

    window_is_empty

    fn window_is_empty(summary : WindowSummary) -> Bool

    window_merge_summaries

    fn window_merge_summaries(summaries : Array[WindowSummary]) -> WindowSummary

    window_snv_fraction

    fn window_snv_fraction(summary : WindowSummary) -> Double?