// Protocol buffers for representing gnomAD-SV v2 data.
//
// Note that we don't attempt to parse everything out of gnomAD-SV yet, just
// the parts that are important for identifying SVs as potentially benign.

syntax = "proto3";

package annonars.gnomad.v1.gnomad_sv2;

// Protocol buffer enum for site-level filters.
enum Filter {
    // All filters passed.
    PASS = 0;
    // Site does not meet minimum requirements for fraction of PCR- samples
    // with non-null genotypes. Flags sites more prone to false discoveries.
    LOW_CALL_RATE = 1;
    // Multiallelic site.
    MULTIALLELIC = 2;
    // Site enriched for non-reference genotypes among PCR+ samples. Likely
    // reflects technical batch effects. All PCR- samples have been assigned
    // null GTs for these sites.
    PCRPLUS_ENRICHED = 3;
    // Variant is unresolved.
    UNRESOLVED = 4;
    // Allele frequency for this variant in PCR- samples is sensitive to
    // choice of GQ filtering thresholds. All PCR- samples have been assigned
    // null GTs for these sites.
    UNSTABLE_AF_PCRMINUS = 5;
}

// The types of SV in gnomad-SV v2.
enum SvType {
    // Breakend.
    BND = 0;
    // Complex variant.
    CPX = 1;
    // Translocation.
    CTX = 2;
    // Deletion.
    DEL = 3;
    // Duplication.
    DUP = 4;
    // Insertion.
    INS = 5;
    // Inversion.
    INV = 6;
    // Copy number variable region.
    MCNV = 7;
}

// Further definition of CPX type.
enum CpxType {
    // CCR: Complex chromosomal rearrangement, involving two or more
    // chromosomes and multiple SV signatures.
    CCR = 0;
    // INS_iDEL: Insertion with deletion at insertion site.
    INS_IDEL = 1;
    // INVdel: Complex inversion with 3' flanking deletion.
    INV_Del = 2;
    // INVdup: Complex inversion with 3' flanking duplication.
    INV_DUP = 3;
    // dDUP: Dispersed duplication.
    DDUP = 4;
    // dDUP_iDEL: Dispersed duplication with deletion at insertion site.
    DDUP_IDEL = 5;
    // delINVdel: Complex inversion with 5' and 3' flanking deletions.
    DEL_INV_DEL = 6;
    // delINVdup: Complex inversion with 5' flanking deletion and 3' flanking
    // duplication.
    DEL_INV_DUP = 7;
    // delINV: Complex inversion with 5' flanking deletion.
    DEL_INV = 8;
    // dupINVdel: Complex inversion with 5' flanking duplication and 3'
    // flanking deletion.
    DUP_INV_DEL = 9;
    // dupINVdup: Complex inversion with 5' and 3' flanking duplications.
    DUP_INV_DUP = 10;
    // dupINV: Complex inversion with 5' flanking duplication.
    DUP_INV = 11;
    // piDUP_FR: Palindromic inverted tandem duplication, forward-reverse
    // orientation.
    PI_DUP_FR = 12;
    // piDUP_RF: Palindromic inverted tandem duplication, reverse-forward
    // orientation.
    PI_DUP_RF = 13;
}

// Store the relevant allele counts and frequencies in a given sub cohort.
message AlleleCounts {
    // Total number of alleles genotyped (for biallelic sites) or individuals
    // with copy-state estimates (for multiallelic sites).
    int32 ac = 1;
    // Number of non-reference alleles observed (for biallelic sites) or
    // individuals at each copy state (for multiallelic sites).
    int32 an = 2;
    // Allele frequency (for biallelic sites) or copy-state frequency (for
    // multiallelic sites).
    float af = 3;
    // Total number of individuals with complete genotypes (biallelic sites
    // only).
    int32 n_bi_genos = 4;
    // Number of individuals with homozygous reference genotypes (biallelic
    // sites only).
    int32 n_homref = 5;
    // Number of individuals with heterozygous genotypes (biallelic sites
    // only).
    int32 n_het = 6;
    // Number of individuals with homozygous alternate genotypes (biallelic
    // sites only).
    int32 n_homalt = 7;
    // Homozygous reference genotype frequency (biallelic sites only).
    float freq_homref = 8;
    // Heterozygous genotype frequency (biallelic sites only).
    float freq_het = 9;
    // Homozygous alternate genotype frequency (biallelic sites only).
    float freq_homalt = 10;
}

// Store the allele counts for the given sub cohort and sub cohort factored by sex.
message AlleleCountsBySex {
    // Overall allele counts in the sub cohort.
    AlleleCounts overall = 1;
    // Allele counts in female/XX karyotype individuals of sub cohort.
    AlleleCounts xx = 2;
    // Allele counts in male/XY karyotype individuals of sub cohort.
    AlleleCounts xy = 3;
}

// gnomAD SV population.
enum Population {
    // African
    AFR = 0;
    // Ad Mixed American
    AMR = 1;
    // East Asian
    EAS = 2;
    // European.
    EUR = 3;
    // Other,
    OTHER = 4;
}

// Store the allele counts for the given sub cohort in the given population.
message PopulationAlleleCounts {
    // Name of the population.
    Population population = 1;
    // The overall allele counts and the one by sex.
    AlleleCountsBySex counts = 2;
}

// Store the allele counts for the given cohort.
message CohortAlleleCounts {
    // Name of the cohort, empty for global.
    optional string cohort = 1;
    // The overall allele counts and the one by sex.
    AlleleCountsBySex by_sex = 2;
    // Allele counts for each population.
    repeated PopulationAlleleCounts by_population = 3;
}

// Protocol buffer for the gnomAD-SV v2 VCF record.
//
// The more specialized fields from the INFO column are stored in separate, optional fields such
// that we don't end up with a humongous message.
message Record {
    // Chromosome name.
    string chrom = 1;
    // 1-based start position.
    int32 pos = 2;
    // End position of the structural variant
    optional int32 end = 3;
    // Chromosome of second breakpoint position.
    optional string chrom2 = 4;
    // End coordinate of second breakpoint position.
    optional int32 end2 = 5;
    // Identifier of the record.
    string id = 6;

    // Site-level filters.
    repeated Filter filters = 7;
    // SV Type.
    SvType sv_type = 8;
    // Refined complex type.
    optional CpxType cpx_type = 9;

    // Variant allele counts in the different cohorts and population.
    //
    // The populations in gnomAD v2/3 are: empty for global, "controls", "non_neuro",
    // and "non_topmed".
    repeated CohortAlleleCounts allele_counts = 10;
}
