def build_variant(variant, institute_id, gene_to_panels = None,<EOL>hgncid_to_gene=None, sample_info=None):
gene_to_panels = gene_to_panels or {}<EOL>hgncid_to_gene = hgncid_to_gene or {}<EOL>sample_info = sample_info or {}<EOL>variant_obj = dict(<EOL>_id = variant['<STR_LIT>']['<STR_LIT>'],<EOL>document_id=variant['<STR_LIT>']['<STR_LIT>'],<EOL>variant_id=variant['<STR_LIT>']['<STR_LIT>'],<EOL>display_name=variant['<STR_LIT>']['<STR_LIT>'],<EOL>variant_type=variant['<STR_LIT>'],<EOL>case_id=variant['<STR_LIT>'],<EOL>chromosome=variant['<STR_LIT>'],<EOL>reference=variant['<STR_LIT>'],<EOL>alternative=variant['<STR_LIT>'],<EOL>institute=institute_id,<EOL>)<EOL>variant_obj['<STR_LIT>'] = False<EOL>variant_obj['<STR_LIT>'] = int(variant['<STR_LIT>'])<EOL>variant_obj['<STR_LIT>'] = float(variant['<STR_LIT>'])<EOL>end = variant.get('<STR_LIT:end>')<EOL>if end:<EOL><INDENT>variant_obj['<STR_LIT:end>'] = int(end)<EOL><DEDENT>length = variant.get('<STR_LIT>')<EOL>if length:<EOL><INDENT>variant_obj['<STR_LIT>'] = int(length)<EOL><DEDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>'].get('<STR_LIT>')<EOL>variant_obj['<STR_LIT>'] = float(variant['<STR_LIT>']) if variant['<STR_LIT>'] else None<EOL>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL>variant_obj['<STR_LIT>'] = variant.get('<STR_LIT>')<EOL>variant_obj['<STR_LIT>'] = variant.get('<STR_LIT>')<EOL>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL>variant_obj['<STR_LIT>'] = variant.get('<STR_LIT>')<EOL>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>gt_types = []<EOL>for sample in variant.get('<STR_LIT>', []):<EOL><INDENT>gt_call = build_genotype(sample)<EOL>gt_types.append(gt_call)<EOL>if sample_info:<EOL><INDENT>sample_id = sample['<STR_LIT>']<EOL>if sample_info[sample_id] == '<STR_LIT>':<EOL><INDENT>key = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>key = '<STR_LIT>'<EOL><DEDENT>variant_obj[key] = {<EOL>'<STR_LIT>': sample['<STR_LIT>'],<EOL>'<STR_LIT>': sample['<STR_LIT>'],<EOL>'<STR_LIT>': sample['<STR_LIT>'],<EOL>'<STR_LIT>': sample['<STR_LIT>'],<EOL>'<STR_LIT>': sample_id<EOL>}<EOL><DEDENT><DEDENT>variant_obj['<STR_LIT>'] = gt_types<EOL>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>compounds = []<EOL>for compound in variant.get('<STR_LIT>', []):<EOL><INDENT>compound_obj = build_compound(compound)<EOL>compounds.append(compound_obj)<EOL><DEDENT>if compounds:<EOL><INDENT>variant_obj['<STR_LIT>'] = compounds<EOL><DEDENT>genes = []<EOL>for index, gene in enumerate(variant.get('<STR_LIT>', [])):<EOL><INDENT>if gene.get('<STR_LIT>'):<EOL><INDENT>gene_obj = build_gene(gene, hgncid_to_gene)<EOL>genes.append(gene_obj)<EOL>if index > <NUM_LIT:30>:<EOL><INDENT>variant_obj['<STR_LIT>'] = True<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if genes:<EOL><INDENT>variant_obj['<STR_LIT>'] = genes<EOL><DEDENT>if '<STR_LIT>' in variant:<EOL><INDENT>variant_obj['<STR_LIT>'] = [hgnc_id for hgnc_id in variant['<STR_LIT>'] if hgnc_id]<EOL><DEDENT>hgnc_symbols = []<EOL>for hgnc_id in variant_obj['<STR_LIT>']:<EOL><INDENT>gene_obj = hgncid_to_gene.get(hgnc_id)<EOL>if gene_obj:<EOL><INDENT>hgnc_symbols.append(gene_obj['<STR_LIT>'])<EOL><DEDENT><DEDENT>if hgnc_symbols:<EOL><INDENT>variant_obj['<STR_LIT>'] = hgnc_symbols<EOL><DEDENT>panel_names = set()<EOL>for hgnc_id in variant_obj['<STR_LIT>']:<EOL><INDENT>gene_panels = gene_to_panels.get(hgnc_id, set())<EOL>panel_names = panel_names.union(gene_panels)<EOL><DEDENT>if panel_names:<EOL><INDENT>variant_obj['<STR_LIT>'] = list(panel_names)<EOL><DEDENT>clnsig_objects = []<EOL>for entry in variant.get('<STR_LIT>', []):<EOL><INDENT>clnsig_obj = build_clnsig(entry)<EOL>clnsig_objects.append(clnsig_obj)<EOL><DEDENT>if clnsig_objects:<EOL><INDENT>variant_obj['<STR_LIT>'] = clnsig_objects<EOL><DEDENT>call_info = variant.get('<STR_LIT>', {})<EOL>for caller in call_info:<EOL><INDENT>if call_info[caller]:<EOL><INDENT>variant_obj[caller] = call_info[caller]<EOL><DEDENT><DEDENT>conservation_info = variant.get('<STR_LIT>', {})<EOL>if conservation_info.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = conservation_info['<STR_LIT>']<EOL><DEDENT>if conservation_info.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = conservation_info['<STR_LIT>']<EOL><DEDENT>if conservation_info.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = conservation_info['<STR_LIT>']<EOL><DEDENT>if variant.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if variant.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>frequencies = variant.get('<STR_LIT>', {})<EOL>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = float(frequencies['<STR_LIT>'])<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = float(frequencies['<STR_LIT>'])<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = float(frequencies['<STR_LIT>'])<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = float(frequencies['<STR_LIT>'])<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = float(frequencies['<STR_LIT>'])<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = float(frequencies['<STR_LIT>'])<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = float(frequencies['<STR_LIT>'])<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = float(frequencies['<STR_LIT>'])<EOL><DEDENT>if variant.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] =  variant['<STR_LIT>']<EOL><DEDENT>if variant.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = frequencies['<STR_LIT>']<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = frequencies['<STR_LIT>']<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = frequencies['<STR_LIT>']<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = frequencies['<STR_LIT>']<EOL><DEDENT>if frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = frequencies['<STR_LIT>']<EOL><DEDENT>elif frequencies.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = frequencies['<STR_LIT>']<EOL><DEDENT>if variant.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>if variant.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = variant['<STR_LIT>']<EOL><DEDENT>rank_results = []<EOL>for category in variant.get('<STR_LIT>', []):<EOL><INDENT>rank_result = {<EOL>'<STR_LIT>': category,<EOL>'<STR_LIT>': variant['<STR_LIT>'][category]<EOL>}<EOL>rank_results.append(rank_result)<EOL><DEDENT>if rank_results:<EOL><INDENT>variant_obj['<STR_LIT>'] = rank_results<EOL><DEDENT>if variant.get('<STR_LIT>'):<EOL><INDENT>variant_obj['<STR_LIT>'] = True<EOL><DEDENT>return variant_obj<EOL>
Build a variant object based on parsed information

        Args:
            variant(dict)
            institute_id(str)
            gene_to_panels(dict): A dictionary with
                {<hgnc_id>: {
                    'panel_names': [<panel_name>, ..],
                    'disease_associated_transcripts': [<transcript_id>, ..]
                    }
                    .
                    .
                }

            hgncid_to_gene(dict): A dictionary with
                {<hgnc_id>: <hgnc_gene info>
                    .
                    .
                }
            sample_info(dict): A dictionary with info about samples.
                               Strictly for cancer to tell which is tumor


        Returns:
            variant_obj(dict)

        variant = dict(
            # document_id is a md5 string created by institute_genelist_caseid_variantid:
            _id = str, # required, same as document_id
            document_id = str, # required
            # variant_id is a md5 string created by chrom_pos_ref_alt (simple_id)
            variant_id = str, # required
            # display name is variant_id (no md5)
            display_name = str, # required

            # chrom_pos_ref_alt
            simple_id = str,
            # The variant can be either research or clinical.
            # For research variants we display all the available information while
            # the clinical variants have limited annotation fields.
            variant_type = str, # required, choices=('research', 'clinical'))

            category = str, # choices=('sv', 'snv', 'str')
            sub_category = str, # choices=('snv', 'indel', 'del', 'ins', 'dup', 'inv', 'cnv', 'bnd')
            mate_id = str, # For SVs this identifies the other end

            case_id = str, # case_id is a string like owner_caseid
            chromosome = str, # required
            position = int, # required
            end = int, # required
            length = int, # required
            reference = str, # required
            alternative = str, # required

            rank_score = float, # required
            variant_rank = int, # required
            rank_score_results = list, # List if dictionaries
            variant_rank = int, # required

            institute = str, # institute_id, required

            sanger_ordered = bool,
            validation = str, # Sanger validation, choices=('True positive', 'False positive')

            quality = float,
            filters = list, # list of strings
            samples = list, # list of dictionaries that are <gt_calls>
            genetic_models = list, # list of strings choices=GENETIC_MODELS
            compounds = list, # sorted list of <compound> ordering='combined_score'

            genes = list, # list with <gene>
            dbsnp_id = str,

            # Gene ids:
            hgnc_ids = list, # list of hgnc ids (int)
            hgnc_symbols = list, # list of hgnc symbols (str)
            panels = list, # list of panel names that the variant ovelapps

            # Frequencies:
            thousand_genomes_frequency = float,
            thousand_genomes_frequency_left = float,
            thousand_genomes_frequency_right = float,
            exac_frequency = float,
            max_thousand_genomes_frequency = float,
            max_exac_frequency = float,
            local_frequency = float,
            local_obs_old = int,
            local_obs_hom_old = int,
            local_obs_total_old = int, # default=638

            # Predicted deleteriousness:
            cadd_score = float,
            clnsig = list, # list of <clinsig>
            spidex = float,

            missing_data = bool, # default False

            # STR specific information
            str_repid = str, repeat id generally corresponds to gene symbol
            str_ru = str, used e g in PanelApp naming of STRs
            str_ref = int, reference copy number
            str_len = int, number of repeats found in case
            str_status = str, this indicates the severity of the expansion level

            # Callers
            gatk = str, # choices=VARIANT_CALL, default='Not Used'
            samtools = str, # choices=VARIANT_CALL, default='Not Used'
            freebayes = str, # choices=VARIANT_CALL, default='Not Used'

            # Conservation:
            phast_conservation = list, # list of str, choices=CONSERVATION
            gerp_conservation = list, # list of str, choices=CONSERVATION
            phylop_conservation = list, # list of str, choices=CONSERVATION
            # Database options:
            gene_lists = list,
            manual_rank = int, # choices=[0, 1, 2, 3, 4, 5]
            dismiss_variant = list,

            acmg_evaluation = str, # choices=ACMG_TERMS
        )